Skip to content

Commit

Permalink
Merge pull request #663 from eclipse/CHE-673
Browse files Browse the repository at this point in the history
CHE-673. Correct handling buttons of Commands dialog when Enter is clicked
  • Loading branch information
RomanNikitenko committed Mar 11, 2016
2 parents de2422f + 4d6379d commit a277622
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,24 @@ public class EditCommandsPresenter implements EditCommandsView.ActionDelegate {
private final EditCommandsView view;
private final WorkspaceServiceClient workspaceServiceClient;
private final CommandManager commandManager;
private final String workspaceId;
private final DtoFactory dtoFactory;
private final CommandTypeRegistry commandTypeRegistry;
private final DialogFactory dialogFactory;
private final MachineLocalizationConstant machineLocale;
private final CoreLocalizationConstant coreLocale;
private final Provider<SelectCommandComboBoxReady> selectCommandActionProvider;
private final Set<ConfigurationChangedListener> configurationChangedListeners;
private final AppContext appContext;
/** Set of the existing command names. */
private final Set<String> commandNames;
private CommandConfigurationPage<CommandConfiguration> editedPage;
/** Command that being edited. */
private CommandConfiguration editedCommand;
/** Name of the edited command before editing. */
private String editedCommandOriginName;
private String editedCommandOriginPreviewUrl;
String editedCommandOriginName;
String editedCommandOriginPreviewUrl;
String workspaceId;
CommandProcessingCallback commandProcessingCallback;

@Inject
protected EditCommandsPresenter(EditCommandsView view,
Expand All @@ -95,15 +97,14 @@ protected EditCommandsPresenter(EditCommandsView view,
this.view = view;
this.workspaceServiceClient = workspaceServiceClient;
this.commandManager = commandManager;
this.workspaceId = appContext.getWorkspace().getId();
this.dtoFactory = dtoFactory;
this.commandTypeRegistry = commandTypeRegistry;
this.dialogFactory = dialogFactory;
this.machineLocale = machineLocale;
this.coreLocale = coreLocale;
this.selectCommandActionProvider = selectCommandActionProvider;
this.view.setDelegate(this);

this.appContext = appContext;
configurationChangedListeners = new HashSet<>();
commandNames = new HashSet<>();
}
Expand Down Expand Up @@ -134,6 +135,7 @@ public void onSaveClicked() {
updateCommand(selectedConfiguration).then(new Operation<UsersWorkspaceDto>() {
@Override
public void apply(UsersWorkspaceDto arg) throws OperationException {
commandProcessingCallback = getCommandProcessingCallback();
fetchCommands();
fireConfigurationUpdated(selectedConfiguration);
}
Expand Down Expand Up @@ -172,6 +174,7 @@ public Promise<UsersWorkspaceDto> apply(UsersWorkspaceDto arg) throws FunctionEx

@Override
public void onCancelClicked() {
commandProcessingCallback = getCommandProcessingCallback();
fetchCommands();
}

Expand Down Expand Up @@ -293,6 +296,7 @@ public void accepted() {
@Override
public void apply(UsersWorkspaceDto arg) throws OperationException {
view.selectNextItem();
commandProcessingCallback = getCommandProcessingCallback();
fetchCommands();
fireConfigurationRemoved(selectedConfiguration);
}
Expand Down Expand Up @@ -324,6 +328,20 @@ public void onExecuteClicked() {
view.close();
}

@Override
public void onEnterClicked() {
if (view.isCancelButtonInFocus()) {
onCancelClicked();
return;
}

if (view.isCloseButtonInFocus()) {
onCloseClicked();
return;
}
onSaveClicked();
}

private void reset() {
editedCommand = null;
editedCommandOriginName = null;
Expand Down Expand Up @@ -436,6 +454,7 @@ public void onPreviewUrlChanged() {

/** Show dialog. */
public void show() {
workspaceId = appContext.getWorkspaceId();
fetchCommands();
view.show();
}
Expand Down Expand Up @@ -497,6 +516,11 @@ public int compare(CommandConfiguration o1, CommandConfiguration o2) {
}
view.setData(categories);
view.setFilterState(!commandConfigurations.isEmpty());

if (commandProcessingCallback != null) {
commandProcessingCallback.onCompleted();
commandProcessingCallback = null;
}
}
}).catchError(new Operation<PromiseError>() {
@Override
Expand Down Expand Up @@ -533,6 +557,15 @@ private void fireConfigurationUpdated(CommandConfiguration command) {
}
}

private CommandProcessingCallback getCommandProcessingCallback() {
return new CommandProcessingCallback() {
@Override
public void onCompleted() {
view.setCloseButtonInFocus();
}
};
}

public void addConfigurationsChangedListener(ConfigurationChangedListener listener) {
configurationChangedListeners.add(listener);
}
Expand All @@ -549,4 +582,9 @@ public interface ConfigurationChangedListener {

void onConfigurationsUpdated(CommandConfiguration command);
}

interface CommandProcessingCallback {
/** Called when handling of command is completed successfully. */
void onCompleted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.che.ide.extension.machine.client.command.CommandType;

import org.eclipse.che.commons.annotation.Nullable;

import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -67,7 +68,7 @@ public interface EditCommandsView extends View<EditCommandsView.ActionDelegate>

/** Sets enabled state of the 'Apply' button. */
void setSaveButtonState(boolean enabled);

/** Sets enabled state of the filter input field. */
void setFilterState(boolean enabled);

Expand All @@ -82,6 +83,15 @@ public interface EditCommandsView extends View<EditCommandsView.ActionDelegate>
@Nullable
CommandConfiguration getSelectedConfiguration();

/** Sets the focus on the 'Close' button. */
void setCloseButtonInFocus();

/** Returns {@code true} if cancel button is in the focus and {@code false} - otherwise. */
boolean isCancelButtonInFocus();

/** Returns {@code true} if close button is in the focus and {@code false} - otherwise. */
boolean isCloseButtonInFocus();

/** Action handler for the view actions/controls. */
interface ActionDelegate {

Expand All @@ -106,6 +116,9 @@ interface ActionDelegate {
/** Called when 'Execute' button is clicked. */
void onExecuteClicked();

/** Performs any actions appropriate in response to the user having clicked the Enter key. */
void onEnterClicked();

/**
* Called when some command configuration is selected.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.che.ide.extension.machine.client.MachineLocalizationConstant;
import org.eclipse.che.ide.extension.machine.client.command.CommandConfiguration;
import org.eclipse.che.ide.extension.machine.client.command.CommandType;
import org.eclipse.che.ide.ui.WidgetFocusTracker;
import org.eclipse.che.ide.ui.list.CategoriesList;
import org.eclipse.che.ide.ui.list.Category;
import org.eclipse.che.ide.ui.list.CategoryRenderer;
Expand All @@ -73,10 +74,12 @@ public class EditCommandsViewImpl extends Window implements EditCommandsView {

private final EditCommandResources commandResources;
private final IconRegistry iconRegistry;
private final WidgetFocusTracker widgetFocusTracker;
private final CoreLocalizationConstant coreLocale;
private final Button cancelButton;
private final Button saveButton;
private final Label hintLabel;
private Button cancelButton;
private Button saveButton;
private Button closeButton;

private final CategoryRenderer<CommandConfiguration> projectImporterRenderer =
new CategoryRenderer<CommandConfiguration>() {
Expand Down Expand Up @@ -136,11 +139,13 @@ protected EditCommandsViewImpl(org.eclipse.che.ide.Resources resources,
EditCommandResources commandResources,
MachineLocalizationConstant machineLocale,
CoreLocalizationConstant coreLocale,
IconRegistry iconRegistry) {
IconRegistry iconRegistry,
WidgetFocusTracker widgetFocusTracker) {
this.commandResources = commandResources;
this.machineLocale = machineLocale;
this.coreLocale = coreLocale;
this.iconRegistry = iconRegistry;
this.widgetFocusTracker = widgetFocusTracker;

selectConfiguration = null;
categories = new HashMap<>();
Expand Down Expand Up @@ -178,24 +183,7 @@ public void onKeyDown(KeyDownEvent event) {
previewUrlPanel.setVisible(false);
contentPanel.clear();

saveButton = createButton(coreLocale.save(), "window-edit-configurations-save", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
delegate.onSaveClicked();
}
});
saveButton.addStyleName(this.resources.windowCss().primaryButton());
overFooter.add(saveButton);

cancelButton = createButton(coreLocale.cancel(), "window-edit-configurations-cancel", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
delegate.onCancelClicked();
}
});
overFooter.add(cancelButton);

createFooterButton();
createButtons();
resetFilter();

getWidget().getElement().getStyle().setPadding(0, Style.Unit.PX);
Expand Down Expand Up @@ -357,14 +345,31 @@ public void setData(Map<CommandType, List<CommandConfiguration>> categories) {
renderCategoriesList(categories);
}

private void createFooterButton() {
final Button closeButton = createButton(coreLocale.close(), "window-edit-configurations-close",
new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
delegate.onCloseClicked();
}
});
private void createButtons() {
saveButton = createButton(coreLocale.save(), "window-edit-configurations-save", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
delegate.onSaveClicked();
}
});
saveButton.addStyleName(this.resources.windowCss().primaryButton());
overFooter.add(saveButton);

cancelButton = createButton(coreLocale.cancel(), "window-edit-configurations-cancel", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
delegate.onCancelClicked();
}
});
overFooter.add(cancelButton);

closeButton = createButton(coreLocale.close(), "window-edit-configurations-close",
new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
delegate.onCloseClicked();
}
});
closeButton.addDomHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent blurEvent) {
Expand Down Expand Up @@ -398,11 +403,13 @@ public void show() {
super.show(focusPanel);
configurationName.setText("");
configurationPreviewUrl.setText("");
trackFocusForWidgets();
}

@Override
public void close() {
this.hide();
unTrackFocusForWidgets();
}

@Override
Expand Down Expand Up @@ -472,6 +479,11 @@ public CommandConfiguration getSelectedConfiguration() {
return selectConfiguration;
}

@Override
public void setCloseButtonInFocus() {
closeButton.setFocus(true);
}

@UiHandler("configurationName")
public void onNameKeyUp(KeyUpEvent event) {
delegate.onNameChanged();
Expand All @@ -492,16 +504,35 @@ public void onFilterKeyUp(KeyUpEvent event) {

@Override
protected void onEnterClicked() {
if (saveButton.isEnabled()) {
delegate.onSaveClicked();
}
delegate.onEnterClicked();
}

@Override
protected void onClose() {
setSelectedConfiguration(selectConfiguration);
unTrackFocusForWidgets();
}

@Override
public boolean isCancelButtonInFocus() {
return widgetFocusTracker.isWidgetFocused(cancelButton);
}

@Override
public boolean isCloseButtonInFocus() {
return widgetFocusTracker.isWidgetFocused(closeButton);
}

private void trackFocusForWidgets() {
widgetFocusTracker.subscribe(cancelButton);
widgetFocusTracker.subscribe(closeButton);
}

private void unTrackFocusForWidgets() {
widgetFocusTracker.unSubscribe(cancelButton);
widgetFocusTracker.unSubscribe(closeButton);
}

interface EditCommandsViewImplUiBinder extends UiBinder<Widget, EditCommandsViewImpl> {
}
}
}
Loading

0 comments on commit a277622

Please sign in to comment.