Skip to main content
Jump to: navigation, search

STP/BPMN Component/STP BPMN Presentation Hands on tutorial

< STP‎ | BPMN Component
Revision as of 17:30, 3 March 2007 by Atoulme.intalio.com (Talk | contribs) (Adding a property tab to see your annotation)

This tutorial is presented as part of the STP BPMN Presentation at EclipseCon 2007.

Participants

In this section, we are going to begin to play with the modeler and try to extend its use.

We want to add a participant to our shapes. A participant represents a person with a name and a role.


Adding a property tab to see your annotation

The easiest way to add a participant to your shape is to create a property tab to represent it and enable us to enter his name and his role.

In the plugin.xml, we define a new property tab named "Participants". We add one section to the tab.

The contributor for the new tab, it defines a new category

   <extension
        point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
     <propertyContributor
           contributorId="org.eclipse.gmf.runtime.diagram.ui.properties">
        <propertyCategory category="Participants"/>
     </propertyContributor>
  </extension>

The definition of the tab itself

   <extension point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
     <propertyTabs contributorId="org.eclipse.gmf.runtime.diagram.ui.properties">
        <propertyTab
              category="Participants"
              id="Participants"
              indented="false"
              label="Participants"/>
     </propertyTabs>
   </extension>

The definition of the section inside the property tab

   <extension point="org.eclipse.ui.views.properties.tabbed.propertySections">
     <propertySections contributorId="org.eclipse.gmf.runtime.diagram.ui.properties">
        <propertySection
              class="org.eclipse.stp.samples.eclipsecon2007.participant.properties.ParticipantPropertySection"
              id="ParticipantsSection"
              tab="Participants">
           <input type="org.eclipse.stp.bpmn.Activity"/>
           <input type="java.lang.Object"/>
        </propertySection>
     </propertySections>
   </extension>

Now we are going to code the tab itself.

A tab is an instance of AbstractPropertySection.

Create a class in org.eclipse.stp.samples.eclipsecon2007.participant.properties as ParticipantPropertySection.

Two methods are important there :

the property tab UI is defined in createPartControl, and the input management in setInput. We need to implement those two methods.

Let's create a first version of createPartControl, with two text fields:

       /**
       * Creates the UI of the section.
       */
       @Override
       public void createControls(Composite parent, 
               TabbedPropertySheetPage aTabbedPropertySheetPage) {
               super.createControls(parent, aTabbedPropertySheetPage);
               GridLayout layout = new GridLayout(2, false);
               parent.setLayout(layout);
               
               GridData gd = new GridData(SWT.FILL);
               gd.minimumWidth = 500;
               gd.widthHint = 500;
               getWidgetFactory().createCLabel(parent, "Name");
               nameText = getWidgetFactory().createText(parent, "");
               nameText.setLayoutData(gd);
               getWidgetFactory().createCLabel(parent, "Role");
               roleText = getWidgetFactory().createText(parent, "");
               roleText.setLayoutData(gd);
       }


Now let's handle the data.

       /**
       * Manages the input.
       */
       @Override
       public void setInput(IWorkbenchPart part, ISelection selection) {
       
               super.setInput(part, selection);
               if(selection instanceof IStructuredSelection) {
                       Object unknownInput = 
                              ((IStructuredSelection) selection).getFirstElement();
                       if (unknownInput instanceof IGraphicalEditPart && 
                               (((IGraphicalEditPart) unknownInput).
                                       resolveSemanticElement() != null)) {
                                unknownInput = ((IGraphicalEditPart) unknownInput).
                                       resolveSemanticElement();
                       }
                       if (unknownInput instanceof Activity) {
                                       Activity elt = (Activity) unknownInput;
                                       EAnnotation ea = elt.getEAnnotation(ParticipantConstants.
                                                       PARTICIPANT_ANNOTATION);
                                       if (ea != null) {
                                       nameText.setText((String) ea.getDetails().get(
                                                       ParticipantConstants.PARTICIPANT_NAME));
                                       roleText.setText((String) ea.getDetails().get(
                                                       ParticipantConstants.PARTICIPANT_ROLE));
                                       }
                                       activity = (Activity) elt;
                                       nameText.setEnabled(true);
                                       roleText.setEnabled(true);
                                       return;
                       }
               }
               activity = null;
               nameText.setText("");
               roleText.setText("");
               nameText.setEnabled(false);
               roleText.setEnabled(false);
       }

Adding a drop action

Back to the top