Search in sources :

Example 6 with ResourceDelta

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

the class RefactoringUpdater method updateAfterRefactoring.

/**
     * Iterates over each refactoring change and according to change type performs specific update operation.
     * i.e. for {@code ChangeName#UPDATE} updates only opened editors, for {@code ChangeName#MOVE or ChangeName#RENAME_COMPILATION_UNIT}
     * updates only new paths and opened editors, for {@code ChangeName#RENAME_PACKAGE} reloads package structure and restore expansion.
     *
     * @param changes
     *         applied changes
     */
public void updateAfterRefactoring(List<ChangeInfo> changes) {
    if (changes == null || changes.isEmpty()) {
        return;
    }
    ExternalResourceDelta[] deltas = new ExternalResourceDelta[0];
    final List<String> pathChanged = new ArrayList<>();
    for (ChangeInfo change : changes) {
        final ExternalResourceDelta delta;
        final Path newPath = Path.valueOf(change.getPath());
        final Path oldPath = !isNullOrEmpty(change.getOldPath()) ? Path.valueOf(change.getOldPath()) : Path.EMPTY;
        switch(change.getName()) {
            case MOVE:
            case RENAME_COMPILATION_UNIT:
                delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
                registerRemovedFile(change);
                break;
            case RENAME_PACKAGE:
                delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
                break;
            case UPDATE:
                if (!isFileRemoved(change.getPath(), changes)) {
                    pathChanged.add(change.getPath());
                    registerRemovedFile(change);
                }
            default:
                continue;
        }
        final int index = deltas.length;
        deltas = Arrays.copyOf(deltas, index + 1);
        deltas[index] = delta;
    }
    //here we need to remove file for file that moved or renamed JDT lib sent it to
    for (int i = 0; i < deltas.length; i++) {
        if (pathChanged.contains(deltas[i].getToPath().toString())) {
            pathChanged.remove(deltas[i].getToPath().toString());
        }
        if (pathChanged.contains(deltas[i].getFromPath().toString())) {
            pathChanged.remove(deltas[i].getFromPath().toString());
        }
    }
    if (deltas.length > 0) {
        appContext.getWorkspaceRoot().synchronize(deltas).then(new Operation<ResourceDelta[]>() {

            @Override
            public void apply(final ResourceDelta[] appliedDeltas) throws OperationException {
                for (ResourceDelta delta : appliedDeltas) {
                    eventBus.fireEvent(new RevealResourceEvent(delta.getToPath()));
                }
                for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
                    final String path = editorPartPresenter.getEditorInput().getFile().getLocation().toString();
                    if (pathChanged.contains(path)) {
                        eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
                    }
                }
                setActiveEditor();
            }
        });
    } else {
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

            @Override
            public void execute() {
                for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
                    eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
                }
                setActiveEditor();
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Path(org.eclipse.che.ide.resource.Path) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) Scheduler(com.google.gwt.core.client.Scheduler) ArrayList(java.util.ArrayList) ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with ResourceDelta

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

the class EditorTabWidget method onResourceChanged.

@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    if (delta.getKind() == ADDED) {
        if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
            return;
        }
        final Resource resource = delta.getResource();
        final Path movedFrom = delta.getFromPath();
        if (file.getLocation().equals(movedFrom)) {
            file = (VirtualFile) resource;
            title.setText(file.getDisplayName());
        }
    } else if (delta.getKind() == UPDATED) {
        if (!delta.getResource().isFile()) {
            return;
        }
        final Resource resource = delta.getResource();
        if (file.getLocation().equals(resource.getLocation())) {
            file = (VirtualFile) resource;
            title.setText(file.getDisplayName());
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 8 with ResourceDelta

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

the class CopyPasteManager method onResourceChanged.

@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    //delta should be removed and resources is not null
    if (delta.getKind() != REMOVED || resources == null) {
        return;
    }
    for (int i = 0; i < resources.length; i++) {
        final Resource resource = resources[i];
        if (delta.getResource().getLocation().isPrefixOf(resource.getLocation())) {
            int size = resources.length;
            int numMoved = resources.length - i - 1;
            if (numMoved > 0) {
                System.arraycopy(resources, i + 1, resources, i, numMoved);
            }
            resources = copyOf(resources, --size);
        }
    }
}
Also used : ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 9 with ResourceDelta

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

the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFileLocationIsChanged.

@Test
public void shouldUpdatePathForGroupWhenFileLocationIsChanged() {
    Resource resource = mock(Resource.class);
    ResourceDelta delta = mock(ResourceDelta.class);
    ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
    Path fromPath = new Path(FILE_PATH);
    Path toPath = new Path("testProject/src/main/java/org/eclipse/che/examples/changedFile");
    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(true);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
    final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(fromPath);
    final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(toPath);
    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 10 with ResourceDelta

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

the class EmptyEditorsPanel method onResourceChanged.

@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;
    }
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            updateOnProjectsChange();
        }
    });
}
Also used : ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Scheduler(com.google.gwt.core.client.Scheduler) Resource(org.eclipse.che.ide.api.resources.Resource) CssResource(com.google.gwt.resources.client.CssResource)

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