Skip Navigation

Creating a Sample Editor

This procedure creates a sample editor that uses Sabre Red 360 classes. The sample editor uses these classes because Sabre Red 360 classes include most of the behaviors that developers and end-users require. In addition, the procedure includes sample code that an editor uses. An example of the plugin.xml file that this procedure builds is provided.

Before you create the sample editor, create a new plug-in project or use an existing project.

  1. In Eclipse Package Explorer view, open your project, and then open the Extensions tab.

image002
  1. Click Add to open the New Extension dialog.

image004
  1. Remove the selection from Show Only Extension Points from the Required Plug-ins.

  2. In the Extension Point Filter field, type org.eclipse.ui.editors.

You can type either the complete name or * followed by the partial name to display a list of names that contain the characters you enter. Select org.eclipse.ui.editors when it appears in the list.

  1. Click Finish.

  1. If Eclipse displays the following New Plug-in Dependency dialog, click Yes.

image005

Adding Minimal Required Dependencies for Sabre Red 360

If you do not have a project that uses required dependencies for Sabre Red 360, you must add them. If you have logic in your project, these dependencies are already present.

  1. Open the Dependencies tab.

image007
  1. Add the following required dependencies.

    • org.eclipse.core.runtime

    • com.sabre.edge.platform.core.editor

Eclipse automatically adds the org.eclipse.ui dependency because the plug-in project was set up to contribute to the UI.

  1. Open the Extensions tab. Eclipse adds the org.eclipse.ui.editors extension point and a new editor element. If Eclipse does not add the editor element, right-click org.eclipse.ui.editors, and then choose New > editor.

image009

 

  1. In Extension Element Details, add properties to the editor element in the following fields:

id

The value in id does not match anything now, but this value is used later.
Common practice is to use the package name followed by the type. In the example, the type is SampleEditor.
Example of completed id field: com.sabre.redapp.example.editor.basic.SampleEditor

name

This name appears on the Extensions tab in Eclipse to make it easy to identify the editor.
Common practice is to type a value that matches the type in the id field. In the sample editor, the name is Sample Editor.

icon

This is the icon to associate with the editor. The icon appears on the tab next to the label.
This value must point to the path and file name of the resource that has the image file within the plug-in.
Click Browse and select the file.

 

  1. In Extension Element Details, click the class link. The New Java Class dialog is displayed.

image011

When you create an editor, always implement your own class as a subclass of the Sabre Red 360 AbstractAppEditor class.

  1. If the Package field is not populated, type the package name. Sample package: com.sabre.redapp.example.editor.basic

  1. In the Name field, type the same value that you entered in the id field for the org.eclipse.ui.editors extension. Your editor class must extend com.sabre.edge.platform.core.editor.editors.AbstractAppEditor. Sample value: SampleEditor

  2. In the Superclass field, type com.sabre.edge.platform.core.editor.editors.AbstractAppEditor.

  3. Select the following check boxes:

    • Constructors from superclass

    • Inherited abstract methods

  1. Click Finish.

You are done adding a new extension with dependencies and properties.

Sample Java code for the extended AbstractAppEditor is shown below. This code sample creates a label object named Sample Editor. The code has the class name that you added to extend AbstractAppEditor, and it describes the label with your text.

package com.sabre.redapp.example.editor.basic;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import com.sabre.edge.platform.core.editor.editors.AbstractAppEditor;
public class SampleEditor extends AbstractAppEditor {
     public SampleEditor() {
          super();
     }

     public void createPartControl(Composite parent) {
          progressAnimation.init(parent);
          Label label = new Label(parent, SWT.NONE);
          label.setText("Sample Editor");
          parent.setLayout(new FillLayout());
     }
}

 

  1. Add the createPartControl() method manually now. This method allows you to create user interface elements, such as buttons or labels.

Adding the org.eclipse.ui.elementFactories Extension for the Element Factory

  1. On the Extensions tab, click Add to display the New Extension dialog.

image013

 

  1. Select Show Only Extension Points from the Required Plug-ins.

  2. In the Extension Point Filter field, type org.eclipse.ui.elementFactories.

  3. Click Finish.

  4. Eclipse adds the org.eclipse.ui.elementFactories extension and the factory element to the Extensions tab. If Eclipse does not add the factory element, right-click org.eclipse.ui.elementFactories, and then choose New > factory.

image015
  1. Add the id property to factory.

        Type the fully-qualified name of your package, followed by a name for the type. In the sample editor, this value is com.sabre.redapp.example.editor.basic.SampleElementFactory .

  1. Click the class link to display the New Java Class dialog.

image017

On this dialog, you will extend the com.sabre.edge.platform.core.editor.editors.elements.AbstractElementFactory class.

  1. If the Package field is not populated, type the package name. Sample package: com.sabre.redapp.example.editor.basic

  1. In the Name field, type the name of your class. Your class must extend com.sabre.edge.platform.core.editor.editors.elements.AbstractElementFactory. Sample name: SampleElementFactory

  2. In the Superclass field, type the following:

        com.sabre.edge.platform.core.editor.editors.elements.AbstractElementFactory

        Your class must implement the getEditorInput() method, and return the appropriate instance of the class  to extend the following:

        com.sabre.edge.platform.core.editor.editors.inputs.AbstractEditorInput

        In the sample editor, your class is SampleElementFactory .

  1. In the Interfaces field, add org.eclipse.ui.IElementFactory.

  1. Select the following check boxes:

    • Constructors from superclass

    • Inherited abstract methods

  1. Click Finish.

Sample Java code for the SampleEditorInput class is shown below. In this code sample, AbstractEditorInput implements getFactoryId()   and returns the same value for ID that you defined in org.eclipse.ui.elementFactories .

package com.sabre.redapp.example.editor.basic;
import com.sabre.edge.platform.core.editor.editors.inputs.AbstractEditorInput;

public class SampleEditorInput extends AbstractEditorInput {

   @Override
   public String getFactoryId() {
      return SampleElementFactory.ID;
   }
}

 

Sample Java code for getEditorInput() is shown below. In this code sample, getEditorInput() returns the SampleEditorInput to com.sabre.edge.platform.core.editor.editors.inputs.AbstractEditorInput.

package com.sabre.redapp.example.editor.basic;
import org.eclipse.ui.IElementFactory;
import com.sabre.edge.platform.core.editor.editors.elements.AbstractElementFactory;
import com.sabre.edge.platform.core.editor.editors.inputs.AbstractEditorInput;

public class SampleElementFactory extends AbstractElementFactory implements
      IElementFactory {

   public static final String ID = "com.sabre.redapp.example.editor.basic.SampleElementFactory";

   @Override
   public AbstractEditorInput getEditorInput() {
      return new SampleEditorInput();
   }
}

 

Adding the com.sabre.edge.platform.core.editor.editorApp Extension

The extension com.sabre.edge.platform.core.editor.editorApp is required for any editor you create for Sabre Red 360.

  1. On the Extensions tab, click Add to display the New Extension dialog.

image019
  1. Select Show Only Extension Points from the Required Plug-ins.

  1. In the Extension Point Filter field, type com.sabre.edge.platform.core.editor.editorApp.

  2. Click Finish.

  3. Eclipse adds the com.sabre.edge.platform.core.editor.editorApp extension point and a new editorApp element on the Extensions tab. If Eclipse does not add editorApp, right-click com.sabre.edge.platform.core.editor.editorApp. Choose New > editorApp from the menu.

image021

 

  1. Add properties to the editorApp element in the following fields:

class

The value that you type must match the class that you defined in org.eclipse.ui.editors.
In the sample editor, the value is SampleEditor.

inputClass

Type the class that you used in getEditorInput() to extend AbstractEditorInput.
In the sample editor, this name is com.sabre.redapp.example.editor.basic.SampleEditorInput.

name

Type the text for the label that you want to display on the tab. The tab for the editor appears on the GUI.
In the sample editor, the name is Sample Editor.

toolTipText

Type the text that end-users see when their mouse hovers over the label on the tab.
In the sample editor, the text is Sample Editor.

editorId

This value must match the id that you defined for org.eclipse.ui.editors. This is the first extension that you added.
The format for editorId must be the fully-qualified package name followed by the editor identifier.
In the sample editor, this value is com.sabre.redapp.example.editor.basic.SampleEditor.

  1. (Optional) Save MANIFEST.MF.

You are done creating the classes and extensions that you need for an editor.

Next, you must add commands with handlers. Afterwards, you will bind these commands and handlers to the editor.

Adding the org.eclipse.ui.commands Extension

  1. On the Extensions tab, click Add to display the New Extension dialog.

image024
  1. Remove the selection from Show only extension points from the required plug-ins.

  1. In the Extension Point Filter field, type org.eclipse.ui.commands.

  2. Click Finish.

  3. If Eclipse displays the New Plug-in Dependency dialog, click Yes.

Eclipse adds the org.eclipse.ui.commands extension point to the Extensions tab. Next, add a new command for the extension.

  1. Right-click org.eclipse.ui.commands, and then choose New > command.

  1. Add properties to the command element in the following fields:

id

This is the command identifier. The value is used throughout the Eclipse application.
Common practice is to use the package name followed by a name you choose to identify your editor command. In the sample editor, the id is com.sabre.redapp.example.editor.basic.OpenSampleEditorCommand.
The com.sabre.redapp.example.editor.basic.OpenSampleEditorCommand id is used later.

name

This name appears on the Extensions tab in Eclipse to make it easy to identify the command name.
In the sample editor, the text for this command is Sample Command.

Informing the Handler Which Editor to Open with a Command Parameter

  1. Add a new parameter to the command org.eclipse.ui.commands. On the Extensions tab, right-click Sample Command, and then choose New > commandParameter. (SampleCommand is the command parameter.)

  1. Add properties to the Sample Command element in the following fields:

id

This is the parameter identifier.
When you are using a Sabre Red 360 handler, the required value is editorId. This ensures compatibility with the pre-defined handler for opening editors in Sabre Red 360.
The Sabre Red 360 handler class is com.sabre.edge.platform.core.editor.commands.handlers.FocusOrOpenEditorHandler.

name

This is the definition of the parameter that is added to the menuContribution element in org.eclipse.ui.menus. This name does not appear on the GUI.
Common practice is to choose a brief name that describes the command parameter. In the sample editor, this name is EditorId.

Creating a New Handler to Implement the Command

  1. On the Extensions tab, click Add. You will add a handlers extension on the New Extension dialog.

  1. Remove the selection from Show only extension points from the required plug-ins. In the Extension Point Filter field on the New Extensions screen, type org.eclipse.ui.handlers. Click Finish. If Eclipse displays the New Plug-in Dependency dialog, click Yes. Eclipse adds the org.eclipse.ui.handlers extension point and a new handler element to the Extensions tab. If Eclipse does not add the handler element, right-click org.eclipse.ui.handlers, and then choose New > handler. Add properties to the handler element in the following fields.

commandId

This must be the identifier of the new command that you selected when you added the org.eclipse.ui.commands extension.
You can type it manually or browse for the name.
For the sample editor, the value is com.sabre.redapp.example.editor.basic.OpenSampleEditorCommand.

class

Instead of creating a new handler class, select the Sabre Red 360 handler class. Click Browse next to the class field.
From the Select Type dialog, select the following handler class:
com.sabre.edge.platform.core.editor.commands.handlers.FocusOrOpenEditorHandler
When you use FocusOrOpenEditorHandler, you do not need to write code to handle the opening of a new editor.
You can, however, provide your own handler that extends the class org.eclipse.core.commands.AbstractHandler if you need it.

  1. Save MANIFEST.MF.

View the sample plugin.xml file for this sample editor.