@Override @Test public void testXMIID() { final Model leftModel = (Model) leftElement; final Model rightModel = (Model) rightElement; final ProfileApplication leftApplication = leftModel.getProfileApplications().get(0); final ProfileApplication rightApplication = rightModel.getProfileApplications().get(0); Assert.assertNotNull(leftApplication); Assert.assertNotNull(rightApplication); final EAnnotation leftEAnnotation = leftApplication.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML"); final EAnnotation rightEAnnotation = rightApplication.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML"); Assert.assertNotNull(leftEAnnotation); Assert.assertNotNull(rightEAnnotation); // the test itself Assert.assertEquals( "The ID of the ProfileApplication has not been correctly merged", EMFHelper.getXMIID(leftApplication), EMFHelper.getXMIID(rightApplication)); Assert.assertEquals( "The ID of the ProfileApplication has not been correctly merged", EMFHelper.getXMIID(leftEAnnotation), EMFHelper.getXMIID(rightEAnnotation)); }
protected ZombieStereotypesDescriptor getZombieStereotypes(Resource resource) { ZombieStereotypesDescriptor result = null; Element root = getRootUMLElement(resource); // Only check for zombies in resources that we can modify (those being the resources in the user // model opened in the editor) if ((root instanceof Package) && !EMFHelper.isReadOnly(resource, EMFHelper.resolveEditingDomain(root))) { result = getZombieStereotypes(resource, (Package) root); } return result; }
/** * initialize the background for a graphical element * * @param view the element to initialize * @param store the preference store * @param elementName the name to the element */ public static void initBackgroundFromPrefs( View view, final IPreferenceStore store, String elementName) { if (!usePreferenceInitializer(view)) { return; } String fillColorConstant = getpreferenceKey(view, elementName, PreferenceConstantHelper.COLOR_FILL); String gradientColorConstant = getpreferenceKey(view, elementName, PreferenceConstantHelper.COLOR_GRADIENT); String gradientPolicyConstant = getpreferenceKey(view, elementName, PreferenceConstantHelper.GRADIENT_POLICY); String shadowConstant = getpreferenceKey(view, elementName, PreferenceConstantHelper.SHADOW); String elementIcon = getpreferenceKey(view, elementName, PreferenceConstantHelper.ELEMENTICON); String qualifiedName = getpreferenceKey(view, elementName, PreferenceConstantHelper.QUALIFIEDNAME); org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(store, fillColorConstant); ViewUtil.setStructuralFeatureValue( view, NotationPackage.eINSTANCE.getFillStyle_FillColor(), FigureUtilities.RGBToInteger(fillRGB)); FillStyle fillStyle = (FillStyle) view.getStyle(NotationPackage.Literals.FILL_STYLE); fillStyle.setFillColor(FigureUtilities.RGBToInteger(fillRGB).intValue()); if (store.getBoolean(gradientPolicyConstant)) { GradientPreferenceConverter gradientPreferenceConverter = new GradientPreferenceConverter(store.getString(gradientColorConstant)); fillStyle.setGradient(gradientPreferenceConverter.getGradientData()); fillStyle.setTransparency(gradientPreferenceConverter.getTransparency()); } EditingDomain domain = EMFHelper.resolveEditingDomain(view); if (domain instanceof TransactionalEditingDomain) { TransactionalEditingDomain editingDomain = (TransactionalEditingDomain) domain; // shadow RecordingCommand shadowcommand = AnnotationStyleProvider.getSetShadowCommand( editingDomain, view, store.getBoolean(shadowConstant)); if (shadowcommand.canExecute()) { shadowcommand.execute(); } // icon label RecordingCommand namelabelIconCommand = AnnotationStyleProvider.getSetElementIconCommand( editingDomain, view, store.getBoolean(elementIcon)); if (namelabelIconCommand.canExecute()) { namelabelIconCommand.execute(); } // qualified name if (!store.getBoolean(qualifiedName)) { RecordingCommand qualifiedNameCommand = AnnotationStyleProvider.getSetQualifiedNameDepthCommand(editingDomain, view, 1000); if (qualifiedNameCommand.canExecute()) { qualifiedNameCommand.execute(); } } } }
/** * @param input * @return */ public static URI getUri(IEditorInput input, String editorID) { String uriString = null; if (input instanceof URIEditorInput) { uriString = PathsUtil.getRelativeWorkspaceFromEditorInputWithFragment(input); } else { uriString = PathsUtil.getRelativeWorkspaceFromEditorInput(input); String fragment = MDTUtil.getLastOpenedDiagramPropertyForEditor(uriString, editorID); if (fragment != null) { uriString = URI.createURI(uriString).appendFragment(fragment).toString(); } } if (input != null) { URI uri = URI.createURI(uriString); if (uri.hasFragment()) { return uri; } ResourceSet resourceSet = new ResourceSetImpl(); try { resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); Resource resource = resourceSet.getResource(uri, true); Diagram diagram = MDTUtil.getFirstDiagramFromResource(resource); if (diagram != null) { String fragment = resource.getURIFragment(diagram); uri = uri.appendFragment(fragment); } } finally { EMFHelper.unload(resourceSet); } return uri; } return null; }
/** * The default implementation of this <code>IContributionItem</code> method does nothing. * Subclasses may override. */ @Override public void fill(Menu menu, int index) { // retrieves current selection final Object selectedElement = getSelectedElement(); // first case: this class was not able to retrieve the selection service // or does not understand the current selection. // does not build any sub-menu and returns. if (selectedElement == null) { return; } // get the UML object type of this element, using the business resolver final Object businessObject = EMFHelper.getEObject(selectedElement); // no object found: exit if (businessObject == null) { return; } // retrieves all editor configurations for this kind of element final Collection<DirectEditorExtensionPoint> configurations = DirectEditorExtensionPoint.getDirectEditorConfigurations(businessObject.getClass()); // if configurations is not empty, a submenu should open to select which // editor to use... if (configurations.size() < 1) { return; } createSubMenu(menu, index, businessObject, configurations); }
/** * {@inheritedDoc}. * * @param e the e */ @Override public void widgetSelected(SelectionEvent e) { try { if (treeViewer.getSelection().isEmpty()) { return; } IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); EObject elt = EMFHelper.getEObject(selection.getFirstElement()); if (elt == null) { return; } setContainer(elt); ModelSet modelSet = ServiceUtilsForEObject.getInstance().getModelSet(elt); ICreationCommand creationCommand = iCreationCommandRegistry.getCommand(commandDescriptor.getCommandId()); creationCommand.createDiagram(modelSet, container, null); // refresh several filtered tree getDiagramfilteredTree().getViewer().refresh(); getModeFilteredTree().getViewer().refresh(); } catch (NotFoundException ex) { Activator.log.error(ex); } catch (ServiceException ex) { Activator.log.error(ex); } }
/** * Tests if all elements in the selection are EObject * * @param selection * @return */ private boolean isObject(IStructuredSelection selection) { if (!selection.isEmpty()) { Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { EObject current = EMFHelper.getEObject(iter.next()); return current != null; } } return false; }
@Override public boolean isValidValue(Object value) { Object adaptedValue = getAdaptedValue(value); if (adaptedValue instanceof EObject) { // We cannot create objects in a read-only object if (EMFHelper.isReadOnly((EObject) adaptedValue)) { return false; } // We need at least one valid containment reference to store this // type of object for (EReference reference : ((EObject) adaptedValue).eClass().getEAllReferences()) { if (reference.isContainment() && EMFHelper.isSubclass(this.type, reference.getEReferenceType())) { return true; } } } return false; }
protected boolean hasEClass(IStructuredSelection selection, String eClassQName) { if (!selection.isEmpty()) { // Resolve the EClass in the context of the first element. If we can't resolve it // in this context, then that element necessarily isn't an instance of that EClass, // so not all of the selection is an instance of that class. Thus, it doesn't // matter that we choose the first element to resolve the EClass EClassifier eClassifier = resolveEClass(EMFHelper.getEObject(selection.getFirstElement()), eClassQName); if (eClassifier != null) { boolean result = true; for (Iterator<?> iter = selection.iterator(); result && iter.hasNext(); ) { EObject next = EMFHelper.getEObject(iter.next()); result = (next != null) && eClassifier.isInstance(next); } return result; } } return false; }
protected void refresh(Object selectedElement) { selectedElement = EMFHelper.getEObject(selectedElement); Button but = getOKbutton(); if (isAValidEditor(selectedElement)) { but = getOKbutton(); but.setEnabled(true); selectedEditor = selectedElement; } else { but.setEnabled(false); selectedEditor = 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; }
/** * @param selection the current selection * @return <code>true</code> if all selected elements are pages */ private boolean isPage(IStructuredSelection selection) { IPageManager pageManager = getPageManager(selection); if (pageManager != null) { if (!selection.isEmpty()) { Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { EObject current = EMFHelper.getEObject(iter.next()); if (!isPage(current, pageManager)) { return false; } } return true; } } return false; }
/** * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, * org.eclipse.jface.viewers.IStructuredSelection) */ public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { // no selection if (aSelection == null || aSelection.isEmpty()) { return; } ISelectionService selectService = aPage.getWorkbenchWindow().getSelectionService(); ISelection selection = selectService.getSelection(); // test if the selection come the tree viewer in order to avoid cycle: Diagram -> tree-> // diagram // if the diagram has been selected the selection is not a TreeSelection if (selection instanceof ITreeSelection) { try { ISashWindowsContainer windowsContainer = ServiceUtilsForWorkbenchPage.getInstance().getISashWindowsContainer(aPage); Iterator<IEditorPart> iterPart = windowsContainer.getVisibleIEditorParts().iterator(); while (iterPart.hasNext()) { IEditorPart diagramEditor = iterPart.next(); if (diagramEditor instanceof IRevealSemanticElement) { if (aSelection instanceof IStructuredSelection) { Iterator<?> selectionIterator = aSelection.iterator(); ArrayList<Object> semanticElementList = new ArrayList<Object>(); while (selectionIterator.hasNext()) { Object currentSelection = selectionIterator.next(); Object semanticElement = EMFHelper.getEObject(currentSelection); if (semanticElement != null) { semanticElementList.add(semanticElement); } } ((IRevealSemanticElement) diagramEditor).revealSemanticElement(semanticElementList); } } } } catch (ServiceException ex) { // We cannot access the service registry. The PapyrusEditor is probably closed. } catch (Exception ex) { Activator.log.error("Impossible to acces to windows Container", ex); // $NON-NLS-1$ } } }
/** * This method selects an element in the modelexplorer and test that the new selection is the * wanted selection using assertion * * @param elementToSelect the element to select */ protected void selectElementInTheModelexplorer(EObject elementToSelect) { final List<EObject> selectedElement = new ArrayList<EObject>(); selectedElement.add(elementToSelect); Display.getDefault() .syncExec( new Runnable() { public void run() { modelExplorerView.revealSemanticElement(selectedElement); } }); IStructuredSelection currentSelection = (IStructuredSelection) selectionService.getSelection(); Assert.assertEquals( "Only one element should be selected", 1, currentSelection.size()); // $NON-NLS-1$ Object obj = currentSelection.getFirstElement(); obj = EMFHelper.getEObject(obj); Assert.assertSame( "the current selected element is not the wanted element", elementToSelect, obj); //$NON-NLS-1$ }
/** * Import the profiles in the model. * * @param profilesToImport the profiles to import */ protected void importProfiles(IRegisteredProfile[] profilesToImport) { // create a temporary resource set. Be sure to unload it so that we don't leak models in the // CacheAdapter! ResourceSet resourceSet = Util.createTemporaryResourceSet(); try { for (int i = 0; i < profilesToImport.length; i++) { IRegisteredProfile currentLibrary = (profilesToImport[i]); URI modelUri = currentLibrary.getUri(); Resource modelResource = resourceSet.getResource(modelUri, true); // PackageImportTreeSelectionDialog dialog = new // PackageImportTreeSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ((Package)modelResource.getContents().get(0))); ProfileTreeSelectionDialog dialog = new ProfileTreeSelectionDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ((Package) modelResource.getContents().get(0))); int ret = dialog.open(); if (ret == Window.OK) { Collection<ImportSpec<Profile>> result = dialog.getResult(); Iterator<ImportSpec<Profile>> resultIter = result.iterator(); while (resultIter.hasNext()) { Package element = resultIter.next().getElement(); PackageImport ei = UMLFactory.eINSTANCE.createPackageImport(); ei.setImportedPackage(element); // we import only once an element : List<Package> importedPackages = ((Package) getSelectedElement()).getImportedPackages(); if (!importedPackages.contains(element)) { ((Package) getSelectedElement()).getPackageImports().add(ei); } } } } } finally { EMFHelper.unload(resourceSet); } }