Search in sources :

Example 1 with URIBasedStorage

use of org.eclipse.n4js.ts.ui.navigation.URIBasedStorage in project n4js by eclipse.

the class NfarStorageMapper method getStorages.

@Override
public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
    if (uri.isArchive()) {
        URIBasedStorage storage = new URIBasedStorage(uri);
        String authority = uri.authority();
        URI archiveFileURI = URI.createURI(authority.substring(0, authority.length() - 1));
        Optional<? extends IN4JSEclipseProject> optionalProject = eclipseCore.findProject(archiveFileURI);
        if (optionalProject.isPresent()) {
            return Collections.singletonList(Tuples.<IStorage, IProject>create(storage, optionalProject.get().getProject()));
        } else {
            return Collections.singletonList(Tuples.create(storage, null));
        }
    } else {
        return Collections.emptyList();
    }
}
Also used : URIBasedStorage(org.eclipse.n4js.ts.ui.navigation.URIBasedStorage) URI(org.eclipse.emf.common.util.URI)

Example 2 with URIBasedStorage

use of org.eclipse.n4js.ts.ui.navigation.URIBasedStorage in project n4js by eclipse.

the class N4JSToBeBuiltComputer method updateStorage.

@Override
public boolean updateStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
    if (storage instanceof IFile) {
        IFile file = (IFile) storage;
        String extension = file.getFileExtension();
        // changed archive - schedule contents
        if (IN4JSArchive.NFAR_FILE_EXTENSION.equals(extension)) {
            IProject project = file.getProject();
            String key = project.getName() + "|" + storage.getFullPath().toPortableString();
            Set<URI> cachedURIs = knownEntries.remove(key);
            if (cachedURIs != null) {
                toBeBuilt.getToBeDeleted().addAll(cachedURIs);
            }
            cachedURIs = Sets.newHashSet();
            storageMapper.collectNfarURIs((IFile) storage, cachedURIs);
            knownEntries.put(key, cachedURIs);
            toBeBuilt.getToBeUpdated().addAll(cachedURIs);
            return true;
        } else if (IN4JSProject.N4MF_MANIFEST.equals(file.getName())) {
            // changed manifest - schedule all resources from source folders
            final IN4JSEclipseProject project = eclipseCore.create(file.getProject()).orNull();
            if (null != project && project.exists()) {
                List<? extends IN4JSEclipseSourceContainer> sourceContainers = project.getSourceContainers();
                Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
                for (IN4JSEclipseSourceContainer sourceContainer : sourceContainers) {
                    for (URI uri : sourceContainer) {
                        if (uriValidator.canBuild(uri, new URIBasedStorage(uri))) {
                            toBeUpdated.add(uri);
                        }
                    }
                }
            }
            IProject resourceProject = file.getProject();
            String projectName = resourceProject.getName();
            Set<URI> toBeDeleted = toBeBuilt.getToBeDeleted();
            for (final IResourceDescription description : builderState.getAllResourceDescriptions()) {
                URI uri = description.getURI();
                if (uri.isPlatformResource()) {
                    if (projectName.equals(uri.segment(1))) {
                        toBeDeleted.add(uri);
                    }
                }
            }
            // still return false because we want to do the normal processing for the manifest file, too
            return false;
        }
    }
    return false;
}
Also used : IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) IFile(org.eclipse.core.resources.IFile) Set(java.util.Set) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URIBasedStorage(org.eclipse.n4js.ts.ui.navigation.URIBasedStorage) IN4JSEclipseSourceContainer(org.eclipse.n4js.ui.projectModel.IN4JSEclipseSourceContainer) List(java.util.List) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Example 3 with URIBasedStorage

use of org.eclipse.n4js.ts.ui.navigation.URIBasedStorage in project n4js by eclipse.

the class N4JSResourceLinkHelper method activateEditor.

@Override
public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) {
    if (null != selection && !selection.isEmpty()) {
        final Object firstElement = selection.getFirstElement();
        if (firstElement instanceof ResourceNode) {
            final File fileResource = ((ResourceNode) firstElement).getResource();
            if (fileResource.exists() && fileResource.isFile()) {
                final URI uri = URI.createFileURI(fileResource.getAbsolutePath());
                final IResource resource = externalLibraryWorkspace.getResource(uri);
                if (resource instanceof IFile) {
                    final IEditorInput editorInput = EditorUtils.createEditorInput(new URIBasedStorage(uri));
                    final IEditorPart editor = page.findEditor(editorInput);
                    if (null != editor) {
                        page.bringToTop(editor);
                        return;
                    }
                }
            }
        }
    }
    super.activateEditor(page, selection);
}
Also used : IFile(org.eclipse.core.resources.IFile) URIBasedStorage(org.eclipse.n4js.ts.ui.navigation.URIBasedStorage) IEditorPart(org.eclipse.ui.IEditorPart) File(java.io.File) IFile(org.eclipse.core.resources.IFile) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

URI (org.eclipse.emf.common.util.URI)3 URIBasedStorage (org.eclipse.n4js.ts.ui.navigation.URIBasedStorage)3 IFile (org.eclipse.core.resources.IFile)2 File (java.io.File)1 List (java.util.List)1 Set (java.util.Set)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IN4JSEclipseProject (org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject)1 IN4JSEclipseSourceContainer (org.eclipse.n4js.ui.projectModel.IN4JSEclipseSourceContainer)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1