Posts Tagged ‘RCP’

Eclipse Development – In which plugin do I find this class?

Tuesday, September 28th, 2010

A common question for Eclipse Plugin or Eclipse RCP developer is in which plugin a certain class is included.

A very easy way for finding this information is the Open Type Dialog (Hotkey Ctrl + Shift +T). Just look in the right bottom corner.

Thanks for Ralf Ebert for reminding me that this is a common problem.

Using Eclipse Templates to show off

Tuesday, September 14th, 2010

Have you ever been in a software demo there the presenter was that fast with the editor that you were scared?

He might have been using personal templates. Templates allow you to save a block of coding and insert it as you desire. You find them under Window-> Preferences -> Java -> Editor -> Templates.

Try it out in the Editor for the SWT templates (within an Eclipse plugin or Eclipse RCP application). Type Label and press Cntr+Space three times until you see only the Java template suggestions.

Select the template and change the code to your liking. Do the same for GridData. You end up the following code almost without typing.

Label label1 = new Label(parent, SWT.NONE);
label1.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,false));
label1.setText("Test");
GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData2.widthHint = SWT.DEFAULT;
gridData2.heightHint = SWT.DEFAULT;
label1.setLayoutData(gridData2);

The great thing about templates is that you can define your own once. So if you have something longer which you need to type again and again you can use your own templates.

Eclipse 3.6M4 – Tiny nice things

Saturday, December 12th, 2009

I personally believe that little things make a difference. Eclipse 3.6 is going to be great for new (and perhaps also for experienced) plugin and RCP developers.

Especially I like in the Eclipse 3.6M4 release:

-consoleLog included per default in a new launch configuration
RCP with a View

I believe the solution of Bug for -consoleLog will solve the most common problem with getting started for new Plugin / RCP developers. Also the update of the PDE RCP templates will hopefully guide new developers in using commands instead of actions.

The change in Bug for -consoleLog was also a community decision, which is a good example that Eclipse does consider user feedback.

Thanks to all involved parties and the Eclipse community for these changes. :-)

Update Unfortunately Mail Template was not part of M4.

Re-using the Eclipse proxy preference settings in your Eclipse RCP application

Tuesday, December 8th, 2009

The following demonstrates how to re-use the Eclipse proxy preferences in an Eclipse RCP application.

Create a project “de.vogella.rcp.net.proxy” and select the “RCP application with a view” as template.

Add the preferences command to your application. See Eclipse Preferences Tutorial for details.

Add the plugin “org.eclipse.ui.net” and “org.eclipse.core.net” as dependency to your plugin.

Run your plugin and open preferences.

proxy_settings

Fantastic! You already have the preference dialog.

Now change your view to the following.


package de.vogella.rcp.net.proxy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;

public class View extends ViewPart {
	public static final String ID = "de.vogella.rcp.net.proxy.view";
	private final ServiceTracker proxyTracker;

	public View() {
		proxyTracker = new ServiceTracker(FrameworkUtil.getBundle(
				this.getClass()).getBundleContext(), IProxyService.class
				.getName(), null);
		proxyTracker.open();
	}

	/**
	 * This is a callback that will allow us to create the viewer and initialize
	 * it.
	 */
	public void createPartControl(Composite parent) {
		StyledText text = new StyledText(parent, SWT.NONE);
		text.setText(readWebpage());
	}

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

	private String readWebpage() {
		BufferedReader in = null;
		StringBuffer sb = new StringBuffer();

		try {
			URI uri = new URI("http://www.vogella.de");
			IProxyService proxyService = getProxyService();
			IProxyData[] proxyDataForHost = proxyService.select(uri);

			for (IProxyData data : proxyDataForHost) {
				if (data.getHost() != null) {
					System.setProperty("http.proxySet", "true");
					System.setProperty("http.proxyHost", data.getHost());
				}
				if (data.getHost() != null) {
					System.setProperty("http.proxyPort", String.valueOf(data
							.getPort()));
				}
			}
			// Close the service and close the service tracker
			proxyService = null;

			URL url;

			url = uri.toURL();

			in = new BufferedReader(new InputStreamReader(url.openStream()));
			String inputLine;

			while ((inputLine = in.readLine()) != null) {
				// Process each line.
				sb.append(inputLine + "\n");
			}

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		}
		return sb.toString();

	}

	public IProxyService getProxyService() {
		return (IProxyService) proxyTracker.getService();
	}

	@Override
	public void dispose() {
		proxyTracker.close();
		super.dispose();
	}

}

If you run your application behind a firewall and if you have maintained the proxy correctly then the View should display the HTML code.

Hope this helps!

Defining menu entries (commands) at runtime in Eclipse RCP

Thursday, December 3rd, 2009

A common question I receive is how menu entries can be defined at runtime in an RCP application. The following gives an example how this can be done.

Create the RCP project “de.vogella.rcp.commands.runtimecommands” using the “Hello RCP” template.

Define a menu contribution. Maintain the class “de.vogella.rcp.commands.runtimecommands.DefineCommands” in this menu contribution.


<?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.commands.runtimecommands.Application">
         </run>
      </application>
   </extension>
   <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            name="RCP Perspective"
            class="de.vogella.rcp.commands.runtimecommands.Perspective"
            id="de.vogella.rcp.commands.runtimecommands.perspective">
      </perspective>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            class="de.vogella.rcp.commands.runtimecommands.DefineCommands"
            locationURI="menu:org.eclipse.ui.main.menu">
      </menuContribution>
   </extension>

</plugin>

Create the following class.

package de.vogella.rcp.commands.runtimecommands;

import org.eclipse.swt.SWT;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.menus.ExtensionContributionFactory;
import org.eclipse.ui.menus.IContributionRoot;
import org.eclipse.ui.services.IServiceLocator;

public class DefineCommands extends ExtensionContributionFactory {

	@Override
	public void createContributionItems(IServiceLocator serviceLocator,
			IContributionRoot additions) {
		CommandContributionItemParameter p = new CommandContributionItemParameter(
				serviceLocator, "",
				"org.eclipse.ui.file.exit",
				SWT.PUSH);
		p.label = "Exit the application";
		p.icon = Activator.getImageDescriptor("icons/alt_window_16.gif");

		CommandContributionItem item = new CommandContributionItem(p);
		item.setVisible(true);
		additions.addContributionItem(item, null);
	}

}

Run the example, your application should have the Exit command in the menu.

Thanks to Robert Einsle for the tip.

This description has also be added to my Eclipse command tutorial.

Poll – Default launch configuration for Eclipse plugin / RCP development

Friday, November 20th, 2009

Eclipse shows errors during a launch via the log views in both the host and the target system and on the file system. In addition the developer can specify the flag “-consoleLog” in the launch configuration so see potential error messages in the console view.

Bug 284704 had been opened asking if the “-consoleLog” flag could be included by default in a new launch configuration.

What do you think? If you are a plugin or RCP developer please participate in the following survey:

Link to Survey

——————————
Please note that this is my first attempt using SurveyMonkey, I hope this works well. I believe the survey will close after the first 100 answers. If this number has not reached I’m planning to close the survey next week 27. Nov. 2009.

Profiling Eclipse RCP applications with Eclipse TPTP

Wednesday, November 18th, 2009

I believe approx. one or two years ago I tried to profile an Eclipse RCP application with the Eclipse TPTP project. I believe at this point in time profiling an RCP application with TPTP was not possible.

I learned from Eugene Chan that the TPTP release which is part of Eclipse Galileo allows to profile Eclipse RCP applications.

I suggest you give it a try, it is as easy as profiling a standard ;-) Java application.

You find an updated description here: Eclipse TPTP Tutorial.

Thanks to Eugene Chan, Paul Slauenwhite and Kathy Chan from the TPTP team for feedback on the article.

Eclipse RCP – Removing the minimize and maximize buttons from Views

Friday, November 13th, 2009

I got the question how someone could remove the maximize and minimize buttons from a view in an Eclipse RCP application.

To archive this I know two ways.

Either set the layout to fixed in initialLayout() in Perspective.java


package de.vogella.intro.rcp.fixedview;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

	public void createInitialLayout(IPageLayout layout) {
		String editorArea = layout.getEditorArea();
		layout.setEditorAreaVisible(false);
		layout.setFixed(true);

//		layout.addStandaloneView(View.ID,  false, IPageLayout.LEFT, 1.0f, editorArea);
	}

}

Or use the Perspective.java to add a standalone view.


package de.vogella.intro.rcp.fixedview;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

	public void createInitialLayout(IPageLayout layout) {
		String editorArea = layout.getEditorArea();
		layout.setEditorAreaVisible(false);
//		layout.setFixed(true);

		layout.addStandaloneView(View.ID,  false, IPageLayout.LEFT, 1.0f, editorArea);
	}

}

If I add a standalone view via the extension “org.eclipse.ui.perspectiveExtensions” then the minimize and maximize buttons are still there.

<?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.intro.rcp.fixedview.Application">
         </run>
      </application>
   </extension>
   <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            name="Perspective"
            class="de.vogella.intro.rcp.fixedview.Perspective"
            id="de.vogella.intro.rcp.fixedview.perspective">
      </perspective>
   </extension>
   <extension
         point="org.eclipse.ui.views">
      <view
            name="View"
            class="de.vogella.intro.rcp.fixedview.View"
            id="de.vogella.intro.rcp.fixedview.view">
      </view>
   </extension>
   <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension
            targetID="*">
         <view
               id="de.vogella.intro.rcp.fixedview.view"
               minimized="false"
               ratio="1.0f"
               relationship="left"
               relative="org.eclipse.ui.editorss"
               standalone="true"
               visible="true">
         </view>
      </perspectiveExtension>
   </extension>

</plugin>

The behavior seems inconsistent. If I use coding to add a standalone view the minimize / maximize buttons are not there, if I use extension points they are still there.

Does anymore know if I’m missing something? Or is this a bug? If you know please comment on this blog post or contact me via twitter.

Update: Projekt attached.

FixedView.zip

Eclipse PDE templates – Your action is my command

Wednesday, September 23rd, 2009

The Eclipse PDE templates are fantastic to help people to learn the platform and to get oven the first initial resistence to start with Eclipse RCP or Eclipse Plugin development.

Templates indicates to their consumers that they represent best development practices. This puts a certain burden on the quality to the templates. Unfortunately the PDE RCP templates in Eclipse 3.5 were all based on actions which I believe are superseded by Eclipse Commands.

I have seen in the past lots of questions regarding actions in the Eclipse RCP and PDE newsgroups. I believe that at least some of these questions are based on the fact that the PDE templates still promote actions.

I’m therefore happy to see the changes of Bug 265231 applied for the “RCP with a view” template for the upcoming Eclipse 3.6. Special thanks for this to Chris Aniszczyk.

It also looks good for the mail example. It seems that work is happening in Bug 253105

Actions are (a little bit more) dead. Long live the command! ;-)

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.


Switch to our mobile site