Java Reference
In-Depth Information
<extension point="org.eclipse.ui.commands">
<command
id="org.eclipse.mindmap.insertSubtopic"
name="Insert Subtopic"
description="Inserts a new subtopic"
categoryId="org.eclipse.ui.category.edit"/>
</extension>
We're using the Ctrl+I ( Cmd+I on the Mac) key combination to insert new
subtopics, and we're using the provided edit category for the command. Also
note that we are using the contextId that is declared in our generated diagram
plug-in for use with the F5 diagram refresh action. This is the implementation of
our create subtopic action:
public class MindmapCreateSubtopicAction implements
IObjectActionDelegate {
public final static String ID =
"org.eclipse.mindmap.popup.MindmapCreateSubtopicActionID";
private ShapeNodeEditPart selectedElement;
public void run(IAction action) {
if (selectedElement == null ) {
return;
}
CompoundCommand cc = new CompoundCommand("Create Subtopic and
Link");
// create the new topic for the other end
CreateViewRequest topicRequest =
CreateViewRequestFactory.getCreateShapeRequest(
MindmapElementTypes.Topic_2001,
selectedElement.getDiagramPreferencesHint());
MapEditPart mapEditPart = (MapEditPart)
selectedElement.getParent();
Command createTopicCmd = mapEditPart.getCommand(topicRequest);
cc.add(createTopicCmd);
// create the subtopics link command
IAdaptable topicViewAdapter = (IAdaptable) ((List)
topicRequest.getNewObject()).get(0);
CreateConnectionViewAndElementRequest ccver = new
CreateConnectionViewAndElementRequest(
MindmapElementTypes.TopicSubtopics_4001,((IHintedType)
MindmapElementTypes.TopicSubtopics_4001).getSemanticHint(),
selectedElement.getDiagramPreferencesHint());
ICommand createSubTopicsCmd = new
DeferredCreateConnectionViewAndElementCommand(ccver, new
EObjectAdapter((EObject) selectedElement.getModel()),
topicViewAdapter, selectedElement.getViewer());
cc.add( new ICommandProxy(createSubTopicsCmd));
selectedElement.getDiagramEditDomain().getDiagramCommandStack()
.execute(cc);
Search WWH ::




Custom Search