Search in sources :

Example 1 with ActivePartChangedHandler

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

the class OpenFileAction method promise.

@Override
public Promise<Void> promise(final ActionEvent actionEvent) {
    if (actionEvent.getParameters() == null) {
        return Promises.reject(JsPromiseError.create(localization.canNotOpenFileWithoutParams()));
    }
    final String pathToOpen = actionEvent.getParameters().get(FILE_PARAM_ID);
    if (pathToOpen == null) {
        return Promises.reject(JsPromiseError.create(localization.fileToOpenIsNotSpecified()));
    }
    final Call<Void, Throwable> call = new Call<Void, Throwable>() {

        HandlerRegistration handlerRegistration;

        @Override
        public void makeCall(final Callback<Void, Throwable> callback) {
            actionCompletedCallback = callback;
            handlerRegistration = eventBus.addHandler(ActivePartChangedEvent.TYPE, new ActivePartChangedHandler() {

                @Override
                public void onActivePartChanged(ActivePartChangedEvent event) {
                    if (event.getActivePart() instanceof EditorPartPresenter) {
                        EditorPartPresenter editor = (EditorPartPresenter) event.getActivePart();
                        handlerRegistration.removeHandler();
                        if (Path.valueOf(pathToOpen).equals(editor.getEditorInput().getFile().getLocation())) {
                            callback.onSuccess(null);
                        }
                    }
                }
            });
            actionPerformed(actionEvent);
        }
    };
    return createFromCallback(call);
}
Also used : HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) ActivePartChangedHandler(org.eclipse.che.ide.api.event.ActivePartChangedHandler) Call(org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper.Call) CallbackPromiseHelper.createFromCallback(org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper.createFromCallback) Callback(com.google.gwt.core.client.Callback) ActivePartChangedEvent(org.eclipse.che.ide.api.event.ActivePartChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 2 with ActivePartChangedHandler

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

the class FileWatcher method handleFileOperations.

@Inject
private void handleFileOperations(EventBus eventBus) {
    eventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {

        @Override
        public void onResourceChanged(ResourceChangedEvent event) {
            if (event.getDelta().getKind() != REMOVED) {
                return;
            }
            if ((event.getDelta().getFlags() & DERIVED) == 0) {
                return;
            }
            final Resource resource = event.getDelta().getResource();
            final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
            if (srcFolder.isPresent()) {
                reparseAllOpenedFiles();
            }
        }
    });
    eventBus.addHandler(ActivePartChangedEvent.TYPE, new ActivePartChangedHandler() {

        @Override
        public void onActivePartChanged(ActivePartChangedEvent event) {
            if (event.getActivePart() instanceof TextEditor) {
                if (editor2reconcile.contains(event.getActivePart())) {
                    reParseEditor((TextEditor) event.getActivePart());
                }
            }
        }
    });
}
Also used : ActivePartChangedHandler(org.eclipse.che.ide.api.event.ActivePartChangedHandler) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Optional(com.google.common.base.Optional) ActivePartChangedEvent(org.eclipse.che.ide.api.event.ActivePartChangedEvent) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) Inject(com.google.inject.Inject)

Aggregations

ActivePartChangedEvent (org.eclipse.che.ide.api.event.ActivePartChangedEvent)2 ActivePartChangedHandler (org.eclipse.che.ide.api.event.ActivePartChangedHandler)2 Optional (com.google.common.base.Optional)1 Callback (com.google.gwt.core.client.Callback)1 Inject (com.google.inject.Inject)1 HandlerRegistration (com.google.web.bindery.event.shared.HandlerRegistration)1 Call (org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper.Call)1 CallbackPromiseHelper.createFromCallback (org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper.createFromCallback)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)1