i am trying to build an eclipse plugin. There are 2 following components of the plugin. 1) File Browser. 2) A JFreeChart
The goal: after browsing and selecting a file with the file browser, JFreeChart will make a chart with the selected file. No matter how many times i select different file, the chart will project those file into my required chart.
I have one viewpart. Both File-Browser and JFreeChart uses the parent composite. I have already implemented the static part that means with my plugin i can browse files and the chart can represent any file (not the file i browse yet and that's is where i am stuck). Here i want to make a chart that will update as i browse to different files. Please have a look at my code.
FileChooser.java
mButton = new Button(this, SWT.NONE);
mButton.setText("Browse");
//mText.setText("F:\\Java Works\\Ground\\bin\\test.txt");
mText.setText("");
chartDraw = mText.getText();
mButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
FileDialog dlg = new FileDialog(mButton.getShell(), SWT.OPEN );
dlg.setText("Open");
path = dlg.open();
if (path == null) return;
mText.setText(path);
chartDraw = mText.getText();
}
});
ChartView.java
public void createPartControl(Composite parent){
Composite top = new Composite(parent, SWT.NONE);// embedded Composite
// setup the layout of top to be GridLayout.
GridLayout layout1 = new GridLayout();
layout1.marginHeight = 0;
layout1.marginWidth = 0;
top.setLayout(layout1);
// top banner
Composite banner = new Composite(top, SWT.NONE);// banner is added to
// "top"
banner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL,
GridData.VERTICAL_ALIGN_BEGINNING, true, false));
layout1 = new GridLayout();
layout1.marginHeight = 5;
layout1.marginWidth = 10;
layout1.numColumns = 1;
banner.setLayout(layout1);
// setup bold font
Font boldFont = JFaceResources.getFontRegistry().getBold(
JFaceResources.DEFAULT_FONT);
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.minimumWidth = 400;
gridData.minimumHeight = 50;
gridData.grabExcessHorizontalSpace = true;
Label l = new Label(banner, SWT.WRAP);
l.setText("Source File:");
l.setFont(boldFont);
final FileChooser fileChooser = new FileChooser(banner);
gridData.heightHint = 25;
fileChooser.setLayoutData(gridData);
ami = fileChooser.getchartDraw();
// Viewing Chart Starts Here
FetchDataChart chart1 = new FetchDataChart();
//XYSeriesCollection dataset = chart1.createDataset();
XYSeriesCollection dataset = chart1.createDataset(fileChooser.getchartDraw()); // I am extracting the file path and drawing the chart.
JFreeChart chart;
try {
chart = chart1.createChart(dataset);
ChartComposite frame = new ChartComposite(parent, SWT.NONE, chart, true);
frame.pack();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public String getAmi() {
return ami;
}
Now my question is how can i connect with FileBrowser and JFreeChart so that i can know the file path immediately after it changes and the view part shows the chart as file changes in FileBrowser? Some guideline and reference would be helpful. For your kind information, i am totally new in Eclipse PDE/RCP zone.
Thanks for the help. Please let me know if you want to know something more to solve this issue.