Skip to content

Commit

Permalink
Add ability to display ephemeral state in status bar
Browse files Browse the repository at this point in the history
Signed-off-by: Vladyslav Zhukovskyi <vzhukovs@redhat.com>
  • Loading branch information
vzhukovs committed Mar 28, 2019
1 parent 1263f06 commit d22433c
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
import org.eclipse.che.ide.ui.toolbar.ToolbarPresenter;
import org.eclipse.che.ide.util.browser.UserAgent;
import org.eclipse.che.ide.util.input.KeyCodeMap;
import org.eclipse.che.ide.workspace.EphemeralStateStatusBarItem;
import org.eclipse.che.ide.workspace.StartWorkspaceAction;
import org.eclipse.che.ide.workspace.StopWorkspaceAction;
import org.vectomatic.dom.svg.ui.SVGImage;
Expand Down Expand Up @@ -411,6 +412,8 @@ public interface ParserResource extends ClientBundle {

@Inject private FreeDiskSpaceStatusBarAction freeDiskSpaceStatusBarAction;

@Inject private EphemeralStateStatusBarItem ephemeralStateStatusBarItem;

@Inject
@Named("XMLFileType")
private FileType xmlFile;
Expand Down Expand Up @@ -884,6 +887,7 @@ public void initialize() {
DefaultActionGroup rightStatusPanelGroup =
(DefaultActionGroup) actionManager.getAction(GROUP_RIGHT_STATUS_PANEL);
rightStatusPanelGroup.add(freeDiskSpaceStatusBarAction);
rightStatusPanelGroup.add(ephemeralStateStatusBarItem);

// Define hot-keys
keyBinding
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.workspace;

import static java.lang.Boolean.parseBoolean;

import com.google.gwt.dom.client.Style;
import com.google.gwt.i18n.client.Messages;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Map;
import org.eclipse.che.ide.FontAwesome;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.action.BaseAction;
import org.eclipse.che.ide.api.action.CustomComponentAction;
import org.eclipse.che.ide.api.action.Presentation;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.workspace.model.WorkspaceConfigImpl;
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;

/**
* Status bar action that indicates ephemeral state of the pvc volume. Ephemeral means that pvc
* volume is not persisted after workspace stop.
*
* @author Vlad Zhukovskyi
* @since 7.0.0-beta-3.0
*/
@Singleton
public class EphemeralStateStatusBarItem extends BaseAction implements CustomComponentAction {

private final AppContext appContext;
private final Locale locale;
private final HorizontalPanel panel;

private static final String PERSIST_VOLUMES_ATTRIBUTE = "persistVolumes";

@Inject
public EphemeralStateStatusBarItem(AppContext appContext, Locale locale) {
super();
this.appContext = appContext;
this.locale = locale;

panel = new HorizontalPanel();
panel.ensureDebugId("statusBarEphemeralStatePanel");
}

@Override
public void actionPerformed(ActionEvent e) {}

@Override
public Widget createCustomComponent(Presentation presentation) {
return panel;
}

@Override
public void update(ActionEvent e) {
super.update(e);
panel.clear();

WorkspaceImpl workspace = appContext.getWorkspace();
if (workspace == null) {
return;
}

WorkspaceConfigImpl workspaceConfig = workspace.getConfig();
if (workspaceConfig == null) {
return;
}

Map<String, String> attributes = workspaceConfig.getAttributes();
if (attributes.containsKey(PERSIST_VOLUMES_ATTRIBUTE)
&& !parseBoolean(attributes.get(PERSIST_VOLUMES_ATTRIBUTE))) {
Widget icon = new HTML(FontAwesome.EXCLAMATION_TRIANGLE);
icon.getElement().getStyle().setMarginRight(5., Style.Unit.PX);
icon.getElement().getStyle().setColor("#fcc13d");
panel.add(icon);

Label ephemeralMode = new Label(locale.label());
ephemeralMode.setTitle(locale.description());
ephemeralMode.ensureDebugId("statusBarEphemeralStatePanelEphemeralMode");
ephemeralMode.getElement().getStyle().setMarginRight(5., Style.Unit.PX);
ephemeralMode.getElement().getStyle().setColor("#fcc13d");
panel.add(ephemeralMode);
}
}

interface Locale extends Messages {
@DefaultMessage("Ephemeral Mode")
String label();

@DefaultMessage(
"All changes to the source code will be lost when the workspace is stopped unless they are pushed to a source code repository.")
String description();
}
}

0 comments on commit d22433c

Please sign in to comment.