/* @NonNull */ @Override public Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri) { List<Pair<IStorage, IProject>> result = newArrayListWithCapacity(1); List<PackageFragmentRootData> packageFragmentRootDatas; synchronized (cachedPackageFragmentRootData) { packageFragmentRootDatas = newArrayList(cachedPackageFragmentRootData.values()); } Iterator<PackageFragmentRootData> iterator = packageFragmentRootDatas.iterator(); while (iterator.hasNext()) { PackageFragmentRootData data = iterator.next(); if (data.exists()) { if (data.uriPrefix == null || uri.toString().startsWith(data.uriPrefix.toString())) { IStorage storage = data.uri2Storage.get(uri); if (storage != null) { for (IPackageFragmentRoot root : data.associatedRoots.values()) { result.add(Tuples.create(storage, root.getJavaProject().getProject())); } } } } else { iterator.remove(); } } if (result.isEmpty() && uri.isArchive()) { String authority = uri.authority(); authority = authority.substring(0, authority.length() - 1); URI archiveURI = URI.createURI(authority); if (archiveURI.isFile() || archiveURI.isPlatformResource()) { IPath archivePath = new Path( archiveURI.isPlatformResource() ? archiveURI.toPlatformString(true) : archiveURI.toFileString()); for (PackageFragmentRootData data : packageFragmentRootDatas) { if (data.uriPrefix != null && archivePath.equals(data.getPath())) { // prefixes have an empty last segment. URI prefix = data.uriPrefix.lastSegment().length() == 0 ? data.uriPrefix.trimSegments(1) : data.uriPrefix; URI expectedURI = prefix.appendSegments(uri.segments()); IStorage storage = data.uri2Storage.get(expectedURI); if (storage != null) { for (IPackageFragmentRoot root : data.associatedRoots.values()) { result.add(Tuples.create(storage, root.getJavaProject().getProject())); } } } } } } return result; }
/** * SIMPLY COPIED; * * @param diagram * @return */ private IProject getProjectFromDiagram(Diagram diagram) { IProject currentProject = null; Resource resource = diagram.eResource(); URI uri = resource.getURI(); URI uriTrimmed = uri.trimFragment(); if (uriTrimmed.isPlatformResource()) { String platformString = uriTrimmed.toPlatformString(true); IResource fileResource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString); if (fileResource != null) { currentProject = fileResource.getProject(); } } else { IResource fileResource = ResourcesPlugin.getWorkspace().getRoot().findMember(uriTrimmed.toString()); if (fileResource != null) { currentProject = fileResource.getProject(); } } return currentProject; }
private String relative(String path) { path = substitute(path); URI sourceURI = source.eResource().getURI(); URI result = URI.createURI(path).resolve(sourceURI); if (result.isFile()) { return result.path(); } else if (result.isPlatformResource()) { return getFileFromProjectPath(result.toPlatformString(true)); } return ""; }
/** @generated */ public StateMachine_MAVONewDiagramFileWizard( URI domainModelURI, EObject diagramRoot, TransactionalEditingDomain editingDomain) { assert domainModelURI != null : "Domain model uri must be specified"; // $NON-NLS-1$ assert diagramRoot != null : "Doagram root element must be specified"; // $NON-NLS-1$ assert editingDomain != null : "Editing domain must be specified"; // $NON-NLS-1$ myFileCreationPage = new WizardNewFileCreationPage( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_CreationPageName, StructuredSelection.EMPTY); myFileCreationPage.setTitle( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_CreationPageTitle); myFileCreationPage.setDescription( NLS.bind( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_CreationPageDescription, edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts.StateMachineEditPart .MODEL_ID)); IPath filePath; String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment()); if (domainModelURI.isPlatformResource()) { filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true)); } else if (domainModelURI.isFile()) { filePath = new Path(domainModelURI.trimSegments(1).toFileString()); } else { // TODO : use some default path throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); // $NON-NLS-1$ } myFileCreationPage.setContainerFullPath(filePath); myFileCreationPage.setFileName( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part .StateMachine_MAVODiagramEditorUtil.getUniqueFileName( filePath, fileName, "statemachinediag_mavo")); // $NON-NLS-1$ diagramRootElementSelectionPage = new DiagramRootElementSelectionPage( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageName); diagramRootElementSelectionPage.setTitle( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageTitle); diagramRootElementSelectionPage.setDescription( edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageDescription); diagramRootElementSelectionPage.setModelElement(diagramRoot); myEditingDomain = editingDomain; }
@Override public InputStream loadFile(Resource resource, String filename) { if (resource == null) return null; URI uri = resource.getURI(); if (uri.isPlatformResource()) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile modelFile = root.getFile(new Path(uri.toPlatformString(false))); IContainer modelParent = modelFile.getParent(); if (modelParent instanceof IFolder) { IFolder modelDir = (IFolder) modelParent; IFile file = modelDir.getFile(filename); try { return file.getContents(); } catch (CoreException e) { LOGGER.warn("Can't handle file '" + filename + "': " + e.getMessage()); } } } LOGGER.warn("Can't find file '" + filename + "' in project"); return null; }
private GenModel loadGenmodel(String resourceOrNsURI, ResourceSet resourceSet) { URI uri = null; try { uri = URI.createURI(resourceOrNsURI); if (uri.fragment() == null) { Resource resource = resourceSet.getResource(uri, true); return (GenModel) resource.getContents().get(0); } return (GenModel) resourceSet.getEObject(uri, true); } catch (IllegalArgumentException ex) { LOG.trace("Invalid package URI: '" + resourceOrNsURI + "'", ex); return null; } catch (RuntimeException ex) { if (uri != null && uri.isPlatformResource()) { String platformString = uri.toPlatformString(true); URI platformPluginURI = URI.createPlatformPluginURI(platformString, true); return loadGenmodel(platformPluginURI.toString(), resourceSet); } LOG.trace("Cannot load package with URI '" + resourceOrNsURI + "'", ex); return null; } }
// copy/pasted from PreferenceStoreWhitespaceInformationProvider, just call to // senseLineDelimiter() commented out protected String getLineSeparatorPreference(URI uri) { // if (uri.isPlatformResource()) { // IFile file = workspace.getRoot().getFile(new Path(uri.toPlatformString(true))); // String delimiter = senseLineDelimiter(file); // if (delimiter != null) return delimiter; // } IProject project = null; if (uri.isPlatformResource()) { project = workspace.getRoot().getProject(uri.segment(1)); } else { for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(uri)) { project = storage.getSecond(); break; } } if (project != null) { String result = getLineSeparatorPreference(new ProjectScope(project)); if (result != null) return result; } @SuppressWarnings("all") String result = getLineSeparatorPreference(new InstanceScope()); if (result != null) return result; return System.getProperty("line.separator"); }