Archive for August, 2008

Aug 12 2008

Eclipse RCP launcher icon

Published by under Eclipse,IT,Java

Eclipse RCP allows easily create an application. Additional advantage of the platform is a native launcher of the application which allows it to behave more like “native” application. It much better to have a process called your_application.exe running instead of another java.exe process.  You will probably also want to have some nice icon attached to *.exe file of your application. This can be done easily in Eclipse 3.4. First you need to create *.ico file (containing all necassary images inside) – one of the generators available on the web can be used for this (for example).

Next step is configuration in *.product file:

   <launcher name="caracal">
      <solaris>
      <win useico="true">
         <ico path="/pl.edu.agh.caracal.application/icons/caracal.ico"></ico>
         <bmp></bmp>
      </win>
   </solaris>
</launcher>

You can also use product file editor for this (a lot of enhancements were added in Eclipse 3.4):

Launcher icon configuration

After building the application based on product file launcher will have your custom icon. No resource hacking, nor recompiling native C code is required!

Launcher custom icon

2 responses so far

Aug 05 2008

Long-running operation in a wizard page

Published by under Eclipse,IT,Java

Some time you may need to do some long running operation in one of the pages in your wizard. Probably the best solution would be to redesign the flow of an application in such way that this operation can be performed outside the wizard as a background task (using Eclipse Jobs API). If you really need to place this inside wizard than in order to not freeze your application completely with such operation you can use IRunnableWithProgress. Sample usage of this interface is presented below.

import java.lang.reflect.InvocationTargetException;
import java.util.logging.Logger;
 
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
 
/**
 * Wizard Page with long running operation
 *
 */
public class DummyWizardPage extends WizardPage {
    private Logger logger = Logger.getLogger(DummyWizardPage.class.getName());
 
    protected DummyWizardPage(String pageName) {
	super(pageName);
    }
 
    /**
     * {@inheritDoc}
     */
    public void createControl(Composite parent) {
	Composite composite = new Composite(parent, SWT.NONE);
 
	Button button = new Button(composite, SWT.PUSH);
	button.addSelectionListener(new SelectionAdapter() {
	    public void widgetSelected(SelectionEvent event) {
		try {
 
		    // Invoking long running operation
		    getContainer().run(true, false,
			    new IRunnableWithProgress() {
				public void run(IProgressMonitor monitor)
					throws InvocationTargetException,
					InterruptedException {
				    // Some time consuming operation
				}
 
			    });
		} catch (InvocationTargetException e) {
		    logger.warning(e.getMessage());
		} catch (InterruptedException e) {
		    logger.warning(e.getMessage());
		}
	    }
	});
 
	// Setting control for Wizard Page
	setControl(composite);
    }
}

3 responses so far