mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
Buttons panel
This commit is contained in:
parent
df2f63edb5
commit
d39af52417
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Nikolay Gorodnov
|
||||
* Created: 15.12.2009 16:06:40
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ButtonsPanel extends BoxLayout {
|
||||
void addButton(Button actionButton);
|
||||
|
||||
void removeButton(Button actionButton);
|
||||
|
||||
Collection<Button> getButtons();
|
||||
|
||||
Button getButton(String id);
|
||||
|
||||
public interface Provider {
|
||||
Collection<Button> getButtons();
|
||||
}
|
||||
}
|
@ -216,4 +216,9 @@ public interface Component {
|
||||
String getIcon();
|
||||
void setIcon(String icon);
|
||||
}
|
||||
|
||||
interface HasButtonsPanel {
|
||||
ButtonsPanel getButtonsPanel();
|
||||
void setButtonsPanel(ButtonsPanel panel);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||
|
||||
public interface Table
|
||||
extends
|
||||
com.haulmont.cuba.gui.components.List, Component.Editable, Component.HasSettings, Component.Expandable
|
||||
com.haulmont.cuba.gui.components.List, Component.Editable, Component.HasSettings, Component.Expandable, Component.HasButtonsPanel
|
||||
{
|
||||
List<Column> getColumns();
|
||||
Column getColumn(String id);
|
||||
@ -180,60 +180,4 @@ public interface Table
|
||||
}
|
||||
|
||||
void setPagingProvider(PagingProvider pagingProvider);
|
||||
|
||||
interface ActionButtonsProvider {
|
||||
List<ActionButton> getButtons();
|
||||
ActionButton getButton(String id);
|
||||
}
|
||||
|
||||
ActionButtonsProvider getActionButtonsProvider();
|
||||
void setActionButtonsProvider(ActionButtonsProvider buttonsPanel);
|
||||
|
||||
public class ActionButton implements HasXmlDescriptor, HasCaption, HasIcon, ActionOwner {
|
||||
protected String id;
|
||||
protected String caption;
|
||||
protected String icon;
|
||||
protected Action action;
|
||||
protected Element element;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(String icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Element getXmlDescriptor() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public void setXmlDescriptor(Element element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,18 +300,9 @@
|
||||
<xs:group name="component">
|
||||
<xs:sequence>
|
||||
<xs:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element name="button">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="id" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="action" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="caption" type="xs:string" use="optional" default="msg://"/>
|
||||
<xs:attribute name="visible" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="enable" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="stylename" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="icon" type="xs:string" use="optional" default="icon://"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="button" type="buttonType" />
|
||||
|
||||
<xs:element name="buttonsPanel" type="buttonsPanelType" />
|
||||
|
||||
<xs:element name="label">
|
||||
<xs:complexType>
|
||||
@ -599,7 +590,7 @@
|
||||
|
||||
<xs:complexType name="tableType">
|
||||
<xs:sequence>
|
||||
<xs:element name="actionButtons" minOccurs="0" maxOccurs="1" type="actionButtonsType"/>
|
||||
<xs:element name="buttonsPanel" minOccurs="0" maxOccurs="1" type="buttonsPanelType"/>
|
||||
<xs:element name="columns" minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
@ -633,18 +624,27 @@
|
||||
<xs:attribute name="format" type="xs:string" use="optional"/>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="actionButtonsType">
|
||||
<xs:complexType name="buttonsPanelType">
|
||||
<xs:sequence>
|
||||
<xs:element name="actionButton" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="id" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="caption" type="xs:string" use="optional" default="msg://"/>
|
||||
<xs:attribute name="icon" type="xs:string" use="optional" default="icon://"/>
|
||||
<xs:attribute name="action" type="xs:string" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="button" minOccurs="0" maxOccurs="unbounded" type="buttonType" />
|
||||
</xs:sequence>
|
||||
<xs:attribute name="class" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="id" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="width" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="height" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="expand" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="align" type="align" use="optional"/>
|
||||
<xs:attribute name="stylename" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="providerClass" type="xs:string" use="optional"/>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="buttonType">
|
||||
<xs:attribute name="id" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="action" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="caption" type="xs:string" use="optional" default="msg://"/>
|
||||
<xs:attribute name="visible" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="enable" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="stylename" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="icon" type="xs:string" use="optional" default="icon://"/>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:simpleType name="orientation">
|
||||
|
@ -20,7 +20,7 @@ public class LayoutLoaderConfig {
|
||||
|
||||
private static LayoutLoaderConfig windowLoaders = new LayoutLoaderConfig();
|
||||
private static LayoutLoaderConfig editorLoaders = new LayoutLoaderConfig();
|
||||
private static LayoutLoaderConfig lookupLoaders = new LayoutLoaderConfig();
|
||||
private static LayoutLoaderConfig lookupLoaders = new LayoutLoaderConfig();
|
||||
private static LayoutLoaderConfig frameLoaders = new LayoutLoaderConfig();
|
||||
|
||||
private static Map<String, Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader>> customLoaders =
|
||||
@ -60,7 +60,7 @@ public class LayoutLoaderConfig {
|
||||
config.register("optionsGroup", OptionsGroupLoader.class);
|
||||
config.register("upload", FileUploadFieldLoader.class);
|
||||
config.register("table", TableLoader.class);
|
||||
config.register("treeTable", TreeTableLoader.class);
|
||||
config.register("treeTable", TreeTableLoader.class);
|
||||
config.register("iframe", IFrameLoader.class);
|
||||
config.register("split", SplitPanelLoader.class);
|
||||
config.register("tree", TreeLoader.class);
|
||||
@ -68,6 +68,7 @@ public class LayoutLoaderConfig {
|
||||
config.register("embedded", EmbeddedLoader.class);
|
||||
config.register("filter", FilterLoader.class);
|
||||
config.register("accessControl", AccessControlLoader.class);
|
||||
config.register("buttonsPanel", ButtonsPanelLoader.class);
|
||||
}
|
||||
|
||||
public static void registerLoader(String tagName, Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader> aClass) {
|
||||
|
@ -114,11 +114,7 @@ public abstract class AbstractTableLoader<T extends Table> extends ComponentLoad
|
||||
}
|
||||
}
|
||||
|
||||
//action buttons
|
||||
final Element actionButtonsElement = element.element("actionButtons");
|
||||
if (actionButtonsElement != null) {
|
||||
loadActionButtons(component, actionButtonsElement);
|
||||
}
|
||||
loadButtonsPanel(component, element);
|
||||
|
||||
addAssignWindowTask(component);
|
||||
|
||||
@ -132,6 +128,17 @@ public abstract class AbstractTableLoader<T extends Table> extends ComponentLoad
|
||||
}
|
||||
}
|
||||
|
||||
private void loadButtonsPanel(Component.HasButtonsPanel component, Element element)
|
||||
throws InstantiationException, IllegalAccessException {
|
||||
Element panelElement = element.element("buttonsPanel");
|
||||
if (panelElement != null) {
|
||||
ButtonsPanelLoader loader = (ButtonsPanelLoader) getLoader("buttonsPanel");
|
||||
ButtonsPanel panel = (ButtonsPanel) loader.loadComponent(factory, panelElement, null);
|
||||
|
||||
component.setButtonsPanel(panel);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadPaging(Table component, final Element element) {
|
||||
component.setPagingProvider(new Table.PagingProvider() {
|
||||
public String firstCaption() {
|
||||
@ -179,62 +186,6 @@ public abstract class AbstractTableLoader<T extends Table> extends ComponentLoad
|
||||
});
|
||||
}
|
||||
|
||||
private void loadActionButtons(final T component, Element element) throws InstantiationException {
|
||||
final String className = element.attributeValue("class");
|
||||
if (className != null) {
|
||||
final Class<Table.ActionButtonsProvider> clazz = ReflectionHelper.getClass(className);
|
||||
|
||||
try {
|
||||
final Constructor<Table.ActionButtonsProvider> constructor = clazz.getConstructor(Element.class);
|
||||
try {
|
||||
final Table.ActionButtonsProvider instance = constructor.newInstance(element);
|
||||
component.setActionButtonsProvider(instance);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
try {
|
||||
final Table.ActionButtonsProvider instance = clazz.newInstance();
|
||||
component.setActionButtonsProvider(instance);
|
||||
} catch (Throwable e1) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final List<Element> actionButtonElements = element.elements("actionButton");
|
||||
if (!actionButtonElements.isEmpty()) {
|
||||
final TableActionButtonsProvider actionButtonsProvider = new TableActionButtonsProvider();
|
||||
for (final Element actionButtonElement : actionButtonElements) {
|
||||
actionButtonsProvider.addActionButton(loadActionButton(component, actionButtonElement));
|
||||
}
|
||||
context.addLazyTask(new LazyTask() {
|
||||
public void execute(Context context, IFrame frame) {
|
||||
component.setActionButtonsProvider(actionButtonsProvider);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw new InstantiationException(
|
||||
"<actionButtons> element must contains \"class\" attribute or at least one <actionButton> element");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Table.ActionButton loadActionButton(T component, Element element) {
|
||||
final Table.ActionButton actionButton = new Table.ActionButton();
|
||||
actionButton.setXmlDescriptor(element);
|
||||
|
||||
final String id = element.attributeValue("id");
|
||||
if (!StringUtils.isEmpty(id)) {
|
||||
actionButton.setId(id);
|
||||
}
|
||||
|
||||
loadCaption(actionButton, element);
|
||||
loadIcon(actionButton, element);
|
||||
loadAction(actionButton, element);
|
||||
|
||||
return actionButton;
|
||||
}
|
||||
|
||||
private void loadRequired(T component, Table.Column column) {
|
||||
Element element = column.getXmlDescriptor();
|
||||
final String required = element.attributeValue("required");
|
||||
@ -395,24 +346,27 @@ public abstract class AbstractTableLoader<T extends Table> extends ComponentLoad
|
||||
}
|
||||
}
|
||||
|
||||
class TableActionButtonsProvider implements Table.ActionButtonsProvider {
|
||||
|
||||
private List<Table.ActionButton> actionButtons = new LinkedList<Table.ActionButton>();
|
||||
private Map<String, Table.ActionButton> idActionButton = new HashMap<String, Table.ActionButton>();
|
||||
|
||||
public void addActionButton(Table.ActionButton actionButton) {
|
||||
actionButtons.add(actionButton);
|
||||
if (actionButton.getId() != null) {
|
||||
idActionButton.put(actionButton.getId(), actionButton);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
public List<Table.ActionButton> getButtons() {
|
||||
return Collections.unmodifiableList(actionButtons);
|
||||
com.haulmont.cuba.gui.xml.layout.ComponentLoader loader;
|
||||
try {
|
||||
final Constructor<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader> constructor =
|
||||
loaderClass.getConstructor(Context.class, LayoutLoaderConfig.class, ComponentsFactory.class);
|
||||
loader = constructor.newInstance(context, config, factory);
|
||||
|
||||
loader.setLocale(locale);
|
||||
loader.setMessagesPack(messagesPack);
|
||||
} catch (Throwable e) {
|
||||
loader = loaderClass.newInstance();
|
||||
loader.setLocale(locale);
|
||||
loader.setMessagesPack(messagesPack);
|
||||
}
|
||||
|
||||
public Table.ActionButton getButton(String id) {
|
||||
return idActionButton.get(id);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Nikolay Gorodnov
|
||||
* Created: 15.12.2009 16:26:40
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.bali.util.ReflectionHelper;
|
||||
import com.haulmont.cuba.gui.components.Button;
|
||||
import com.haulmont.cuba.gui.components.ButtonsPanel;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Collection;
|
||||
|
||||
public class ButtonsPanelLoader <T extends ButtonsPanel> extends ContainerLoader {
|
||||
public ButtonsPanelLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element, Component parent)
|
||||
throws InstantiationException, IllegalAccessException {
|
||||
final ButtonsPanel component = factory.createComponent("buttonsPanel");
|
||||
|
||||
assignXmlDescriptor(component, element);
|
||||
loadId(component, element);
|
||||
loadVisible(component, element);
|
||||
|
||||
loadStyleName(component, element);
|
||||
loadAlign(component, element);
|
||||
|
||||
loadExpandable(component, element);
|
||||
|
||||
loadWidth(component, element);
|
||||
loadHeight(component, element);
|
||||
|
||||
if (!element.elements().isEmpty()) {
|
||||
loadSubComponents(component, element, "visible");
|
||||
} else {
|
||||
String className = element.attributeValue("providerClass");
|
||||
if (className != null) {
|
||||
final Class<ButtonsPanel.Provider> clazz = ReflectionHelper.getClass(className);
|
||||
|
||||
try {
|
||||
final Constructor<ButtonsPanel.Provider> constructor = clazz.getConstructor();
|
||||
final ButtonsPanel.Provider instance = constructor.newInstance();
|
||||
applyButtonsProvider(factory, component, instance);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new InstantiationException(
|
||||
"<buttonsPanel> element must contains \"class\" attribute or at least one <button> element");
|
||||
}
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
private void applyButtonsProvider(ComponentsFactory factory, ButtonsPanel panel, ButtonsPanel.Provider buttonsProvider)
|
||||
throws IllegalAccessException, InstantiationException {
|
||||
final Collection<Button> buttons = buttonsProvider.getButtons();
|
||||
for (final Button button : buttons) {
|
||||
panel.addButton(button);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,10 +5,7 @@ import com.google.common.collect.HashBiMap;
|
||||
import com.vaadin.event.Action;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class WebAbstractActionOwnerComponent<T extends com.vaadin.ui.Component>
|
||||
extends WebAbstractComponent<T>
|
||||
@ -27,7 +24,7 @@ public class WebAbstractActionOwnerComponent<T extends com.vaadin.ui.Component>
|
||||
}
|
||||
|
||||
public Collection<com.haulmont.cuba.gui.components.Action> getActions() {
|
||||
return actionsOrder;
|
||||
return Collections.unmodifiableCollection(actionsOrder);
|
||||
}
|
||||
|
||||
public com.haulmont.cuba.gui.components.Action getAction(String id) {
|
||||
|
@ -27,10 +27,10 @@ import com.haulmont.cuba.security.entity.EntityAttrAccess;
|
||||
import com.haulmont.cuba.security.entity.EntityOp;
|
||||
import com.haulmont.cuba.security.global.UserSession;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.gui.CompositionLayout;
|
||||
import com.haulmont.cuba.web.gui.data.CollectionDsWrapper;
|
||||
import com.haulmont.cuba.web.gui.data.ItemWrapper;
|
||||
import com.haulmont.cuba.web.gui.data.PropertyWrapper;
|
||||
import com.haulmont.cuba.web.gui.CompositionLayout;
|
||||
import com.haulmont.cuba.web.toolkit.data.AggregationContainer;
|
||||
import com.haulmont.cuba.web.toolkit.ui.TableSupport;
|
||||
import com.vaadin.data.Item;
|
||||
@ -42,7 +42,6 @@ import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.Layout;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
@ -78,9 +77,8 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
|
||||
new LinkedHashSet<com.haulmont.cuba.gui.components.Field.Validator>();
|
||||
|
||||
protected VerticalLayout componentComposition;
|
||||
protected Layout actionButtonsLayout;
|
||||
|
||||
protected Table.ActionButtonsProvider actionButtonsProvider;
|
||||
protected ButtonsPanel buttonsPanel;
|
||||
|
||||
public java.util.List<Table.Column> getColumns() {
|
||||
return columnsOrder;
|
||||
@ -150,11 +148,9 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
|
||||
component.setAggregatable(aggregatable);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Component getComposition() {
|
||||
return componentComposition != null
|
||||
? componentComposition : component;
|
||||
return componentComposition;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
@ -233,7 +229,8 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
|
||||
});
|
||||
|
||||
componentComposition = new CompositionLayout(component);
|
||||
componentComposition.setSpacing(true);
|
||||
componentComposition.setSpacing(false);
|
||||
componentComposition.setMargin(false);
|
||||
componentComposition.setExpandRatio(component, 1);
|
||||
}
|
||||
|
||||
@ -290,7 +287,7 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
|
||||
component.setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final Collection<MetaPropertyPath> columns;
|
||||
if (this.columns.isEmpty()) {
|
||||
columns = null;
|
||||
@ -557,6 +554,20 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
|
||||
}
|
||||
}
|
||||
|
||||
public ButtonsPanel getButtonsPanel() {
|
||||
return buttonsPanel;
|
||||
}
|
||||
|
||||
public void setButtonsPanel(ButtonsPanel panel) {
|
||||
if (buttonsPanel != null) {
|
||||
componentComposition.removeComponent(WebComponentsHelper.unwrap(buttonsPanel));
|
||||
}
|
||||
buttonsPanel = panel;
|
||||
if (panel != null) {
|
||||
componentComposition.addComponentAsFirst(WebComponentsHelper.unwrap(panel));
|
||||
}
|
||||
}
|
||||
|
||||
public void setPagingProvider(final Table.PagingProvider pagingProvider) {
|
||||
this.pagingProvider = pagingProvider;
|
||||
component.setPagingProvider(new com.haulmont.cuba.web.toolkit.ui.Table.PagingProvider() {
|
||||
@ -606,74 +617,6 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
|
||||
);
|
||||
}
|
||||
|
||||
public Table.ActionButtonsProvider getActionButtonsProvider() {
|
||||
return actionButtonsProvider;
|
||||
}
|
||||
|
||||
public void setActionButtonsProvider(Table.ActionButtonsProvider buttonsProvider) {
|
||||
if (actionButtonsProvider != null) {
|
||||
componentComposition.removeComponent(actionButtonsLayout);
|
||||
}
|
||||
actionButtonsProvider = buttonsProvider;
|
||||
if (buttonsProvider != null) {
|
||||
actionButtonsLayout = createActionButtonsLayout();
|
||||
componentComposition.addComponentAsFirst(actionButtonsLayout);
|
||||
}
|
||||
}
|
||||
|
||||
protected Layout createActionButtonsLayout() {
|
||||
final HorizontalLayout buttonsLayout = new HorizontalLayout();
|
||||
buttonsLayout.setSpacing(true);
|
||||
buttonsLayout.setMargin(true, true, false, true);
|
||||
for (final Table.ActionButton actionButton : actionButtonsProvider.getButtons()) {
|
||||
buttonsLayout.addComponent(createButton(actionButton));
|
||||
}
|
||||
return buttonsLayout;
|
||||
}
|
||||
|
||||
protected Component createButton(Table.ActionButton actionButton) {
|
||||
final WebButton webButton = new WebButton();
|
||||
webButton.setId(actionButton.getId());
|
||||
webButton.setAction(new ActionButtonAction(actionButton));
|
||||
return WebComponentsHelper.getComposition(webButton);
|
||||
}
|
||||
|
||||
private class ActionButtonAction extends com.haulmont.cuba.gui.components.AbstractAction {
|
||||
|
||||
private Table.ActionButton actionButton;
|
||||
|
||||
public ActionButtonAction(Table.ActionButton actionButton) {
|
||||
super(null);
|
||||
this.actionButton = actionButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return actionButton.getAction() != null
|
||||
? actionButton.getAction().getId() : actionButton.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
String caption = actionButton.getCaption();
|
||||
if (StringUtils.isEmpty(caption) && actionButton.getAction() != null) {
|
||||
caption = actionButton.getAction().getCaption();
|
||||
}
|
||||
return caption;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIcon() {
|
||||
return actionButton.getIcon();
|
||||
}
|
||||
|
||||
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
|
||||
if (actionButton.getAction() != null) {
|
||||
actionButton.getAction().actionPerform(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class TablePropertyWrapper extends PropertyWrapper {
|
||||
public TablePropertyWrapper(Object item, MetaPropertyPath propertyPath) {
|
||||
super(item, propertyPath);
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Nikolay Gorodnov
|
||||
* Created: 15.12.2009 16:29:37
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Button;
|
||||
import com.haulmont.cuba.gui.components.ButtonsPanel;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class WebButtonsPanel extends WebHBoxLayout
|
||||
implements ButtonsPanel {
|
||||
|
||||
public WebButtonsPanel() {
|
||||
super();
|
||||
setSpacing(true);
|
||||
setMargin(true);
|
||||
}
|
||||
|
||||
public void addButton(com.haulmont.cuba.gui.components.Button actionButton) {
|
||||
add(actionButton);
|
||||
}
|
||||
|
||||
public void removeButton(com.haulmont.cuba.gui.components.Button actionButton) {
|
||||
remove(actionButton);
|
||||
}
|
||||
|
||||
public Collection<com.haulmont.cuba.gui.components.Button> getButtons() {
|
||||
final Collection<Component> components = getComponents();
|
||||
final Collection<com.haulmont.cuba.gui.components.Button> buttons = new ArrayList<Button>(components.size());
|
||||
for (final Component component : components) {
|
||||
buttons.add((Button) component);
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public com.haulmont.cuba.gui.components.Button getButton(String id) {
|
||||
return getComponent(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Component component) {
|
||||
if (component instanceof com.haulmont.cuba.gui.components.Button) {
|
||||
super.add(component);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Component is not a button");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Component component) {
|
||||
if (component instanceof com.haulmont.cuba.gui.components.Button) {
|
||||
super.remove(component);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Component is not a button");
|
||||
}
|
||||
}
|
||||
}
|
@ -27,8 +27,6 @@ import java.util.*;
|
||||
|
||||
public class WebComponentsHelper {
|
||||
|
||||
private static Boolean useNativeButtons;
|
||||
|
||||
public static Resource getResource(String resURL) {
|
||||
if (StringUtils.isEmpty(resURL)) return null;
|
||||
|
||||
@ -246,11 +244,11 @@ public class WebComponentsHelper {
|
||||
default: throw new IllegalArgumentException("Unknown function: " + function);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Button createButton() {
|
||||
return createButton(null);
|
||||
}
|
||||
|
||||
|
||||
public static Button createButton(String icon) {
|
||||
WebButton webButton = new WebButton();
|
||||
webButton.setIcon(icon);
|
||||
|
@ -38,9 +38,6 @@ public class Table
|
||||
|
||||
protected PagingProvider pagingProvider = null;
|
||||
|
||||
// protected List<ActionButton> actionButtons = null;
|
||||
// protected KeyMapper idActionButtons = null;
|
||||
|
||||
protected boolean aggregatable = false;
|
||||
|
||||
public enum PagingMode {
|
||||
@ -108,16 +105,6 @@ public class Table
|
||||
clientNeedsContentRefresh = true;
|
||||
}
|
||||
|
||||
/*
|
||||
if (variables.containsKey("actionButton")) {
|
||||
final String key = (String) variables.get("actionButton");
|
||||
ActionButton actionButton = (ActionButton) idActionButtons.get(key);
|
||||
if (actionButton != null) {
|
||||
actionButton.actionPerform(this);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return clientNeedsContentRefresh;
|
||||
}
|
||||
|
||||
@ -297,8 +284,6 @@ public class Table
|
||||
}
|
||||
target.addAttribute("vcolorder", visibleColOrder.toArray());
|
||||
|
||||
// paintActionButtons(target);
|
||||
|
||||
if (items instanceof AggregationContainer && isAggregatable()
|
||||
&& !((AggregationContainer) items).getAggregationPropertyIds().isEmpty()) {
|
||||
paintAggregationRow(target, ((AggregationContainer) items).aggregate(items.getItemIds()));
|
||||
@ -806,32 +791,6 @@ public class Table
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
protected void paintActionButtons(PaintTarget target) throws PaintException {
|
||||
if (actionButtons != null) {
|
||||
if (idActionButtons == null) {
|
||||
idActionButtons = new KeyMapper();
|
||||
}
|
||||
|
||||
target.startTag("actionButtons");
|
||||
|
||||
for (final ActionButton actionButton : actionButtons) {
|
||||
target.startTag("actionButton");
|
||||
target.addAttribute("key", idActionButtons.key(actionButton));
|
||||
if (actionButton.getCaption() != null) {
|
||||
target.addAttribute("caption", actionButton.getCaption());
|
||||
}
|
||||
if (actionButton.getIcon() != null) {
|
||||
target.addAttribute("icon", actionButton.getIcon());
|
||||
}
|
||||
target.endTag("actionButton");
|
||||
}
|
||||
|
||||
target.endTag("actionButtons");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public Map<Object, String> aggregate(Collection itemIds) {
|
||||
if (items instanceof AggregationContainer && isAggregatable()) {
|
||||
return ((AggregationContainer) items).aggregate(itemIds);
|
||||
@ -914,34 +873,6 @@ public class Table
|
||||
requestRepaint();
|
||||
}
|
||||
|
||||
/*
|
||||
public void addActionButton(ActionButton actionButton) {
|
||||
if (actionButtons == null) {
|
||||
actionButtons = new LinkedList<ActionButton>();
|
||||
idActionButtons = new KeyMapper();
|
||||
}
|
||||
actionButtons.add(actionButton);
|
||||
requestRepaint();
|
||||
}
|
||||
|
||||
public void removeActionButton(ActionButton actionButton) {
|
||||
if (actionButtons != null) {
|
||||
actionButtons.remove(actionButton);
|
||||
if (actionButtons.isEmpty()) {
|
||||
actionButtons = null;
|
||||
}
|
||||
requestRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ActionButton> getActionButtons() {
|
||||
if (actionButtons != null) {
|
||||
return Collections.unmodifiableList(actionButtons);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
*/
|
||||
|
||||
public interface PagingProvider extends Serializable {
|
||||
String firstCaption();
|
||||
String prevCaption();
|
||||
@ -952,12 +883,4 @@ public class Table
|
||||
boolean showPageLengthSelector();
|
||||
int[] pageLengths();
|
||||
}
|
||||
|
||||
/*
|
||||
public interface ActionButton extends Serializable {
|
||||
String getCaption();
|
||||
Resource getIcon();
|
||||
void actionPerform(Table source);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ public class WebComponentsFactory implements ComponentsFactory {
|
||||
classes.put("embedded", WebEmbedded.class);
|
||||
classes.put("filter", WebFilter.class);
|
||||
classes.put("accessControl", WebAccessControl.class);
|
||||
classes.put("buttonsPanel", WebButtonsPanel.class);
|
||||
}
|
||||
|
||||
public <T extends Component> T createComponent(String name) throws InstantiationException, IllegalAccessException {
|
||||
|
Loading…
Reference in New Issue
Block a user