Skip to content

Commit

Permalink
Merge pull request #2240 from eclipse/fixProcessesPanel
Browse files Browse the repository at this point in the history
Fix Processes panel behavior
  • Loading branch information
azatsarynnyy authored Aug 29, 2016
2 parents 5d0869c + 7883904 commit 29c4133
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.gwt.user.client.ui.IsWidget;

import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.ui.multisplitpanel.panel.SubPanelView;

import java.util.List;

Expand All @@ -32,7 +33,7 @@
public interface SubPanel {

/** Returns the panel's view. */
IsWidget getView();
SubPanelView getView();

/** Split this panel horizontally on two sub-panels. */
void splitHorizontally();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public SubPanelPresenter(SubPanelFactory subPanelFactory,
view.setDelegate(this);

if (parentPanel != null) {
view.setParentPanel((SubPanelView)parentPanel.getView());
view.setParentPanel(parentPanel.getView());
} else {
view.setParentPanel(null);
}
}

@Override
public IsWidget getView() {
public SubPanelView getView() {
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
package org.eclipse.che.ide.ui.multisplitpanel.panel;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.mvp.View;
import org.eclipse.che.ide.ui.multisplitpanel.SubPanel;
import org.eclipse.che.ide.ui.multisplitpanel.WidgetToShow;
Expand All @@ -28,13 +28,13 @@ public interface SubPanelView extends View<SubPanelView.ActionDelegate> {
* Split panel horizontally on two sub-panels
* and set the given {@code widget} for additional panel.
*/
void splitHorizontally(IsWidget view);
void splitHorizontally(SubPanelView view);

/**
* Split panel vertically on two sub-panels
* and set the given {@code widget} for additional panel.
*/
void splitVertically(IsWidget view);
void splitVertically(SubPanelView view);

/**
* Add the given {@code widget} to this panel.
Expand All @@ -57,18 +57,11 @@ public interface SubPanelView extends View<SubPanelView.ActionDelegate> {
*/
void removeWidget(WidgetToShow widget);

/**
* Close panel. It may mean removing panel from it's
* parent in case this panel is the last one or
* removing only central part and moving additional part to the center.
*/
/** Close panel. */
void closePanel();

/** Remove child panel. */
void removeChildSubPanel(Widget widget);

/** Set parent {@link SubPanelView} in case this panel is 'child' of another panel. */
void setParentPanel(SubPanelView parentPanel);
void setParentPanel(@Nullable SubPanelView parentPanel);

interface ActionDelegate {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;

import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.ui.multisplitpanel.SubPanel;
import org.eclipse.che.ide.ui.multisplitpanel.WidgetToShow;
Expand All @@ -38,9 +39,13 @@
import org.eclipse.che.ide.ui.multisplitpanel.tab.Tab;
import org.eclipse.che.ide.ui.multisplitpanel.tab.TabItemFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.google.gwt.user.client.ui.DockLayoutPanel.Direction.CENTER;

/**
* Implementation of {@link SubPanelView}.
*
Expand All @@ -55,6 +60,8 @@ public class SubPanelViewImpl extends Composite implements SubPanelView,
private final Map<Tab, WidgetToShow> tabs2Widgets;
private final Map<WidgetToShow, Tab> widgets2Tabs;
private final Map<WidgetToShow, MenuItemWidget> widgets2ListItems;
private final MenuItem closePaneMenuItem;


@UiField(provided = true)
SplitLayoutPanel splitLayoutPanel;
Expand All @@ -68,9 +75,10 @@ public class SubPanelViewImpl extends Composite implements SubPanelView,
@UiField
DeckLayoutPanel widgetsPanel;

private ActionDelegate delegate;

private SubPanelView parentPanel;
private ActionDelegate delegate;
private SubPanelView parentPanel;
private List<SubPanelView> eastSubPanels;
private List<SubPanelView> southSubPanels;

@Inject
public SubPanelViewImpl(SubPanelViewImplUiBinder uiBinder,
Expand All @@ -83,7 +91,8 @@ public SubPanelViewImpl(SubPanelViewImplUiBinder uiBinder,
this.tabItemFactory = tabItemFactory;
this.menu = menu;

menu.addListItem(new MenuItemActionWidget(closePaneAction));
closePaneMenuItem = new MenuItemActionWidget(closePaneAction);
menu.addListItem(closePaneMenuItem);
menu.addListItem(new MenuItemActionWidget(removeAllWidgetsInPaneAction));
menu.addListItem(new MenuItemActionWidget(splitHorizontallyAction));
menu.addListItem(new MenuItemActionWidget(splitVerticallyAction));
Expand All @@ -93,6 +102,8 @@ public SubPanelViewImpl(SubPanelViewImplUiBinder uiBinder,
tabs2Widgets = new HashMap<>();
widgets2Tabs = new HashMap<>();
widgets2ListItems = new HashMap<>();
eastSubPanels = new ArrayList<>();
southSubPanels = new ArrayList<>();

splitLayoutPanel = new SplitLayoutPanel(3);

Expand All @@ -114,17 +125,21 @@ public void setDelegate(ActionDelegate delegate) {
}

@Override
public void splitHorizontally(IsWidget subPanelView) {
int height = splitLayoutPanel.getOffsetHeight() / 2;
public void splitHorizontally(SubPanelView subPanelView) {
southSubPanels.add(0, subPanelView);

final int height = mainPanel.getOffsetHeight() / 2;

splitLayoutPanel.remove(mainPanel);
splitLayoutPanel.addSouth(subPanelView, height);
splitLayoutPanel.add(mainPanel);
}

@Override
public void splitVertically(IsWidget subPanelView) {
int width = splitLayoutPanel.getOffsetWidth() / 2;
public void splitVertically(SubPanelView subPanelView) {
eastSubPanels.add(0, subPanelView);

final int width = mainPanel.getOffsetWidth() / 2;

splitLayoutPanel.remove(mainPanel);
splitLayoutPanel.addEast(subPanelView, width);
Expand Down Expand Up @@ -172,6 +187,19 @@ public void removeWidget(WidgetToShow widget) {
}
}

private void closeTab(Tab tab) {
final WidgetToShow widget = tabs2Widgets.get(tab);

if (widget != null) {
delegate.onWidgetRemoving(widget.getWidget(), new SubPanel.RemoveCallback() {
@Override
public void remove() {
removeWidgetFromUI(widget);
}
});
}
}

private void removeWidgetFromUI(WidgetToShow widget) {
final Tab tab = widgets2Tabs.remove(widget);
if (tab != null) {
Expand All @@ -190,44 +218,75 @@ private void removeWidgetFromUI(WidgetToShow widget) {

@Override
public void closePanel() {
if (splitLayoutPanel.getWidgetCount() == 1) {
parentPanel.removeChildSubPanel(this);
if (parentPanel == null) {
// do not allow to close root panel
return;
}

splitLayoutPanel.remove(mainPanel);
if (splitLayoutPanel.getWidgetCount() == 1 && !isInTheCenterOfTheParent()) {
// this panel doesn't have any child sub-panels
// so just remove it from it's parent
((SubPanelViewImpl)parentPanel).removeWidgetFromSplitPanel(this);
return;
}

// move widget from east/south part to the center
final Widget lastWidget = splitLayoutPanel.getWidget(0);
splitLayoutPanel.setWidgetSize(lastWidget, 0);
splitLayoutPanel.remove(lastWidget);
splitLayoutPanel.add(lastWidget);
if (isInTheCenterOfTheParent()) {
((SubPanelViewImpl)parentPanel).removeChildSubPanel(this);
} else {
removeChildSubPanel(mainPanel);
}
}

@Override
public void removeChildSubPanel(Widget widget) {
if (splitLayoutPanel.getWidgetDirection(widget) == DockLayoutPanel.Direction.CENTER) {
// this is the only widget on the panel
// don't allow to remove it
return;
/** Checks whether this panel is in the central part of it's parent. */
private boolean isInTheCenterOfTheParent() {
return ((SubPanelViewImpl)parentPanel).splitLayoutPanel.getWidgetDirection(this) == CENTER;
}

private void removeChildSubPanel(Widget widget) {
removeWidgetFromSplitPanel(widget.asWidget());

IsWidget lastWidget = null;
if (!southSubPanels.isEmpty()) {
lastWidget = southSubPanels.get(0);
} else if (!eastSubPanels.isEmpty()) {
lastWidget = eastSubPanels.get(0);
}

if (lastWidget != null) {
removeWidgetFromSplitPanel(lastWidget.asWidget());
splitLayoutPanel.add(lastWidget);
} else {
((SubPanelViewImpl)parentPanel).removeWidgetFromSplitPanel(this);
}
}

private void removeWidgetFromSplitPanel(Widget widget) {
if (splitLayoutPanel.getWidgetDirection(widget) != CENTER) {
// collapse east/south part in order to maximize central part
splitLayoutPanel.setWidgetSize(widget, 0);
}

splitLayoutPanel.setWidgetSize(widget, 0);
splitLayoutPanel.remove(widget);

southSubPanels.remove(widget);
eastSubPanels.remove(widget);
}

@Override
public void setParentPanel(SubPanelView parentPanel) {
public void setParentPanel(@Nullable SubPanelView parentPanel) {
this.parentPanel = parentPanel;

if (parentPanel == null) {
// do not allow to remove root panel (if it doesn't have parent)
menu.removeListItem(closePaneMenuItem);
}
}

@Override
public void onMenuItemSelected(MenuItem menuItem) {
final Object data = menuItem.getData();
if (data instanceof Tab) {
selectTab((Tab)data);

WidgetToShow widget = tabs2Widgets.get(data);
final WidgetToShow widget = tabs2Widgets.get(data);
if (widget != null) {
activateWidget(widget);
delegate.onWidgetFocused(widget.getWidget());
Expand All @@ -247,10 +306,7 @@ public void onMenuItemClosing(MenuItem menuItem) {

@Override
public void onTabClicked(Tab tab) {
selectTab(tab);

// TODO: extract code to the separate method
WidgetToShow widget = tabs2Widgets.get(tab);
final WidgetToShow widget = tabs2Widgets.get(tab);
if (widget != null) {
activateWidget(widget);
delegate.onWidgetFocused(widget.getWidget());
Expand All @@ -266,24 +322,10 @@ private void selectTab(Tab tab) {
}

@Override

public void onTabClosing(Tab tab) {
closeTab(tab);
}

private void closeTab(Tab tab) {
final WidgetToShow widget = tabs2Widgets.get(tab);

if (widget != null) {
delegate.onWidgetRemoving(widget.getWidget(), new SubPanel.RemoveCallback() {
@Override
public void remove() {
removeWidgetFromUI(widget);
}
});
}
}

interface SubPanelViewImplUiBinder extends UiBinder<Widget, SubPanelViewImpl> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
<g:center>
<g:DockLayoutPanel ui:field="mainPanel" width="100%" height="100%">
<g:north size="23">
<g:FlowPanel ui:field="tabsPanel" addStyleNames="{style.tabsPanel}" debugId="multiSplitPanel-tabsPanel">
</g:FlowPanel>
<g:FlowPanel ui:field="tabsPanel" addStyleNames="{style.tabsPanel}" debugId="multiSplitPanel-tabsPanel"/>
</g:north>
<g:center>
<g:DeckLayoutPanel ui:field="widgetsPanel"/>
Expand Down
Loading

0 comments on commit 29c4133

Please sign in to comment.