Posts Tagged ‘eclipse rcp’

Dynamic menus and toolbar contributions

There are two options to add dynamic menus or toolbar contributions to an Eclipse RCP application. Use the fill* methods of ApplicationActionBarAdvisor to add a manager (like a MenuManager). After changes call update(true) on the manager so that the changes will get visible in the UI. Use the IMenuService: IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class); AbstractContributionFactory [...]

MultiStatus with AggregateValidationStatus

Example snippet of a MultiStatus together with AggregateValidationStatus. aggregateValidationStatus = new AggregateValidationStatus(bindingContext, AggregateValidationStatus.MERGED); aggregateValidationStatus.addValueChangeListener(new VersionRangeValidator());   private class VersionRangeValidator implements IValueChangeListener {   @Override public void handleValueChange(ValueChangeEvent event) { Status status = (Status) event.getObservableValue().getValue(); if (status.isMultiStatus()) { MultiStatus multiStatus = (MultiStatus) status; System.out.println("multi"); } if (status.isOK()) { System.out.println("yes, it is fine"); } } }

Databinding of an EMF EObject EMap value

Example to bind an EMF EObject EMap value (as it is a bit tricky) to a text field: bindingContext.bindValue( SWTObservables.observeText(textField), EMFObservables.observeValue((EObject) document.getProperties().get(document.getProperties().indexOfKey("title")), DocumentModelPackage.Literals.DOCUMENT_PROPERTY_MAP__VALUE), null, null );

EMF notifications of children of an EObject

The normal Adapter just get change events of the EObject it is bound to itself. To also get change events of children of the EObject simply use EContentAdapter instead. Cave: The overwritten notifyChanged method of EContentAdapter must at first call super.notifyChanged.

Hide/show toolbar items on perspective switch

There are three alternatives to hide resp. show toolbar items when switching the perspective in Eclipse RCP. Simply using the PerspectiveListener. Using a dummy actionSet. The actionSet will be active if the appropriate perspective is active, too. The actionSet can then be simply used for further expressions. <visibleWhen> <with variable="activeContexts"> <iterate operator="or"> <equals value="my.action.set.id"/> <iterate> [...]

Add documentation comments EMF Ecore models

To add documentation that will be available in the generated EMF models use eAnnotations in your Ecore files: <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel";> <details key="documentation" value="This is the generated comment text."/> </eAnnotations>

Start jobs immediately after the workbench started

There are several options to start jobs immediately after workbench started: Use the org.eclipse.ui.startup extension point in your plugin.xml. Note that UI manipulations have to be executed by Display.syncExec() resp Display.asyncExec() as we are not in UI thread at that moment. ApplicationWorkbenchWindowAdvisor has several methods like postWindowOpen where custom code can be executed. Using UIJob. [...]

Enable/disable handlers

There are two options to enable or disable handler in Eclipse RCP: Declarative by using enabledWhen. This also requires a PropertyTester specified by the org.eclipse.core.expressions.propertyTesters extension point. // plugin.xml … <extension point="org.eclipse.core.expressions.propertyTesters"> <propertyTester class="org.pubcurator.core.testers.DatabaseTester" id="org.pubcurator.core.databaseTester" namespace="org.pubcurator.core.database" properties="connected, remoteServerUp" type="java.lang.Object"> </propertyTester> </extension>   <extension point="org.eclipse.ui.handlers"> <handler class="org.pubcurator.documentor.handlers.ImportDocumentsHandler" commandId="org.pubcurator.documentor.commands.importDocuments"> <enabledWhen> <test forcePluginActivation="true" property="org.pubcurator.core.database.connected" value="true"> </test> </enabledWhen> </handler> [...]