Search in sources :

Example 6 with RevealResourceEvent

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

use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.

the class NewJavaSourceFilePresenter method createSourceFile.

private void createSourceFile(final String nameWithoutExtension, String packageFragment, final String content) {
    if (!isNullOrEmpty(packageFragment)) {
        parent.newFolder(packageFragment.replace('.', '/')).then(pkg -> {
            pkg.newFile(nameWithoutExtension + ".java", content).then(file -> {
                eventBus.fireEvent(FileEvent.createOpenFileEvent(file));
                eventBus.fireEvent(new RevealResourceEvent(file));
            });
        });
    } else {
        parent.newFile(nameWithoutExtension + ".java", content).then(file -> {
            eventBus.fireEvent(FileEvent.createOpenFileEvent(file));
            eventBus.fireEvent(new RevealResourceEvent(file));
        });
    }
}
Also used : RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent)

Example 8 with RevealResourceEvent

use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.

the class UploadFilePresenter method onSubmitComplete.

/** {@inheritDoc} */
@Override
public void onSubmitComplete(String result) {
    if (!isNullOrEmpty(result)) {
        view.closeDialog();
        notificationManager.notify(locale.failedToUploadFiles(), parseMessage(result), StatusNotification.Status.FAIL, FLOAT_MODE);
        return;
    }
    container.getFile(Path.valueOf(view.getFileName())).then(new Operation<Optional<File>>() {

        @Override
        public void apply(final Optional<File> file) throws OperationException {
            if (file.isPresent()) {
                eventBus.fireEvent(new RevealResourceEvent(file.get()));
                final NotificationListener notificationListener = new NotificationListener() {

                    boolean clicked = false;

                    @Override
                    public void onClick(Notification notification) {
                        if (!clicked) {
                            eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
                            clicked = true;
                            notification.setListener(null);
                            notification.setContent("");
                        }
                    }

                    @Override
                    public void onDoubleClick(Notification notification) {
                    //stub
                    }

                    @Override
                    public void onClose(Notification notification) {
                    //stub
                    }
                };
                notificationManager.notify("File '" + view.getFileName() + "' has uploaded successfully", "Click here to open it", StatusNotification.Status.SUCCESS, FLOAT_MODE, notificationListener);
                view.closeDialog();
            }
        }
    });
//TODO this should process editor agent
//        if (view.isOverwriteFileSelected()) {
//            String path = ((HasStorablePath)getResourceBasedNode()).getStorablePath() + "/" + view.getFileName();
//            eventBus.fireEvent(new FileContentUpdateEvent(path));
//        }
}
Also used : Optional(com.google.common.base.Optional) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException) Notification(org.eclipse.che.ide.api.notification.Notification) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) NotificationListener(org.eclipse.che.ide.api.notification.NotificationListener)

Example 9 with RevealResourceEvent

use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.

the class NewPackageAction method onAccepted.

private void onAccepted(String value) {
    final Resource resource = appContext.getResource();
    checkState(resource instanceof Container, "Parent should be a container");
    ((Container) resource).newFolder(value.replace('.', '/')).then(new Operation<Folder>() {

        @Override
        public void apply(Folder pkg) throws OperationException {
            eventBus.fireEvent(new RevealResourceEvent(pkg));
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            dialogFactory.createMessageDialog(coreLocalizationConstant.invalidName(), error.getMessage(), null).show();
        }
    });
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Folder(org.eclipse.che.ide.api.resources.Folder) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 10 with RevealResourceEvent

use of org.eclipse.che.ide.resources.reveal.RevealResourceEvent in project che by eclipse.

the class EditorAgentImpl method onActivePartChanged.

@Override
public void onActivePartChanged(ActivePartChangedEvent event) {
    activePart = event.getActivePart();
    if (!(event.getActivePart() instanceof EditorPartPresenter)) {
        return;
    }
    activeEditor = (EditorPartPresenter) event.getActivePart();
    activeEditor.activate();
    final String isLinkedWithEditor = preferencesManager.getValue(LinkWithEditorAction.LINK_WITH_EDITOR);
    if (parseBoolean(isLinkedWithEditor)) {
        final VirtualFile file = activeEditor.getEditorInput().getFile();
        eventBus.fireEvent(new RevealResourceEvent(file.getLocation()));
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent)

Aggregations

RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)11 OperationException (org.eclipse.che.api.promises.client.OperationException)7 Resource (org.eclipse.che.ide.api.resources.Resource)6 Operation (org.eclipse.che.api.promises.client.Operation)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 Container (org.eclipse.che.ide.api.resources.Container)3 Path (org.eclipse.che.ide.resource.Path)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 Function (org.eclipse.che.api.promises.client.Function)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 Promise (org.eclipse.che.api.promises.client.Promise)2 RequestCall (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall)2 CancelCallback (org.eclipse.che.ide.api.dialogs.CancelCallback)2 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)2 InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)2 File (org.eclipse.che.ide.api.resources.File)2 Folder (org.eclipse.che.ide.api.resources.Folder)2 Optional (com.google.common.base.Optional)1 Scheduler (com.google.gwt.core.client.Scheduler)1