public Object execute(ExecutionEvent event) throws ExecutionException { Element selectedElement = getSelection(); ServicesRegistry registry = null; try { registry = ServiceUtilsForHandlers.getInstance().getServiceRegistry(event); } catch (ServiceException e1) { e1.printStackTrace(); } ModelSet modelSet; try { modelSet = registry.getService(ModelSet.class); } catch (ServiceException e) { throw new ExecutionException("Can't get ModelSet", e); } FeatureArchitectureWizard bWizard = new FeatureArchitectureWizard(false); WizardDialog wizardDialog = new WizardDialog(new Shell(), bWizard); if (wizardDialog.open() == Window.OK) { TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain(); if (selectedElement instanceof Package) { CompleteFeaturesArchitectureSnapshotCommand comd = new CompleteFeaturesArchitectureSnapshotCommand( dom, (Package) selectedElement, bWizard.getSelectedBundle()); dom.getCommandStack().execute(comd); } } return null; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.commands.ICreationCommand#createDiagram(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.EObject, * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype, java.lang.String) */ @Override public final Diagram createDiagram( ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) { ICommand createCmd = getCreateDiagramCommand(modelSet, owner, element, prototype, name); TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain(); CompositeCommand cmd = new CompositeCommand("Create diagram"); cmd.add(createCmd); cmd.add(new OpenDiagramCommand(dom, createCmd)); try { IStatus status = CheckedOperationHistory.getInstance().execute(cmd, new NullProgressMonitor(), null); if (status.isOK()) { CommandResult result = cmd.getCommandResult(); Object returnValue = result.getReturnValue(); // CompositeCommands should always return a collection if (returnValue instanceof Collection<?>) { for (Object returnElement : (Collection<?>) returnValue) { if (returnElement instanceof Diagram) { return (Diagram) returnElement; } } } } else if (status.getSeverity() != IStatus.CANCEL) { StatusManager.getManager().handle(status, StatusManager.SHOW); } } catch (ExecutionException ex) { Activator.log.error(ex); } return null; }
protected Resource getNotationResource(ModelSet modelSet, EObject owner, EObject element) { if (element == null) { // If the element is null, the root element of the main model will be used. // Return the main notation resource return NotationUtils.getNotationResource(modelSet); } URI uriWithoutExtension = element.eResource().getURI().trimFileExtension(); URI notationURI = uriWithoutExtension.appendFileExtension(NotationModel.NOTATION_FILE_EXTENSION); Resource notationResource = modelSet.getResource(notationURI, false); // The resource doesn't exist. Maybe we're trying to create a // diagram on a pure-UML library. Try to create a new resource if (notationResource == null) { notationResource = modelSet.createResource(notationURI); if (notationResource == null) { modelSet.getResources().remove(notationResource); return null; } EditingDomain editingDomain = EMFHelper.resolveEditingDomain(element); if (EMFHelper.isReadOnly(notationResource, editingDomain)) { // Check whether the resource can be made writable IReadOnlyHandler2 roHandler = ReadOnlyManager.getReadOnlyHandler(editingDomain); if (roHandler .canMakeWritable(ReadOnlyAxis.anyAxis(), new URI[] {notationResource.getURI()}) .or(false)) { return notationResource; // The read-only manager will eventually ask for a user // confirmation } else { modelSet.getResources().remove(notationResource); return null; // The resource can't be made writable; don't go further } } } return notationResource; }
/** * Returns the di resource where to add the new Table * * @param eObject the semantic object linked to the Table or the Table itself. * @param domain the editing domain * @return the resource where the Table should be added or <code>null</code> if no resource was * found */ public Resource getDiResourceForTable(EObject eObject, TransactionalEditingDomain domain) { Object object = BusinessModelResolver.getInstance().getBusinessModel(eObject); EObject semanticObject; if (!(object instanceof EObject)) { semanticObject = eObject; } else { semanticObject = (EObject) object; } Resource containerResource = semanticObject.eResource(); if (containerResource == null) { return null; } // retrieve the model set from the container resource ResourceSet resourceSet = containerResource.getResourceSet(); if (resourceSet instanceof ModelSet) { ModelSet modelSet = (ModelSet) resourceSet; Resource destinationResource = modelSet.getAssociatedResource(semanticObject, DiModel.DI_FILE_EXTENSION, true); return destinationResource; } else throw new RuntimeException("Resource Set is not a ModelSet or is null"); // $NON-NLS-1$ }
/** Returns the root EObject of currently opened model */ private EObject getRoot(ModelSet modelSet) { UmlModel openedModel = (UmlModel) modelSet.getModel(UmlModel.MODEL_ID); if (openedModel != null) { EObject root; try { root = openedModel.lookupRoot(); } catch (NotFoundException e) { return null; } return root; } return null; }
public IStatus repair(ModelSet modelSet) { IStatus result = Status.OK_STATUS; if (presenter != null) { for (Resource next : ImmutableList.copyOf(modelSet.getResources())) { if (next.isLoaded()) { handleResourceLoaded(next); } } // Wait for the presenter to have shown its dialog and finished try { presenter.awaitPending(false); // Did we fix all of the zombies? for (Resource next : ImmutableList.copyOf(modelSet.getResources())) { if (next.isLoaded() && (getZombieStereotypes(next) != null)) { result = new Status( IStatus.WARNING, Activator.PLUGIN_ID, "Stereotype repair did not successfully repair all stereotype application problems."); break; } } } catch (InterruptedException e) { result = new Status( IStatus.ERROR, Activator.PLUGIN_ID, "Stereotype repair was interrupted while waiting for user input.", e); } } return result; }
/* * (non-Javadoc) * * @see org.eclipse.papyrus.commands.ICreationCommand#getCreateDiagramCommand(org.eclipse.papyrus.infra.core.resource.ModelSet, * org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype, * java.lang.String) */ @Override public final ICommand getCreateDiagramCommand( final ModelSet modelSet, final EObject owner, final EObject element, final ViewPrototype prototype, final String name) { // Diagram creation should not change the semantic resource final Resource notationResource = NotationUtils.getNotationResource(modelSet); final Resource diResource = DiModelUtils.getDiResource(modelSet); ArrayList<IFile> modifiedFiles = new ArrayList<IFile>(); if (notationResource.getURI().isPlatformResource()) { modifiedFiles.add( ResourcesPlugin.getWorkspace() .getRoot() .getFile(new Path(notationResource.getURI().toPlatformString(true)))); } if (diResource.getURI().isPlatformResource()) { modifiedFiles.add( ResourcesPlugin.getWorkspace() .getRoot() .getFile(new Path(diResource.getURI().toPlatformString(true)))); } return new AbstractTransactionalCommand( modelSet.getTransactionalEditingDomain(), Messages.AbstractPapyrusGmfCreateDiagramCommandHandler_CreateDiagramCommandLabel, modifiedFiles) { private Diagram diagram = null; private EObject diagramElement = null; private EObject diagramOwner = null; @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Creator creator = new Creator(modelSet, owner, element, prototype, name); try { CommandResult commandResult = creator.createDiagram(); if (!commandResult.getStatus().isOK()) { return commandResult; } diagram = (Diagram) commandResult.getReturnValue(); diagramElement = diagram.getElement(); diagramOwner = DiagramUtils.getOwner(diagram); return commandResult; } catch (ServiceException e) { Activator.log.error(e); } return CommandResult.newErrorCommandResult("Error during diagram creation"); } @Override protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { // the undo corresponds to a destroy diagram command // during diagram creation no adapters are set to the diagram so the setElement is not // registered // to remove the cross reference using the element reference it is better to use the destroy // element command // DestroyElementPapyrusCommand depc = (diagram != null) ? new // DestroyElementPapyrusCommand(new DestroyElementRequest(diagram, false)) : null; IStatus status = super.doUndo(monitor, info); diagram.setElement(null); return status; } @Override protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { diagram.setElement(diagramElement); DiagramUtils.setOwner(diagram, diagramOwner); IStatus status = super.doRedo(monitor, info); return status; } }; }