[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[News.eclipse.technology.gmf] how to create element without create view?
|
I know I can create Element and its view by request, I can do this in two
ways:
first way:
overwrite the getcommand method of EditPolicy:
@Override
protected Command getCreateCommand(CreateViewRequest request) {
...
IElementType type = ProcessElementTypes.Data_1002; //type of new node
ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
new CreateElementRequestAdapter(
new CreateElementRequest(type)),
Node.class,
((IHintedType) type).getSemanticHint(),
ProcessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
CreateViewAndElementRequest req = new
CreateViewAndElementRequest(viewDescriptor);
CompoundCommand cc = new
CompoundCommand(DiagramUIMessages.AddCommand_Label);
cc.add(targetDiagramEditor.getDiagramEditPart().getCommand(req));
return cc;
}
second way, Use commandstack:
// Get the command to create the new element and its view
CreateViewRequest createRequest = CreateViewRequestFactory
.getCreateShapeRequest(elementType,
container
.getDiagramPreferencesHint());
Command command = container.getCommand(createRequest);
if (command == null || !(command.canExecute())) {
// Action enablement criteria expected to prevent this
throw new IllegalArgumentException("Command for '" //$NON-NLS-1$
+ actionId + "' is not executable.");
//$NON-NLS-1$
}
// Create the new element
DiagramCommandStack commandStack = container.getDiagramEditDomain()
.getDiagramCommandStack();
commandStack.execute(command);
All these ways, only can create View and element simultaneously . How can I
create element without create View and get the element I just created?