/** Perform some actions to create new child object and append it to the <factory> element. */ void addButtonSelected(SelectionEvent e) { /** Create a new object which is instance of factoryChildClass. */ EObject obj = createFactoryChildObject(); if (obj != null) { boolean needRefreshAll = false; Command command = null; if (getInput() instanceof FactoryType) { /** The input is a <factory> element and not null, append the new object to it. */ FactoryType factory = (FactoryType) getInput(); command = AddCommand.create(getEditingDomain(), factory, null, obj); } else { /** The input is null, create a <factory> element and append it to <faces-config>. */ needRefreshAll = true; List list = new ArrayList(2); FactoryType factory = FacesConfigFactory.eINSTANCE.createFactoryType(); Command cmd1 = AddCommand.create(getEditingDomain(), factory, null, obj); list.add(cmd1); Command cmd2 = AddCommand.create(getEditingDomain(), this.getPage().getInput(), null, factory); list.add(cmd2); command = new CompoundCommand(list); } if (command.canExecute()) { getEditingDomain().getCommandStack().execute(command); if (needRefreshAll) ((OthersPage) this.getPage()).resetFactoryInput(); } } }
protected void copyAndAdd( final Set additionalObjects, final EObject container, final EStructuralFeature feature) { final CopyCommand.Helper helper = this.mainCopyCommand.getCopyKeyedByOriginalMap(); final Command copyCommand = ModelEditorImpl.createCopyCommand(this.domain, additionalObjects, helper); final boolean copied = this.appendAndExecute(copyCommand); if (copied) { // Create the add command to place all of the annotations into the annotation container ... final Collection copiedAnnotations = copyCommand.getResult(); final Command addCommand = AddCommand.create(this.domain, container, feature, copiedAnnotations); final boolean added = this.appendAndExecute(addCommand); if (!added) { // Failed, but the copied objects will be left without a parent // and will simply be garbage collected. However, log anyway ... final Object[] params = new Object[] {new Integer(copiedAnnotations.size()), feature.getName()}; final String msg = ModelerCore.Util.getString( "CopyWithRelatedToClipboardCommand.Failed_to_add_{0}_copied_{1}_to_clipboard", params); //$NON-NLS-1$ ModelerCore.Util.log(msg); } } }
/** Add the created invoked object to its selected parent */ protected void addParameter(Parameter createdParameter) { TransactionalEditingDomain editingdomain = EditorUtils.getTransactionalEditingDomain(); // Let the command find the relation on its own. Command addCmd = AddCommand.create( editingdomain, parameterOwner, null, Collections.singleton(createdParameter)); addCmd.execute(); }
public void testRemoveEqualValues() { E e = refFactory.createE(); String s0 = "0"; String s1 = "1"; String s2 = "2"; String s3 = new String(s1); EList<String> labels = e.getLabels(); labels.add(s0); labels.add(s1); labels.add(s3); labels.add(s2); labels.add(s1); Collection<String> collection = new ArrayList<String>(); collection.add(s1); collection.add(s1); collection.add(s1); Command remove = RemoveCommand.create(editingDomain, e, refPackage.getE_Labels(), collection); assertEquals(5, labels.size()); assertSame(s0, labels.get(0)); assertSame(s1, labels.get(1)); assertSame(s3, labels.get(2)); assertSame(s2, labels.get(3)); assertSame(s1, labels.get(4)); assertNotSame(s1, labels.get(2)); assertTrue(remove.canExecute()); CommandStack stack = editingDomain.getCommandStack(); stack.execute(remove); assertEquals(2, labels.size()); assertSame(s0, labels.get(0)); assertSame(s2, labels.get(1)); assertTrue(stack.canUndo()); stack.undo(); assertEquals(5, labels.size()); assertSame(s0, labels.get(0)); assertSame(s1, labels.get(1)); assertSame(s3, labels.get(2)); assertSame(s2, labels.get(3)); assertSame(s1, labels.get(4)); assertNotSame(s1, labels.get(2)); assertTrue(stack.canRedo()); stack.redo(); assertEquals(2, labels.size()); assertSame(s0, labels.get(0)); assertSame(s2, labels.get(1)); assertTrue(stack.canUndo()); }
/** * execute command for the drop * * @param commandList * @return true or false */ protected void execute(List<Command> commandList) { Iterator<Command> iterator = commandList.iterator(); while (iterator.hasNext()) { Command abstractCommand = (Command) iterator.next(); if (abstractCommand.canExecute()) { getEditingDomain().getCommandStack().execute(abstractCommand); } } }
/** Execute a command within the editing domain. */ public void executeViaUndoManager(String label, Command command) { if (command.canExecute()) { if (undoManager != null) { undoManager.beginRecording(this, label); command.execute(); undoManager.endRecording(this); } else executeViaStack(command); } }
/** * verify from a list of command if it can be dropped * * @param commandList, cannot be null but can be an empty list * @return true or false */ protected boolean canDrop(List<Command> commandList) { Iterator<Command> iterator = commandList.iterator(); while (iterator.hasNext()) { Command abstractCommand = (Command) iterator.next(); if (abstractCommand.canExecute()) { return true; } } return false; }
private void addToModel(MPerspective perspective) { setElementId(perspective); Command cmd = AddCommand.create( getEditingDomain(), getMaster().getValue(), UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, perspective); if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); getEditor().setSelection(perspective); } }
@Execute void execute() { Group group = ContactsFactory.eINSTANCE.createGroup(); group.setName("New Group"); Command command = AddCommand.create( contactsManager.getEditingDomain(), contactsManager.getRootGroup(), ContactsPackage.Literals.GROUP__GROUPS, group); if (command != null && command.canExecute()) contactsManager.getEditingDomain().getCommandStack().execute(command); }
protected void handleAdd() { MParameter handler = MCommandsFactory.INSTANCE.createParameter(); setElementId(handler); Command cmd = AddCommand.create( getEditingDomain(), getMaster().getValue(), MenuPackageImpl.Literals.HANDLED_ITEM__PARAMETERS, handler); if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); getEditor().setSelection(handler); } }
protected void handleAdd() { MToolBarContribution command = MMenuFactory.INSTANCE.createToolBarContribution(); setElementId(command); Command cmd = AddCommand.create( getEditingDomain(), getMaster().getValue(), MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTIONS__TOOL_BAR_CONTRIBUTIONS, command); if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); getEditor().setSelection(command); } }
protected void addChild(FormGroup fw, FormElement f) { if (headless) { fw.getChildren().add(f); } else { Command create = AddCommand.create(domain, fw, FormPackage.eINSTANCE.getFormGroup_Children(), f); boolean canExecute = create.canExecute(); System.out.println( "SynchronizeWorkflowFormWithClass.addChild() canExecute :" + fw.getId() + "->" + f + canExecute); cc.append(create); } }
/** {@inheritDoc} */ @Override protected void doExecute() { // ResetClipboard (in case of multi-paste) domain.setClipboard(clipboard); paste.execute(); }
/** {@inheritDoc} */ @Override protected boolean prepare() { prepareClipboard(); paste = PasteFromClipboardCommand.create(domain, container, null); return paste.canExecute(); }
protected void handleAddCommandParameter() { MCommandParameter param = MCommandsFactory.INSTANCE.createCommandParameter(); setElementId(param); Command cmd = AddCommand.create( getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.COMMAND__PARAMETERS, param); if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); getEditor().setSelection(param); } }
@Override public void undo() { EList currentList = (EList) (style.eGet(styleFeature)); command.undo(); if (needsCreate) { view.getStyles().remove(style); } }
private void runRevealCommand( final RootEditPart root, final DDiagramEditor editor, final DDiagramElement vpe) { final Object adapter = editor.getAdapter(IDiagramCommandFactoryProvider.class); final IDiagramCommandFactoryProvider cmdFactoryProvider = (IDiagramCommandFactoryProvider) adapter; final TransactionalEditingDomain transactionalEditingDomain = TransactionUtil.getEditingDomain(editor.getEditingDomain().getResourceSet()); final IDiagramCommandFactory emfCommandFactory = cmdFactoryProvider.getCommandFactory(transactionalEditingDomain); final Command cmd = emfCommandFactory.buildRevealCommand(vpe); final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(vpe); CompoundCommand allInOne = new CompoundCommand(cmd.getLabel()); allInOne.append(cmd); domain.getCommandStack().execute(allInOne); }
/** * Sets the sibling type descriptor used to create the sibling. * * @param theDescriptor the sibling type descriptor or <code>null</code> if no sibling can be * created */ public void setCommand(Command theDescriptor) { descriptor = theDescriptor; if (descriptor == null || descriptor.getResult().isEmpty()) { configureNoneAllowedState(); } else { configureAllowedState(); if (descriptor instanceof DisabledCommand) { super.setEnabled(false); } } }
/** @generated */ protected boolean prepare() { final boolean[] resultHolder = new boolean[1]; // To validate the reconnection against constraints, the current link should be deleted. Of // course, we must then undo its deletion. final TransactionalEditingDomain domainModelEditDomain = TransactionUtil.getEditingDomain(oldTarget.getDiagram().getElement()); Command command = new AbstractCommand() { private Command deleteCommand = createDomainModelRemoveCommand(domainModelEditDomain); public boolean canExecute() { return deleteCommand.canExecute(); } public boolean canUndo() { return true; } public void redo() {} public void undo() {} public void execute() { deleteCommand.execute(); try { resultHolder[0] = canReconnect(); } finally { deleteCommand.undo(); } } }; if (!command.canExecute()) { return false; } new WrappingCommand(domainModelEditDomain, command).execute(); if (!resultHolder[0]) { return false; } return super.prepare(); }
public void execute() { // FIXME: Related to CompoundCommand vs StrictCompoundCommand. // Sometimes, canExecute() is not called, and the command is not prepared if (!isPrepared) { prepare(); isPrepared = true; } if (needsCreate) { view.getStyles().add(style); } command.execute(); }
@Override public boolean prepare() { style = view.getNamedStyle(styleClass, styleName); if (needsCreate = (style == null)) { style = (NamedStyle) NotationFactory.eINSTANCE.create(styleClass); style.setName(styleName); } command = createCommand(); // return true; return command.canExecute(); }
/** Configures the action by setting text, image, and enabled state. */ private void configureAllowedState() { Object result = descriptor.getResult().iterator().next(); // If the descriptor represents a disabled command then extract the // underlying command to use when getting labels Command cmd = descriptor; if (descriptor instanceof DisabledCommand) { cmd = ((DisabledCommand) descriptor).getDisabledCommand(); } // Use the CreateChildCommand label for the menu text String label = cmd.getLabel(); // If the label does not exist of if we are creating a new root entity // in a model (i.e. AddCommand) then use the label provider's text since // AddCommand labels do not provide meaningful text for a "new" child if (label == null || label.length() == 0 || cmd instanceof AddCommand) { label = provider.getText(result); } // Remove the "New" prefix present in labels from CreateChildCommand instances if (label != null && label.startsWith("New ")) { // $NON-NLS-1$ label = label.substring(4); } setText(label); if (result instanceof Diagram) { setImage(diagramProvider.getImage(result)); } else if (result instanceof EObject) { setImage(provider.getImage((EObject) result, ModelObjectUtilities.isVirtual(sibling))); } else { setImage(provider.getImage(result)); } setToolTipText(cmd.getDescription()); setEnabled(true); }
/** @generated */ protected Command getReconnectSourceCommand(ReconnectRequest request) { ConnectionEditPart connection = request.getConnectionEditPart(); if (connection.getModel() instanceof Edge == false) { return null; } Edge edge = (Edge) connection.getModel(); String modelID = ImaginDataVisualIDRegistry.getModelID(edge); if (!DiagramEditPart.MODEL_ID.equals(modelID)) { return null; } org.eclipse.emf.common.command.Command result = null; int visualID = ImaginDataVisualIDRegistry.getVisualID(edge); switch (visualID) { case TransitionEditPart.VISUAL_ID: result = new ReconnectTransition4001SourceCommand(request); break; } if (result == null || !result.canExecute()) { return null; } return new WrappingCommand( TransactionUtil.getEditingDomain(((Node) getHost().getModel()).getDiagram().getElement()), result); }
/** * Can undo. * * @return true, if can undo * @see org.eclipse.gef.commands.Command#canUndo() */ @Override public boolean canUndo() { return emfCommand.canUndo(); }
/** * Undo. * * @see org.eclipse.gef.commands.Command#undo() */ @Override public void undo() { emfCommand.undo(); }
/** * Drop a semantic element and create the corresponding view in the given container * * @param newContainer Semantic container * @param semanticElement Element to drop * @param containerView Container view * @param moveSemanticElement True to move the dropped semantic element or false to just show the * element on a diagram */ private void drop( final Element newContainer, final Element semanticElement, final DSemanticDecorator containerView, boolean moveSemanticElement) { final Session session = SessionManager.INSTANCE.getSession(newContainer); final Element oldContainer = semanticElement.getOwner(); if (moveSemanticElement && oldContainer != newContainer) { // Manage stereotypes and profiles final List<Stereotype> stereotypesToApply = Lists.newArrayList(); for (final Stereotype stereotype : semanticElement.getAppliedStereotypes()) { stereotypesToApply.add(stereotype); } // Move the semantic element to the selected container final TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); // The feature is set to null because the domain will deduce it Command cmd = AddCommand.create(domain, newContainer, null, semanticElement); if (cmd.canExecute()) { cmd.execute(); } cmd = RemoveCommand.create(domain, oldContainer, null, semanticElement); if (cmd.canExecute()) { cmd.execute(); } if (semanticElement instanceof UseCase) { // Reset the current element as subject cmd = SetCommand.create( domain, semanticElement, UMLPackage.Literals.USE_CASE__SUBJECT, SetCommand.UNSET_VALUE); if (cmd.canExecute()) { cmd.execute(); } final List<Element> subjects = new ArrayList<Element>(); subjects.add(newContainer); cmd = SetCommand.create( domain, semanticElement, UMLPackage.Literals.USE_CASE__SUBJECT, subjects); if (cmd.canExecute()) { cmd.execute(); } } // Apply stereotypes on dropped element and apply the necessary // profiles automatically StereotypeServices.INSTANCE.applyAllStereotypes(semanticElement, stereotypesToApply); // Check if profile should be unapplied for (final Stereotype stereotype : stereotypesToApply) { StereotypeServices.INSTANCE.unapplyProfile(oldContainer, stereotype); } } // Show the semantic element on the diagram showView( semanticElement, containerView, session, "[self.getContainerView(newContainerView)/]"); //$NON-NLS-1$ }
/** * Constructor. * * @param command the wrapped EMF command */ public EMFtoGEFCommandWrapper( final org.eclipse.emf.common.command.Command command, EditingDomain domain) { super(command.getLabel()); emfCommand = command; this.domain = domain; }
/** * Dispose. * * @see org.eclipse.gef.commands.Command#dispose() */ @Override public void dispose() { emfCommand.dispose(); }
/** * Can execute. * * @return true, if can execute * @see org.eclipse.gef.commands.Command#canExecute() */ @Override public boolean canExecute() { return emfCommand.canExecute(); }
/** Execute a command within the editing domain. */ public void execute(Command command) { execute(command.getLabel(), command); }