Skip to content
Jiří Vinárek edited this page Mar 17, 2015 · 3 revisions

Common practices used in project

Introduction

This page is intended to collect basic guidelines used across whole reprotool project.

<wiki:toc max_depth="2" />

Error handling in eclipse (displaying + logging)

Eclipse has own mechanism to display and log exceptions.

Main parts are:

  • IStatus - Wrapped information (message, exception) with severity.
  • StatusManager - Class accepting statuses and hints how to handle them. In the example below the status is passed with flag StatusManager.BLOCK | StatusManager.LOG thus it will be logged to the file (and showed in the Problems view) and modal dialog will be shown to the user.

Example (from ProjectWizard.java)

IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error during project initialization", exception);
StatusManager.getManager().handle(status, StatusManager.BLOCK | StatusManager.LOG);

Log file is located in <workspace-dir>\.metadata\.log

More about eclipse error handling can be found at http://wiki.eclipse.org/Status_Handling_Best_Practices:)

How to access resources bundled in plugins

See http://www.vogella.de/blog/2010/07/06/reading-resources-from-plugin/

Javadoc

Minimal requirement is to have top level comment for each class with @author tag filled. Desired situation is to have every public class/method/field documented when work is finished.

Hint: Comments can be inserted with shortcut `alt + shift + j`

Code formatting

Project reprotool.ide has associated code-formatting settings to unify formatting style (i.e. indenting with tabs vs spaces, line length, ...). Style defined by this settings should be "the right one", so that the whole project can be reformatted with it.

To prevent eclipse from formatting your code, surround the code with @formatter tags like this (this should be rather rare):

//@formatter:off
MyClass.method()
  .anotherMethod()
  .yetAnotherMethod();
//@formatter:on

Path to view/edit settings: Project -> Properties -> Java Code Style -> Formatter -> Edit

Hint: Code can be formatted with shortcut `ctrl + shift + f`

Internationalization

Externalized strings are placed by EMF code generator into into plugin.properties file. This how-to explains string externalization in non-generated EMF plugin.

To externalize strings from java source files:

  1. Open META-INF/MANIFEST.MF file and add "Bundle-Localization: plugin" line.

  1. Right click on project, select Source and Externalize Strings...
  2. In Externalize Strings dialog change "Key" of each externalized string to something meaningful.
  3. Click on "Configure", change Class name to class containing plugin activator.
  4. Change Property file name to plugin.properties.
  5. Click on "Configure" again and change "Substitution pattern" to INSTANCE.getString(${key}).
  6. In Externalize Strings dialog click on Next and Finish.
  7. Move generated plugin.properties to plugin root folder.
  8. Open plugin.xml, go to "Build" tab and check "plugin.properties" in Binary Build.
  9. Try to run plugin(s) with new configuration.

To externalize strings from bundle files:

Open plugin.xml and in "Overview" tab click to "Externalize Strings Wizard", select strings and finish dialog.

Eclipse/EMF databinding

Data binding is mechanism for data synchronization between model and view. Using this framework is preferred over using property change listeners which may cause infinite loops or memory leaks when used incorrectly.

Note that !WindowBuilder Pro v1.0.0 does not have support for EMFEditProperties which interact with domain model trough EMF commands. Therefore GUI designer is not used to generate a binding and it is created manually.

Useful links

[- tutorial about eclipse plugin development.

http://code.google.com/javadevtools/wbpro/features/swt/data_binding/index.html - eclipse databinding in !WindowBuilder Pro

[- eclipse databinding tutorial.

http://tomsondev.bestsolution.at/2009/06/06/galileo-improved-emf-databinding-support/ - series of blog posts about new EMF binding using EMF commands to interact with domain model.

[- Automatic creation of dialogs (panels, ...) with databinding.

How to display a launch configuration in "favorites" menu

  • Open menu Run -> Run Configurations...
  • Select an existing Launch Configuration or create a new one
  • Select the Common tab
  • Select Shared file and insert path to the directory where the configuration will be stored, such as /myproject/.launch
  • Adjust the checkboxes in Display in favorites menu (Run, Debug or both)

Accessing eclipse plug-in extensions from code

  IExtensionPoint[](http://code.google.com/javadevtools/wbpro/wizards/databinding/automatic_0.html]) extPoints =
    Platform.getExtensionRegistry().getExtensionPoints("my.plugin.id");

  for (IExtensionPoint extPoint : extPoints) {
    IExtension[] extensions = extPoint.getExtensions();
    // do simething with extensions
  }