Skip to content

Commit

Permalink
Merge pull request #1057 from eclipse/CHE-994
Browse files Browse the repository at this point in the history
CHE-994 Update the list of machines on toolbar and console panel
  • Loading branch information
Vitaliy Guliy committed Apr 15, 2016
2 parents fea6aff + ce19d4f commit 862e7cf
Show file tree
Hide file tree
Showing 32 changed files with 336 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class CustomListBox extends FocusWidget implements HasChangeHandlers {
private int defaultSelectedIndex = -1;
private boolean isActive = false;


public static CustomListBox wrap(Element element) {
// Assert that the element is attached.
assert Document.get().getBody().isOrHasChild(element);
Expand Down Expand Up @@ -411,17 +410,47 @@ public void setSelectedIndex(int index) {
if (index < 0) {
return;
}

//set default index if not added options yet
if (index >= getItemCount()) {
defaultSelectedIndex = index;
return;
}

selectedIndex = index;
currentItemLabel.setInnerText(getItemText(index));
final InputElement inputElement = getListItemElement(index);
InputElement inputElement = getListItemElement(index);
inputElement.setChecked(true);
}

/**
* Selects an item with given text.
*
* @param text
* text of an item to be selected
*/
public void select(String text) {
// uncheck previous value
if (selectedIndex >= 0) {
InputElement inputElement = getListItemElement(selectedIndex);
inputElement.setChecked(false);
}

// find and select a new one
if (text != null) {
for (int i = 0; i < getItemCount(); i++) {
if (text.equals(getItemText(i))) {
setSelectedIndex(i);
return;
}
}
}

// clear the selection
selectedIndex = -1;
currentItemLabel.setInnerText("");
}

/**
* Sets the value associated with the item at a given index.
*
Expand Down Expand Up @@ -459,4 +488,5 @@ private native boolean isActive(Element element) /*-{
var activeElement = $doc.activeElement;
return activeElement.isEqualNode(element);
}-*/;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
* @author Valeriy Svydenko
*/
public interface DropDownListFactory {

/**
* Create an instance of {@link DropDownWidget} with a given identifier for registering.
* Create an instance of {@link DropDownWidget} managing action group registered in action manager.
*
* @param actionGroupId
* identifier of {@link org.eclipse.che.ide.api.action.ActionGroup} registered in action manager
*
* @param listId
* list identifier
* @return an instance of {@link DropDownWidget}
* @return
* an instance of {@link DropDownWidget}
*/
@NotNull
DropDownWidget createList(@NotNull String listId);
DropDownWidget createDropDown(@NotNull String actionGroupId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@
*
* @author Valeriy Svydenko
* @author Oleksii Orel
* @author Vitaliy Gulily
*/
public interface DropDownWidget {
/** returns name of the selected element* */

/**
* Returns name of the selected element.
*
* @return
* name of the selected element
*/
@Nullable
String getSelectedName();

/** returns id of the selected element* */
/**
* Returns id of the selected element.
*
* @return
* selected element identifier
*/
@Nullable
String getSelectedId();

Expand All @@ -39,7 +51,7 @@ public interface DropDownWidget {
void selectElement(@Nullable String id, @Nullable String name);

/**
* Create an instance of element action with given name amd id for displaying it.
* Creates an instance of element action with given name and id for displaying it.
*
* @param id
* id of element
Expand All @@ -51,8 +63,8 @@ public interface DropDownWidget {
Action createAction(String id, String name);

/**
* Update popup elements in drop down part of widget.
* Updates popup elements in drop down part of widget.
*/
void updatePopup();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
*
* @author Valeriy Svydenko
* @author Oleksii Orel
* @author Vitaliy Guliy
*/
public class DropDownWidgetImpl extends Composite implements ActionSelectedHandler, ClickHandler, DropDownWidget {

Expand All @@ -62,14 +63,18 @@ interface DropDownWidgetImplUiBinder extends UiBinder<Widget, DropDownWidgetImpl

@UiField
FlowPanel marker;

@UiField
Label selectedElementName;

@UiField
FlowPanel selectedElement;

@UiField
FlowPanel listHeader;

private final String listId;
private final String actionGroupId;

private final Resources resources;
private final ActionManager actionManager;
private final KeyBindingAgent keyBindingAgent;
Expand All @@ -84,10 +89,13 @@ interface DropDownWidgetImplUiBinder extends UiBinder<Widget, DropDownWidgetImpl


@AssistedInject
public DropDownWidgetImpl(Resources resources, ActionManager actionManager, KeyBindingAgent keyBindingAgent,
Provider<PerspectiveManager> managerProvider, @NotNull @Assisted String listId) {
public DropDownWidgetImpl(Resources resources,
ActionManager actionManager,
KeyBindingAgent keyBindingAgent,
Provider<PerspectiveManager> managerProvider,
@NotNull @Assisted String actionGroupId) {
this.resources = resources;
this.listId = listId;
this.actionGroupId = actionGroupId;

initWidget(UI_BINDER.createAndBindUi(this));

Expand Down Expand Up @@ -140,7 +148,7 @@ public void onClick(ClickEvent event) {
int left = getAbsoluteLeft();
int top = getAbsoluteTop() + listHeader.getOffsetHeight();
int width = listHeader.getOffsetWidth();
this.show(left, top, width, listId);
show(left, top, width);
}

/** {@inheritDoc} */
Expand All @@ -151,7 +159,7 @@ public void updatePopup() {
}
this.hide();
int top = getAbsoluteTop() + listHeader.getOffsetHeight();
this.show(getAbsoluteLeft(), top, listHeader.getOffsetWidth(), listId);
show(getAbsoluteLeft(), top, listHeader.getOffsetWidth());
}

/** {@inheritDoc} */
Expand All @@ -175,12 +183,10 @@ public void onActionSelected(Action action) {
* vertical position
* @param width
* header width
* @param itemId
* list identifier
*/
private void show(final int left, final int top, final int width, @NotNull String itemId) {
private void show(int left, int top, int width) {
hide();
this.updateActions(itemId);
updateActions();

lockLayer = new MenuLockLayer();
popupMenu = new PopupMenu(actions,
Expand All @@ -190,7 +196,7 @@ private void show(final int left, final int top, final int width, @NotNull Strin
lockLayer,
this,
keyBindingAgent,
itemId);
actionGroupId);
popupMenu.addStyleName(resources.dropdownListCss().dropDownListMenu());
popupMenu.getElement().getStyle().setTop(top, PX);
popupMenu.getElement().getStyle().setLeft(left, PX);
Expand All @@ -200,15 +206,12 @@ private void show(final int left, final int top, final int width, @NotNull Strin
}

/**
* Updates the list of visible actions.
*
* @param listId
* identifier of action group which contains elements of list
* Refresh the list of visible actions.
*/
private void updateActions(@NotNull String listId) {
private void updateActions() {
actions.removeAll();

ActionGroup mainActionGroup = (ActionGroup)actionManager.getAction(listId);
ActionGroup mainActionGroup = (ActionGroup)actionManager.getAction(actionGroupId);
if (mainActionGroup == null) {
return;
}
Expand Down Expand Up @@ -286,4 +289,5 @@ public interface Resources extends ClientBundle {
@Source("expansionIcon.svg")
SVGResource expansionImage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ enum MachineOperationType {
*/
void startMachine(String recipeURL, String displayName);

/**
* Start new SSH machine in workspace.
*
* @param recipeURL
* special recipe url to get docker image.
* @param displayName
* display name for machine
*/
void startSSHMachine(String recipeURL, String displayName);

/**
* Destroy machine.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.che.api.machine.gwt.client.events;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

import org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent;
Expand All @@ -19,10 +20,28 @@
*
* @author Roman Nikitenko
*/
public class DevMachineStateEvent extends GwtEvent<DevMachineStateHandler> {
public class DevMachineStateEvent extends GwtEvent<DevMachineStateEvent.Handler> {

public interface Handler extends EventHandler {
/**
* Called when dev machine has been started.
*
* @param event
* the fired {@link DevMachineStateEvent}
*/
void onDevMachineStarted(DevMachineStateEvent event);

/**
* Called when dev machine has been destroyed.
*
* @param event
* the fired {@link DevMachineStateEvent}
*/
void onDevMachineDestroyed(DevMachineStateEvent event);
}

/** Type class used to register this event. */
public static Type<DevMachineStateHandler> TYPE = new Type<>();
public static Type<DevMachineStateEvent.Handler> TYPE = new Type<>();
private final MachineStatusEvent.EventType status;
private final String machineId;
private final String workspaceId;
Expand All @@ -44,7 +63,7 @@ public DevMachineStateEvent(MachineStatusEvent event) {
}

@Override
public Type<DevMachineStateHandler> getAssociatedType() {
public Type<DevMachineStateEvent.Handler> getAssociatedType() {
return TYPE;
}

Expand All @@ -70,16 +89,15 @@ public String getError() {
}

@Override
protected void dispatch(DevMachineStateHandler handler) {
protected void dispatch(DevMachineStateEvent.Handler handler) {
switch (status) {
case RUNNING:
handler.onMachineStarted(this);
handler.onDevMachineStarted(this);
break;
case DESTROYED:
handler.onMachineDestroyed(this);
break;
default:
handler.onDevMachineDestroyed(this);
break;
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public SelectDebugConfigurationComboBoxAction(DebuggerLocalizationConstant local
this.actionManager = actionManager;

this.debugConfigurationsManager = debugConfigurationsManager;
this.dropDownHeaderWidget = dropDownListFactory.createList(GROUP_DEBUG_CONFIGURATIONS);
this.dropDownHeaderWidget = dropDownListFactory.createDropDown(GROUP_DEBUG_CONFIGURATIONS);

configurations = new LinkedList<>();

Expand Down
Loading

0 comments on commit 862e7cf

Please sign in to comment.