Java Code Examples for org.eclipse.emf.common.util.URI#isPlatformPlugin()

The following examples show how to use org.eclipse.emf.common.util.URI#isPlatformPlugin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerationFileNamesPage.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates the {@link Generation#getTemplateFileName() template URI}.
 * 
 * @param gen
 *            the {@link Generation}
 * @param templateURI
 *            the new {@link Generation#getTemplateFileName() template URI}
 */
private void updateTemplateURI(Generation gen, final URI templateURI) {
    final URI genconfURI = gen.eResource().getURI();
    final String relativeTemplatePath;
    if (!templateURI.isPlatformPlugin()) {
        relativeTemplatePath = URI.decode(templateURI.deresolve(genconfURI).toString());
    } else {
        relativeTemplatePath = URI.decode(templateURI.toString());
    }
    final EditingDomain editingDomain = TransactionUtil.getEditingDomain(gen);
    templateCustomProperties = validatePage(gen,
            GenconfUtils.getResolvedURI(gen, URI.createURI(gen.getTemplateFileName(), false)));
    editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, gen,
            GenconfPackage.Literals.GENERATION__TEMPLATE_FILE_NAME, relativeTemplatePath));
    if (gen.getResultFileName() == null || gen.getResultFileName().isEmpty()) {
        editingDomain.getCommandStack()
                .execute(SetCommand.create(editingDomain, gen, GenconfPackage.Literals.GENERATION__RESULT_FILE_NAME,
                        relativeTemplatePath.replace("." + M2DocUtils.DOCX_EXTENSION_FILE, "-generated.docx")));
    }
    if (gen.getValidationFileName() == null || gen.getValidationFileName().isEmpty()) {
        editingDomain.getCommandStack()
                .execute(SetCommand.create(editingDomain, gen,
                        GenconfPackage.Literals.GENERATION__VALIDATION_FILE_NAME,
                        relativeTemplatePath.replace("." + M2DocUtils.DOCX_EXTENSION_FILE, "-validation.docx")));
    }
}
 
Example 2
Source File: AbstractResourceDescription.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected URI getNormalizedURI(Resource resource) {
	URI uri = resource.getURI();
	URIConverter uriConverter = resource.getResourceSet()!=null?resource.getResourceSet().getURIConverter():null;
	if (uri != null && uriConverter != null) {
		if (!uri.isPlatform()) {
			return uriConverter.normalize(uri);
		}
		// This is a fix for resources which have been loaded using a platform:/plugin URI
		// This happens when one resource has absolute references using a platform:/plugin uri and the corresponding
		// ResourceDescriptionManager resolves references in the first phase, i.e. during EObjectDecription computation.
		// EMF's GenModelResourceDescriptionStrategy does so as it needs to call GenModel.reconcile() eagerly.
		if (uri.isPlatformPlugin()) {
			URI resourceURI = uri.replacePrefix(URI.createURI("platform:/plugin/"), URI.createURI("platform:/resource/"));
			if (uriConverter.normalize(uri).equals(uriConverter.normalize(resourceURI)))
				return resourceURI;
		}
	}
	return uri;
}
 
Example 3
Source File: PlatformPluginAwareEditorOpener.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * If a platform plugin URI is given, a read-only Xtext editor is opened and returned. {@inheritDoc}
 *
 * @see {@link org.eclipse.emf.common.util.URI#isPlatformPlugin()}
 */
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
  IEditorPart result = super.open(uri, crossReference, indexInList, select);
  if (result == null && (uri.isPlatformPlugin() || OSGI_RESOURCE_URL_PROTOCOL.equals(uri.scheme()))) {
    final IModelLocation modelLocation = getModelLocation(uri.trimFragment());
    if (modelLocation != null) {
      PlatformPluginStorage storage = new PlatformPluginStorage(modelLocation);
      IEditorInput editorInput = new XtextReadonlyEditorInput(storage);
      IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
      try {
        IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID);
        selectAndReveal(editor, uri, crossReference, indexInList, select);
        return EditorUtils.getXtextEditor(editor);
      } catch (WrappedException e) {
        LOG.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); //$NON-NLS-1$ //$NON-NLS-2$
      } catch (PartInitException partInitException) {
        LOG.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); //$NON-NLS-1$ //$NON-NLS-2$
      }
    }
  }
  return result;
}
 
Example 4
Source File: AbstractResourceTypeDetector.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies if the given URI corresponds to a test resource.
 *
 * @param uri the uri to test against the test folder name.
 * @param testFolderName the name of the test folder.
 * @return {@code true} if the URI is for a test resource.
 */
protected static boolean isTestURI(URI uri, List<String> testFolderName) {
	if (uri.isArchive() || uri.isEmpty() || uri.isCurrentDocumentReference()) {
		return false;
	}
	final List<String> segments = new ArrayList<>(uri.segmentsList());
	if (segments.isEmpty()) {
		return false;
	}
	if (uri.isPlatformResource() || uri.isPlatformPlugin()) {
		segments.remove(0);
	}
	// Usually, the first segment is the project's folder
	if (segments.isEmpty()) {
		return false;
	}
	segments.remove(0);
	for (int i = 0; i < testFolderName.size() && i < segments.size(); ++i) {
		final String expected = testFolderName.get(i);
		final String actual = segments.get(i);
		if (!Objects.equals(expected, actual)) {
			return false;
		}
	}
	return true;
}
 
Example 5
Source File: DefaultResourceUIServiceProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
@Override
public boolean isSource(URI uri) {
	if (delegate instanceof IResourceServiceProviderExtension) {
		if (!((IResourceServiceProviderExtension) delegate).isSource(uri))
			return false;
	}
	if (workspace != null) {
		if (uri.isPlatformResource()) {
			String projectName = URI.decode(uri.segment(1));
			IProject project = workspace.getRoot().getProject(projectName);
			return project.isAccessible();
		}
		if (uri.isPlatformPlugin()) {
			return false;
		}
	}
	Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(uri);
	for (Pair<IStorage, IProject> pair : storages) {
		IStorage storage = pair.getFirst();
		if (storage instanceof IFile) {
			return ((IFile)storage).isAccessible();
		} else {
			return false;
		}
	}
	return true;
}