Menu

eclipse tips

Anonymous

Eclipse for developers

Setting up Eclipse is only required by developers on the Fable project who want to develop the gui applications.

We are currently using the following versions :

  • Eclipse SDK Version: 3.3.2
  • Java Version 1.5

Eclipse Links

Some useful Eclipse links :

Eclipse Tips

Here are some tips for developers new to Eclipse :

Welcome_screen_on_Linux_problems?

Welcome screen on Linux problems

If the Welcome screen is blank or all funny e.g. white background, no images, then you are probably missing
the MOZILLA_FIVE_HOME environment variable which SWT needs to find mozilla to render with.

  • On Ubuntu Hardy Heron you must use : MOZILLA_FIVE_HOME=/usr/lib/mozilla

Using_3rd_party_jars?

Using 3rd party jars

If you have a 3rd party jar which you want to use in your plugin then the best is to make a plugin out of it :

Use New>Project>Plug-in Development>Plug-in from existing JAR archive.

That will turn one or more jar files into a single jar plugin. For something like log4j you can then set up Buddy-Classloading, etc.
Do not expand the jars, keep them in jars ! This is more compact and easier when you want to export your project.

Exporting_3rd_part_jars_as_part_of_an_RCP_application?

Exporting 3rd part jars as part of an RCP application

Make sure you have made a plugin out of your jars (cf. Using 3rd party jars).

Open the MANIFEST.MF and go to the Build panel
Tick the jars in the Binary Build.


Use Export -> Eclipse Product wizard to export your RCP application.

It should find your third party packages.
See also 1

Using JFreeChart in RCP applications?

Using JFreeChart in Eclipse/RCP application

NOTE : we prefer to use JLChart instead of JFreeChart for performance reasons (TODO: update this recipe)

JFreeChart is a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications

How_to_use_JFreeChart.3F?

How to use JFreeChart?

Creating charts with JFreeChart:

  • create a dataset (data displayed in the chart)
  • create a chart
  • display the chart / store the chart in a file

Example_1_-_PieChart?

Example 1 - BarChart

Dataset - DefaultCategoryDataset

// row keys...
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
// column keys...
String category1 = "Category 1";
String category2 = "Category 2";
String category3 = "Category 3";
String category4 = "Category 4";
String category5 = "Category 5";
// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, series1, category1); dataset.addValue(4.0, series1, category2); dataset.addValue(3.0, series1, category3);dataset.addValue(5.0, series1, category4);dataset.addValue(5.0, series1, category5);
dataset.addValue(5.0, series2, category1);dataset.addValue(7.0, series2, category2);dataset.addValue(6.0, series2, category3);dataset.addValue(8.0, series2, category4);dataset.addValue(4.0, series2, category5);
dataset.addValue(4.0, series3, category1);dataset.addValue(3.0, series3, category2);dataset.addValue(2.0, series3, category3);dataset.addValue(3.0, series3, category4);dataset.addValue(6.0, series3, category5);

Chart - BarChart

// create the chart...
JFreeChart chart = ChartFactory.createBarChart(
"Bar Chart Demo",            // chart title
"Category",                  // domain axis label
"Value",                     // range axis label
dataset,                     // data
PlotOrientation.VERTICAL,    // orientation
true,                        // include legend
true,                        // tooltips?
false                        // URLs?
);

Display the chart

// create and display a frame
ChartFrame frame = new ChartFrame("Title of the frame", chart);
frame.pack();
frame.setVisible(true);

JFreeChart_in_RCP?

JFreeChart in RCP

Integrating JFreeCharts in SWT applications e.g. Eclipse RCP views, is very easy using the SWT-SWING bridge. Copy and paste this code into a view of your own alternatively you can use the wizard to generate the RCP with a View example and replace the TableVIewer code with this code. You should see a view with a resizeable chart like in the picture.

DefaultPieDataset pieData = new DefaultPieDataset();
pieData.setValue("Slice 1", 50);
pieData.setValue("Slice 2", 70);
pieData.setValue("Slice 3", 90);
pieData.setValue("Slice 4", 20);
JFreeChart chart = ChartFactory.createPieChart3D("Sample Chart", pieData, true, true, false);
Composite swtAwtComponent = new Composite(parent, SWT.EMBEDDED);
java.awt.Frame chartFrame = SWT_AWT.new_Frame(swtAwtComponent);
chartFrame.setLayout(new GridLayout());
ChartPanel cp = new ChartPanel(chart);
chartFrame.add(cp);

Samples
JFreeChart 1.0.2 API Documentation
Installation Guide
Using JFreeChart in SWT

Using_images_in_SWT?

Using images in SWT

Images must be stored relative to the plugin so that they can be found at any time. Images must never be referred to by their absolute path names !
Here is one method of using URLs to get to the image :

ImageDescriptor image;
image = Activator.getImageDescriptor("images/my_image.gif");

More info can be found in the article Using Images in the Eclipse UI. The article proposes using :

 private static ImageDescriptor image;
 static {
   URL url = null;
   try {
   url = new URL(MyPlugin.getInstance().getDescriptor().getInstallURL(),
                 "images/my_action.gif");
   } catch (MalformedURLException e) {
   }
   image = ImageDescriptor.createFromURL(url);

Related

Wiki: Home
Wiki: RCP tips

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.