add tabsheet component

This commit is contained in:
Dmitry Abramov 2009-02-02 14:02:50 +00:00
parent 5b02364869
commit e403f6e4e3
7 changed files with 166 additions and 5 deletions

View File

@ -10,16 +10,20 @@
package com.haulmont.cuba.gui.components;
import java.util.List;
import java.util.Collection;
public interface Tabsheet extends Component {
void addTab(String name, Component component);
void removeTab(String name);
Tab getTab();
void setTab(Tab tab);
void setTab(String name);
List<Tab> getTabs();
Collection<Tab> getTabs();
interface Tab {
String getName();
void setName();
void setName(String name);
}
}

View File

@ -47,6 +47,7 @@ public class LayoutLoaderConfig {
config.registerLoader("iframe", IFrameLoader.class);
config.registerLoader("split", SplitPanelLoader.class);
config.registerLoader("tree", TreeLoader.class);
config.registerLoader("tabsheet", TabsheetLoader.class);
}
public static LayoutLoaderConfig getWindowLoaders() {

View File

@ -10,11 +10,15 @@
package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.data.DsContext;
import org.dom4j.Element;
import org.apache.commons.lang.StringUtils;
import java.util.Locale;
import java.util.ResourceBundle;
import java.lang.reflect.Constructor;
public abstract class ComponentLoader implements com.haulmont.cuba.gui.xml.layout.ComponentLoader {
protected Locale locale;

View File

@ -11,9 +11,7 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.OrderedLayout;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
import com.haulmont.cuba.gui.xml.layout.*;
import com.haulmont.cuba.gui.data.DsContext;
import org.dom4j.Element;
import org.apache.commons.lang.StringUtils;
@ -22,6 +20,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import java.lang.reflect.Constructor;
public abstract class ContainerLoader extends ComponentLoader {
protected ComponentsFactory factory;
@ -77,4 +76,25 @@ public abstract class ContainerLoader extends ComponentLoader {
}
return null;
}
protected com.haulmont.cuba.gui.xml.layout.ComponentLoader getLoader(String name) throws IllegalAccessException, InstantiationException {
Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader> loaderClass = config.getLoader(name);
if (loaderClass == null) {
throw new IllegalStateException(String.format("Unknown component '%s'", name));
}
com.haulmont.cuba.gui.xml.layout.ComponentLoader loader;
try {
final Constructor<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader> constructor =
loaderClass.getConstructor(LayoutLoaderConfig.class, ComponentsFactory.class, DsContext.class);
loader = constructor.newInstance(config, factory, dsContext);
loader.setLocale(locale);
} catch (Throwable e) {
loader = loaderClass.newInstance();
}
return loader;
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 02.02.2009 16:46:18
* $Id$
*/
package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.Tabsheet;
import com.haulmont.cuba.gui.data.DsContext;
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import org.dom4j.Element;
import java.util.List;
public class TabsheetLoader extends ContainerLoader {
public TabsheetLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
super(config, factory, dsContext);
}
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
final Tabsheet component = factory.createComponent("tabsheet");
loadId(component, element);
assignXmlDescriptor(component, element);
final List<Element> tabElements = element.elements("tab");
for (Element tabElement : tabElements) {
final String name = tabElement.attributeValue("name");
final ComponentLoader loader = getLoader("vbox");
component.addTab(name, loader.loadComponent(factory, tabElement));
}
return component;
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 02.02.2009 17:05:00
* $Id$
*/
package com.haulmont.cuba.web.components;
import com.haulmont.cuba.gui.components.Component;
import com.itmill.toolkit.ui.TabSheet;
import java.util.HashMap;
import java.util.Map;
import java.util.Collection;
public class Tabsheet
extends
AbstractComponent<TabSheet>
implements
com.haulmont.cuba.gui.components.Tabsheet, Component.Wrapper
{
public Tabsheet() {
component = new TabSheet();
}
protected Map<String, Tab> tabs = new HashMap<String, Tab>();
protected Map<Component, String> components = new HashMap<Component, String>();
protected class Tab implements com.haulmont.cuba.gui.components.Tabsheet.Tab {
private String name;
private Component component;
public Tab(String name, Component component) {
this.name = name;
this.component = component;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Component getComponent() {
return component;
}
}
public void addTab(String name, Component component) {
this.tabs.put(name, new Tab(name, component));
this.components.put(component, name);
this.component.addTab(ComponentsHelper.unwrap(component));
}
public void removeTab(String name) {
final Tab tab = tabs.get(name);
if (tab == null) throw new IllegalStateException(String.format("Can't find tab '%s'", name));
this.component.removeComponent(ComponentsHelper.unwrap(tab.getComponent()));
}
public Tab getTab() {
final com.itmill.toolkit.ui.Component component = this.component.getSelectedTab();
final String name = components.get(component);
return tabs.get(name);
}
public void setTab(com.haulmont.cuba.gui.components.Tabsheet.Tab tab) {
this.component.setSelectedTab(ComponentsHelper.unwrap(((Tab) tab).getComponent()));
}
public void setTab(String name) {
Tab tab = tabs.get(name);
if (tab == null) throw new IllegalStateException(String.format("Can't find tab '%s'", name));
this.component.setSelectedTab(ComponentsHelper.unwrap(tab.getComponent()));
}
public Collection<com.haulmont.cuba.gui.components.Tabsheet.Tab> getTabs() {
return (Collection)tabs.values();
}
}

View File

@ -39,6 +39,7 @@ public class WebComponentsFactory implements ComponentsFactory {
classes.put("lookup-field", LookupField.class);
classes.put("split", SplitPanel.class);
classes.put("tree", Tree.class);
classes.put("tabsheet", Tabsheet.class);
}
public <T extends Component> T createComponent(String name) throws InstantiationException, IllegalAccessException {