/*******************************************************************************
* Copyright 2011 Thingtrack
*
* 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.
******************************************************************************/
package com.thingtrack.konekti.view.layout.workbench;
import java.util.Hashtable;
import com.thingtrack.konekti.view.kernel.ui.layout.IViewContainer;
import com.thingtrack.konekti.view.kernel.ui.layout.IWorkbenchLayout;
import com.thingtrack.konekti.view.kernel.ui.layout.IWorkbenchPanel;
import com.thingtrack.konekti.view.kernel.ui.layout.LOCATION;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.terminal.Resource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
public class WorkbenchLayout extends CustomComponent implements IWorkbenchLayout {
@AutoGenerated
private HorizontalLayout mainLayout;
@AutoGenerated
private VerticalLayout workBenchLayout;
@AutoGenerated
private WorkbenchPanel bottonPanelWorkbench;
@AutoGenerated
private HorizontalLayout centralMainLayout;
@AutoGenerated
private WorkbenchPanel rightPanelWorkbench;
@AutoGenerated
private WorkbenchPanel centralPanelWorkbench;
@AutoGenerated
private WorkbenchPanel leftPanelWorkbench;
@AutoGenerated
private WorkbenchPanel topPanelWorkbench;
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
private Hashtable<String, LOCATION> modules;
/**
* The constructor should first build the main layout, set the
* composition root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the
* visual editor.
*/
public WorkbenchLayout() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
topPanelWorkbench.setLocationLayout(LOCATION.TOP);
leftPanelWorkbench.setLocationLayout(LOCATION.LEFT);
centralPanelWorkbench.setLocationLayout(LOCATION.CENTER);
rightPanelWorkbench.setLocationLayout(LOCATION.RIGHT);
bottonPanelWorkbench.setLocationLayout(LOCATION.BOTTON);
modules = new Hashtable<String, LOCATION>();
}
@Override
public void setTopPanelWorkbenchVisible(boolean visible) {
topPanelWorkbench.setVisible(visible);
}
@Override
public boolean isTopPanelWorkbenchVisible() {
return topPanelWorkbench.isVisible();
}
@Override
public void setLeftPanelWorkbenchVisible(boolean visible) {
leftPanelWorkbench.setVisible(visible);
}
@Override
public boolean isLeftPanelWorkbenchVisible() {
return leftPanelWorkbench.isVisible();
}
@Override
public void setRightPanelWorkbenchVisible(boolean visible) {
rightPanelWorkbench.setVisible(visible);
}
@Override
public boolean isRightPanelWorkbenchVisible() {
return rightPanelWorkbench.isVisible();
}
@Override
public void setBottonPanelWorkbenchVisible(boolean visible) {
bottonPanelWorkbench.setVisible(visible);
}
@Override
public boolean isBottonPanelWorkbenchVisible() {
return bottonPanelWorkbench.isVisible();
}
@Override
public IWorkbenchPanel getTopPanelWorkbench() {
return (IWorkbenchPanel) this.topPanelWorkbench;
}
@Override
public IWorkbenchPanel getLeftPanelWorkbench() {
return (IWorkbenchPanel) this.leftPanelWorkbench;
}
@Override
public IWorkbenchPanel getCentralPanelWorkbench() {
return (IWorkbenchPanel) this.centralPanelWorkbench;
}
@Override
public IWorkbenchPanel getRightPanelWorkbench() {
return (IWorkbenchPanel) this.rightPanelWorkbench;
}
@Override
public IWorkbenchPanel getBottonPanelWorkbench() {
return (IWorkbenchPanel) this.bottonPanelWorkbench;
}
@Override
public void addModule(String id, String name, IViewContainer viewComponent, boolean closeable, Resource icon, LOCATION location) {
if (location == LOCATION.TOP)
getTopPanelWorkbench().addModule(id, name, viewComponent, closeable, icon, location);
else if (location == LOCATION.LEFT)
getLeftPanelWorkbench().addModule(id, name, viewComponent, closeable, icon, location);
else if(location == LOCATION.CENTER)
getCentralPanelWorkbench().addModule(id, name, viewComponent, closeable, icon, location);
else if(location == LOCATION.RIGHT)
getRightPanelWorkbench().addModule(id, name, viewComponent, closeable, icon, location);
else if(location == LOCATION.BOTTON)
getBottonPanelWorkbench().addModule(id, name, viewComponent, closeable, icon, location);
modules.put(id, location);
}
@Override
public void removeModule(String id) {
Object loc = modules.get(id);
if (loc == null)
return;
LOCATION location = (LOCATION)loc;
if (location == LOCATION.TOP)
getTopPanelWorkbench().removeModule(id);
else if (location == LOCATION.LEFT)
getLeftPanelWorkbench().removeModule(id);
else if(location == LOCATION.CENTER)
getCentralPanelWorkbench().removeModule(id);
else if(location == LOCATION.RIGHT)
getRightPanelWorkbench().removeModule(id);
else if(location == LOCATION.BOTTON)
getBottonPanelWorkbench().removeModule(id);
}
@Override
public void removeModules(LOCATION location) {
if (location == LOCATION.TOP)
getTopPanelWorkbench().removeModules(location);
else if (location == LOCATION.LEFT)
getLeftPanelWorkbench().removeModules(location);
else if(location == LOCATION.CENTER)
getCentralPanelWorkbench().removeModules(location);
else if(location == LOCATION.RIGHT)
getRightPanelWorkbench().removeModules(location);
else if(location == LOCATION.BOTTON)
getBottonPanelWorkbench().removeModules(location);
}
@AutoGenerated
private HorizontalLayout buildMainLayout() {
// common part: create layout
mainLayout = new HorizontalLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
mainLayout.setMargin(false);
// top-level component properties
setWidth("100.0%");
setHeight("100.0%");
// workBenchLayout
workBenchLayout = buildWorkBenchLayout();
mainLayout.addComponent(workBenchLayout);
return mainLayout;
}
@AutoGenerated
private VerticalLayout buildWorkBenchLayout() {
// common part: create layout
workBenchLayout = new VerticalLayout();
workBenchLayout.setImmediate(false);
workBenchLayout.setWidth("100.0%");
workBenchLayout.setHeight("100.0%");
workBenchLayout.setMargin(false);
// topPanelWorkbench
topPanelWorkbench = new WorkbenchPanel();
topPanelWorkbench.setImmediate(false);
topPanelWorkbench.setWidth("100.0%");
topPanelWorkbench.setHeight("80px");
workBenchLayout.addComponent(topPanelWorkbench);
// centralMainLayout
centralMainLayout = buildCentralMainLayout();
workBenchLayout.addComponent(centralMainLayout);
workBenchLayout.setExpandRatio(centralMainLayout, 1.0f);
// bottonPanelWorkbench
bottonPanelWorkbench = new WorkbenchPanel();
bottonPanelWorkbench.setImmediate(false);
bottonPanelWorkbench.setWidth("100.0%");
bottonPanelWorkbench.setHeight("80px");
workBenchLayout.addComponent(bottonPanelWorkbench);
return workBenchLayout;
}
@AutoGenerated
private HorizontalLayout buildCentralMainLayout() {
// common part: create layout
centralMainLayout = new HorizontalLayout();
centralMainLayout.setImmediate(false);
centralMainLayout.setWidth("100.0%");
centralMainLayout.setHeight("100.0%");
centralMainLayout.setMargin(true);
// leftPanelWorkbench
leftPanelWorkbench = new WorkbenchPanel();
leftPanelWorkbench.setImmediate(false);
leftPanelWorkbench.setWidth("200px");
leftPanelWorkbench.setHeight("100.0%");
centralMainLayout.addComponent(leftPanelWorkbench);
// centralPanelWorkbench
centralPanelWorkbench = new WorkbenchPanel();
centralPanelWorkbench.setImmediate(false);
centralPanelWorkbench.setWidth("100.0%");
centralPanelWorkbench.setHeight("100.0%");
centralMainLayout.addComponent(centralPanelWorkbench);
centralMainLayout.setExpandRatio(centralPanelWorkbench, 1.0f);
centralMainLayout.setComponentAlignment(centralPanelWorkbench,
new Alignment(48));
// rightPanelWorkbench
rightPanelWorkbench = new WorkbenchPanel();
rightPanelWorkbench.setImmediate(false);
rightPanelWorkbench.setWidth("200px");
rightPanelWorkbench.setHeight("100.0%");
centralMainLayout.addComponent(rightPanelWorkbench);
centralMainLayout.setComponentAlignment(rightPanelWorkbench,
new Alignment(6));
return centralMainLayout;
}
}