Skip to content

Commit

Permalink
CHE-4774: Improvements for command toolbar (#4875)
Browse files Browse the repository at this point in the history
  • Loading branch information
azatsarynnyy authored Apr 24, 2017
1 parent 6403d21 commit 43ac679
Show file tree
Hide file tree
Showing 36 changed files with 537 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void start(Callback<WsAgentComponent, Exception> callback) {

refreshView();

eventBus.addHandler(CommandAddedEvent.getType(), e -> refreshView());
eventBus.addHandler(CommandAddedEvent.getType(), e -> refreshViewAndSelectCommand(e.getCommand()));
eventBus.addHandler(CommandRemovedEvent.getType(), e -> refreshView());
eventBus.addHandler(CommandUpdatedEvent.getType(), e -> refreshView());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CommandCreationGuide(Provider<WorkspaceAgent> workspaceAgentProvider,
}


/** Shows the guide of creating a command. */
/** Shows the guide of creating a command of the 'Run' goal. */
public void guide() {
guide(runGoal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import org.eclipse.che.ide.command.toolbar.commands.ExecuteCommandPresenter;
import org.eclipse.che.ide.command.toolbar.previews.PreviewsPresenter;
import org.eclipse.che.ide.command.toolbar.processes.ProcessesListPresenter;
import org.eclipse.che.ide.ui.menubutton.MenuButton;

import javax.inject.Inject;
import javax.inject.Singleton;

/** Presenter for command toolbar. */
/** Presenter for the commands toolbar. */
@Singleton
public class CommandToolbarPresenter implements Presenter, CommandToolbarView.ActionDelegate {

Expand All @@ -32,7 +31,7 @@ public class CommandToolbarPresenter implements Presenter, CommandToolbarView.Ac
private final ExecuteCommandPresenter executeCommandPresenter;
private final ToolbarButtonsFactory toolbarButtonsFactory;
private final CommandToolbarView view;
private MenuButton openCommandsPaletteButton;
private ToolbarButton openCommandsPaletteButton;

@Inject
public CommandToolbarPresenter(CommandToolbarView view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.gwt.user.client.ui.AcceptsOneWidget;

import org.eclipse.che.ide.api.mvp.View;
import org.eclipse.che.ide.ui.menubutton.MenuButton;

/** View for command toolbar. */
public interface CommandToolbarView extends View<CommandToolbarView.ActionDelegate> {
Expand All @@ -24,7 +23,7 @@ public interface CommandToolbarView extends View<CommandToolbarView.ActionDelega

AcceptsOneWidget getPreviewUrlsListContainer();

void addButton(MenuButton button);
void addButton(ToolbarButton button);

interface ActionDelegate {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

import org.eclipse.che.ide.ui.menubutton.MenuButton;

import javax.inject.Inject;
import javax.inject.Singleton;

Expand Down Expand Up @@ -73,7 +71,7 @@ public AcceptsOneWidget getPreviewUrlsListContainer() {
}

@Override
public void addButton(MenuButton button) {
public void addButton(ToolbarButton button) {
buttonsPanel.add(button);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

.processesListPanel {
width: literal("calc(100% - 285px)");
width: literal("calc(100% - 290px)");
float: left;
margin-left: 15px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,15 @@
import org.eclipse.che.ide.command.palette.PaletteMessages;
import org.eclipse.che.ide.command.palette.ShowCommandsPaletteAction;
import org.eclipse.che.ide.ui.Tooltip;
import org.eclipse.che.ide.ui.menubutton.ItemsProvider;
import org.eclipse.che.ide.ui.menubutton.MenuButton;
import org.eclipse.che.ide.ui.menubutton.MenuItem;
import org.eclipse.che.ide.util.Pair;
import org.eclipse.che.ide.util.dom.Elements;
import org.eclipse.che.ide.util.input.CharCodeWithModifiers;
import org.eclipse.che.ide.util.input.KeyMapUtil;

import java.util.List;
import java.util.Optional;

import static java.util.Collections.emptyList;
import static org.eclipse.che.ide.ui.menu.PositionController.HorizontalAlign.MIDDLE;
import static org.eclipse.che.ide.ui.menu.PositionController.VerticalAlign.BOTTOM;

/** Button for opening Commands Palette. */
class OpenCommandsPaletteButton extends MenuButton {
class OpenCommandsPaletteButton extends ToolbarButton {

private final Provider<ActionManager> actionManagerProvider;
private final Provider<KeyBindingAgent> keyBindingAgentProvider;
Expand All @@ -55,31 +47,7 @@ class OpenCommandsPaletteButton extends MenuButton {
Provider<KeyBindingAgent> keyBindingAgentProvider,
Provider<ShowCommandsPaletteAction> showCommandsPaletteActionProvider,
@Assisted SafeHtml content) {
super(content, new ItemsProvider() {
@Override
public Optional<MenuItem> getDefaultItem() {
return Optional.empty();
}

@Override
public List<MenuItem> getItems() {
return emptyList();
}

@Override
public boolean isGroup(MenuItem item) {
return false;
}

@Override
public Pair<List<MenuItem>, String> getChildren(MenuItem parent) {
return null;
}

@Override
public void setDataChangedHandler(DataChangedHandler handler) {
}
});
super(content);

this.actionManagerProvider = actionManagerProvider;
this.keyBindingAgentProvider = keyBindingAgentProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* 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:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.command.toolbar;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.ui.FocusWidget;

/** Button for the commands toolbar. */
class ToolbarButton extends FocusWidget {

private static final Resources RESOURCES;

ToolbarButton(SafeHtml content) {
super(Document.get().createDivElement());

getElement().setInnerSafeHtml(content);

addStyleName(RESOURCES.css().button());
}

public interface Resources extends ClientBundle {
@Source({"button.css", "org/eclipse/che/ide/api/ui/style.css"})
Css css();
}

public interface Css extends CssResource {
String button();
}

static {
RESOURCES = GWT.create(Resources.class);
RESOURCES.css().ensureInjected();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public interface ToolbarMessages extends Messages {

@Key("guide.label")
String guideItemLabel();
String guideItemLabel(String goalName);

@Key("goal_button.tooltip.no_command")
String goalButtonTooltipNoCommand(String goalId);
Expand All @@ -37,6 +37,9 @@ public interface ToolbarMessages extends Messages {
@Key("previews.tooltip")
String previewsTooltip();

@Key("previews.no_previews")
String previewsNoPreviews();

@Key("previews.error.not_available")
String previewsNotAvailableError();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public ExecuteCommandButtonFactory(CommandResources resources,
* @return {@link ExecuteCommandButton}
*/
public ExecuteCommandButton newButton(CommandGoal goal, ActionDelegate delegate, @Nullable CharCodeWithModifiers keyBinding) {
final ExecuteCommandButtonItemsProvider itemsProvider = new ExecuteCommandButtonItemsProvider(appContext, menuItemsFactory);
final ExecuteCommandButtonItemsProvider itemsProvider = new ExecuteCommandButtonItemsProvider(appContext,
menuItemsFactory,
goal);
final ExecuteCommandButton button = new ExecuteCommandButton(goal,
getIconForGoal(goal),
itemsProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.command.toolbar.commands.button;

import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.command.CommandGoal;
import org.eclipse.che.ide.api.command.CommandImpl;
import org.eclipse.che.ide.api.machine.MachineEntity;
import org.eclipse.che.ide.ui.menubutton.ItemsProvider;
Expand All @@ -29,16 +30,18 @@
/** Provides items for {@link ExecuteCommandButton}. */
public class ExecuteCommandButtonItemsProvider implements ItemsProvider {

private final Set<CommandImpl> commands;
private final AppContext appContext;
private final MenuItemsFactory menuItemsFactory;
private final CommandGoal goal;
private final Set<CommandImpl> commands;

private DataChangedHandler dataChangedHandler;
private MenuItem defaultItem;

ExecuteCommandButtonItemsProvider(AppContext appContext, MenuItemsFactory menuItemsFactory) {
ExecuteCommandButtonItemsProvider(AppContext appContext, MenuItemsFactory menuItemsFactory, CommandGoal goal) {
this.appContext = appContext;
this.menuItemsFactory = menuItemsFactory;
this.goal = goal;
this.commands = new HashSet<>();
}

Expand All @@ -64,7 +67,7 @@ public List<MenuItem> getItems() {
}

if (items.isEmpty()) {
items.add(menuItemsFactory.newGuideItem());
items.add(menuItemsFactory.newGuideItem(goal));
}

return items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
package org.eclipse.che.ide.command.toolbar.commands.button;

import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;

import org.eclipse.che.ide.api.command.CommandGoal;
import org.eclipse.che.ide.command.toolbar.ToolbarMessages;
import org.eclipse.che.ide.ui.menubutton.MenuItem;

/** A {@link MenuItem} represents a hint which guides the user into the flow of creating a command. */
public class GuideItem implements MenuItem {

private final ToolbarMessages messages;
private final CommandGoal goal;

@Inject
public GuideItem(ToolbarMessages messages) {
public GuideItem(ToolbarMessages messages, @Assisted CommandGoal goal) {
this.messages = messages;
this.goal = goal;
}

@Override
public String getName() {
return messages.guideItemLabel();
return messages.guideItemLabel(goal.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
package org.eclipse.che.ide.command.toolbar.commands.button;

import org.eclipse.che.api.core.model.machine.Machine;
import org.eclipse.che.ide.api.command.CommandGoal;
import org.eclipse.che.ide.api.command.CommandImpl;
import org.eclipse.che.ide.ui.menubutton.MenuItem;

/** Factory for {@link MenuItem}s for {@link ExecuteCommandButton}. */
public interface MenuItemsFactory {

GuideItem newGuideItem();
GuideItem newGuideItem(CommandGoal goal);

CommandItem newCommandItem(CommandImpl command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@
*******************************************************************************/
package org.eclipse.che.ide.command.toolbar.previews;

import elemental.dom.Element;

import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import org.eclipse.che.ide.FontAwesome;
import org.eclipse.che.ide.command.CommandResources;
import org.eclipse.che.ide.command.toolbar.ToolbarMessages;
import org.eclipse.che.ide.ui.Tooltip;
import org.eclipse.che.ide.ui.dropdown.BaseListItem;
import org.eclipse.che.ide.ui.dropdown.DropdownListItemRenderer;

import static com.google.gwt.dom.client.Style.Unit.PX;
import static org.eclipse.che.ide.ui.menu.PositionController.HorizontalAlign.MIDDLE;
import static org.eclipse.che.ide.ui.menu.PositionController.VerticalAlign.BOTTOM;

/**
* Renders widgets for the 'Previews' list. Always returns the same
Expand Down Expand Up @@ -62,7 +56,6 @@ public Widget renderListWidget() {
private static class HeaderWidget extends Label {

private static final CommandResources RESOURCES = GWT.create(CommandResources.class);
private static final ToolbarMessages MESSAGES = GWT.create(ToolbarMessages.class);

HeaderWidget() {
super();
Expand All @@ -72,8 +65,6 @@ private static class HeaderWidget extends Label {
final SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
safeHtmlBuilder.appendHtmlConstant(FontAwesome.BULLSEYE);
getElement().setInnerSafeHtml(safeHtmlBuilder.toSafeHtml());

Tooltip.create((Element)getElement(), BOTTOM, MIDDLE, MESSAGES.previewsTooltip());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.core.model.machine.Machine;
import org.eclipse.che.api.core.model.machine.MachineRuntimeInfo;
import org.eclipse.che.api.core.model.machine.Server;
import org.eclipse.che.api.core.model.workspace.WorkspaceRuntime;
import org.eclipse.che.api.machine.shared.dto.execagent.GetProcessResponseDto;
Expand All @@ -37,7 +38,7 @@
import org.eclipse.che.ide.api.mvp.Presenter;
import org.eclipse.che.ide.command.toolbar.ToolbarMessages;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

import static com.google.common.base.Strings.isNullOrEmpty;
Expand Down Expand Up @@ -98,7 +99,7 @@ private void updateView() {

if (runtime != null) {
runtime.getMachines().forEach(machine -> execAgentClient.getProcesses(machine.getId(), false).then(processes -> {
processes.forEach(process -> getPreviewUrl(process.getPid(), machine).then(view::addUrl));
processes.forEach(process -> getPreviewUrl(process.getPid(), machine).then(view::addUrl).catchError(ignore -> {}));
}));
}
}
Expand Down Expand Up @@ -132,12 +133,20 @@ private Promise<PreviewUrlItem> getPreviewUrl(int pid, Machine machine) {

private Optional<String> getPreviewUrlDisplayName(String previewUrl) {
final DevMachine devMachine = appContext.getDevMachine();
final Map<String, ? extends Server> servers = devMachine.getRuntime().getServers();
final MachineRuntimeInfo devMachineRuntime = devMachine.getRuntime();

for (Map.Entry<String, ? extends Server> entry : servers.entrySet()) {
if (devMachineRuntime == null) {
return Optional.empty();
}

for (Entry<String, ? extends Server> entry : devMachineRuntime.getServers().entrySet()) {
Server server = entry.getValue();
String serverUrl = server.getUrl();

if (serverUrl == null) {
continue;
}

if (previewUrl.startsWith(serverUrl)) {
String displayName = previewUrl.replace(serverUrl, devMachine.getDisplayName() + ':' + entry.getKey());

Expand Down
Loading

0 comments on commit 43ac679

Please sign in to comment.