Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Explorer UI improvements #8581

Merged
merged 2 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface IdeActions {
String GROUP_PROJECT_EXPLORER_CONTEXT_MENU = "projectExplorerContextMenu";
String GROUP_EDITOR_TAB_CONTEXT_MENU = "editorTabContextMenu";
String GROUP_CONSOLES_TREE_CONTEXT_MENU = "consolesTreeContextMenu";
String GROUP_COMMAND_EXPLORER_CONTEXT_MENU = "commandExplorerContextMenu";
String GROUP_EDITOR_CONTEXT_MENU = "editorContextMenu";

String GROUP_PART_MENU = "partMenu";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import javax.validation.constraints.NotNull;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.api.promises.client.callback.CallbackPromiseHelper;
Expand All @@ -30,12 +28,15 @@
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.PromisableAction;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.command.CommandImpl;
import org.eclipse.che.ide.api.command.CommandManager;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.parts.ActivePartChangedEvent;
import org.eclipse.che.ide.api.parts.ActivePartChangedHandler;
import org.eclipse.che.ide.api.parts.PartPresenter;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.selection.Selection;
import org.eclipse.che.ide.command.explorer.CommandsExplorerPresenter;
import org.eclipse.che.ide.command.explorer.CommandsExplorerView;
import org.eclipse.che.ide.resources.DeleteResourceManager;

/**
Expand All @@ -51,87 +52,98 @@ public class DeleteResourceAction extends AbstractPerspectiveAction implements P

private final DeleteResourceManager deleteResourceManager;
private final AppContext appContext;
private final CommandsExplorerPresenter commandsExplorer;
private final CommandManager commandManager;

private Callback<Void, Throwable> actionCompletedCallBack;
private PartPresenter partPresenter;
private PartPresenter activePart;

@Inject
public DeleteResourceAction(
Resources resources,
DeleteResourceManager deleteResourceManager,
CoreLocalizationConstant localization,
AppContext appContext,
EventBus eventBus) {
EventBus eventBus,
CommandsExplorerPresenter commandsExplorer,
CommandManager commandManager) {
super(
singletonList(PROJECT_PERSPECTIVE_ID),
localization.deleteItemActionText(),
localization.deleteItemActionDescription(),
resources.delete());
this.deleteResourceManager = deleteResourceManager;
this.appContext = appContext;
this.commandsExplorer = commandsExplorer;
this.commandManager = commandManager;

eventBus.addHandler(
ActivePartChangedEvent.TYPE,
new ActivePartChangedHandler() {
@Override
public void onActivePartChanged(ActivePartChangedEvent event) {
partPresenter = event.getActivePart();
}
});
eventBus.addHandler(ActivePartChangedEvent.TYPE, event -> activePart = event.getActivePart());
}

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
deleteResourceManager
.delete(true, appContext.getResources())
.then(
new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
if (actionCompletedCallBack != null) {
actionCompletedCallBack.onSuccess(null);
}
}
})
.catchError(
new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (actionCompletedCallBack != null) {
actionCompletedCallBack.onFailure(arg.getCause());
}
}
});
if (activePart instanceof CommandsExplorerPresenter) {
CommandImpl command =
((CommandsExplorerView) commandsExplorer.getView()).getSelectedCommand();
if (command != null) {
commandManager
.removeCommand(command.getName())
.then(this::onSuccess)
.catchError(this::onFailure);
}
} else {
deleteResourceManager
.delete(true, appContext.getResources())
.then(this::onSuccess)
.catchError(this::onFailure);
}
}

/** {@inheritDoc} */
@Override
public void updateInPerspective(@NotNull ActionEvent event) {
event.getPresentation().setVisible(true);

if (activePart instanceof CommandsExplorerPresenter) {
CommandImpl command =
((CommandsExplorerView) commandsExplorer.getView()).getSelectedCommand();
event.getPresentation().setEnabled(command != null);
return;
}

final Resource[] resources = appContext.getResources();

event.getPresentation().setVisible(true);
event
.getPresentation()
.setEnabled(
resources != null
&& resources.length > 0
&& !(partPresenter instanceof TextEditor)
&& !(partPresenter.getSelection() instanceof Selection.NoSelectionProvided));
&& !(activePart instanceof TextEditor)
&& !(activePart.getSelection() instanceof Selection.NoSelectionProvided));
}

/** {@inheritDoc} */
@Override
public Promise<Void> promise(final ActionEvent event) {
final CallbackPromiseHelper.Call<Void, Throwable> call =
new CallbackPromiseHelper.Call<Void, Throwable>() {
@Override
public void makeCall(Callback<Void, Throwable> callback) {
actionCompletedCallBack = callback;
actionPerformed(event);
}
callback -> {
actionCompletedCallBack = callback;
actionPerformed(event);
};

return createFromCallback(call);
}

private void onSuccess(Void arg) {
if (actionCompletedCallBack != null) {
actionCompletedCallBack.onSuccess(arg);
}
}

private void onFailure(PromiseError error) {
if (actionCompletedCallBack != null) {
actionCompletedCallBack.onFailure(error.getCause());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.command.actions;

import com.google.gwt.i18n.client.Messages;

public interface ActionMessages extends Messages {
@Key("rename.command.action.title")
String renameCommandActionTitle();

@Key("rename.command.action.description")
String renameCommandActionDescription();

@Key("move.command.action.title")
String moveCommandActionTitle();

@Key("move.command.action.description")
String moveCommandActionDescription();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.command.actions;

import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.che.ide.api.action.ActionManager;
import org.eclipse.che.ide.api.action.IdeActions;
import org.eclipse.che.ide.api.keybinding.KeyBindingAgent;
import org.eclipse.che.ide.api.parts.PerspectiveManager;
import org.eclipse.che.ide.menu.ContextMenu;

public class CommandExplorerContextMenu extends ContextMenu {

@Inject
public CommandExplorerContextMenu(
ActionManager actionManager,
KeyBindingAgent keyBindingAgent,
Provider<PerspectiveManager> managerProvider) {
super(actionManager, keyBindingAgent, managerProvider);
}

@Override
protected String getGroupMenu() {
return IdeActions.GROUP_COMMAND_EXPLORER_CONTEXT_MENU;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.command.actions;

import static org.eclipse.che.ide.FontAwesome.SHARE_SQUARE;

import com.google.gwt.core.client.Scheduler;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.DelayedTask;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.BaseAction;
import org.eclipse.che.ide.api.command.CommandImpl;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.command.editor.CommandEditor;
import org.eclipse.che.ide.command.editor.page.goal.GoalPage;
import org.eclipse.che.ide.command.explorer.CommandsExplorerPresenter;
import org.eclipse.che.ide.command.explorer.CommandsExplorerView;
import org.eclipse.che.ide.command.node.NodeFactory;

@Singleton
public class MoveCommandAction extends BaseAction {

private CommandsExplorerPresenter commandsExplorer;
private NodeFactory nodeFactory;
private EditorAgent editorAgent;

@Inject
public MoveCommandAction(
CommandsExplorerPresenter commandsExplorer,
NodeFactory nodeFactory,
EditorAgent editorAgent,
ActionMessages messages) {
super(messages.moveCommandActionTitle(), messages.moveCommandActionDescription(), SHARE_SQUARE);
this.commandsExplorer = commandsExplorer;
this.nodeFactory = nodeFactory;
this.editorAgent = editorAgent;
}

@Override
public void update(ActionEvent e) {
CommandImpl command = ((CommandsExplorerView) commandsExplorer.getView()).getSelectedCommand();

e.getPresentation().setEnabledAndVisible(command != null);
}

@Override
public void actionPerformed(ActionEvent e) {
CommandImpl command = ((CommandsExplorerView) commandsExplorer.getView()).getSelectedCommand();

editorAgent.openEditor(
nodeFactory.newCommandFileNode(command),
new EditorAgent.OpenEditorCallback() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {}

@Override
public void onEditorActivated(EditorPartPresenter editor) {
if (editor instanceof CommandEditor) {
new DelayedTask() {
@Override
public void onExecute() {
((CommandEditor) editor)
.getPages()
.stream()
.filter(page -> page instanceof GoalPage)
.findFirst()
.ifPresent(page -> Scheduler.get().scheduleFinally(page::focus));
}
}.delay(500);
}
}

@Override
public void onInitializationFailed() {}
});
}
}
Loading