Difference between revisions of "Tutorial: Model Development"

From Developer Documents
Jump to navigation Jump to search
Line 45: Line 45:
 
** Casting: [[File:Casting.png]]
 
** Casting: [[File:Casting.png]]
 
** Role: [[File:Role.png]]
 
** Role: [[File:Role.png]]
 
+
** Create a new folder '''icons''' in your ''com.acme.movie.ui'' plug-in and download these images into that directory so that we can use them with the contributions.
  
 
Start by creating a new java package for the contributions:
 
Start by creating a new java package for the contributions:
 
* Select '''File''' >> ''New''' >> '''Package'''
 
* Select '''File''' >> ''New''' >> '''Package'''
 
* Specify package '''com.acme.movie.ui.browser.contributions'''
 
* Specify package '''com.acme.movie.ui.browser.contributions'''
 +
  
 
The ''com.acme.movie.ui.browser.contributions.Movies'' contribution takes care of contributing all movie resources when given a ''Project'' resource as input. Download [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/contributions/Movies.java|the source]] and put it into the contributions package.
 
The ''com.acme.movie.ui.browser.contributions.Movies'' contribution takes care of contributing all movie resources when given a ''Project'' resource as input. Download [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/contributions/Movies.java|the source]] and put it into the contributions package.
 
TODO: Movies contribution walkthrough
 
  
 
One more thing needs to be done in order to put the Movies contribution to use: define an extension for binding it to the ''browsing context'' of the Productions browser.
 
One more thing needs to be done in order to put the Movies contribution to use: define an extension for binding it to the ''browsing context'' of the Productions browser.
Line 63: Line 62:
 
** preference = 1
 
** preference = 1
  
* [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/contributions/Casting.java|Casting Node]]
+
Create another package '''com.acme.movie.ui.browser.nodes''' as before and download these files into that package: [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/nodes/CastingNode.java|Casting node class]], [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/nodes/CastNode.java|Cast Role class]]
* [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/contributions/Movies.java|Movies]]
+
 
 +
Do the same, i.e. download and add extensions for the remaining two viewpoint contributors:
 +
* [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/contributions/Casting.java|Casting node contributor]]
 +
* [[svn:tutorials/trunk/com.acme.movie.ui/src/com/acme/movie/ui/browser/contributions/Roles.java|Role node contributor]]
 +
 
  
 
==== Labelers Contributions ====
 
==== Labelers Contributions ====

Revision as of 15:56, 21 October 2010

In this part of the tutorial we will focus on implementing the basic functionality for the following parts of the UI:

  • Model Browser for modelling movie production cases
    • Basic context menu actions for the browser
      • Add > Movie Project
      • Add > Role
  • Property View for editing properties of model entities
  • Movie Database Library for searching available movies, actors, directors, etc.

Step 1: Model Browser

Dependencies

To get the model browser working, UI plugin needs some more plug-ins, add dependencies.

  • Open com.acme.movie.ui / META-INF/MANIFEST.MF >> Dependencies
  • In the Required Plug-ins section, add dependencies on
    • org.simantics.ui
    • org.simantics.browsing.ui.platform
    • org.simantics.layer0
    • com.acme.movie.ontology

Enable Browser Contributions

At this point, the browser is empty since there is neither data to be shown nor the contributions for producing the data to show.

Before going into the contributions themselves, we need to make our Productions browser capable of receiving contributions. This can be achieved by adding an browseContext argument for the view extension. A browseContext is simply any unique string identifier to which contributions are bound. The set of browseContexts used by the browser view will therefore define which contributions are used.

  • Open com.acme.movie.ui / META-INF/MANIFEST.MF >> Extensions
  • Find the Productions view extension: org.eclipse.ui.views >> Productions (view)
  • Append the following to the class attribute value:
    • :browseContext=http://com.acme/Movie-1.0/Productions

Add Browser Contributions

Now let's focus on adding some basic contributions for making data visible to the user.

There are several kinds of contributions that can to be added to make data visible in the browser. The most important contributions are viewpoints, i.e. the contributions that produce the contents for the browser tree. Take another look at the previous tutorial's UI sketch. We will need contributions for doing the following things in the browser:

  • Content production (∼ViewpointContribution):
    • Show all movie productions in the active project
    • Show a casting node for a movie
    • Show all roles cast for a movie under the casting node
  • Content labeling (∼LabelerContribution):
    • Movie: show name
    • Casting: show fixed name Casting
    • Role: show
  • Giving images for contents (∼ImagerContribution)
    • Movies: Film.png
    • Casting: Casting.png
    • Role: Role.png
    • Create a new folder icons in your com.acme.movie.ui plug-in and download these images into that directory so that we can use them with the contributions.

Start by creating a new java package for the contributions:

  • Select File' >> New >> Package
  • Specify package com.acme.movie.ui.browser.contributions


The com.acme.movie.ui.browser.contributions.Movies contribution takes care of contributing all movie resources when given a Project resource as input. Download the source and put it into the contributions package.

One more thing needs to be done in order to put the Movies contribution to use: define an extension for binding it to the browsing context of the Productions browser.

  • Open com.acme.movie.ui / META-INF/MANIFEST.MF >> Extensions
  • Add a new extension, org.simantics.browsing.ui.common.viewpointContributionBinding
  • A node will appear, select it and set browseContext=http://com.acme/Movie-1.0/Productions
  • Select http://com.acme/Movie-1.0/Productions >> right click new >> implementation. Select it and set the attributes:
    • class = com.acme.movie.ui.browser.contributions.Movies
    • preference = 1

Create another package com.acme.movie.ui.browser.nodes as before and download these files into that package: Casting node class, Cast Role class

Do the same, i.e. download and add extensions for the remaining two viewpoint contributors:


Labelers Contributions

Step 2: Add Context Menu Actions for Model Browser

Workbench context menus are contribution-based. Each context menu is given a unique ID and popup contributions are then bound to that ID. For the Productions view, we will select #ProductionsPopup as the menu ID.

First the context menu for the Productions browser needs to be registered with this ID. This can be achieved by once again modifying the class attribute of our view extension.

  • Find our production view extension: org.eclipse.ui.views >> Productions (view)
  • Append a new argument to the class attribute: ;contextMenuId=#ProductionsPopup

Now your browser should have a context menu registered with the specified ID. You can check this by launching the movie product, activating the Productions view and pressing Control+Shift+F1. A Plug-in Spy window should pop up and give information on the view. It should say:

The active menu contribution identifiers:
    #ProductionsPopup
TODO
* add commands for menu actions
* add empty stub handlers for the commands
* add menu contributions for the commands
* define visibility/activity for menu contribution/handlers
* add graph modification code to handlers

Step 3: Add Property View for Model Browser

The Productions browser is responsible for contributing its own property page. To do this, two things must be done:

  1. An implementation of IPropertyPage must be created
  2. Once again, the class attribute of our Productions view extensions must be modified to offer our IPropertyPage implementation.

Here's the IPropertyPage implementation we will be using:

<syntaxhighlight lang="java"> package com.acme.movie.ui;

import java.util.Collections; import java.util.Set;

import org.eclipse.ui.IWorkbenchPartSite; import org.simantics.browsing.ui.swt.StandardPropertyPage;

public class ProductionsPropertyPage extends StandardPropertyPage {

   public ProductionsPropertyPage(IWorkbenchPartSite site) {
       super(site);
   }
   @Override
   protected Set<String> getContexts() {
       return Collections.singleton("http://com.acme/Movie-1.0/Productions/Properties");
   }

} </syntaxhighlight>

Now we modify the view extension to use this implementation.

  • Find the production view extension: org.eclipse.ui.views >> Productions (view)
  • Append a new argument to the class attribute: ;propertyPageClass=com.acme.movie.ui.ProductionsPropertyPage

Technical Details

The property view is a generic view. It's contents follow the active workbench part, i.e. the active view or editor. When a view or editor is activated, the property view will see this and request for the activated part to provide an IPropertyPage implementation through the platform's IAdaptable interface.

Step 4: Add Content for Movie Database Library

Things TODO:

  • Implement the fixed set of ISymbolGroups for movies, actors and characters.
  • Add code to the project feature that contributes a fixed set of ISymbolGroups into the ISymbolManager.KEY_SYMBOL_GROUPS hint of IProject
  • Add new symbol group interface for adding a filtered version of the symbol group getItems() method. This is needed for making the view such results are only shown if a search criterion is specified.


Step 5: Final Tweaking

Last we remove the comparator and viewpoint selector combo boxes and the filter area from the Productions browser since they are not needed for this tutorial. Once again the removal happens by adding the following arguments to the Productions view extension:

  • hideComparatorSelector
  • hideViewpointSelector
  • hideFilter


Tip.png Arguments can be specified to extensions, such as views, through the class attribute of the extension. The general format of the class attribute is

<class name>:<arguments>

The arguments part of the attribute value is specified similarly to URI scheme query strings. Individual arguments are separated by semicolons (;) and specified either as plain strings or as key=value pairs.

The arguments supported by org.simantics.browsing.ui.swt.GraphExplorerView are:

browseContext=ID
For specifying browse contexts for the view. This will determine which contributions the view will use. 0 to many browse contexts may be defined. Not defining browse contexts will always result in zero contributions.
uiContext=ID
For specifying ID's of org.eclipse.ui.context extensions to be activated for the view. 0 to many UI contexts may be defined.
contextMenuId=ID
Specifies the ID of the context menu to register for this browser view. Only one ID can be specified, the last one specified is used.
hideComparatorSelector
Hides the comparator selector combo box from the UI.
hideViewpointSelector
Hides the viewpoint selector combo box from the UI.
hideFilter
Hides the filter control from the UI.
propertyPageClass=class-name
Defines the property page that will be created by the view when requested for it. The class-name must point to an IPropertyPage implementation.



Handshake.png{{{1}}}

Good Job You have now created the basic parts of a functional UI.

In the next part you will be developing a diagram editor.
Next.png Tutorial 4: Diagram Development