-
Notifications
You must be signed in to change notification settings - Fork 12
How To Write A Bridge
This page describes how to write a new designer bridge. "Designer Bridge" allows you to plug EIP Designer within another target designer such as we did for Obeo TOGAF Designer.
Let just start with a new base Eclipse plugin! Nothing special here, just be sure to reference the com.github.lbroudoux.dsl.eip
and the com.github.lbroudoux.dsl.eip.bridge.core
into your dependencies.
[Optional]
If your target designer contains many elements, it may be helpful to write this part to enable your new menu item to appear only on the workspace elements you choose.
First declare a new propertyTester
extension into you plugin plugin.xml
file, this extension will be responsible of checking if selected workspace element is the correct semantic element and then to value a given property (here name isATargetService
)
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
id="com.company.eip.bridge.mymodeler.ui.IsATargetServiceTester"
type="org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart"
namespace="com.company.eip.bridge.mymodeler.ui"
properties="isATargetService"
class="com.company.eip.bridge.mymodeler.ui.testers.IsATargetServiceTester">
</propertyTester>
</extension>
In the above sample, I made the assumptions that workspace element is also a Sirius diagram element (see org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart
) but you may replace this type with your own choice. It may be a non graphical workspace element too!
Now, just write the IsATargetServiceTester
java class has an extension of org.eclipse.core.expressions.PropertyTester
like this:
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver instanceof IGraphicalEditPart) {
final IGraphicalEditPart part = (IGraphicalEditPart) receiver;
if ("isATargetService".equals(property)) {
// Determine true nature of selected element...
}
}
return false;
}
Extends com.github.lbroudoux.dsl.eip.bridge.core.ui.actions.AbstractCreateEIPRouteDesignActionHandler
class and implement protected String checkEventCurrentSelection(ISelection currentSelection)
and protected List<ServiceRefWrapper> extractServiceRefs()
methods.
The checkEventCurrentSelection()
method is responsible for checking that current selection is correct and - if it's the case - to return the name of the EIP Route to create lately. It is always invoked first by the abstract parent class. The extractServiceRefs()
method is responsible for computing Service References (see Other concepts) from the semantic elements. You may need to store some objects has private class attributes in your handler to easily do the references extraction.
Here's a sample skeleton:
@Override
protected String checkEventCurrentSelection(ISelection currentSelection) {
if (currentSelection != null && currentSelection instanceof IStructuredSelection) {
// Retrieve semantic element (ie. a target service) corresponding to current selection.
IStructuredSelection selection = (IStructuredSelection)currentSelection;
Object receiver = selection.getFirstElement();
// Pass some check and logic here to retrieve actual service semantic infos
// service = ...
return service.getName() + "Route";
}
return null;
}
@Override
protected List<ServiceRefWrapper> extractServiceRefs() {
if (service != null) {
List<Service> serviceRefs = service.getConsumesServices();
// Produce a list of wrapped ServiceRef.
List<ServiceRefWrapper> serviceRefW = new ArrayList<ServiceRefWrapper>();
for (Service serviceRef : serviceRefs) {
// Build some corresponding ServiceRefWrapper objects.
}
return serviceRefW;
}
return null;
}
First declare a new command for describing the command to launch when activating bridge:
<extension point="org.eclipse.ui.commands">
<command
id="com.company.eip.bridge.mymodeler.command.createRouteDesign"
name="Design an EIP Route">
</command>
</extension>
Then, add a new extension for your ActionHandler referencing the above command id:
<extension point="org.eclipse.ui.handlers">
<handler
class="com.company.eip.bridge.mymodeler.ui.actions.CreateEIPRouteDesignActionHandler"
commandId="com.company.eip.bridge.mymodeler.command.createRouteDesign">
</handler>
</extension>
Finally, you should add a final extension to provide a new menu contribution linking together command and visibility conditions. Remind that I suppose here working on another Sirius based modeler, thus the Sirius stuffs in declaration. Please adapt this part to your workspace element definitions accordingly.
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=org.eclipse.sirius.diagram.ui.popup.otherActions">
<command
commandId="com.company.eip.bridge.mymodeler.command.createRouteDesign"
icon="icons/Route.gif"
label="Design an EIP Route..."
style="push">
<visibleWhen checkEnabled="false">
<with variable="activeMenuSelection">
<iterate operator="and">
<instanceof value="org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart"></instanceof>
<test property="com.company.eip.bridge.mymodeler.ui.isATargetService"></test>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>