Search in sources :

Example 1 with ResourceDelta

use of org.eclipse.che.ide.api.resources.ResourceDelta 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 ResourceDelta

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

the class ProjectExplorerPresenter method onResourceChanged.

@Override
@SuppressWarnings("unchecked")
public void onResourceChanged(ResourceChangedEvent event) {
    final Tree tree = view.getTree();
    final ResourceDelta delta = event.getDelta();
    final Resource resource = delta.getResource();
    final NodeSettings nodeSettings = settingsProvider.getSettings();
    // process root projects, they have only one segment in path
    if (resource.getLocation().segmentCount() == 1) {
        if (delta.getKind() == ADDED) {
            if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) != 0) {
                Node node = getNode(delta.getFromPath());
                if (node != null) {
                    boolean expanded = tree.isExpanded(node);
                    tree.getNodeStorage().remove(node);
                    node = nodeFactory.newContainerNode((Container) resource, nodeSettings);
                    tree.getNodeStorage().add(node);
                    if (expanded) {
                        tree.setExpanded(node, true);
                    }
                }
            } else if (getNode(resource.getLocation()) == null) {
                tree.getNodeStorage().add(nodeFactory.newContainerNode((Container) resource, nodeSettings));
            }
        } else if (delta.getKind() == REMOVED) {
            Node node = getNode(resource.getLocation());
            if (node != null) {
                tree.getNodeStorage().remove(node);
            }
        } else if (delta.getKind() == UPDATED) {
            for (Node node : tree.getNodeStorage().getAll()) {
                if (node instanceof ResourceNode && ((ResourceNode) node).getData().getLocation().equals(delta.getResource().getLocation())) {
                    final String oldId = tree.getNodeStorage().getKeyProvider().getKey(node);
                    ((ResourceNode) node).setData(delta.getResource());
                    tree.getNodeStorage().reIndexNode(oldId, node);
                    tree.refresh(node);
                    updateTask.submit(delta.getResource().getLocation());
                }
            }
        }
    } else {
        if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) != 0) {
            final Node node = getNode(delta.getFromPath());
            if (node != null && tree.isExpanded(node)) {
                expandQueue.add(delta.getToPath());
            }
        }
        updateTask.submit(resource.getLocation());
        if (delta.getFromPath() != null) {
            updateTask.submit(delta.getFromPath());
        }
    }
}
Also used : NodeSettings(org.eclipse.che.ide.api.data.tree.settings.NodeSettings) Container(org.eclipse.che.ide.api.resources.Container) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Tree(org.eclipse.che.ide.ui.smartTree.Tree) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 3 with ResourceDelta

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

the class FindResultPresenter method onResourceChanged.

@Override
@SuppressWarnings("unchecked")
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    final Tree tree = view.getTree();
    if (delta.getKind() == REMOVED) {
        for (Node node : tree.getNodeStorage().getAll()) {
            if (node instanceof ResourceNode && ((ResourceNode) node).getData().getLocation().equals(delta.getResource().getLocation())) {
                tree.getNodeStorage().remove(node);
                return;
            }
        }
    }
}
Also used : ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) Tree(org.eclipse.che.ide.ui.smartTree.Tree) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 4 with ResourceDelta

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

the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFolderLocationIsChanged.

@Test
public void shouldUpdatePathForGroupWhenFolderLocationIsChanged() {
    Resource resource = mock(Resource.class);
    ResourceDelta delta = mock(ResourceDelta.class);
    ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
    Path fromPath = new Path(FOLDER_PATH);
    Path toPath = new Path("testProject/src/main/java/org/eclipse/che/samples/");
    Path oldFilePath = new Path(FILE_PATH);
    Path newFilePath = new Path("testProject/src/main/java/org/eclipse/che/samples/" + FILE_NAME);
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    when(delta.getKind()).thenReturn(ResourceDelta.ADDED);
    when(delta.getFlags()).thenReturn(5632);
    when(delta.getFromPath()).thenReturn(fromPath);
    when(delta.getToPath()).thenReturn(toPath);
    when(delta.getResource()).thenReturn(resource);
    when(resource.isFile()).thenReturn(false);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
    final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(oldFilePath);
    final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(newFilePath);
    assertNull(oldGroup);
    assertNotNull(newGroup);
}
Also used : Path(org.eclipse.che.ide.resource.Path) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 5 with ResourceDelta

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

the class EditorContentSynchronizerImpl method onResourceChanged.

@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    if (delta.getKind() != ADDED || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
        return;
    }
    final Path fromPath = delta.getFromPath();
    final Path toPath = delta.getToPath();
    if (delta.getResource().isFile()) {
        onFileChanged(fromPath, toPath);
    } else {
        onFolderChanged(fromPath, toPath);
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta)

Aggregations

ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)11 Resource (org.eclipse.che.ide.api.resources.Resource)7 Path (org.eclipse.che.ide.resource.Path)6 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)4 Scheduler (com.google.gwt.core.client.Scheduler)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)2 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)2 Tree (org.eclipse.che.ide.ui.smartTree.Tree)2 Test (org.junit.Test)2 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)2 CssResource (com.google.gwt.resources.client.CssResource)1 ArrayList (java.util.ArrayList)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 NodeSettings (org.eclipse.che.ide.api.data.tree.settings.NodeSettings)1 FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)1 Container (org.eclipse.che.ide.api.resources.Container)1 ExternalResourceDelta (org.eclipse.che.ide.api.resources.ExternalResourceDelta)1 Project (org.eclipse.che.ide.api.resources.Project)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1