/** * @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; }
/** * 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); } }