Java - Eclipse-RCP

open editor

In the following example an editor is opened.
This occurs in a seperate thread, so that the GUI doesn't „freeze up“ during the opening.
The method openEditor(..) doesn't have to be compulsory within the editor.



The editor must be registered in the extensions within the plugin.xml under the extension point org.eclipse.ui.editors (use PDE-editor for it; call occurs by opening the MANIFEST.MF-file).
You have to name minimal id (here: com.sowas.javawiki.MyEditor) and class (here: com.sowas.javawiki.MyEditor); recommendable are also name and icon, which both are, of course, free electable).

package com.sowas.javawiki;
...
public class MyEditor extends FormEditor implements IMyEditor {
   public static final String ID = "com.sowas.javawiki.MyEditor";
 
   ...
 
   public static IEditorPart openEditor(final Object myDataObject) {
      final IWorkbenchPage wbp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      final MutableObject response = new MutableObject();
      Display.getCurrent().asyncExec(new Runnable() {
         public void run() {
            final IMyEditorInput input = new MyEditorInput(myDataObject);
            final IEditorPart editor = wbp.openEditor(input, MyEditor.ID);
            response.setValue(editor);
         }
      });
      IEditorPart editorPart = (IEditorPart) response.getValue();
      return editorPart;
   }
}
 
class MutableObject {
   private Object obj = null;
 
   public Object getObj(){
      return obj;
   }
 
   public void setObj(Object obj){
      this.obj = obj;
   }
}


MyEditorInput has to be configured as follows:

public class MyEditorInput extends PlatformObject implements IMyEditorInput {
   ...
}
 
public interface IMyEditorInput extends IEditorInput {
   ...
}



Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007