Search in sources :

Example 41 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorPartStackPresenter method onCloseNonPinnedEditors.

/** {@inheritDoc} */
@Override
public void onCloseNonPinnedEditors(CloseNonPinnedEditorsEvent event) {
    EditorPartPresenter editorPart = event.getEditorTab().getRelativeEditorPart();
    if (!containsPart(editorPart)) {
        return;
    }
    Iterable<TabItem> nonPinned = filter(parts.keySet(), new Predicate<TabItem>() {

        @Override
        public boolean apply(@Nullable TabItem input) {
            return input instanceof EditorTab && !((EditorTab) input).isPinned();
        }
    });
    for (final TabItem tabItem : nonPinned) {
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

            @Override
            public void execute() {
                eventBus.fireEvent(FileEvent.createCloseFileEvent((EditorTab) tabItem));
            }
        });
    }
}
Also used : TabItem(org.eclipse.che.ide.api.parts.PartStackView.TabItem) EditorTab(org.eclipse.che.ide.api.parts.EditorTab) Scheduler(com.google.gwt.core.client.Scheduler) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 42 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class SwitchNextEditorAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent event) {
    final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    checkNotNull(activeEditor, "Null editor occurred");
    final EditorPartPresenter previousEditor = getNextEditorBaseOn(activeEditor);
    editorAgent.activateEditor(previousEditor);
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 43 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class RunClassTestAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final StatusNotification notification = new StatusNotification("Running Tests...", PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    final Project project = appContext.getRootProject();
    EditorPartPresenter editorPart = editorAgent.getActiveEditor();
    final VirtualFile file = editorPart.getEditorInput().getFile();
    String fqn = JavaUtil.resolveFQN(file);
    Map<String, String> parameters = new HashMap<>();
    parameters.put("fqn", fqn);
    parameters.put("runClass", "true");
    parameters.put("updateClasspath", "true");
    Promise<TestResult> testResultPromise = service.getTestResult(project.getPath(), "testng", parameters);
    testResultPromise.then(new Operation<TestResult>() {

        @Override
        public void apply(TestResult result) throws OperationException {
            notification.setStatus(SUCCESS);
            if (result.isSuccess()) {
                notification.setTitle("Test runner executed successfully");
                notification.setContent("All tests are passed");
            } else {
                notification.setTitle("Test runner executed successfully with test failures.");
                notification.setContent(result.getFailureCount() + " test(s) failed.\n");
            }
            presenter.handleResponse(result);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError exception) throws OperationException {
            final String errorMessage = (exception.getMessage() != null) ? exception.getMessage() : "Failed to run test cases";
            notification.setContent(errorMessage);
            notification.setStatus(FAIL);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) HashMap(java.util.HashMap) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) TestResult(org.eclipse.che.api.testing.shared.TestResult) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 44 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class FormatterAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
    final EditorPartPresenter editor = editorAgent.getActiveEditor();
    boolean isCanDoOperation = false;
    HandlesTextOperations handlesOperations;
    if (editor instanceof HandlesTextOperations) {
        handlesOperations = (HandlesTextOperations) editor;
        isCanDoOperation = handlesOperations.canDoOperation(TextEditorOperations.FORMAT);
    }
    event.getPresentation().setEnabled(isCanDoOperation);
}
Also used : HandlesTextOperations(org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 45 with EditorPartPresenter

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

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)79 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)21 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)19 OperationException (org.eclipse.che.api.promises.client.OperationException)13 Project (org.eclipse.che.ide.api.resources.Project)13 Resource (org.eclipse.che.ide.api.resources.Resource)11 Test (org.junit.Test)10 Operation (org.eclipse.che.api.promises.client.Operation)9 Path (org.eclipse.che.ide.resource.Path)8 File (org.eclipse.che.ide.api.resources.File)7 Scheduler (com.google.gwt.core.client.Scheduler)6 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)6 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)6 Optional (com.google.common.base.Optional)5 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 HandlesTextOperations (org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 JsonObject (elemental.json.JsonObject)3