Browse files

some toolbar improvements

  - now a perspective can define that it doesn't have toolbar
  - experimental: expand/collapse toolbar
  • Loading branch information...
1 parent 3ac1528 commit 11ad6b8729e7c15520141631e3fbee5363d73645 @porcelli porcelli committed Apr 10, 2013
View
27 uberfire-api/src/main/java/org/uberfire/client/workbench/model/PerspectiveDefinition.java
@@ -24,38 +24,43 @@
/**
* Get whether the Perspective is transient, i.e. will not be persisted.
- *
* @return True if the Perspective is transient and is not to be persisted.
*/
public boolean isTransient();
/**
* Set whether the Perspective is transient, i.e. will not be persisted.
- *
- * @param isTransient
- * True if the Perspective is not to be persisted.
+ * @param isTransient True if the Perspective is not to be persisted.
*/
- public void setTransient(final boolean isTransient);
+ public void setTransient( final boolean isTransient );
/**
* Get the name of the Perspective.
- *
* @return The name of the Perspective.
*/
public String getName();
/**
* Set the name of the Perspective.
- *
- * @param name
- * The name of the Perspective.
+ * @param name The name of the Perspective.
*/
- public void setName(final String name);
+ public void setName( final String name );
+
+ /**
+ * Get whether the Perspective has a visible toolbar.
+ * @return True if the Perspective has a visible toolbar.
+ */
+ public boolean isToolbarVisible();
+
+ /**
+ * Set whether the Perspective has a visible toolbar or not..
+ * @param isVisible True if the Perspective has a visible toolbar.
+ */
+ public void setToolbarVisible( boolean isVisible );
/**
* Get the root Panel for this Perspective. The root Panel contains all
* child Panels. A Perspective is based on a single root Panel.
- *
* @return The root Panel.
*/
public PanelDefinition getRoot();
View
26 ...api/src/main/java/org/uberfire/client/workbench/model/impl/PerspectiveDefinitionImpl.java
@@ -24,22 +24,24 @@
*/
@Portable
public class PerspectiveDefinitionImpl
- implements
- PerspectiveDefinition {
+ implements
+ PerspectiveDefinition {
- private String name;
+ private String name;
- private boolean isTransient = false;
+ private boolean isTransient = false;
- private PanelDefinition root = new PanelDefinitionImpl( true );
+ private boolean isToolbarVisible = true;
+
+ private PanelDefinition root = new PanelDefinitionImpl( true );
@Override
public boolean isTransient() {
return isTransient;
}
@Override
- public void setTransient(boolean isTransient) {
+ public void setTransient( boolean isTransient ) {
this.isTransient = isTransient;
}
@@ -49,11 +51,21 @@ public String getName() {
}
@Override
- public void setName(final String name) {
+ public void setName( final String name ) {
this.name = name;
}
@Override
+ public boolean isToolbarVisible() {
+ return isToolbarVisible;
+ }
+
+ @Override
+ public void setToolbarVisible( boolean isVisible ) {
+ this.isToolbarVisible = isVisible;
+ }
+
+ @Override
public PanelDefinition getRoot() {
return root;
}
View
1 ...wcase/uberfire-webapp/src/main/java/org/uberfire/client/perspectives/HomePerspective.java
@@ -19,6 +19,7 @@
@Perspective
public PerspectiveDefinition buildPerspective() {
final PerspectiveDefinition p = new PerspectiveDefinitionImpl();
+ p.setToolbarVisible( false );
p.setName( "Home" );
final PanelDefinition west = new PanelDefinitionImpl();
View
14 ...workbench/src/main/java/org/uberfire/client/mvp/AbstractWorkbenchPerspectiveActivity.java
@@ -179,10 +179,16 @@ private void initialisePerspective( final PerspectiveDefinition perspective ) {
//Set up Menu Bar for perspective
menuBar.aggregatePerspectiveMenus( getMenus() );
- //Set up Tool Bar for perspective
- final ToolBar toolBar = getToolBar();
- if ( toolBar != null ) {
- toolBarPresenter.addWorkbenchPerspective( toolBar );
+ if ( perspective.isToolbarVisible() ) {
+ toolBarPresenter.show();
+
+ //Set up Tool Bar for perspective
+ final ToolBar toolBar = getToolBar();
+ if ( toolBar != null ) {
+ toolBarPresenter.addWorkbenchPerspective( toolBar );
+ }
+ } else {
+ toolBarPresenter.hide();
}
onReveal();
View
4 uberfire-workbench/src/main/java/org/uberfire/client/resources/i18n/WorkbenchConstants.java
@@ -32,4 +32,8 @@
String minimizePanel();
+ String expandToolbar();
+
+ String collapseToolbar();
+
}
View
5 uberfire-workbench/src/main/java/org/uberfire/client/workbench/Workbench.java
@@ -198,11 +198,10 @@ public void onResize() {
private void doResizeWorkbenchContainer( final int width,
final int height ) {
final int menuBarHeight = menuBarPresenter.getView().asWidget().getOffsetHeight();
- final int toolBarHeight = toolBarPresenter.getView().asWidget().getOffsetHeight();
+ final int toolBarHeight = toolBarPresenter.getHeight();
// final int statusBarHeight = statusBarPresenter.getView().asWidget().getOffsetHeight();
final int availableHeight = height - menuBarHeight - toolBarHeight;// - statusBarHeight;
- workbenchContainer.setPixelSize( width,
- availableHeight );
+ workbenchContainer.setPixelSize( width, availableHeight );
workbench.setPixelSize( width,
availableHeight );
View
18 ...rc/main/java/org/uberfire/client/workbench/widgets/toolbar/WorkbenchToolBarPresenter.java
@@ -46,6 +46,12 @@
void addToolBar( final ToolBar toolBar );
void removeToolBar( final ToolBar toolBar );
+
+ int getHeight();
+
+ void hide();
+
+ void show();
}
private PlaceRequest activePlace;
@@ -72,6 +78,18 @@ public IsWidget getView() {
return this.view;
}
+ public int getHeight() {
+ return this.view.getHeight();
+ }
+
+ public void hide() {
+ this.view.hide();
+ }
+
+ public void show() {
+ this.view.show();
+ }
+
//Handle removing the WorkbenchPart Tool Bar items
void onWorkbenchPartClose( @Observes ClosePlaceEvent event ) {
if ( event.getPlace().equals( activePlace ) ) {
View
184 ...nch/src/main/java/org/uberfire/client/workbench/widgets/toolbar/WorkbenchToolBarView.java
@@ -24,10 +24,20 @@
import com.github.gwtbootstrap.client.ui.Tooltip;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.github.gwtbootstrap.client.ui.constants.Placement;
+import com.google.gwt.animation.client.Animation;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
-import org.uberfire.client.resources.WorkbenchResources;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.SimplePanel;
+import org.uberfire.client.resources.i18n.WorkbenchConstants;
/**
* The Tool Bar widget
@@ -36,14 +46,47 @@
implements
WorkbenchToolBarPresenter.View {
- private final ButtonToolbar toolBar = new ButtonToolbar();
+ interface WorkbenchToolBarViewBinder
+ extends
+ UiBinder<Panel, WorkbenchToolBarView> {
+
+ }
+
+ private static WorkbenchToolBarViewBinder uiBinder = GWT.create( WorkbenchToolBarViewBinder.class );
+
+ @UiField
+ public FlowPanel masterContainer;
+
+ @UiField
+ public FlowPanel container;
+
+ @UiField
+ public ButtonToolbar toolBar;
+
+ @UiField
+ public SimplePanel simpleMargin;
+
+ @UiField
+ public com.google.gwt.user.client.ui.Button viewControl;
+
+ @UiField
+ public Tooltip tip;
+
+ private State state = State.EXPANDED;
+
+ enum State {
+ EXPANDED, COLLAPSED;
+ }
//Map of ToolBar to GWT Widgets used to represent them
private final Map<String, ButtonGroup> toolBarItemsMap = new HashMap<String, ButtonGroup>();
public WorkbenchToolBarView() {
- toolBar.addStyleName( WorkbenchResources.INSTANCE.CSS().toolbar() );
- initWidget( toolBar );
+ initWidget( uiBinder.createAndBindUi( this ) );
+ tip.setText( WorkbenchConstants.INSTANCE.collapseToolbar() );
+ tip.setPlacement( Placement.LEFT );
+ tip.setWidget( viewControl );
+ simpleMargin.setVisible( false );
}
/**
@@ -55,6 +98,10 @@ public void addToolBar( final ToolBar _toolBar ) {
final ButtonGroup bgroup = new ButtonGroup();
+ if ( toolBarItemsMap.size() == 0 ) {
+ bgroup.getElement().getStyle().setPaddingLeft( 19, Style.Unit.PX );
+ }
+
for ( final ToolBarItem item : _toolBar.getItems() ) {
bgroup.add( new Tooltip( item.getTooltip() ) {{
setPlacement( Placement.BOTTOM );
@@ -84,4 +131,133 @@ public void removeToolBar( final ToolBar _toolBar ) {
toolBar.remove( toolBarItemsMap.remove( _toolBar.getId() ) );
}
+ @Override
+ public int getHeight() {
+ if ( isExpanded() ) {
+ return getOffsetHeight();
+ }
+ return 0;
+ }
+
+ private boolean isExpanded() {
+ return state == State.EXPANDED;
+ }
+
+ @Override
+ public void hide() {
+ container.setVisible( false );
+ simpleMargin.setVisible( true );
+ }
+
+ @Override
+ public void show() {
+ container.setVisible( true );
+ simpleMargin.setVisible( false );
+ }
+
+ @UiHandler("viewControl")
+ void handleClick( final ClickEvent e ) {
+ if ( isExpanded() ) {
+ collapse();
+ } else {
+ expand();
+ }
+ }
+
+ private void expand() {
+ container.removeFromParent();
+ container.getElement().getStyle().clearTop();
+ container.getElement().getStyle().clearPosition();
+ container.getElement().getStyle().clearZIndex();
+ masterContainer.add( container );
+
+ tip.setText( WorkbenchConstants.INSTANCE.collapseToolbar() );
+ tip.setPlacement( Placement.LEFT );
+ tip.setWidget( viewControl );
+ tip.reconfigure();
+
+ new ExpandAnimation().animate( 8, getOffsetWidth() - 1, 500 );
+ state = State.EXPANDED;
+ }
+
+ private void collapse() {
+ new CollapseAnimation().animate( getOffsetWidth(), 8, 500 );
+
+ container.removeFromParent();
+ container.getElement().getStyle().setTop( getAbsoluteTop(), Style.Unit.PX );
+ container.getElement().getStyle().setPosition( Style.Position.FIXED );
+ container.getElement().getStyle().setZIndex( Integer.MAX_VALUE );
+ RootPanel.get().add( container );
+
+ tip.setText( WorkbenchConstants.INSTANCE.expandToolbar() );
+ tip.setPlacement( Placement.RIGHT );
+ tip.setWidget( viewControl );
+ tip.reconfigure();
+
+ state = State.COLLAPSED;
+ }
+
+ private class ExpandAnimation extends Animation {
+
+ private int endSize;
+ private int startSize;
+ private int startTabLeft;
+ private int endTabLeft;
+
+ @Override
+ protected void onComplete() {
+ toolBar.getElement().getStyle().clearLeft();
+ container.getElement().getStyle().clearWidth();
+ }
+
+ @Override
+ protected void onUpdate( double progress ) {
+ double delta = ( endSize - startSize ) * progress;
+ double newSize = startSize + delta;
+
+ double deltaLeft = ( endTabLeft - startTabLeft ) * progress;
+ double newLeft = startTabLeft + deltaLeft;
+
+ toolBar.getElement().getStyle().setLeft( newLeft, Style.Unit.PX );
+ container.setWidth( newSize + "px" );
+ }
+
+ void animate( int startSize,
+ int endSize,
+ int duration ) {
+ this.startSize = startSize;
+ this.endSize = endSize;
+ this.startTabLeft = toolBar.getAbsoluteLeft();
+ this.endTabLeft = 0;
+ run( duration );
+ }
+ }
+
+ private class CollapseAnimation extends Animation {
+
+ private int endSize;
+ private int startSize;
+
+ @Override
+ protected void onComplete() {
+ container.setWidth( null );
+ }
+
+ @Override
+ protected void onUpdate( double progress ) {
+ double delta = ( endSize - startSize ) * progress;
+ double newSize = startSize + delta;
+ toolBar.getElement().getStyle().setLeft( delta, Style.Unit.PX );
+ container.setWidth( newSize + "px" );
+ }
+
+ void animate( int startSize,
+ int endSize,
+ int duration ) {
+ this.startSize = startSize;
+ this.endSize = endSize;
+ run( duration );
+ }
+ }
+
}
View
60 ...h/src/main/java/org/uberfire/client/workbench/widgets/toolbar/WorkbenchToolBarView.ui.xml
@@ -0,0 +1,60 @@
+<!--
+ ~ Copyright 2013 JBoss Inc
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ ~ use this file except in compliance with the License. You may obtain a copy of
+ ~ the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ ~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ ~ License for the specific language governing permissions and limitations under
+ ~ the License.
+ -->
+
+<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
+<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
+ xmlns:g="urn:import:com.google.gwt.user.client.ui"
+ xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
+
+ <ui:with field='res' type='org.uberfire.client.resources.WorkbenchResources'/>
+
+ <ui:style>
+ .margin {
+ height: 5px;
+ }
+
+ .container {
+ border-right-width: 1px !important;
+ border-bottom-width: 1px !important;
+ padding-right: 0 !important;
+ }
+
+ .reset_toolbar_margin {
+ float: left !important;
+ margin-top: 0 !important;
+ margin-bottom: 0 !important;
+ position: absolute !important;
+ }
+
+ .expand {
+ float: right;
+ border-right-width: 1px;
+ padding-right: 1px;
+ padding-left: 1px;
+ }
+ </ui:style>
+
+ <g:FlowPanel ui:field="masterContainer">
+ <g:FlowPanel ui:field="container" addStyleNames="{style.container} {res.CSS.toolbar}">
+ <b:ButtonToolbar ui:field="toolBar" addStyleNames="{style.reset_toolbar_margin}"/>
+ <b:Tooltip ui:field="tip">
+ <g:Button ui:field="viewControl" addStyleNames="{style.expand}">&#8942;</g:Button>
+ </b:Tooltip>
+ </g:FlowPanel>
+
+ <g:SimplePanel ui:field="simpleMargin" addStyleNames="{style.margin}"/>
+ </g:FlowPanel>
+</ui:UiBinder>
View
3 uberfire-workbench/src/main/resources/org/uberfire/client/resources/css/workbench.css
@@ -8,7 +8,8 @@
min-height: 30px;
margin-top: 0;
margin-bottom: 5px;
- padding: 5px 19px;
+ padding-bottom: 5px;
+ padding-top: 5px;
background-color: #f5f5f5;
border: 1px solid #e3e3e3;
-webkit-border-radius: 4px;
View
2 ...bench/src/main/resources/org/uberfire/client/resources/i18n/WorkbenchConstants.properties
@@ -1,2 +1,4 @@
maximizePanel=Maximize panel to fit full screen
minimizePanel=Minimize panel to the Status Bar
+expandToolbar=Expand Toolbar
+collapseToolbar=Collapse Toolbar

0 comments on commit 11ad6b8

Please sign in to comment.