Search in sources :

Example 1 with Project

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

the class AppContextImpl method onResourceChanged.

/** {@inheritDoc} */
@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    final Resource resource = delta.getResource();
    if (!(resource.getResourceType() == PROJECT && resource.getLocation().segmentCount() == 1)) {
        return;
    }
    if (projects == null) {
        //Normal situation, workspace config updated and project has not been loaded fully. Just skip this situation.
        return;
    }
    if (delta.getKind() == ADDED) {
        Project[] newProjects = copyOf(projects, projects.length + 1);
        newProjects[projects.length] = (Project) resource;
        projects = newProjects;
        sort(projects, ResourcePathComparator.getInstance());
    } else if (delta.getKind() == REMOVED) {
        int size = projects.length;
        int index = java.util.Arrays.binarySearch(projects, resource, ResourcePathComparator.getInstance());
        int numMoved = projects.length - index - 1;
        if (numMoved > 0) {
            System.arraycopy(projects, index + 1, projects, index, numMoved);
        }
        projects = copyOf(projects, --size);
        if (currentResource != null && currentResource.equals(delta.getResource())) {
            currentResource = null;
        }
        if (currentResources != null) {
            for (Resource currentResource : currentResources) {
                if (currentResource.equals(delta.getResource())) {
                    currentResources = Arrays.remove(currentResources, currentResource);
                }
            }
        }
    } else if (delta.getKind() == UPDATED) {
        int index = -1;
        if (delta.getFlags() == MOVED_FROM) {
            for (int i = 0; i < projects.length; i++) {
                if (projects[i].getLocation().equals(delta.getFromPath())) {
                    index = i;
                    break;
                }
            }
        } else {
            index = binarySearch(projects, resource);
        }
        if (index != -1) {
            projects[index] = (Project) resource;
        }
        sort(projects, ResourcePathComparator.getInstance());
    } else if (delta.getKind() == SYNCHRONIZED && resource.isProject() && resource.getLocation().segmentCount() == 1) {
        for (int i = 0; i < projects.length; i++) {
            if (projects[i].getLocation().equals(resource.getLocation())) {
                projects[i] = (Project) resource;
            }
        }
        if (currentResources != null) {
            for (int i = 0; i < currentResources.length; i++) {
                if (currentResources[i].getLocation().equals(resource.getLocation())) {
                    currentResources[i] = resource;
                    break;
                }
            }
        }
        if (currentResource != null && currentResource.getLocation().equals(resource.getLocation())) {
            currentResource = resource;
        }
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 2 with Project

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

the class ExplorerCurrentProjectTypeMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    List<Node> selectedNodes = projectExplorer.getTree().getSelectionModel().getSelectedNodes();
    if (selectedNodes.isEmpty() || selectedNodes.size() > 1) {
        return promises.resolve("");
    }
    final Node node = selectedNodes.get(0);
    if (node instanceof ResourceNode) {
        final Optional<Project> project = ((ResourceNode) node).getData().getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        return promises.resolve(project.get().getType());
    }
    return promises.resolve("");
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 3 with Project

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

the class GdbDebugger method fqnToPath.

@Override
protected String fqnToPath(@NotNull Location location) {
    final Resource resource = appContext.getResource();
    if (resource == null) {
        return location.getTarget();
    }
    final Optional<Project> project = resource.getRelatedProject();
    if (project.isPresent()) {
        return project.get().getLocation().append(location.getTarget()).toString();
    }
    return location.getTarget();
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 4 with Project

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

the class NewJavaSourceFileAction method updateProjectAction.

@Override
public void updateProjectAction(ActionEvent e) {
    final Resource resource = appContext.getResource();
    if (resource == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    final Optional<Project> project = resource.getRelatedProject();
    if (!project.isPresent()) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    e.getPresentation().setEnabledAndVisible(isJavaProject(project.get()) && resource.getParentWithMarker(ID).isPresent());
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 5 with Project

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

the class OutputDirMacro method expand.

@Override
public Promise<String> expand() {
    final Resource[] resources = appContext.getResources();
    if (resources != null && resources.length == 1) {
        final Resource resource = resources[0];
        final Optional<Project> project = resource.getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        Project relatedProject = project.get();
        if (!isJavaProject(relatedProject)) {
            return promises.resolve("");
        }
        if (relatedProject.getAttributes().containsKey(OUTPUT_FOLDER)) {
            return promises.resolve(appContext.getProjectsRoot().append(relatedProject.getLocation()).append(relatedProject.getAttributes().get(OUTPUT_FOLDER).get(0)).toString());
        } else {
            return promises.resolve(appContext.getProjectsRoot().append(relatedProject.getLocation()).toString());
        }
    }
    return promises.resolve("");
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) JavaUtil.isJavaProject(org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject) Resource(org.eclipse.che.ide.api.resources.Resource)

Aggregations

Project (org.eclipse.che.ide.api.resources.Project)127 Resource (org.eclipse.che.ide.api.resources.Resource)74 OperationException (org.eclipse.che.api.promises.client.OperationException)53 Operation (org.eclipse.che.api.promises.client.Operation)51 PromiseError (org.eclipse.che.api.promises.client.PromiseError)48 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)24 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)18 Promise (org.eclipse.che.api.promises.client.Promise)16 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)14 Container (org.eclipse.che.ide.api.resources.Container)14 List (java.util.List)12 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)12 Path (org.eclipse.che.ide.resource.Path)12 Optional (com.google.common.base.Optional)11 ArrayList (java.util.ArrayList)10 File (org.eclipse.che.ide.api.resources.File)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 FunctionException (org.eclipse.che.api.promises.client.FunctionException)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8