Skip to content

Commit

Permalink
CHE-2286: disable menu items until the workspace is not loaded or sto…
Browse files Browse the repository at this point in the history
…pped

Signed-off-by: Oleksii Orel <oorel@codenvy.com>
  • Loading branch information
Oleksii Orel committed Sep 19, 2016
1 parent d546578 commit c843408
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 85 deletions.
Expand Up @@ -11,12 +11,16 @@
package org.eclipse.che.ide.api.action;

import com.google.gwt.resources.client.ImageResource;
import com.google.inject.Inject;

import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.parts.PerspectiveManager;
import org.vectomatic.dom.svg.ui.SVGResource;

import javax.validation.constraints.NotNull;
import org.eclipse.che.commons.annotation.Nullable;
import java.util.List;

/**
Expand All @@ -27,12 +31,50 @@
*/
public abstract class AbstractPerspectiveAction extends Action {


@Inject
private AppContext appContext;

/**
* A list of perspectives in which the action is enabled.
* Null or empty list means the action is enabled everywhere.
*/
private final List<String> perspectives;

/**
* Creates a new action with the specified text.
*
* @param perspectives
* list of perspective action IDs
* @param text
* Serves as a tooltip when the presentation is a button and the name of the
* menu item when the presentation is a menu item.
*/
public AbstractPerspectiveAction(@Nullable List<String> perspectives,
@NotNull String text) {
super(text);
this.perspectives = perspectives;
}

/**
* Constructs a new action with the specified text, description.
*
* @param perspectives
* list of perspective action IDs
* @param text
* Serves as a tooltip when the presentation is a button and the name of the
* menu item when the presentation is a menu item
* @param description
* Describes current action, this description will appear on
* the status bar when presentation has focus
*/
public AbstractPerspectiveAction(@Nullable List<String> perspectives,
@NotNull String text,
@NotNull String description) {
super(text, description, null, null);
this.perspectives = perspectives;
}

public AbstractPerspectiveAction(@Nullable List<String> perspectives,
@NotNull String text,
@NotNull String description,
Expand All @@ -59,11 +101,18 @@ public final void update(@NotNull ActionEvent event) {

Presentation presentation = event.getPresentation();

boolean isWorkspaceRunning = false;

if (appContext != null) {
Workspace workspace = appContext.getWorkspace();
isWorkspaceRunning = workspace != null && WorkspaceStatus.RUNNING.equals(workspace.getStatus());
}

boolean inPerspective = perspectives == null || perspectives.isEmpty() ? true : perspectives.contains(manager.getPerspectiveId());

presentation.setEnabledAndVisible(inPerspective);
presentation.setEnabledAndVisible(inPerspective && isWorkspaceRunning);

if (inPerspective) {
if (inPerspective && isWorkspaceRunning) {
updateInPerspective(event);
}
}
Expand Down
Expand Up @@ -13,13 +13,13 @@
import com.google.common.annotations.Beta;

import org.eclipse.che.api.core.model.factory.Factory;
import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.ide.api.machine.DevMachine;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;
import org.eclipse.che.ide.resource.Path;

import java.util.List;
Expand Down Expand Up @@ -187,13 +187,18 @@ public interface AppContext {

String getWorkspaceId();

/* Deprecated methods */

/* No more supported, will be removed soon. */
@Deprecated
WorkspaceDto getWorkspace();
/**
* Returns {@link Workspace} instance of current workspace.
*
* @return current workspace
*/
Workspace getWorkspace();

/* No more supported, will be removed soon. */
@Deprecated
void setWorkspace(WorkspaceDto workspace);
/**
* Sets current workspace.
*
* @param workspace
* current workspace or {@code null}
*/
void setWorkspace(Workspace workspace);
}
Expand Up @@ -14,39 +14,41 @@
import com.google.inject.Singleton;

import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations;
import org.eclipse.che.ide.api.editor.texteditor.TextEditorOperations;

import javax.validation.constraints.NotNull;

/**
* Calls editor complete(Ctrl+Space)
*
* @author Evgen Vidolob
*/
@Singleton
public class CompleteAction extends Action {
public class CompleteAction extends AbstractPerspectiveAction {

private EditorAgent editorAgent;

@Inject
public CompleteAction(CoreLocalizationConstant coreLocalizationConstant, EditorAgent editorAgent) {
super(coreLocalizationConstant.actionCompetitionsTitle());
super(null, coreLocalizationConstant.actionCompetitionsTitle());
this.editorAgent = editorAgent;
}

@Override
public void actionPerformed(ActionEvent e) {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if(activeEditor instanceof HandlesTextOperations){
if (activeEditor instanceof HandlesTextOperations) {
((HandlesTextOperations)activeEditor).doOperation(TextEditorOperations.CODEASSIST_PROPOSALS);
}
}

@Override
public void update(ActionEvent e) {

public void updateInPerspective(@NotNull ActionEvent e) {
EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor != null) {
if (activeEditor instanceof HandlesTextOperations) {
Expand Down
Expand Up @@ -11,22 +11,26 @@
package org.eclipse.che.ide.actions;

import com.google.inject.Inject;

import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.hotkeys.dialog.HotKeysDialogPresenter;

import javax.validation.constraints.NotNull;

/**
* Show hotKeys list for IDE and editor
*
* @author Alexander Andrienko
*/
public class HotKeysListAction extends Action {
public class HotKeysListAction extends AbstractPerspectiveAction {

private HotKeysDialogPresenter hotKeysDialogPresenter;

@Inject
public HotKeysListAction(HotKeysDialogPresenter hotKeysDialogPresenter, CoreLocalizationConstant locale) {
super(locale.keyBindingsActionName(), locale.keyBindingsActionDescription(), null, null);
super(null, locale.keyBindingsActionName(), locale.keyBindingsActionDescription(), null, null);
this.hotKeysDialogPresenter = hotKeysDialogPresenter;
}

Expand All @@ -35,4 +39,9 @@ public HotKeysListAction(HotKeysDialogPresenter hotKeysDialogPresenter, CoreLoca
public void actionPerformed(ActionEvent e) {
hotKeysDialogPresenter.showHotKeys();
}

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
event.getPresentation().setEnabledAndVisible(true);
}
}
Expand Up @@ -14,7 +14,7 @@
import com.google.inject.Singleton;

import org.eclipse.che.ide.Resources;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.preferences.PreferencesPresenter;
Expand All @@ -24,17 +24,17 @@
*
* @author Evgen Vidolob
* @author Vlad Zhukovskyi
**/
*/
@Singleton
public class ShowPreferencesAction extends Action {
public class ShowPreferencesAction extends AbstractPerspectiveAction {

private final PreferencesPresenter presenter;

private final AppContext appContext;
private final AppContext appContext;

@Inject
public ShowPreferencesAction(Resources resources, PreferencesPresenter presenter, AppContext appContext) {
super("Preferences", "Preferences", null, resources.preferences());
super(null, "Preferences", "Preferences", null, resources.preferences());
this.presenter = presenter;
this.appContext = appContext;
}
Expand All @@ -46,7 +46,7 @@ public void actionPerformed(ActionEvent e) {
}

@Override
public void update(ActionEvent e) {
public void updateInPerspective(ActionEvent e) {
e.getPresentation().setEnabledAndVisible(true);
}
}
Expand Up @@ -15,29 +15,36 @@

import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.Resources;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;

import javax.validation.constraints.NotNull;

/**
* Action fo find action action
*
* @author Evgen Vidolob
*/
@Singleton
public class FindActionAction extends Action {
public class FindActionAction extends AbstractPerspectiveAction {

private FindActionPresenter presenter;
private FindActionPresenter presenter;

@Inject
public FindActionAction(FindActionPresenter presenter,
CoreLocalizationConstant localization,
Resources resources) {
super(localization.actionFindActionDescription(), localization.actionFindActionTitle(), null, resources.findActions());
super(null, localization.actionFindActionDescription(), localization.actionFindActionTitle(), null, resources.findActions());
this.presenter = presenter;
}

@Override
public void actionPerformed(ActionEvent e) {
presenter.show();
}

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
event.getPresentation().setEnabledAndVisible(true);
}
}
Expand Up @@ -16,10 +16,10 @@
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.app.CurrentUser;
import org.eclipse.che.ide.api.app.StartUpAction;
Expand Down Expand Up @@ -82,11 +82,11 @@ public class AppContextImpl implements AppContext,
private final BrowserQueryFieldRenderer browserQueryFieldRenderer;
private final List<String> projectsInImport;

private WorkspaceDto usersWorkspaceDto;
private CurrentUser currentUser;
private FactoryDto factory;
private DevMachine devMachine;
private Path projectsRoot;
private Workspace usersWorkspace;
private CurrentUser currentUser;
private FactoryDto factory;
private DevMachine devMachine;
private Path projectsRoot;
/**
* List of actions with parameters which comes from startup URL.
* Can be processed after IDE initialization as usual after starting ws-agent.
Expand Down Expand Up @@ -117,22 +117,22 @@ public AppContextImpl(EventBus eventBus,
}

@Override
public WorkspaceDto getWorkspace() {
return usersWorkspaceDto;
public Workspace getWorkspace() {
return usersWorkspace;
}

@Override
public void setWorkspace(WorkspaceDto workspace) {
this.usersWorkspaceDto = workspace;
public void setWorkspace(Workspace workspace) {
this.usersWorkspace = workspace;
}

@Override
public String getWorkspaceId() {
if (usersWorkspaceDto == null) {
if (usersWorkspace == null) {
throw new IllegalArgumentException(getClass() + " Workspace can not be null.");
}

return usersWorkspaceDto.getId();
return usersWorkspace.getId();
}

@Override
Expand Down Expand Up @@ -215,7 +215,7 @@ public void apply(Project[] projects) throws OperationException {

@Override
public String getWorkspaceName() {
return usersWorkspaceDto.getConfig().getName();
return usersWorkspace.getConfig().getName();
}

/** {@inheritDoc} */
Expand Down

0 comments on commit c843408

Please sign in to comment.