Java Reference
In-Depth Information
The implementation of our provider appears next. For
EditPart
s that are
instances of our custom
IntermediateEventImageEditPart
, we install an
OpenHyperlinkEditPolicy
and assign it to the
OPEN_ROLE
. Therefore,
double-click events on our node will trigger this new
EditPolicy
.
public class
ScenarioEditPolicyProvider
extends
AbstractProvider
implements
IEditPolicyProvider {
public void
createEditPolicies(EditPart editPart) {
if
(editPart
instanceof
IntermediateEventImageEditPart) {
editPart.installEditPolicy(EditPolicyRoles.OPEN_ROLE,
new
OpenHyperlinkEditPolicy());
}
}
public boolean
provides(IOperation operation) {
if
(operation
instanceof
CreateEditPoliciesOperation) {
CreateEditPoliciesOperation op =
(CreateEditPoliciesOperation) operation;
if
(op.getEditPart()
instanceof
IntermediateEventImageEditPart)
{
return true
;
}
}
return false
;
}
}
The
OpenHyperlinkEditPolicy
follows, where the override of
getOpenCommand()
will return a
Command
that, when executed, opens the
value of our hyperlink String in the underlying operating system's registered pro-
gram—in this case, a browser for
http://
Strings.
public class
OpenHyperlinkEditPolicy
extends
OpenEditPolicy {
protected
Command getOpenCommand(Request request) {
return new
Command("OpenHyperlinkCommand") {
public void
execute() {
IGraphicalEditPart gep = (IGraphicalEditPart) getHost();
CustomStyle style = (CustomStyle)
gep.getNotationView().getStyle(
StylePackage.eINSTANCE.getCustomStyle());
if
(style !=
null
) {
String location = style.getHyperlink();
Program.launch(location);
}
}
};
}
}
Search WWH ::
Custom Search