diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/base/BaseView.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/base/BaseView.java index 178d7baac55..d093ece9111 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/base/BaseView.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/parts/base/BaseView.java @@ -15,12 +15,8 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.DoubleClickEvent; -import com.google.gwt.event.dom.client.DoubleClickHandler; import com.google.gwt.event.dom.client.MouseUpEvent; -import com.google.gwt.event.dom.client.MouseUpHandler; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.DockLayoutPanel; import com.google.gwt.user.client.ui.FlowPanel; @@ -85,13 +81,10 @@ public BaseView(PartStackUIResources resources) { toolBar = new DockLayoutPanel(Style.Unit.PX); toolBar.addStyleName(resources.partStackCss().ideBasePartToolbar()); toolBar.getElement().setAttribute("role", "toolbar"); - toolBar.addDomHandler(new MouseUpHandler() { - @Override - public void onMouseUp(MouseUpEvent event) { - //activate last focused element if user clicked on part header - if (lastFocused != null) { - lastFocused.setFocus(true); - } + toolBar.addDomHandler(event -> { + //activate last focused element if user clicked on part header + if (lastFocused != null) { + lastFocused.setFocus(true); } }, MouseUpEvent.getType()); container.addNorth(toolBar, 23); @@ -103,7 +96,7 @@ public void onMouseUp(MouseUpEvent event) { toolbarHeader.getElement().setAttribute("role", "toolbar-header"); toolBar.addNorth(toolbarHeader, 22); - // padding 2 pixels from the right + //padding 2 pixels from the right toolbarHeader.addEast(new FlowPanel(), 2); titleLabel = new Label(); @@ -114,15 +107,8 @@ public void onMouseUp(MouseUpEvent event) { addMinimizeButton(); addMenuButton(); - /** - * Handle double clicking on the toolbar header - */ - toolbarHeader.addDomHandler(new DoubleClickHandler() { - @Override - public void onDoubleClick(DoubleClickEvent event) { - onToggleMaximize(); - } - }, DoubleClickEvent.getType()); + //handle double clicking on the toolbar header + toolbarHeader.addDomHandler(event -> onToggleMaximize(), DoubleClickEvent.getType()); } /** @@ -133,12 +119,7 @@ private void addMinimizeButton() { minimize.getElement().setAttribute("name", "workBenchIconMinimize"); minimizeButton = new ToolButton(minimize); - minimizeButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - onMinimize(); - } - }); + minimizeButton.addClickHandler(event -> onMinimize()); addToolButton(minimizeButton); @@ -155,12 +136,7 @@ private void addMaximizeButton() { SVGImage maximize = new SVGImage(resources.maximizePart()); maximize.getElement().setAttribute("name", "workBenchIconMaximize"); ToolButton maximizeButton = new ToolButton(maximize); - maximizeButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - onToggleMaximize(); - } - }); + maximizeButton.addClickHandler(event -> onToggleMaximize()); addToolButton(maximizeButton); @@ -176,13 +152,10 @@ public void onClick(ClickEvent event) { private void addMenuButton() { final ToolButton menuButton = new ToolButton(FontAwesome.COG + " " + FontAwesome.CARET_DOWN); menuButton.getElement().setAttribute("name", "workBenchIconMenu"); - menuButton.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - int left = getAbsoluteLeft(menuButton.getElement()); - int top = getAbsoluteTop(menuButton.getElement()); - delegate.onPartMenu(left, top + 21); - } + menuButton.addClickHandler(event -> { + int left = getAbsoluteLeft(menuButton.getElement()); + int top = getAbsoluteTop(menuButton.getElement()); + delegate.onPartMenu(left, top + 21); }); toolbarHeader.addEast(menuButton, 25); @@ -327,12 +300,9 @@ public final void setToolbarHeight(int height) { public final void setFocus(boolean focused) { this.focused = focused; if (focused) { - Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { - @Override - public void execute() { - focusView(); - } - }); + Scheduler.get().scheduleDeferred(this::focusView); + } else { + Scheduler.get().scheduleDeferred(this::blurView); } } @@ -350,4 +320,8 @@ protected void focusView() { getElement().focus(); } + protected void blurView() { + getElement().blur(); + } + } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerViewImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerViewImpl.java index f4a3bc99865..17870d17638 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerViewImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/part/explorer/project/ProjectExplorerViewImpl.java @@ -193,6 +193,11 @@ protected void focusView() { tree.setFocus(true); } + @Override + protected void blurView() { + tree.setFocus(false); + } + @Override public Tree getTree() { return tree; diff --git a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java index 5cefffabee6..3f8ea55e7fd 100644 --- a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java +++ b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/SelectionModel.java @@ -425,19 +425,19 @@ protected void onMouseClick(ClickEvent ce) { Node sel = node.getNode(); if (e.getCtrlOrMetaKey() && isSelected(sel)) { doDeselect(Collections.singletonList(sel), false); - tree.focus(); + tree.setFocus(true); // reset the starting location of the click when meta is used during a multiselect lastSelectedNode = sel; } else if (e.getCtrlOrMetaKey()) { doSelect(Collections.singletonList(sel), true, false); - tree.focus(); + tree.setFocus(true); // reset the starting location of the click when meta is used during a multiselect lastSelectedNode = sel; } else if (isSelected(sel) && !e.getShiftKey() && !e.getCtrlOrMetaKey() && selectionStorage.size() > 0) { doSelect(Collections.singletonList(sel), false, false); - tree.focus(); + tree.setFocus(true); } } } @@ -466,7 +466,7 @@ protected void onMouseDown(MouseDownEvent mde) { } else { switch (selectionMode) { case SIMPLE: - tree.focus(); + tree.setFocus(true); if (isSelected(sel)) { deselect(sel); } else { @@ -475,7 +475,7 @@ protected void onMouseDown(MouseDownEvent mde) { break; case SINGLE: - tree.focus(); + tree.setFocus(true); if (isMeta && isSelected) { deselect(sel); } else if (!isSelected) { @@ -497,7 +497,7 @@ protected void onMouseDown(MouseDownEvent mde) { // holding shift down, selecting the same item again, selecting itself if (sel == lastSelectedNode) { - tree.focus(); + tree.setFocus(true); doSelect(Collections.singletonList(sel), false, false); } else if (lastSelTreeEl != null && selTreeNodeEl != null) { @@ -529,7 +529,7 @@ protected void onMouseDown(MouseDownEvent mde) { } } - tree.focus(); + tree.setFocus(true); doSelect(selectedItems, false, false); // change back to last selected, the walking causes this need @@ -537,14 +537,14 @@ protected void onMouseDown(MouseDownEvent mde) { } } else if (!isSelected(sel)) { - tree.focus(); + tree.setFocus(true); doSelect(Collections.singletonList(sel), e.getCtrlOrMetaKey(), false); // reset the starting location of multi select lastSelectedNode = sel; } else if (isSelected(sel) && !e.getShiftKey() && !e.getCtrlOrMetaKey() && !selectionStorage.isEmpty()) { doSelect(Collections.singletonList(sel), false, false); - tree.focus(); + tree.setFocus(true); } else if (isSelected(sel) && !selectionStorage.isEmpty()) { doDeselect(Collections.singletonList(sel), false); } diff --git a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/Tree.java b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/Tree.java index 73851640640..873b0b95b62 100644 --- a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/Tree.java +++ b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/Tree.java @@ -273,7 +273,7 @@ public class Tree extends FocusWidget implements HasBeforeExpandNodeHandlers, private boolean focusConstrainScheduled = false; - private boolean focused = false; + protected boolean focused = false; public Tree(NodeStorage nodeStorage, NodeLoader nodeLoader) { this(nodeStorage, nodeLoader, GWT.create(TreeStyles.class)); @@ -673,13 +673,16 @@ public void scrollIntoView(Node node) { container.scrollIntoView(); focusEl.getStyle().setLeft((nodeStorage.getDepth(node) - 1) * 16, Style.Unit.PX); focusEl.getStyle().setTop(container.getOffsetTop(), Style.Unit.PX); + setFocus(true); } - /** - * Sets window focus to current tree. - */ - public void focus() { + @Override + public void setFocus(boolean focused) { + super.setFocus(focused); focusImpl.focus(focusEl); + this.focused = focused; + + view.onFocusUpdated(); } /** @@ -1577,8 +1580,6 @@ private void onClick(Event event) { toggle(node.getNode()); } } - - focus(); } private void onAfterFirstAttach() { diff --git a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/TreeView.java b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/TreeView.java index 0395a99bb6d..96255796676 100644 --- a/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/TreeView.java +++ b/ide/che-core-ide-ui/src/main/java/org/eclipse/che/ide/ui/smartTree/TreeView.java @@ -222,7 +222,9 @@ public void onLoadChange(NodeDescriptor node, boolean loading) { } public void onOverChange(NodeDescriptor node, boolean over) { - setClassName(getNodeContainer(node), tree.getTreeStyles().styles().hover(), over); + if (tree.focused) { + setClassName(getNodeContainer(node), tree.getTreeStyles().styles().hover(), over); + } } public void onSelectChange(Node node, boolean select) { @@ -236,11 +238,23 @@ public void onSelectChange(Node node, boolean select) { if (nodeDescriptor != null) { Element e = getNodeContainer(nodeDescriptor); if (e != null) { - setClassName(e, tree.getTreeStyles().styles().selected(), select); + setClassName(e, tree.getTreeStyles().styles().hover(), false); + setClassName(e, tree.getTreeStyles().styles().selected(), false); + + if (select) { + setClassName(e, tree.focused ? tree.getTreeStyles().styles().selected() : tree.getTreeStyles().styles().hover(), true); + } + } } } + public void onFocusUpdated() { + for (Node node : tree.getSelectionModel().getSelectedNodes()) { + onSelectChange(node, tree.getSelectionModel().isSelected(node)); + } + } + public void onTextChange(NodeDescriptor node, SafeHtml text) { Element textEl = getPresentableTextContainer(node); if (textEl != null) {