mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
component loader lazy tasks
button actions
This commit is contained in:
parent
dfa4e0044d
commit
413fee2532
@ -11,12 +11,13 @@ package com.haulmont.cuba.gui;
|
||||
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.components.IFrame;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.gui.data.impl.DatasourceFactoryImpl;
|
||||
import com.haulmont.cuba.gui.data.impl.DatasourceImplementation;
|
||||
import com.haulmont.cuba.gui.xml.data.DsContextLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
@ -74,13 +75,18 @@ public abstract class WindowManager {
|
||||
final DsContext dsContext = loadDsContext(element);
|
||||
loadDsContextStopWatch.stop();
|
||||
|
||||
final ComponentLoaderContext componentLoaderContext = new ComponentLoaderContext(dsContext);
|
||||
|
||||
StopWatch loadLayoutStopWatch = new Log4JStopWatch("WindowManager.createWindow (loadLayout)");
|
||||
final Window window = loadLayout(element, dsContext, layoutConfig);
|
||||
final Window window = loadLayout(element, componentLoaderContext, layoutConfig);
|
||||
loadLayoutStopWatch.stop();
|
||||
|
||||
componentLoaderContext.setWindow(window);
|
||||
initialize(window, dsContext, params);
|
||||
|
||||
final Window wrapedWindow = wrapByCustomClass(window, element, params);
|
||||
componentLoaderContext.setWindow(wrapedWindow);
|
||||
componentLoaderContext.executeLazyTasks();
|
||||
stopWatch.stop();
|
||||
|
||||
return wrapedWindow;
|
||||
@ -133,8 +139,8 @@ public abstract class WindowManager {
|
||||
});
|
||||
}
|
||||
|
||||
protected Window loadLayout(Element rootElement, DsContext dsContext, LayoutLoaderConfig layoutConfig) {
|
||||
final LayoutLoader layoutLoader = new LayoutLoader(createComponentFactory(), layoutConfig, dsContext);
|
||||
protected Window loadLayout(Element rootElement, ComponentLoader.Context context, LayoutLoaderConfig layoutConfig) {
|
||||
final LayoutLoader layoutLoader = new LayoutLoader(context, createComponentFactory(), layoutConfig);
|
||||
layoutLoader.setLocale(getLocale());
|
||||
|
||||
final Window window = (Window) layoutLoader.loadComponent(rootElement);
|
||||
@ -452,4 +458,37 @@ public abstract class WindowManager {
|
||||
method.setAccessible(true);
|
||||
return (T) method.invoke(window, params);
|
||||
}
|
||||
|
||||
protected static class ComponentLoaderContext implements ComponentLoader.Context {
|
||||
protected DsContext dsContext;
|
||||
protected Window window;
|
||||
|
||||
protected List<ComponentLoader.LazyTask> lazyTasks = new ArrayList<ComponentLoader.LazyTask>();
|
||||
|
||||
public ComponentLoaderContext(DsContext dsContext) {
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
public DsContext getDSContext() {
|
||||
return dsContext;
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
public void setWindow(Window window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
public void addLazyTask(ComponentLoader.LazyTask task) {
|
||||
lazyTasks.add(task);
|
||||
}
|
||||
|
||||
public void executeLazyTasks() {
|
||||
for (ComponentLoader.LazyTask task : lazyTasks) {
|
||||
task.execute(this, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 06.02.2009 12:21:48
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public abstract class AbstractAction implements Action {
|
||||
private String id;
|
||||
|
||||
protected AbstractAction(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface Action {
|
||||
String getId();
|
||||
String getCaption();
|
||||
|
||||
boolean isEnabled();
|
||||
|
@ -11,6 +11,8 @@ package com.haulmont.cuba.gui.components;
|
||||
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface Component {
|
||||
|
||||
interface AlignInfo {
|
||||
@ -67,4 +69,13 @@ public interface Component {
|
||||
Element getXmlDescriptor();
|
||||
void setXmlDescriptor(Element element);
|
||||
}
|
||||
|
||||
interface ActionsOwner {
|
||||
void addAction(Action action);
|
||||
void removeAction(Action action);
|
||||
|
||||
Collection<Action> getActions();
|
||||
|
||||
Action getAction(String id);
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,10 @@ import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Table extends Component {
|
||||
public interface Table extends Component, Component.ActionsOwner {
|
||||
<T> T getSingleSelected();
|
||||
Set getSelected();
|
||||
|
||||
void addAction(Action action);
|
||||
void removeAction(Action action);
|
||||
|
||||
List<Column> getColumns();
|
||||
void addColumn(Column column);
|
||||
void removeColumn(Column column);
|
||||
|
@ -10,12 +10,27 @@
|
||||
package com.haulmont.cuba.gui.xml.layout;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public interface ComponentLoader {
|
||||
public interface Context {
|
||||
DsContext getDSContext();
|
||||
|
||||
void addLazyTask(LazyTask task);
|
||||
void executeLazyTasks();
|
||||
}
|
||||
|
||||
public interface LazyTask {
|
||||
void execute(Context context, Window window);
|
||||
}
|
||||
|
||||
Context getContext();
|
||||
|
||||
Locale getLocale();
|
||||
void setLocale(Locale locale);
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
package com.haulmont.cuba.gui.xml.layout;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
@ -19,20 +18,19 @@ import org.dom4j.io.SAXReader;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LayoutLoader {
|
||||
protected ComponentLoader.Context context;
|
||||
private ComponentsFactory factory;
|
||||
private LayoutLoaderConfig config;
|
||||
private DsContext dsContext;
|
||||
|
||||
private Locale locale;
|
||||
|
||||
public LayoutLoader(ComponentsFactory factory, LayoutLoaderConfig config, DsContext dsContext) {
|
||||
public LayoutLoader(ComponentLoader.Context context, ComponentsFactory factory, LayoutLoaderConfig config) {
|
||||
this.context = context;
|
||||
this.factory = factory;
|
||||
this.config = config;
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
public Component loadComponent(URL uri) {
|
||||
@ -55,7 +53,7 @@ public class LayoutLoader {
|
||||
}
|
||||
}
|
||||
|
||||
protected ComponentLoader getLoader(Element element) throws InstantiationException, IllegalAccessException {
|
||||
protected ComponentLoader getLoader(Element element) {
|
||||
Class<? extends ComponentLoader> loaderClass = config.getLoader(element.getName());
|
||||
if (loaderClass == null) {
|
||||
throw new IllegalStateException(String.format("Unknown component '%s'", element.getName()));
|
||||
@ -64,12 +62,17 @@ public class LayoutLoader {
|
||||
ComponentLoader loader;
|
||||
try {
|
||||
final Constructor<? extends ComponentLoader> constructor =
|
||||
loaderClass.getConstructor(LayoutLoaderConfig.class, ComponentsFactory.class, DsContext.class);
|
||||
loader = constructor.newInstance(config, factory, dsContext);
|
||||
loaderClass.getConstructor(ComponentLoader.Context.class, LayoutLoaderConfig.class, ComponentsFactory.class);
|
||||
loader = constructor.newInstance(context, config, factory);
|
||||
|
||||
loader.setLocale(locale);
|
||||
} catch (Throwable e) {
|
||||
loader = loaderClass.newInstance();
|
||||
try {
|
||||
final Constructor<? extends ComponentLoader> constructor = loaderClass.getConstructor(ComponentLoader.Context.class);
|
||||
loader = constructor.newInstance(context);
|
||||
} catch (Throwable e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
return loader;
|
||||
|
@ -11,22 +11,20 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Field;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class AbstractFieldLoader extends ComponentLoader {
|
||||
protected LayoutLoaderConfig config;
|
||||
protected ComponentsFactory factory;
|
||||
protected DsContext dsContext;
|
||||
|
||||
public AbstractFieldLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
public AbstractFieldLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context);
|
||||
this.config = config;
|
||||
this.factory = factory;
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
@ -38,7 +36,7 @@ public class AbstractFieldLoader extends ComponentLoader {
|
||||
|
||||
final String datasource = element.attributeValue("datasource");
|
||||
if (!StringUtils.isEmpty(datasource)) {
|
||||
final Datasource ds = dsContext.get(datasource);
|
||||
final Datasource ds = context.getDSContext().get(datasource);
|
||||
|
||||
final String property = element.attributeValue("property");
|
||||
if (StringUtils.isEmpty(property))
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 06.02.2009 13:22:23
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AssignActionLazyTask implements com.haulmont.cuba.gui.xml.layout.ComponentLoader.LazyTask {
|
||||
protected Button component;
|
||||
protected String actionName;
|
||||
|
||||
public AssignActionLazyTask(Button component, String actionName) {
|
||||
this.component = component;
|
||||
this.actionName = actionName;
|
||||
}
|
||||
|
||||
public void execute(ComponentLoader.Context context, Window window) {
|
||||
final String[] elements = ValuePathHelper.parse(actionName);
|
||||
if (elements.length > 1) {
|
||||
final String id = elements[elements.length - 1];
|
||||
|
||||
final List<String> subpath = Arrays.asList(elements).subList(0, elements.length - 1);
|
||||
final Component component = window.getComponent(ValuePathHelper.format(subpath.toArray(new String[]{})));
|
||||
if (component != null) {
|
||||
if (component instanceof Component.ActionsOwner) {
|
||||
final Action action = ((Component.ActionsOwner) component).getAction(id);
|
||||
if (action != null) {
|
||||
this.component.setAction(action);
|
||||
} else {
|
||||
throw new IllegalStateException(String.format("Can't find action '%s' in '%s'", id, subpath));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException(String.format("Component '%s' have no actions", subpath));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException(String.format("Can't find component '%s'", subpath));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,19 +9,32 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Button;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class ButtonLoader extends com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoader {
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Button button = factory.createComponent("button");
|
||||
|
||||
assignXmlDescriptor(button, element);
|
||||
loadId(button, element);
|
||||
loadCaption(button, element);
|
||||
|
||||
return button;
|
||||
public ButtonLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Button component = factory.createComponent("button");
|
||||
|
||||
assignXmlDescriptor(component, element);
|
||||
loadId(component, element);
|
||||
loadCaption(component, element);
|
||||
loadAction(component, element);
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
protected void loadAction(Button component, Element element) {
|
||||
final String actionName = element.attributeValue("action");
|
||||
if (!StringUtils.isEmpty(actionName)) {
|
||||
context.addLazyTask(new AssignActionLazyTask(component, actionName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,15 @@ import java.lang.reflect.Constructor;
|
||||
public abstract class ComponentLoader implements com.haulmont.cuba.gui.xml.layout.ComponentLoader {
|
||||
protected Locale locale;
|
||||
protected ResourceBundle resourceBundle;
|
||||
protected Context context;
|
||||
|
||||
protected ComponentLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
|
@ -11,32 +11,32 @@ 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.*;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
protected DsContext dsContext;
|
||||
protected LayoutLoaderConfig config;
|
||||
|
||||
public ContainerLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
public ContainerLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context);
|
||||
this.config = config;
|
||||
this.factory = factory;
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
protected Collection<Component> loadSubComponents(Component component, Element element, String ...exceptTags) {
|
||||
final List<Component> res = new ArrayList<Component>();
|
||||
|
||||
final LayoutLoader loader = new LayoutLoader(factory, config, dsContext);
|
||||
final LayoutLoader loader = new LayoutLoader(context, factory, config);
|
||||
for (Element subElement : (Collection<Element>)element.elements()) {
|
||||
final String name = subElement.getName();
|
||||
if (exceptTags != null && Arrays.binarySearch(exceptTags, name) < 0) {
|
||||
@ -87,8 +87,8 @@ public abstract class ContainerLoader extends ComponentLoader {
|
||||
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);
|
||||
loaderClass.getConstructor(Context.class, LayoutLoaderConfig.class, ComponentsFactory.class);
|
||||
loader = constructor.newInstance(context, config, factory);
|
||||
|
||||
loader.setLocale(locale);
|
||||
} catch (Throwable e) {
|
||||
|
@ -14,16 +14,15 @@ import com.haulmont.cuba.gui.components.IFrame;
|
||||
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 com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class FrameLoader extends ContainerLoader implements ComponentLoader {
|
||||
|
||||
public FrameLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public FrameLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
|
@ -11,7 +11,6 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.GridLayout;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
@ -21,8 +20,8 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class GridLoader extends ContainerLoader implements com.haulmont.cuba.gui.xml.layout.ComponentLoader {
|
||||
public GridLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public GridLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
@ -49,7 +48,7 @@ public class GridLoader extends ContainerLoader implements com.haulmont.cuba.gui
|
||||
}
|
||||
|
||||
protected void loadSubComponents(GridLayout component, Element element, int row) {
|
||||
final LayoutLoader loader = new LayoutLoader(factory, config, dsContext);
|
||||
final LayoutLoader loader = new LayoutLoader(context, factory, config);
|
||||
int col = 0;
|
||||
for (Element subElement : (Collection<Element>)element.elements()) {
|
||||
final Component subComponent = loader.loadComponent(subElement);
|
||||
|
@ -9,16 +9,15 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class GroupBoxLoader extends ContainerLoader implements com.haulmont.cuba.gui.xml.layout.ComponentLoader {
|
||||
public GroupBoxLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public GroupBoxLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
|
@ -9,18 +9,17 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
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 com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class HBoxLoader extends ContainerLoader implements ComponentLoader {
|
||||
public HBoxLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public HBoxLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
|
@ -11,22 +11,21 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.IFrame;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class IFrameLoader extends ContainerLoader implements ComponentLoader {
|
||||
|
||||
public IFrameLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public IFrameLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final String src = element.attributeValue("src");
|
||||
final LayoutLoader loader = new LayoutLoader(factory, LayoutLoaderConfig.getFrameLoaders(), dsContext);
|
||||
final LayoutLoader loader = new LayoutLoader(context, factory, LayoutLoaderConfig.getFrameLoaders());
|
||||
|
||||
final IFrame frame = (IFrame) loader.loadComponent(getClass().getResource(src));
|
||||
if (frame.getResourceBundle() == null) {
|
||||
|
@ -11,10 +11,14 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Label;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.*;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class LabelLoader extends ComponentLoader {
|
||||
public LabelLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Label label = factory.createComponent("label");
|
||||
|
||||
|
@ -20,8 +20,8 @@ import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class LookupFieldLoader extends AbstractFieldLoader {
|
||||
public LookupFieldLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public LookupFieldLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,7 +30,7 @@ public class LookupFieldLoader extends AbstractFieldLoader {
|
||||
|
||||
final String datasource = element.attributeValue("lookupDatasource");
|
||||
if (!StringUtils.isEmpty(datasource)) {
|
||||
final Datasource ds = dsContext.get(datasource);
|
||||
final Datasource ds = context.getDSContext().get(datasource);
|
||||
component.setLookupDatasource((CollectionDatasource) ds);
|
||||
}
|
||||
|
||||
|
@ -11,15 +11,14 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.SplitPanel;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class SplitPanelLoader extends ContainerLoader{
|
||||
public SplitPanelLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public SplitPanelLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
|
@ -30,13 +30,12 @@ import java.util.HashSet;
|
||||
|
||||
public class TableLoader extends ComponentLoader {
|
||||
protected ComponentsFactory factory;
|
||||
protected DsContext dsContext;
|
||||
protected LayoutLoaderConfig config;
|
||||
|
||||
public TableLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
public TableLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context);
|
||||
this.config = config;
|
||||
this.factory = factory;
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
public Component loadComponent(
|
||||
@ -55,7 +54,7 @@ public class TableLoader extends ComponentLoader {
|
||||
final String datasource = rowsElement.attributeValue("datasource");
|
||||
|
||||
if (!StringUtils.isBlank(datasource)) {
|
||||
final CollectionDatasource ds = dsContext.get(datasource);
|
||||
final CollectionDatasource ds = context.getDSContext().get(datasource);
|
||||
table.setDatasource(ds);
|
||||
|
||||
if (columnsElement != null) {
|
||||
|
@ -11,7 +11,6 @@ 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;
|
||||
@ -21,8 +20,8 @@ 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 TabsheetLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
|
@ -13,7 +13,6 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Tree;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -22,13 +21,12 @@ import org.dom4j.Element;
|
||||
public class TreeLoader extends ComponentLoader
|
||||
{
|
||||
protected ComponentsFactory factory;
|
||||
protected DsContext dsContext;
|
||||
protected LayoutLoaderConfig config;
|
||||
|
||||
public TreeLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
public TreeLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context);
|
||||
this.config = config;
|
||||
this.factory = factory;
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element)
|
||||
@ -42,7 +40,7 @@ public class TreeLoader extends ComponentLoader
|
||||
Element itemsElem = element.element("treechildren");
|
||||
String datasource = itemsElem.attributeValue("datasource");
|
||||
if (!StringUtils.isBlank(datasource)) {
|
||||
CollectionDatasource ds = dsContext.get(datasource);
|
||||
CollectionDatasource ds = context.getDSContext().get(datasource);
|
||||
String showProperty = itemsElem.attributeValue("property");
|
||||
String parentProperty = itemsElem.attributeValue("parent");
|
||||
|
||||
|
@ -9,18 +9,17 @@
|
||||
*/
|
||||
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.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class VBoxLoader extends ContainerLoader implements ComponentLoader {
|
||||
public VBoxLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public VBoxLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
|
@ -11,16 +11,15 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
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 com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class WindowLoader extends FrameLoader implements ComponentLoader {
|
||||
|
||||
public WindowLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public WindowLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
@ -40,8 +39,8 @@ public class WindowLoader extends FrameLoader implements ComponentLoader {
|
||||
}
|
||||
|
||||
public static class Editor extends WindowLoader {
|
||||
public Editor(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public Editor(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,8 +50,8 @@ public class WindowLoader extends FrameLoader implements ComponentLoader {
|
||||
}
|
||||
|
||||
public static class Lookup extends WindowLoader {
|
||||
public Lookup(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
public Lookup(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
|
||||
super(context, config, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +26,7 @@ public class SecurityUserBrowser extends AbstractLookup {
|
||||
final Button button = getComponent("filter.apply");
|
||||
final Table table = getComponent("users");
|
||||
|
||||
table.addAction(new Action() {
|
||||
table.addAction(new AbstractAction("edit") {
|
||||
public String getCaption() {
|
||||
return "Edit";
|
||||
}
|
||||
@ -45,7 +45,7 @@ public class SecurityUserBrowser extends AbstractLookup {
|
||||
}
|
||||
}
|
||||
});
|
||||
table.addAction(new Action() {
|
||||
table.addAction(new AbstractAction("refresh") {
|
||||
public String getCaption() {
|
||||
return "Refresh";
|
||||
}
|
||||
@ -60,7 +60,7 @@ public class SecurityUserBrowser extends AbstractLookup {
|
||||
}
|
||||
});
|
||||
|
||||
button.setAction(new Action() {
|
||||
button.setAction(new AbstractAction("refresh") {
|
||||
public String getCaption() {
|
||||
return null;
|
||||
}
|
||||
|
@ -32,6 +32,9 @@
|
||||
<hbox id="table-panel" expand="table">
|
||||
<split orientation="horizontal">
|
||||
<vbox expand="users">
|
||||
<hbox>
|
||||
<button action="users.edit"/>
|
||||
</hbox>
|
||||
<table id="users">
|
||||
<columns>
|
||||
<column id="name" label="Name"/>
|
||||
|
@ -11,6 +11,7 @@ package com.haulmont.cuba.web.app.ui.security.user.edit;
|
||||
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -21,7 +22,7 @@ public class SecurityUserEditor extends AbstractEditor {
|
||||
|
||||
protected void init() {
|
||||
Button button = getComponent("browse");
|
||||
button.setAction(new Action() {
|
||||
button.setAction(new AbstractAction("Browse") {
|
||||
public String getCaption() {
|
||||
return "Browse...";
|
||||
}
|
||||
@ -33,7 +34,11 @@ public class SecurityUserEditor extends AbstractEditor {
|
||||
public void actionPerform(Component component) {
|
||||
openLookup("/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.xml", new Lookup.Handler() {
|
||||
public void handleLookup(Collection items) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
if (items.size() == 1) {
|
||||
final User item = (User) items.iterator().next();
|
||||
final Field field = getComponent("name");
|
||||
field.setValue(item.getName());
|
||||
}
|
||||
}
|
||||
}, WindowManager.OpenType.THIS_TAB);
|
||||
}
|
||||
|
@ -9,19 +9,17 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Action;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.web.data.CollectionDatasourceWrapper;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.cuba.gui.components.Action;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.web.data.CollectionDatasourceWrapper;
|
||||
import com.itmill.toolkit.data.Property;
|
||||
import com.itmill.toolkit.event.ItemClickEvent;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
import com.itmill.toolkit.ui.Button;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -92,6 +90,19 @@ public class Table
|
||||
actionsOrder.remove(action);
|
||||
}
|
||||
|
||||
public Collection<Action> getActions() {
|
||||
return actions.keySet();
|
||||
}
|
||||
|
||||
public Action getAction(String id) {
|
||||
for (Action action : getActions()) {
|
||||
if (ObjectUtils.equals(action.getId(), id)) {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Set<Object> getSelecetdItemIds() {
|
||||
final Object value = component.getValue();
|
||||
if (value == null) {
|
||||
|
@ -239,15 +239,20 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
|
||||
@Override
|
||||
protected com.itmill.toolkit.ui.Component createLayout() {
|
||||
ExpandLayout layout = new ExpandLayout();
|
||||
ExpandLayout layout = new ExpandLayout(OrderedLayout.ORIENTATION_VERTICAL);
|
||||
|
||||
form = new Form();
|
||||
|
||||
Layout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
OrderedLayout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
okbar.setHeight("25px");
|
||||
|
||||
okbar.addComponent(new Button("OK", this, "commit"));
|
||||
okbar.addComponent(new Button("Cancel", this, "close"));
|
||||
Layout buttonsContainer = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
|
||||
buttonsContainer.addComponent(new Button("OK", this, "commit"));
|
||||
buttonsContainer.addComponent(new Button("Cancel", this, "close"));
|
||||
|
||||
okbar.addComponent(buttonsContainer);
|
||||
okbar.setComponentAlignment(buttonsContainer, Layout.AlignmentHandler.ALIGNMENT_LEFT, Layout.AlignmentHandler.ALIGNMENT_VERTICAL_CENTER);
|
||||
|
||||
layout.addComponent(form);
|
||||
layout.addComponent(okbar);
|
||||
@ -353,18 +358,19 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
public void buttonClick(Button.ClickEvent event) {
|
||||
final com.haulmont.cuba.gui.components.Component lookupComponent = getLookupComponent();
|
||||
|
||||
Collection selected;
|
||||
if (lookupComponent instanceof com.haulmont.cuba.gui.components.Table ) {
|
||||
final Set selected = ((com.haulmont.cuba.gui.components.Table) lookupComponent).getSelected();
|
||||
handler.handleLookup(selected);
|
||||
selected = ((com.haulmont.cuba.gui.components.Table) lookupComponent).getSelected();
|
||||
} else if (lookupComponent instanceof com.haulmont.cuba.gui.components.Tree) {
|
||||
final Object selected = ((com.haulmont.cuba.gui.components.Tree) lookupComponent).getSelected();
|
||||
handler.handleLookup(Collections.singleton(selected));
|
||||
selected = Collections.singleton(((com.haulmont.cuba.gui.components.Tree) lookupComponent).getSelected());
|
||||
} else if (lookupComponent instanceof LookupField) {
|
||||
final Object value = ((LookupField) lookupComponent).getValue();
|
||||
handler.handleLookup(Collections.singleton(value));
|
||||
selected = Collections.singleton(((LookupField) lookupComponent).getValue());
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
close();
|
||||
handler.handleLookup(selected);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user