Search in sources :

Example 1 with ExternalResourceDelta

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

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

the class EditorFileStatusNotificationOperation method apply.

public void apply(String endpointId, FileStateUpdateDto params) {
    final FileWatcherEventType status = params.getType();
    final String stringPath = params.getPath();
    final String name = stringPath.substring(stringPath.lastIndexOf("/") + 1);
    switch(status) {
        case MODIFIED:
            {
                Log.debug(getClass(), "Received updated file event status: " + stringPath);
                eventBus.fireEvent(new FileContentUpdateEvent(stringPath, params.getHashCode()));
                break;
            }
        case DELETED:
            {
                Log.debug(getClass(), "Received removed file event status: " + stringPath);
                final Path path = Path.valueOf(stringPath);
                appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(path, path, REMOVED));
                if (notificationManager != null && !deletedFilesController.remove(stringPath)) {
                    notificationManager.notify("External operation", "File '" + name + "' is removed", SUCCESS, EMERGE_MODE);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType)

Example 3 with ExternalResourceDelta

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

the class ProjectTreeStateNotificationOperation method apply.

@Override
public void apply(String endpointId, ProjectTreeStateUpdateDto params) throws JsonRpcException {
    final String path = params.getPath();
    final FileWatcherEventType type = params.getType();
    final int status;
    switch(type) {
        case CREATED:
            {
                status = ADDED;
                break;
            }
        case DELETED:
            {
                status = REMOVED;
                break;
            }
        case MODIFIED:
            {
                status = UPDATED;
                break;
            }
        default:
            {
                status = UPDATED;
                break;
            }
    }
    Log.debug(getClass(), "Received request\npath: " + path + "\ntype:" + type + "\nstatus:" + status);
    if (path == null || path.isEmpty()) {
        appContext.getWorkspaceRoot().synchronize();
    } else {
        appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), status));
    }
    if (status == ADDED) {
        appContext.getWorkspaceRoot().getFile(Path.valueOf(path)).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> arg) throws OperationException {
                if (arg.isPresent()) {
                    appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(Path.valueOf(path), Path.valueOf(path), UPDATED));
                }
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Optional(com.google.common.base.Optional) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ExternalResourceDelta (org.eclipse.che.ide.api.resources.ExternalResourceDelta)3 FileWatcherEventType (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)2 Path (org.eclipse.che.ide.resource.Path)2 Optional (com.google.common.base.Optional)1 Scheduler (com.google.gwt.core.client.Scheduler)1 ArrayList (java.util.ArrayList)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 File (org.eclipse.che.ide.api.resources.File)1 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)1 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)1