Posts Tagged ‘java’

Shindig 2.0 Java on Ubuntu with Tomcat

Yesterday I blogged about how to install Shindig 2.0 PHP on Apache. Today we will do the same with Shindig 2.0 Java on Tomcat. This is even easier. This again should work at least on Ubuntu 10.04 and 10.10. Install Tomcat apt-get install tomcat6 Stop tomcat server (it was automatically started by Ubuntu) sudo /etc/init.d/tomcat6 [...]

MetaMap UIMA Version 0.4

Today I released MetaMap UIMA Version 0.4. It is a wrapper to make MetaMap easily accessible as a Apache UIMA component. I developed it for a bigger biomedical NLP project named PubCurator (but it is completely independent from it). MetaMap UIMA can use a local installed MetaMap application (available for Linux and MacOS) or the [...]

Eclipse databinding without Eclipse

One can use Eclipse databinding also outside of Eclipse (for standalone SWT applications). In that case a Realm must be generated manually: public static void main(String[] args) { Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() { @Override public void run() { // Run your code with Eclipse databindings. } }); }

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 [...]

Casting arrays

As Java is a static typed language the below code is not working (even if objArr contains only Strings): Object[] objArr; // filled with strings. String[] strArr = (String[]) objArr; One workaround is this: String[] strArr = Arrays.asList(objArr).toArray(new String[0]); Another solution (faster for large arrays): Object[] objArr; // filled with strings. String[] strArr = new [...]

Template for a Woodstox XML parser implementation

I can really recommend Woodstox to parse XML files. It is pretty fast and easy to setup. Below is a snippet I always use as a starting point to implement the parsing logic. It also sets up DTD validation. While traversing the XML tree everything is stored on a stack so that it easy to [...]

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=""/> <iterate> [...]