Search in sources :

Example 21 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class SelectPathPresenter method show.

public void show(Resource[] resources, boolean showFiles, SelectionPathHandler handler) {
    checkArgument(resources != null, "Null resources occurred");
    if (resources.length == 0) {
        view.setStructure(Collections.<Node>emptyList(), showFiles);
        return;
    }
    final List<Node> nodes = new ArrayList<>();
    final NodeSettings settings = settingsProvider.getSettings();
    for (Resource resource : resources) {
        if (resource.getResourceType() == Resource.FILE && !showFiles) {
            continue;
        }
        final Node node;
        if (resource.getResourceType() == Resource.FILE) {
            node = nodeFactory.newFileNode((File) resource, settings);
        } else {
            node = nodeFactory.newContainerNode((Container) resource, settings);
        }
        nodes.add(node);
    }
    view.setStructure(nodes, showFiles);
    this.handler = handler;
    view.show();
}
Also used : NodeSettings(org.eclipse.che.ide.api.data.tree.settings.NodeSettings) Container(org.eclipse.che.ide.api.resources.Container) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ArrayList(java.util.ArrayList) Resource(org.eclipse.che.ide.api.resources.Resource) File(org.eclipse.che.ide.api.resources.File)

Example 22 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class ResourceNode method updatePresentation.

@Override
public void updatePresentation(@NotNull NodePresentation presentation) {
    final StringBuilder cssBuilder = new StringBuilder();
    final Optional<Marker> presentableTextMarker = getData().getMarker(PresentableTextMarker.ID);
    if (presentableTextMarker.isPresent() && getData() instanceof Container) {
        presentation.setPresentableText(((PresentableTextMarker) presentableTextMarker.get()).getPresentableText());
    } else {
        presentation.setPresentableText(getData().getName());
    }
    if (resourceIsCut) {
        cssBuilder.append("opacity:0.5;");
    } else {
        cssBuilder.append("opacity:1;");
    }
    SVGResource icon = null;
    for (NodeIconProvider iconProvider : nodeIconProviders) {
        icon = iconProvider.getIcon(getData());
        if (icon != null) {
            break;
        }
    }
    if (icon != null) {
        presentation.setPresentableIcon(icon);
    } else {
        if (getData().getResourceType() == FOLDER) {
            presentation.setPresentableIcon(getData().getName().startsWith(".") ? nodesResources.hiddenSimpleFolder() : nodesResources.simpleFolder());
        } else if (getData().getResourceType() == PROJECT) {
            presentation.setPresentableIcon(((Project) getData()).isProblem() ? nodesResources.notValidProjectFolder() : nodesResources.projectFolder());
            cssBuilder.append("font-weight:bold;");
        } else if (getData().getResourceType() == FILE) {
            presentation.setPresentableIcon(nodesResources.file());
        }
    }
    presentation.setPresentableTextCss(cssBuilder.toString());
}
Also used : SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Container(org.eclipse.che.ide.api.resources.Container) CutResourceMarker(org.eclipse.che.ide.api.resources.modification.CutResourceMarker) PresentableTextMarker(org.eclipse.che.ide.api.resources.marker.PresentableTextMarker) Marker(org.eclipse.che.ide.api.resources.marker.Marker) NodeIconProvider(org.eclipse.che.ide.project.node.icon.NodeIconProvider)

Example 23 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class FullTextSearchPresenter method search.

@Override
public void search(final String text) {
    final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch());
    appContext.getWorkspaceRoot().getContainer(startPoint).then(new Operation<Optional<Container>>() {

        @Override
        public void apply(Optional<Container> optionalContainer) throws OperationException {
            if (!optionalContainer.isPresent()) {
                view.showErrorMessage("Path '" + startPoint + "' doesn't exists");
                return;
            }
            final Container container = optionalContainer.get();
            container.search(view.getFileMask(), prepareQuery(text)).then(new Operation<Resource[]>() {

                @Override
                public void apply(Resource[] result) throws OperationException {
                    view.close();
                    findResultPresenter.handleResponse(result, text);
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 24 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class ProjectWizard method complete.

/** {@inheritDoc} */
@Override
public void complete(@NotNull final CompleteCallback callback) {
    if (mode == CREATE) {
        appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
    } else if (mode == UPDATE) {
        appContext.getWorkspaceRoot().getContainer(Path.valueOf(dataObject.getPath())).then(new Operation<Optional<Container>>() {

            @Override
            public void apply(Optional<Container> optContainer) throws OperationException {
                checkState(optContainer.isPresent(), "Failed to update non existed path");
                final Container container = optContainer.get();
                if (container.getResourceType() == PROJECT) {
                    ((Project) container).update().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
                } else if (container.getResourceType() == FOLDER) {
                    ((Folder) container).toProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
                }
            }
        });
    } else if (mode == IMPORT) {
        appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().thenPromise(new Function<Project, Promise<Project>>() {

            @Override
            public Promise<Project> apply(Project project) throws FunctionException {
                return project.update().withBody(dataObject).send();
            }
        }).then(addCommands(callback)).catchError(onFailure(callback));
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation)

Example 25 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class InMemoryResourceStore method dispose.

/** {@inheritDoc} */
@Override
public void dispose(Path path, boolean withChildren) {
    checkArgument(path != null, "Null path occurred");
    final Path parent = path.segmentCount() == 1 ? Path.ROOT : path.parent();
    Resource[] container = memoryCache.get(parent);
    if (container != null) {
        int index = -1;
        for (int i = 0; i < container.length; i++) {
            if (container[i].getName().equals(path.lastSegment())) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            int size = container.length;
            int numMoved = container.length - index - 1;
            if (numMoved > 0) {
                System.arraycopy(container, index + 1, container, index, numMoved);
            }
            container = copyOf(container, --size);
            memoryCache.put(parent, container);
        }
    }
    if (memoryCache.containsKey(path)) {
        container = memoryCache.remove(path);
        if (container != null && withChildren) {
            for (Resource resource : container) {
                if (resource instanceof Container) {
                    dispose(resource.getLocation(), true);
                }
            }
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Aggregations

Container (org.eclipse.che.ide.api.resources.Container)38 Resource (org.eclipse.che.ide.api.resources.Resource)32 Project (org.eclipse.che.ide.api.resources.Project)13 Operation (org.eclipse.che.api.promises.client.Operation)7 OperationException (org.eclipse.che.api.promises.client.OperationException)7 Optional (com.google.common.base.Optional)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 File (org.eclipse.che.ide.api.resources.File)5 Path (org.eclipse.che.ide.resource.Path)5 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)4 List (java.util.List)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 Folder (org.eclipse.che.ide.api.resources.Folder)3 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)3 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 Promise (org.eclipse.che.api.promises.client.Promise)2 Node (org.eclipse.che.ide.api.data.tree.Node)2