Posts Tagged ‘RCP’

Using Fast Views in Eclipse RCP

Tuesday, September 15th, 2009

In Adding the error view to RCP application one commenter asked how he could add a view as a fast view to an Eclipse RCP application.

To add views as fast view to your RCP application you have to do two things:

1.) Add your view as “fast” via the perspective extension point

fastview10

2.) Activate the FastViewBar via the ApplicationWorkbenchWindow Advisor (configurer.setShowFastViewBars(true);)


package de.vogella.test;

import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
    }

    @Override
	public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ApplicationActionBarAdvisor(configurer);
    }

    @Override
	public void preWindowOpen() {
    	IWorkbenchWindowConfigurer configurer = getWindowConfigurer();

    	configurer.setInitialSize(new Point(1024, 800));
		configurer.setShowStatusLine(true);
		configurer.setTitle("Network Analyser");
		configurer.setShowFastViewBars(true);
    }

}

This should be sufficient to show your view in your RCP application in the fast view pane.

Add the error log view to your Eclipse RCP application

Monday, August 17th, 2009

The Eclipse platform provide error message in case something goes wrong.

During development I use the launch parameter -consoleLog to see if any error has occured. I assume most plugin developer use -consoleLog that is why I opened Bug for making -consoleLog a default in a new launch configuration.

Obviously you don’t want your users to check the console for errors. To make errors visible to the user you can add the exiting error log to your RCP application.

Create a new Eclipse RCP project “de.vogella.rcp.intro.errorview” for this purpose. Use the “Hello RCP” as a template.

Select the plugin.xml and add the dependency to org.eclipse.ui.views.log.

Ddd the standard Eclipse command “org.eclipse.ui.views.showView” to your menu under the Entry “Admin”. See Eclipse Commands how to do this.

This will result in the following plugin.xml


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         id="application"
         point="org.eclipse.core.runtime.applications">
      <application>
         <run
               class="de.vogella.rcp.intro.errorview.Application">
         </run>
      </application>
   </extension>
   <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            name="RCP Perspective"
            class="de.vogella.rcp.intro.errorview.Perspective"
            id="de.vogella.rcp.intro.errorview.perspective">
      </perspective>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               label="Admin">
            <command
                  commandId="org.eclipse.ui.views.showView"
                  label="Show Error View"
                  style="push">
               <parameter
                     name="org.eclipse.ui.views.showView.viewId"
                     value="org.eclipse.pde.runtime.LogView">
               </parameter>
            </command>
         </menu>
      </menuContribution>
   </extension>

</plugin>

Run your new application. You should have a menu entry “Admin” with an entry “Show Error View”. If you select it the error view should open.

errorLogView10

Create your first Eclipse e4 application

Wednesday, August 12th, 2009

Update This description has been updated in the following tutorial: Eclipse e4.

Eclipse released on the 29 July 2009 the tech preview version 0.9 of Eclipse e4, which can be downloaded here.

I wasn’t able to find a description how to create an new application based on E4. Starting from the CVS example is possible but I wanted to start from scratch. After several failed attempts to create an E4 application I believe I have found a way to create an E4 application. I assume others will have similar problems so I wanted to share my experience.

To follow this description you need to have knowledge how to develop Eclipse Plugins in Eclipse 3.5 or earlier. Check out this Eclipse Plugin Development Tutorial.

So lets get started with e4.

Download e4. Extract it and start it is similar to older Eclipse versions.

Currently there is no wizard which creates a working scaffold of an E4 application. We will therefore use the exsting plugin templates.

Create a new Plugin project “de.vogella.e4.first”. Do not select “Generate an activator”, nor “This plug-in will make contributions to the UI” nor “Would you like to create a rich client application”. Do not select a template. Press finish.

e410

This will open the Plugin Perspective, switch here to the Package Explorer to see your new project.

Create the package “de.vogella.e4.first”. The result should look like the following.

e412

Select your MANIFEST.MF and add the following dependencies to your plugin.

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: First
Bundle-SymbolicName: de.vogella.e4.first;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
 org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.9.0",
 org.eclipse.e4.ui.workbench.renderers.swt.contributions;bundle-version="0.9.0",
 org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.0",
 org.eclipse.e4.ui.services;bundle-version="0.9.0",
 org.eclipse.e4.core.services;bundle-version="0.9.0"

You need (some of) these plugins for the usage of E4 features.

Add the following extension points. I noticed that for some of the features you have to modify the plugin.xml directly as the UI does not support them. But you have to create the plugin.xml via the MANIFEST.MF file; as I created it directly as a new file I received a strange system behavior.


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.e4.workbench.parts">
          <part
            class="de.vogella.e4.first.views.View1"
            label="My first E4 View"
            parentId="org.eclipse.e4.ui.tags.navigation">
      </part>
   </extension>
   <extension
         id="product"
         point="org.eclipse.core.runtime.products">
      <product
            application="org.eclipse.e4.ui.workbench.swt.application"
            name="vogella">
             <property
               name="appName"
               value="vogella">
         </property>
         <property
               name="applicationXMI"
               value="de.vogella.e4.first/Application.xmi">
         </property>
      </product>

   </extension>

</plugin>

“org.eclipse.e4.workbench.parts” is a new extension point by which you can define your view parts, formally known as views and editors.

The extension point “org.eclipse.core.runtime.products” has a new parameter “applicationXMI”. This is a parameter to the model of your UI. We came to this later. You also do not define your own application; we use “org.eclipse.e4.ui.workbench.swt.application”.

Create a product configuration called “vogella.product”. This is similar to Eclipse 3.5; see here for a description: Eclipse Product Configuration.

e420

Make sure you select “org.eclipse.e4.ui.workbench.swt.application”.

e430

Add as dependency to your product the plugin “org.eclipse.e4.ui.workbench”. Add also the plugin “de.vogella.e4.first”.
Press “add required plugins”.

Create the following two classes:


package de.vogella.e4.first.handlers;

import org.eclipse.e4.workbench.ui.IWorkbench;

public class ExitHandler {
	public void execute(IWorkbench workbench) {
		workbench.close();
	}
}

and

package de.vogella.e4.first.views;

import org.eclipse.e4.core.services.context.IEclipseContext;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.services.IDisposable;

public class View1 implements IDisposable {

	public View1(Composite parent, final IEclipseContext outputContext) {
		Label label = new Label(parent, SWT.NONE);
		label.setText("E4 is new");
		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gridData.horizontalIndent = 20;
		label.setLayoutData(gridData);
		Text text = new Text(parent, SWT.NONE);
		text.setText("and different");
		GridLayoutFactory.fillDefaults().generateLayout(parent);
	}

	public void dispose() {

	}
}

You need a model for your application. In the parameter “applicationXMI” we earlier defined that this model will be “de.vogella.e4.first/Application.xmi”. Create the file Application.xmi with the following content.


<?xml version="1.0" encoding="ASCII"?>
<application:MApplication xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2008/Application">
  <windows name="Main" x="100" y="100" width="800" height="600">
    <menu>
      <items xsi:type="application:MMenuItem" name="File">
        <menu>
          <items xsi:type="application:MMenuItem" id="" name="Exit" command="//@command.0"/>
        </menu>
      </items>
    </menu>
    <children policy="VerticalComposite">
      <children xsi:type="application:MSashForm" policy="HorizontalSash">
        <children xsi:type="application:MStack">
          <children xsi:type="application:MContributedPart" iconURI="" name="My View" tooltip="My first View" URI="platform:/plugin/de.vogella.e4.first/de.vogella.e4.first.views.View1"/>
        </children>
        <weights>30</weights>
        <weights>70</weights>
      </children>
    </children>
    <handlers id="" URI="platform:/plugin/de.vogella.e4.first/de.vogella.e4.first.handlers.ExitHandler" persistedState="" command="//@command.0"/>
  </windows>
  <command id="application.exit" name="Exit"/>
</application:MApplication>

This is the EMF model which defines your UI. Eclipse should display this model in a EMF editor so that you can investigate it. In this model you find your view and command definition. The content can be viewed via the properities view.

e450

Now start your application from your vogella.product. Starting it directly from the plugin.xml will not work (easily).

If you receive the error “org.eclipse.core.runtime.AssertionFailedException: null argument:-applicationXMI argument missing” check you plugin.xml. E4 created in several cases twice the products entry.

You should be rewarded ;-) with this user interface:

e460

With this first application I hope you can started using the E4 advanced features, e.g. CSS styling, etc.

My final thoughts: Eclipse e4 has already amazing capabilities for a tech review release. The new modeled UI removes the need for a lot of boilerplate code.

Try it out!

TweetHub – Eclipse ECF Twitter client

Monday, August 10th, 2009

Eclipse ECF is a framework for supporting the development of distributed Eclipse-based tools and applications.

With the Galileo release Eclipse ECF provides also a nice Twitter client TweetHub. TweetHub is an Eclipse RCP application for communicating with Twitter.

It took me a while to gather the right information to make TwitterHub work. So I thought it might be helpful to blog about it so that this might be easier for others.

First you need to install the ECF SDK via the update manager from http://download.eclipse.org/rt/ecf/3.0/3.5/repo.

To install TwitterHub you need to download the code from cvs. The cvs connection string is: :pserver:anonymous@ecf1.osuosl.org:/ecf

To learn how to use cvs see Eclipse cvs access.

Check-out the following plugins from the cvs location:

org.eclipse.ecf.provider.twitter.ui.hub.product
org.eclipse.ecf.provider.twitter.ui.hub
org.eclipse.ecf.provider.twitter

TweetHub08

This should be sufficient. You should now be able to run the product.

TweetHub10

So now you can use TwitterHub to follow me on Twitter. ;-)

I would like to thank Marcelo Mayworm who helped on in the eclipse.technology.ecf newsgroup.

Additional links:
ECL New and Noteworthy
TweetHub wiki .

Eclipse RCP File browser

Tuesday, June 23rd, 2009

Eclipse RCP allow you to create easily utility programs.

Lets for example create a mini-file browser which will open a folder / file if you double-click the selection via the standard program.

To create a RCP based file browser create a new Eclipse RCP project, e.g. de.vogella.rcp.intro.filebrowser.

Create a package “de.vogella.rcp.intro.filebrowser.provider” and create the following label and content provider.


package de.vogella.rcp.intro.filebrowser.provider;

import java.io.File;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class FileContentProvider implements ITreeContentProvider {

@Override
public Object[] getChildren(Object parent) {
File file = (File) parent;
return file.listFiles();
}

public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}

@Override
public Object getParent(Object element) {
File file = (File) element;
return file.getParentFile();
}

@Override
public boolean hasChildren(Object parent) {
File file = (File) parent;
return file.isDirectory();
}

@Override
public void dispose() {

}

@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
}

}

package de.vogella.rcp.intro.filebrowser.provider;

import java.io.File;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class FileLabelProvider extends LabelProvider {
private static final Image folderImage = AbstractUIPlugin
.imageDescriptorFromPlugin("de.vogella.rcp.intro.filebrowser",
"icons/folder.gif").createImage();
private static final Image driveImage = AbstractUIPlugin
.imageDescriptorFromPlugin("de.vogella.rcp.intro.filebrowser",
"icons/filenav_nav.gif").createImage();
private static final Image fileImage = AbstractUIPlugin
.imageDescriptorFromPlugin("de.vogella.rcp.intro.filebrowser",
"icons/file_obj.gif").createImage();

@Override
public Image getImage(Object element) {
File file = (File) element;
if (file.isDirectory())
return file.getParent() != null ? folderImage : driveImage;
return fileImage;
}

@Override
public String getText(Object element) {
String fileName = ((File) element).getName();
if (fileName.length() > 0) {
return fileName;
}
return ((File) element).getPath();
}
}

For the label provider you need the referred icons in your folder icons. You can use the following download.

Download the Icons

Adjust then the view.

package de.vogella.rcp.intro.filebrowser;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import de.vogella.rcp.intro.filebrowser.provider.FileContentProvider;
import de.vogella.rcp.intro.filebrowser.provider.FileLabelProvider;

public class View extends ViewPart {
	public static final String ID = "de.vogella.rcp.intro.filebrowser.view";
	private TreeViewer viewer;

	public void createPartControl(Composite parent) {
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		viewer.setContentProvider(new FileContentProvider());
		viewer.setLabelProvider(new FileLabelProvider());
		viewer.setInput(File.listRoots());
		viewer.addOpenListener(new IOpenListener() {

			@Override
			public void open(OpenEvent event) {
				IStructuredSelection selection = (IStructuredSelection) event
						.getSelection();

				File file = (File) selection.getFirstElement();
				if (Desktop.isDesktopSupported()) {
					Desktop desktop = Desktop.getDesktop();
					if (desktop.isSupported(Desktop.Action.OPEN)) {
						try {
							desktop.open(file);
						} catch (IOException e) {
							// DO NOTHING
						}
					}
				}
			}
		});
	}

	public void setFocus() {
		viewer.getControl().setFocus();
	}
}

Eclipse Plug-in Spy in your Eclipse RCP application

Monday, June 22nd, 2009

To use the the Eclipse Plug-in Spy in your Eclipse RCP application include the plug-in org.eclipse.pde.runtime into your application.

SWTChart in Eclipse RCP

Friday, June 19th, 2009

SWTChart provides nice charts which can be easily used in Eclipse RCP applications.

The library is not yet as complete as JFreeChart but have the advantage that they are directly implemented in SWT.

To use swtchart in your Eclipse RCP application, download the zip file from http://www.swtchart.org. The zip file contains two OSGi bundles (org.swtchart and org.swtchart.ext). Import “org.swtchart” into your workspace.

Create a new Plug-in Project (RCP), e.g. de.vogella.swtchart, based on the Eclipse application with a view template. Add org.swtchart and org.swtchart.ext as a dependency to your plug-in.

Now change the code in View.java to the following:

package de.vogella.swtchart;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.swtchart.Chart;
import org.swtchart.IAxis;
import org.swtchart.IAxisSet;
import org.swtchart.IBarSeries;
import org.swtchart.ISeries.SeriesType;

public class View extends ViewPart {
public static final String ID = "de.vogella.swtchart.view";

public void createPartControl(Composite parent) {
Chart chart = new Chart(parent, SWT.NONE);
chart.getTitle().setText("SWT Chart");
chart.getAxisSet().getXAxis(0).getTitle().setText("Operating Systems");
chart.getAxisSet().getYAxis(0).getTitle().setText("Love");
IAxisSet axisSet = chart.getAxisSet();
IAxis xAxis = axisSet.getXAxis(0);
xAxis.setCategorySeries(new String[] { "Linux", "Windows" });
xAxis.enableCategory(true);

IBarSeries series = (IBarSeries) chart.getSeriesSet().createSeries(
SeriesType.BAR, "line series");
series.setBarColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
double[] values = { 0.7, 0.2 };
series.setYSeries(values);
}

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}

If you start your application you should get the following display:

swtchart

For details check out the excellent documentation under http://www.swtchart.org/doc/index.html.


Switch to our mobile site