Java Reference
In-Depth Information
We know from Section 10.6, “Element Creation” that the semantic elements
are created first when creating elements in our diagram. And, since our subtopic
link represents a subtopics relationship element of our Topic class, we should
consider adding a SemanticEditPolicy to our TopicEditPart in order to
create the appropriate CreateRelationshipCommand for the subtopic link. If
we were using GEF alone, we would use the installEditPolicy() method to
do this; in GMF, we could use createDefaultEditPolicies() . However, we
have an editpolicyProvider extension-point and Service in GMF that we can
configure for this purpose, without requiring us to modify our TopicEditPart .
Below is the contribution to the extension-point we will add to our plugin.xml
file.
<extension
point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
<editpolicyProvider
class=
"org.eclipse.mindmap.diagram.providers.MindmapEditPolicyProvider">
<Priority name="Lowest"/>
</editpolicyProvider>
</extension>
Our MindmapEditPolicyProvider class follows. We override the
createEditPolicies() method to reinstall the new TopicSemanticEdit
Policy on our TopicEditPart . We use the provides() method that declares
this offering.
public class MindmapEditPolicyProvider extends AbstractProvider
implements IEditPolicyProvider {
public void createEditPolicies(EditPart editPart) {
if (editPart instanceof TopicEditPart) {
editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new
TopicSemanticEditPolicy());
}
}
public boolean provides(IOperation operation) {
if (operation instanceof CreateEditPoliciesOperation) {
CreateEditPoliciesOperation op =
(CreateEditPoliciesOperation)operation;
if (op.getEditPart() instanceof TopicEditPart) {
return true ;
}
}
return false ;
}
}
Search WWH ::




Custom Search