/** * Close selected page. * * @param pageMngr */ public void execute(final Diagram diagram, final IEditorPart editorPart) { TransactionalEditingDomain editingDomain = EditorUtils.getTransactionalEditingDomain(); if (editingDomain != null) { InputDialog dialog = new InputDialog( Display.getCurrent().getActiveShell(), "Rename an existing diagram", "New name:", diagram.getName(), null); if (dialog.open() == Window.OK) { final String name = dialog.getValue(); if (name != null && name.length() > 0) { Command command = new RecordingCommand(editingDomain) { @Override protected void doExecute() { diagram.setName(name); } }; editingDomain.getCommandStack().execute(command); } } } }
protected void removeAction() { // Erase image content if (getElement() instanceof Image) { TransactionalEditingDomain dom = EditorUtils.getTransactionalEditingDomain(); AbstractTransactionalCommand operation = new AbstractTransactionalCommand(dom, "Remove Image content", null) { /** {@inheritDoc} */ @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { try { ImageUtil.setContent((Image) getElement(), null); } catch (Exception ex) { return CommandResult.newErrorCommandResult(ex); } return CommandResult.newOKCommandResult(); } }; dom.getCommandStack().execute(new GMFtoEMFCommandWrapper(operation)); refresh(); } }
/** 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(); }
/** * Execute the command : create the model element, then the corresponding views * * @see org.eclipse.gef.commands.Command#execute() */ @Override public void execute() { Object constraint = null; if (elementCreationCommand != null) { elementCreationCommand.execute(); constraint = elementCreationCommand.getICommand().getCommandResult().getReturnValue(); } if (constraint instanceof Constraint && compartment != null && type != null) { // construct the complete command for views creation and execute it. viewsCreationCommand = new CompoundCommand(); // creation of the node by the compartment ViewDescriptor descriptor = new CreateViewRequest.ViewDescriptor( new EObjectAdapter((EObject) constraint), Node.class, type.getSemanticHint(), compartment.getDiagramPreferencesHint()); CreateViewRequest request = new CreateViewRequest(descriptor); Command nodeCreationCommand = compartment.getCommand(request); viewsCreationCommand.add(nodeCreationCommand); // try and recover the created edit part, then create the link if (linkedActionEditPart != null && getLinkType() != null) { IAdaptable targetAdapter = extractResult(nodeCreationCommand); if (targetAdapter != null) { IAdaptable sourceAdapter = new SemanticAdapter(null, linkedActionEditPart.getModel()); // descriptor of the link CreateConnectionViewRequest.ConnectionViewDescriptor linkdescriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor( getLinkType(), getLinkType().getSemanticHint(), compartment.getDiagramPreferencesHint()); CommonDeferredCreateConnectionViewCommand aLinkCommand = new CommonDeferredCreateConnectionViewCommand( EditorUtils.getTransactionalEditingDomain(), getLinkType().getSemanticHint(), sourceAdapter, targetAdapter, compartment.getViewer(), compartment.getDiagramPreferencesHint(), linkdescriptor, null); aLinkCommand.setElement((EObject) constraint); viewsCreationCommand.add(new ICommandProxy(aLinkCommand)); } } viewsCreationCommand.execute(); } }
/** * Execute the passed Runnable within a command * * @param label * @param command */ public static void exec(String label, final Runnable command) { TransactionalEditingDomain domain = EditorUtils.getTransactionalEditingDomain(); IOperationHistory history = OperationHistoryFactory.getOperationHistory(); try { history.execute( new AbstractTransactionalCommand(domain, label, Collections.EMPTY_LIST) { @Override public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) { command.run(); return CommandResult.newOKCommandResult(); } }, null, null); } catch (ExecutionException e) { e.printStackTrace(); } }
protected void browseAction() { FileDialog fd = new FileDialog(composite.getShell()); String extensions[] = {"*.jpg;*.bmp;*.ico;*.gif;*.png;*.wmf;*.emf"}; // $NON-NLS-1$ fd.setFilterExtensions(extensions); String iconSelected = fd.open(); // No image selected if (iconSelected == null) { return; } if (getElement() instanceof Image) { final File imgFile = new File(iconSelected); TransactionalEditingDomain domain = EditorUtils.getTransactionalEditingDomain(); AbstractTransactionalCommand operation = new AbstractTransactionalCommand(domain, "Set Image content", null) { /** {@inheritDoc} */ @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { try { ImageUtil.setContent((Image) getElement(), imgFile); ((Image) getElement()).setFormat(PAPYRUS_FORMAT); } catch (Exception ex) { return CommandResult.newErrorCommandResult(ex); } return CommandResult.newOKCommandResult(); } }; domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(operation)); refresh(); } }