Hi
I went through the other posts and based on that i was able to write a plugin which added a view with a Pie chart in it. It worked all fine with eclipse 3.1, but same project is not working in eclipse 3.2
i know this is not a eclipse help forum but still i will like you to comment on this.
Thanks in advance
Adding the code for the plugin
package testforreport.views;
//import org.eclipse.swt.widgets.Composite;
import java.awt.Frame;
import java.awt.Panel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.part.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.*;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.general.PieDataset;
/**
* This sample class demonstrates how to plug-in a new
* workbench view. The view shows data obtained from the
* model. The sample creates a dummy model on the fly,
* but a real implementation would connect to the model
* available either in this or another plug-in (e.g. the workspace).
* The view is connected to the model using a content provider.
* <p>
* The view uses a label provider to define how model
* objects should be presented in the view. Each
* view can present the same model objects using
* different labels and icons, if needed. Alternatively,
* a single label provider can be shared between views
* in order to ensure that objects of the same type are
* presented in the same way everywhere.
* <p>
*/
public class SampleView extends ViewPart {
private TableViewer viewer;
private Action action1;
private Action action2;
private Action doubleClickAction;
static final FontData titleFD = new FontData("Times", 24, SWT.BOLD);
static final FontData normalFD = new FontData("Times", 12, SWT.NORMAL);
static final FontData headerFD = new FontData("Times", 18, SWT.BOLD);
// private SWTGraphicViewer pieViewer;
// private IChart pieChartModel;
/*
* The content provider class is responsible for
* providing objects to the view. It can wrap
* existing objects in adapters or simply return
* objects as-is. These objects may be sensitive
* to the current input of the view, or ignore
* it and always show the same content
* (like Task List, for example).
*/
class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object parent) {
return new String[] { "One", "Two", "Three" };
}
}
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
}
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().
getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
}
}
class NameSorter extends ViewerSorter {
}
/**
* The constructor.
*/
public SampleView() {
}
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(getViewSite());
makeActions();
//new code start
GridLayout layout = new GridLayout(1, true);
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
// setLayout(layout);
Composite jFreeComp = new Composite(parent, SWT.EMBEDDED);
jFreeComp.setLayoutData(new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL));
java.awt.Frame jfreeFrame = SWT_AWT.new_Frame(jFreeComp);
DefaultPieDataset dataset = new DefaultPieDataset();
// XYDataset data = new XYDataset();
dataset.setValue("One", 45);
dataset.setValue("Two", 55);
/* dataset.setValue("Three", 27.5);
dataset.setValue("Four", 17.5);
dataset.setValue("Five", 11.0);
dataset.setValue("Six", 19.4);
*/
JFreeChart chart = ChartFactory.createPieChart(
"Pie Chart Demo 1", // chart title
dataset, // data
false, // include legend
true,
false
);
Color backgroundColor = jFreeComp.getBackground();
/* XYDataset data = "" SampleXYDataset2();
JFreeChart chart = ChartFactory.createScatterPlot(
"Scatter Plot",
"X", "Y",
data,
PlotOrientation.VERTICAL,
true,
true,
false
);*/
/* Legend legend = chart.getLegend();
if (legend instanceof StandardLegend) {
StandardLegend sl = (StandardLegend) legend;
sl.setDisplaySeriesShapes(true);
}*/
// NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
// domainAxis.setAutoRangeIncludesZero(false);
ChartPanel chartPanel = new ChartPanel(chart);
/* chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
chartPanel.setVerticalAxisTrace(true);
chartPanel.setHorizontalAxisTrace(true);
//chartPanel.setVerticalZoom(true);
//chartPanel.setHorizontalZoom(true);
chartPanel.setAutoscrolls(true);
chartPanel.setMouseZoomable(true);
*/
jfreeFrame.add(chartPanel);
//end of new code
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
}
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
SampleView.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
}
private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars();
fillLocalPullDown(bars.getMenuManager());
fillLocalToolBar(bars.getToolBarManager());
}
private void fillLocalPullDown(IMenuManager manager) {
manager.add(action1);
manager.add(new Separator());
manager.add(action2);
}
private void fillContextMenu(IMenuManager manager) {
manager.add(action1);
manager.add(action2);
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
private void fillLocalToolBar(IToolBarManager manager) {
manager.add(action1);
manager.add(action2);
}
private void makeActions() {
action1 = new Action() {
public void run() {
showMessage("Action 1 executed");
}
};
action1.setText("Action 1");
action1.setToolTipText("Action 1 tooltip");
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
action2 = new Action() {
public void run() {
showMessage("Action 2 executed");
}
};
action2.setText("Action 2");
action2.setToolTipText("Action 2 tooltip");
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
doubleClickAction = new Action() {
public void run() {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection)selection).getFirstElement();
showMessage("Double-click detected on "+obj.toString());
}
};
}
private void hookDoubleClickAction() {
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
doubleClickAction.run();
}
});
}
private void showMessage(String message) {
MessageDialog.openInformation(
viewer.getControl().getShell(),
"Sample View",
message);
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
viewer.getControl().setFocus();
}
}
Getting Charts in the View of Eclipse 3.2
-
- Posts: 3
- Joined: Tue Nov 07, 2006 1:25 pm
-
- Posts: 3
- Joined: Tue Nov 07, 2006 1:25 pm
The problem/error message
The eclipse3.2 is not able to find the imported JFreechart classes which are present and are read properly by eclipse3.1.
It simply do not create the charts in the new view
It simply do not create the charts in the new view
-
- Posts: 3
- Joined: Tue Nov 07, 2006 1:25 pm
exact error message
The view is created but the Jfreechart classes are not found, though i can see them physically.
On click of details the error message says classnotfound exception for classes like PieDataset,Labelsomething which were present in org.jfree.data.general.. (the above is got from a jar file jfreechart-1.0.1.jar)
I also tried to add a button in eclipse and on click of that button i tried to run a standalone java program which creates Chart on a frame. It too worked on 3.1 but failed in 3.2. This time it dint even give any error message
On click of details the error message says classnotfound exception for classes like PieDataset,Labelsomething which were present in org.jfree.data.general.. (the above is got from a jar file jfreechart-1.0.1.jar)
I also tried to add a button in eclipse and on click of that button i tried to run a standalone java program which creates Chart on a frame. It too worked on 3.1 but failed in 3.2. This time it dint even give any error message
Sounds like you have maybe the same problem like me. I think you implemented the jar files under Java Build Path -> Libraries. But you have to implement jar files ofr a RCP plug-in at a second postion: dpuble click on plugin.xml and go to runtime. Under the window Classpath you have to add the Jar files a second time. For confirmation you can look at build.properties und bin.includes your jar files should be added there.
Maybe this was your problem...
Maybe this was your problem...