Skip Navigation

Creating a Sample View

This procedure provides instructions for creating a sample view with Sabre Red 360 classes. The instructions show how to create a single, vertical view with a command and handlers. Suggested values for creating a second horizontal view are also included. The screens show values for a vertical view. The sample plugin.xml for basic views includes a menu contribution and both vertical and horizontal views.

Before you create the sample view, complete the following.

Adding Plug-in Dependencies for Sabre Red 360

  1. In Package Explorer view, open the Dependencies tab, and then add the following dependencies:

    • org.eclipse.core.runtime

    • com.sabre.edge.platform.core.ui Eclipse automatically adds org.eclipse.ui because this project is set up to be a singleton.

Adding the org.eclipse.ui.views Extension

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

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

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

    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 the name when it appears in the list.

  2. Click Finish.

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

image005

Adding a View to the Extension

This section shows how to add a view extension element, properties, and the ViewPart class to org.eclipse.ui.views . The screens show sample values for a vertical view, and sample values are suggested for both vertical and horizontal views. If you are creating multiple views, create one view first, and then repeat these steps to create a second view. Some of the element properties and values must be unique for each view to distinguish the views from each other. The steps inform you which fields require unique values.

  1. Open the Extensions tab. Eclipse displays the org.eclipse.ui.views extension that you added in a previous step.

  2. Right-click org.eclipse.ui.views, and then choose New > view. Select the view element.

    image008
  3. In Extension Element Details, add properties to the view element in the following fields:

    id

    This identifier is used across the Eclipse application. It is used again when the perspectiveExtensions extension is added for a view. If you create a menu contribution for your view, this value also identifies the view in the value property of the command parameter for org.eclipse.ui.menus.
    Common practice is to enter the fully-qualified package name followed by the type of extension.
    If you are creating multiple views, this value must be different for each view.
    In the sample vertical view, the id is com.sabre.redapp.example.view.basic.view.
    For a sample horizontal view, assume an id of com.sabre.redapp.example.view.basic.horizontal.

    name

    This is the name of the view. It is displayed to end-users on the header of the view in Sabre Red 360.
    If you are creating multiple views, this value must be different for each view.
    In the sample vertical view, the name is Basic View.
    For a sample horizontal view, assume a name of Horizontal View.

    icon

    This is the icon to associate with the view. The icon appears in the header of the view window on the top left corner.
    This value must point to the path and file name of the resource that contains the image file within the plug-in. You can use the same icon for all views.
    Click Browse and select the file.

    allowMultiple

    The required value for all views is true.

    restorable

    This flag tells Eclipse whether to restore this view upon a restart of the workbench.
    A value of false does not open the view after a workbench restart.[1] The default value is true, however, you can set this value to false. The values for each view can be different.


    1. Description was taken from www.eclipse.org/documentation.

    Next, add a class that implements the content of the view.

  4. Click the class link. Eclipse populates most of the fields automatically on the New Java Class dialog.

    image010
  5. If the Package field is not populated, type the package name. Sample package: com.sabre.redapp.example.view.basic

  6. In the name field, type a name for your class. Your class must extend ViewPart. Sample class: BasicViewPart

  7. In Superclass, type org.eclipse.ui.part.ViewPart.

  8. Select the following check boxes:

    • Constructors from superclass

    • Inherited abstract methods

  9. Click Finish.

    After you click Finish, Eclipse displays the source file for the Java class.

  10. Open the Extensions tab to display the view properties and class that you added.

    image012

You are done adding a new view extension.

  • Save the manifest.

  • (Optional) To add another view, repeat these steps. Start with adding a new view element to the org.eclipse.ui.views extension through the last step in Adding a View to the Extension.

  • In the element properties that require unique values for each view, be sure to add values that differ from the view you already created.

  • When you add a new implementation of the ViewPart class, create a different name in the Name field.

The Java code for the BasicViewPart class is shown below.

package com.sabre.redapp.example.view.basic;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

public class BasicViewPart extends ViewPart {
    public BasicViewPart() {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void createPartControl(Composite parent) {
Composite contents = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, true);
contents.setLayout(layout);
createContents(contents);
    }
    private void createContents(Composite parent) {
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public void setFocus() {
    }
}

The createPartControl(Composite) method is responsible for the user interface of the view. The Composite argument provides your main parent widget.

When the view receives focus, the setFocus() method establishes the widget that receives initial focus.

This code is the same for either a vertical or a horizontal view. However, if you are creating multiple views, you must define multiple classes in order to include different content in each view. Otherwise, if you use the same implementation of the ViewPart class for all views, the views will display the same content.

The code sample below adds another implementation of ViewPart .

public class HorizontalViewPart extends ViewPart {
   public HorizontalViewPart() {
   }

   public void createPartControl(Composite parent) {
   }

   public void setFocus() {
   }
}

Adding the perspectiveExtensions Element

This section shows how to add the org.eclipse.ui.perspectiveExtensions extension with elements and properties for a view. Sample values are suggested for both vertical and horizontal views. If you are creating multiple views, add the extension and elements for one view first, and then repeat these steps to add the second view. Some of the element properties and values must be unique for each view to distinguish the views from each other. The steps inform you which fields require unique values.

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

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

  3. In the Extension Point Filters field, type org.eclipse.ui.perspectiveExtensions.

  4. Click Finish.

  5. If Eclipse displays the New Plug-in Dependencies dialog, click Yes.

    Eclipse adds org.eclipse.ui.perspectiveExtensions and perspectiveExtension on the Extensions tab.

    image014
  6. Select perspectiveExtension.

  7. In Extension Element Details, type the following value for the targetID property: com.sabre.edge.app.ui.perspective.

  8. Right-click perspectiveExtension, and then choose New > view.

    image016
  9. Add properties to the view element in the following fields:

    View Properties of the perspectiveExtension Element Table

    id

    This value must match the value in the id property of the view element for org.eclipse.ui.views.
    Append the : characters to the ID.
    If you are creating multiple views, this value must be different for each view.
    In the sample vertical view, the id is com.sabre.redapp.example.view.basic.view:.
    In a sample horizontal view, assume an id of com.sabre.redapp.example.view.basic.horizontal:.

    relationship

    This value defines where the view extension is placed beside the relative view.
    The value must be either right or bottom. Other values may cause unexpected behavior.
    A value of right displays the view in Sabre Red 360 as a vertical assistant tool panel. This displays the view in portrait mode.
    A value of bottom displays the view as a horizontal assistant tool panel. This displays the view in landscape mode.

    relative

    The required value is org.eclipse.ui.editorss.

    NOTE: The extension point ends with two of the letter "s."
    This is the reference point for placement of the new view within the view. It is a unique identifier for the view that exists in the perspective.

    ratio

    The initial proportion of the screen to allocate to the emulator. This setting does not allocate screen percentage to the view.
    The value must be from 0.1 to 0.95, inclusive.
    Example: A view has an initial proportion of .4. The ratio is set at .6 for the remaining screen area.

    visible

    The required value is false.
    A value of false means that all views are not visible at startup.

    closeable

    The required value is true.

    moveable

    The required value is false.
    Sabre Red 360 views are not moveable.

    standalone

    The required value is true.

    showTitle

    This field applies to standalone views.
    The required value is true.
    A value of true displays the title of the view.

    minimized

    The required value is false.

Adding perspectiveExtensions and Properties for Another View

(Optional) To add another view, repeat all steps in Adding the perspectiveExtensions Element. In the element properties that require unique values for each view, be sure to add values that differ from the view you already created.

Next, add commands and a handler to display the view to end-users.

Adding the org.eclipse.ui.commands Extension

This section shows you how to add the org.eclipse.ui.commands extension with elements and properties for a view. Sample values are provided for both vertical and horizontal views. If you are creating multiple views, add the extension once. Next, add the elements and properties for one view first, and then repeat these steps to add the elements and properties for the second view. Some of the element properties and values must be unique for each view in order to distinguish the views from each other. The steps inform you which fields require unique values.

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

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

  3. In the Extension Point Filters field, type org.eclipse.ui.commands.

  4. Click Finish.

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

    Eclipse adds org.eclipse.ui.commands to the Extensions tab.

    image018
  6. Next, add a new command for the extension. 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. This value is used throughout the Eclipse application. This id is also used for the commandId of the handler.
    Common practice is to enter the fully-qualified name. This consists of the package name followed by a name you want to identify the view command.
    If you are creating multiple views, this value must be different for each view.
    In the sample vertical view, this value is com.sabre.edge.command.example.view.basic.
    In a sample horizontal view, assume a value of com.sabre.edge.command.example.view.horizontal.

    name

    This name appears on the Extensions tab in Eclipse to make it easy to identify the command name.
    If you are creating multiple views, this value must be different for each view.
    In the sample vertical view, this is Example View.
    In a sample horizontal view, assume a value of Horizontal View.

    Add a new parameter to the command in order to inform the handler which view to open.

  2. Right-click the command extension, and then choose New > commandParameter.

  3. Add properties to the commandParameter element in the following fields:

    id

    This is the identifier for the command parameter.
    When you use a Sabre Red 360 handler, the required value is viewId. This ensures compatibility with the pre-defined handler for opening views in Sabre Red 360. This handler is com.sabre.edge.platform.core.ui.handlers.OpenViewHandler.
    This required value is the same for all views and it is used for menu contributions.

    name

    This is the name for the command parameter.
    The purpose of this name is to make it convenient for future developers. You can create a name that describes the functionality of the command parameter that opens the view. Otherwise, this name is not used.
    You are not required to use different names for multiple views.

  4. (Optional) In order to add a command for another view, repeat all steps in Adding the org.eclipse.ui.commands Extension. In the element properties that require unique values for each view, be sure to add values that differ from the view you already created.

Adding a Handler Extension to Associate with the Command

This section shows you how to add the org.eclipse.ui.handlers extension with elements and properties for a view. Sample values are provided for both vertical and horizontal views. If you are creating multiple views, add the extension once. Next, add the elements and properties for one view first, and then repeat these steps to add the elements and properties for the next view. Some of the element properties and values must be unique for each view to distinguish the views from each other. The steps inform you which fields require unique values.

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

  2. Select Show only extension points from the required plug-ins.

  3. In the Extension Point Filters field, type org.eclipse.ui.handlers.

  4. Click Finish.

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

    Eclipse adds the handler extension and the handler element to org.eclipse.ui.handlers .

    image020
  6. Add the commandId property to the handler element.

    The required value is the identifier of the new command that you selected when you added the org.eclipse.ui.commands extension. (This is the id property where you added the new command.) It consists of the fully-qualified package name followed by the type.

    If you are creating multiple views, this value must be different for each view.

    Either type the command identifier manually, or click Browse to select it from the Select Identifier dialog.

    In the sample vertical view, this value is com.sabre.edge.command.example.view.basic .

    In the sample horizontal view, this value is com.sabre.edge.command.example.view.horizontal .

  7. Add a class for the handler by doing one of the following:

    • To use a Sabre Red 360 handler, click Browse . From the Select Type dialog, select com.sabre.edge.platform.core.ui.handlers.OpenViewHandler . (See the following figure.)

      It is not necessary to write code to handle the opening of a new view when you use the Sabre Red 360 handler com.sabre.edge.platform.core.ui.handlers.OpenViewHandler .

    • To use a custom handler class, click the class link. On the New Java Class dialog, extend class org.eclipse.core.commands.AbstractHandler .

      image022
  8. (Optional) In order to add another view, add a new handler to org.eclipse.ui.handlers. Repeat all steps in Adding a Handler Extension to Associate with the Command. In the element properties that require unique values for each view, be sure to add values that differ from the view you already created.

  9. Save MANIFEST.MF.

    You can view the plugin.xml file for the sample that you create in this procedure.

    You are done creating views, however, you need to add a mechanism that will let end-users open your view.

    You have the option to use a Java method to open a view programmatically, or you can add a menu extension point.

Programmatically Opening a View with a Java Method

The static method showView(String viewId) opens a view from within the Java code. If the view is already opened, this method sets focus on the view. Call showView(String viewId) from the OpenViewHandler class. This method returns IViewPart of the opened view and takes the id of the opened view as the argument.

String viewId = "com.sabre.redapp.example.view.basic.view";
BasicViewPart viewPart =
          (BasicViewPart) OpenViewHandler.showView(viewId);

You can see the DialogOpenHandler class in the com.sabre.redapp.example.view.basic sample plug-in.