Search in sources :

Example 1 with FileContentUpdateEvent

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

use of org.eclipse.che.ide.api.event.FileContentUpdateEvent in project che by eclipse.

the class ComparePresenter method onClose.

@Override
public void onClose(final String newContent) {
    if (!compareWithLatest || this.localContent == null || newContent.equals(localContent)) {
        view.hide();
        return;
    }
    ConfirmCallback confirmCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            comparedFile.updateContent(newContent).then(new Operation<Void>() {

                @Override
                public void apply(Void ignored) throws OperationException {
                    final Container parent = comparedFile.getParent();
                    if (parent != null) {
                        parent.synchronize();
                    }
                    eventBus.fireEvent(new FileContentUpdateEvent(comparedFile.getLocation().toString()));
                    view.hide();
                }
            });
        }
    };
    CancelCallback cancelCallback = new CancelCallback() {

        @Override
        public void cancelled() {
            view.hide();
        }
    };
    dialogFactory.createConfirmDialog(locale.compareSaveTitle(), locale.compareSaveQuestion(), locale.buttonYes(), locale.buttonNo(), confirmCallback, cancelCallback).show();
}
Also used : FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) Container(org.eclipse.che.ide.api.resources.Container) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with FileContentUpdateEvent

use of org.eclipse.che.ide.api.event.FileContentUpdateEvent 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)

Aggregations

FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 ExternalResourceDelta (org.eclipse.che.ide.api.resources.ExternalResourceDelta)2 Path (org.eclipse.che.ide.resource.Path)2 Scheduler (com.google.gwt.core.client.Scheduler)1 ArrayList (java.util.ArrayList)1 FileWatcherEventType (org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType)1 CancelCallback (org.eclipse.che.ide.api.dialogs.CancelCallback)1 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 Container (org.eclipse.che.ide.api.resources.Container)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