mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
change parameters naming
lookup screens dataservice
This commit is contained in:
parent
eb8815c62a
commit
dfa4e0044d
@ -12,10 +12,8 @@ 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.data.Context;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.ValueListener;
|
||||
import com.haulmont.cuba.gui.components.IFrame;
|
||||
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;
|
||||
@ -42,13 +40,24 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class WindowManager {
|
||||
private DataService defaultDataService;
|
||||
|
||||
public synchronized DataService getDefaultDataService() {
|
||||
if (defaultDataService == null) {
|
||||
defaultDataService = createDefaultDataService();
|
||||
}
|
||||
return defaultDataService;
|
||||
}
|
||||
|
||||
protected abstract DataService createDefaultDataService();
|
||||
|
||||
public enum OpenType {
|
||||
NEW_TAB,
|
||||
THIS_TAB,
|
||||
DIALOG
|
||||
}
|
||||
|
||||
protected Window createWindow(String template, Map params, LayoutLoaderConfig layoutConfig) {
|
||||
protected Window createWindow(String template, Map<String, Object> params, LayoutLoaderConfig layoutConfig) {
|
||||
StopWatch stopWatch = new Log4JStopWatch("WindowManager.createWindow");
|
||||
|
||||
StopWatch parseDescriptorStopWatch = new Log4JStopWatch("WindowManager.createWindow (parseDescriptor)");
|
||||
@ -71,7 +80,7 @@ public abstract class WindowManager {
|
||||
|
||||
initialize(window, dsContext, params);
|
||||
|
||||
final Window wrapedWindow = wrapByCustomClass(window, element);
|
||||
final Window wrapedWindow = wrapByCustomClass(window, element, params);
|
||||
stopWatch.stop();
|
||||
|
||||
return wrapedWindow;
|
||||
@ -88,7 +97,7 @@ public abstract class WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initialize(final Window window, DsContext dsContext, Map params) {
|
||||
protected void initialize(final Window window, DsContext dsContext, Map<String, Object> params) {
|
||||
window.setDsContext(dsContext);
|
||||
|
||||
for (Datasource ds : dsContext.getAll()) {
|
||||
@ -133,8 +142,9 @@ public abstract class WindowManager {
|
||||
}
|
||||
|
||||
protected DsContext loadDsContext(Element rootElement) {
|
||||
final DsContextLoader dsContextLoader = new DsContextLoader(new DatasourceFactoryImpl());
|
||||
final DsContextLoader dsContextLoader = new DsContextLoader(new DatasourceFactoryImpl(), getDefaultDataService());
|
||||
final DsContext dsContext = dsContextLoader.loadDatasources(rootElement.element("dsContext"));
|
||||
|
||||
return dsContext;
|
||||
}
|
||||
|
||||
@ -152,7 +162,7 @@ public abstract class WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
Window window = createWindow(descriptor, params, LayoutLoaderConfig.getWindowLoaders());
|
||||
|
||||
String caption = loadCaption(window, params);
|
||||
@ -161,7 +171,7 @@ public abstract class WindowManager {
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
protected <T extends Window> String loadCaption(Window window, Map params) {
|
||||
protected <T extends Window> String loadCaption(Window window, Map<String, Object> params) {
|
||||
String caption = window.getCaption();
|
||||
if (!StringUtils.isEmpty(caption)) return caption;
|
||||
|
||||
@ -197,7 +207,7 @@ public abstract class WindowManager {
|
||||
return caption;
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
Window window = createWindow(aclass, params);
|
||||
|
||||
String caption = loadCaption(window, params);
|
||||
@ -206,9 +216,9 @@ public abstract class WindowManager {
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(String descriptor, Object item, OpenType openType, Map params) {
|
||||
params = new HashMap(params);
|
||||
params.put("item", item);
|
||||
public <T extends Window> T openEditor(String descriptor, Object item, OpenType openType, Map<String, Object> params) {
|
||||
params = createParametersMap(params);
|
||||
params.put("parameter$item", item);
|
||||
|
||||
Window window = createWindow(descriptor, params, LayoutLoaderConfig.getEditorLoaders());
|
||||
((Window.Editor) window).setItem(item);
|
||||
@ -219,9 +229,40 @@ public abstract class WindowManager {
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(Class aclass, Object item, OpenType openType, Map params) {
|
||||
params = new HashMap(params);
|
||||
params.put("item", item);
|
||||
public <T extends Window> T openLookup(
|
||||
String descriptor, Window.Lookup.Handler handler,
|
||||
OpenType openType, Map<String, Object> params)
|
||||
{
|
||||
params = createParametersMap(params);
|
||||
|
||||
Window window = createWindow(descriptor, params, LayoutLoaderConfig.getLookupLoaders());
|
||||
|
||||
final Element element = ((Component.HasXmlDescriptor) window).getXmlDescriptor();
|
||||
final String lookupComponent = element.attributeValue("lookupComponent");
|
||||
if (!StringUtils.isEmpty(lookupComponent)) {
|
||||
final Component component = window.getComponent(lookupComponent);
|
||||
((Window.Lookup) window).setLookupComponent(component);
|
||||
}
|
||||
((Window.Lookup) window).setLookupHandler(handler);
|
||||
|
||||
String caption = loadCaption(window, params);
|
||||
|
||||
showWindow(window, caption, openType);
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
protected Map<String, Object> createParametersMap(Map<String, Object> params) {
|
||||
final Map<String, Object> map = new HashMap<String, Object>(params.size());
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
map.put("parameter$" + entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(Class aclass, Object item, OpenType openType, Map<String, Object> params) {
|
||||
params = createParametersMap(params);
|
||||
params.put("parameter$item", item);
|
||||
|
||||
Window window = createWindow(aclass, params);
|
||||
((Window.Editor) window).setItem(item);
|
||||
@ -232,23 +273,45 @@ public abstract class WindowManager {
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(
|
||||
Class aclass, Window.Lookup.Handler handler,
|
||||
OpenType openType, Map<String, Object> params)
|
||||
{
|
||||
params = createParametersMap(params);
|
||||
|
||||
Window window = createWindow(aclass, params);
|
||||
((Window.Lookup) window).setLookupHandler(handler);
|
||||
|
||||
String caption = loadCaption(window, params);
|
||||
|
||||
showWindow(window, caption, openType);
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public <T extends Window> T openEditor(String descriptor, Object item, OpenType openType) {
|
||||
return (T)openEditor(descriptor, item, openType, Collections.emptyMap());
|
||||
return (T)openEditor(descriptor, item, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(Class aclass, Object item, OpenType openType) {
|
||||
return (T)openEditor(aclass, item, openType, Collections.emptyMap());
|
||||
return (T)openEditor(aclass, item, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, OpenType openType) {
|
||||
return (T)openWindow(descriptor, openType, Collections.emptyMap());
|
||||
return (T)openWindow(descriptor, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, OpenType openType) {
|
||||
return (T)openWindow(aclass, openType, Collections.emptyMap());
|
||||
return (T)openWindow(aclass, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(String descriptor, Window.Lookup.Handler handler, OpenType openType) {
|
||||
return (T)openLookup(descriptor, handler, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(Class aclass, Window.Lookup.Handler handler, OpenType openType) {
|
||||
return (T)openLookup(aclass, handler, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
protected abstract void showWindow(Window window, String caption, OpenType openType);
|
||||
@ -258,16 +321,26 @@ public abstract class WindowManager {
|
||||
protected abstract Locale getLocale();
|
||||
protected abstract ComponentsFactory createComponentFactory();
|
||||
|
||||
protected Window wrapByCustomClass(Window window, Element element) {
|
||||
protected Window wrapByCustomClass(Window window, Element element, Map<String, Object> params) {
|
||||
Window res = window;
|
||||
final String screenClass = element.attributeValue("class");
|
||||
if (!StringUtils.isBlank(screenClass)) {
|
||||
try {
|
||||
final Class<?> aClass = Class.forName(screenClass);
|
||||
final Constructor<?> constructor = aClass.getConstructor(Window.class);
|
||||
Constructor<?> constructor;
|
||||
try {
|
||||
constructor = aClass.getConstructor(Window.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
constructor = aClass.getConstructor(IFrame.class);
|
||||
}
|
||||
|
||||
res = (Window) constructor.newInstance(window);
|
||||
|
||||
invokeMethod(res, "init");
|
||||
try {
|
||||
invokeMethod(res, "init", params);
|
||||
} catch (NoSuchMethodException e) {
|
||||
invokeMethod(res, "init");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -286,7 +359,7 @@ public abstract class WindowManager {
|
||||
|
||||
private static final Pattern DS_CONTEXT_PATTERN = Pattern.compile("<dsContext>(\\p{ASCII}+)</dsContext>");
|
||||
|
||||
protected Document parseDescriptor(String resourcePath, Map params, boolean isTemplate) {
|
||||
protected Document parseDescriptor(String resourcePath, Map<String, Object> params, boolean isTemplate) {
|
||||
Document document;
|
||||
if (isTemplate) {
|
||||
final InputStream stream = getClass().getResourceAsStream(resourcePath);
|
||||
@ -348,6 +421,7 @@ public abstract class WindowManager {
|
||||
method = aClass.getMethod(name);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
|
||||
return (T) method.invoke(window);
|
||||
}
|
||||
|
||||
|
@ -106,11 +106,11 @@ public class AbstractFrame implements IFrame, Component.Wrapper {
|
||||
frame.setResourceBundle(resourceBundle);
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return frame.<T>openWindow(descriptor, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return frame.<T>openWindow(aclass, openType, params);
|
||||
}
|
||||
|
||||
@ -122,20 +122,42 @@ public class AbstractFrame implements IFrame, Component.Wrapper {
|
||||
return frame.<T>openWindow(aclass, openType);
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return frame.<T>openEditor(descriptor, item, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return frame.<T>openEditor(aclass, item, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType) {
|
||||
return frame.<T>openEditor(aclass, item, openType, Collections.emptyMap());
|
||||
return frame.<T>openEditor(aclass, item, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType) {
|
||||
return frame.<T>openEditor(descriptor, item, openType, Collections.emptyMap());
|
||||
return frame.<T>openEditor(descriptor, item, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(
|
||||
String descriptor, Window.Lookup.Handler handler,
|
||||
WindowManager.OpenType openType, Map<String, Object> params)
|
||||
{
|
||||
return frame.<T>openLookup(descriptor, handler, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(
|
||||
Class aclass, Window.Lookup.Handler handler,
|
||||
WindowManager.OpenType openType, Map<String, Object> params)
|
||||
{
|
||||
return frame.<T>openLookup(aclass, handler, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(String descriptor, Window.Lookup.Handler handler, WindowManager.OpenType openType) {
|
||||
return frame.<T>openLookup(descriptor, handler, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(Class aclass, Window.Lookup.Handler handler, WindowManager.OpenType openType) {
|
||||
return frame.<T>openLookup(aclass, handler, openType, Collections.<String, Object>emptyMap());
|
||||
}
|
||||
|
||||
public boolean close() {
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 05.02.2009 12:00:29
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public class AbstractLookup extends AbstractWindow implements Window.Lookup {
|
||||
public AbstractLookup(IFrame frame) {
|
||||
super(frame);
|
||||
}
|
||||
|
||||
public Component getLookupComponent() {
|
||||
if (frame instanceof Window.Lookup) {
|
||||
return ((Lookup) frame).getLookupComponent();
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLookupComponent(Component lookupComponent) {
|
||||
if (frame instanceof Window.Lookup) {
|
||||
((Lookup) frame).setLookupComponent(lookupComponent);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public Handler getLookupHandler() {
|
||||
if (frame instanceof Window.Lookup) {
|
||||
return ((Lookup) frame).getLookupHandler();
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLookupHandler(Handler handler) {
|
||||
if (frame instanceof Window.Lookup) {
|
||||
((Lookup) frame).setLookupHandler(handler);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -18,15 +18,29 @@ public interface IFrame extends OrderedLayout, Component.Container {
|
||||
ResourceBundle getResourceBundle();
|
||||
void setResourceBundle(ResourceBundle resourceBundle);
|
||||
|
||||
<T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params);
|
||||
<T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params);
|
||||
<T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map<String, Object> params);
|
||||
<T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params);
|
||||
|
||||
<T extends Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map params);
|
||||
<T extends Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map params);
|
||||
<T extends Window> T openEditor(
|
||||
String descriptor, Object item,
|
||||
WindowManager.OpenType openType, Map<String, Object> params);
|
||||
<T extends Window> T openEditor(
|
||||
Class aclass, Object item,
|
||||
WindowManager.OpenType openType, Map<String, Object> params);
|
||||
|
||||
<T extends Window> T openLookup(
|
||||
String descriptor, Window.Lookup.Handler handler,
|
||||
WindowManager.OpenType openType, Map<String, Object> params);
|
||||
<T extends Window> T openLookup(
|
||||
Class aclass, Window.Lookup.Handler handler,
|
||||
WindowManager.OpenType openType, Map<String, Object> params);
|
||||
|
||||
<T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType);
|
||||
<T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType);
|
||||
|
||||
<T extends Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType);
|
||||
<T extends Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType);
|
||||
|
||||
<T extends Window> T openLookup(String descriptor, Window.Lookup.Handler handler, WindowManager.OpenType openType);
|
||||
<T extends Window> T openLookup(Class aclass, Window.Lookup.Handler handler, WindowManager.OpenType openType);
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ package com.haulmont.cuba.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface Window extends IFrame, Component.HasCaption {
|
||||
DsContext getDsContext();
|
||||
void setDsContext(DsContext dsContext);
|
||||
@ -23,4 +25,16 @@ public interface Window extends IFrame, Component.HasCaption {
|
||||
|
||||
void commit();
|
||||
}
|
||||
|
||||
interface Lookup extends Window {
|
||||
Component getLookupComponent();
|
||||
void setLookupComponent(Component lookupComponent);
|
||||
|
||||
interface Handler {
|
||||
void handleLookup(Collection items);
|
||||
}
|
||||
|
||||
Handler getLookupHandler();
|
||||
void setLookupHandler(Handler handler);
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,17 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.data;
|
||||
|
||||
import com.haulmont.cuba.core.global.BasicInvocationContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DataService {
|
||||
<T> T create(T entity);
|
||||
<T> T update(T entity);
|
||||
void delete(BasicInvocationContext ctx);
|
||||
|
||||
<T> T get(BasicInvocationContext ctx);
|
||||
|
||||
<T> T load(BasicInvocationContext ctx);
|
||||
<T> List<T> loadList(BasicInvocationContext ctx);
|
||||
}
|
||||
|
@ -16,7 +16,9 @@ import java.util.Collection;
|
||||
|
||||
public interface Datasource<T> {
|
||||
String getId();
|
||||
|
||||
DsContext getDsContext();
|
||||
DataService getDataService();
|
||||
|
||||
void commit();
|
||||
|
||||
|
@ -12,8 +12,8 @@ package com.haulmont.cuba.gui.data;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
|
||||
public interface DatasourceFactory {
|
||||
Datasource createDatasource(DsContext dsContext, String id, MetaClass metaClass, String viewName);
|
||||
CollectionDatasource createCollectionDatasource(DsContext dsContext, String id, MetaClass metaClass, String viewName);
|
||||
Datasource createDatasource(DsContext dsContext, DataService dataservice, String id, MetaClass metaClass, String viewName);
|
||||
CollectionDatasource createCollectionDatasource(DsContext dsContext, DataService dataservice, String id, MetaClass metaClass, String viewName);
|
||||
|
||||
Datasource createDatasource(String id, Datasource ds, String property);
|
||||
CollectionDatasource createCollectionDatasource(String id, Datasource ds, String property);
|
||||
|
@ -12,6 +12,8 @@ package com.haulmont.cuba.gui.data;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface DsContext {
|
||||
DataService getDataService();
|
||||
|
||||
<T extends Datasource> T get(String name);
|
||||
Collection<Datasource> getAll();
|
||||
|
||||
|
@ -31,8 +31,12 @@ public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements
|
||||
|
||||
private Collection<T> collection = Collections.emptyList();
|
||||
|
||||
public CollectionDatasourceImpl(DsContext context, String id, MetaClass metaClass, String viewName) {
|
||||
super(context, id, metaClass, viewName);
|
||||
public CollectionDatasourceImpl(
|
||||
DsContext context, DataService dataservice,
|
||||
String id, MetaClass metaClass, String viewName)
|
||||
{
|
||||
super(context, dataservice, id, metaClass, viewName);
|
||||
|
||||
parentDsListener = new CollectionDatasourceListener() {
|
||||
public void itemChanged(Datasource ds, Object prevItem, Object item) {
|
||||
refresh();
|
||||
@ -178,8 +182,6 @@ public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements
|
||||
}
|
||||
|
||||
protected Collection<T> loadData() {
|
||||
BasicService service = Locator.lookupLocal(BasicService.JNDI_NAME);
|
||||
|
||||
final BasicInvocationContext ctx = new BasicInvocationContext();
|
||||
ctx.setEntityClass(metaClass);
|
||||
|
||||
@ -193,10 +195,9 @@ public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements
|
||||
|
||||
final BasicInvocationContext.Query query = ctx.setQueryString(getJPQLQuery(this.query, parameters));
|
||||
query.setParameters(parameters);
|
||||
|
||||
ctx.setView(view);
|
||||
|
||||
collection = (Collection) service.loadList(ctx);
|
||||
collection = (Collection) dataservice.loadList(ctx);
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
@ -9,19 +9,21 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.data.impl;
|
||||
|
||||
import com.haulmont.cuba.gui.data.DatasourceFactory;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
|
||||
public class DatasourceFactoryImpl implements DatasourceFactory {
|
||||
public Datasource createDatasource(DsContext dsContext, String id, MetaClass metaClass, String viewName) {
|
||||
return new DatasourceImpl(dsContext, id, metaClass, viewName);
|
||||
public Datasource createDatasource(
|
||||
DsContext dsContext, DataService dataservice,
|
||||
String id, MetaClass metaClass, String viewName)
|
||||
{
|
||||
return new DatasourceImpl(dsContext, dataservice, id, metaClass, viewName);
|
||||
}
|
||||
|
||||
public CollectionDatasource createCollectionDatasource(DsContext dsContext, String id, MetaClass metaClass, String viewName) {
|
||||
return new CollectionDatasourceImpl(dsContext, id, metaClass, viewName);
|
||||
public CollectionDatasource createCollectionDatasource(
|
||||
DsContext dsContext, DataService dataservice,
|
||||
String id, MetaClass metaClass, String viewName) {
|
||||
return new CollectionDatasourceImpl(dsContext, dataservice, id, metaClass, viewName);
|
||||
}
|
||||
|
||||
public Datasource createDatasource(String id, Datasource ds, String property) {
|
||||
|
@ -17,6 +17,7 @@ import com.haulmont.cuba.core.global.View;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DatasourceListener;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.DataService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -24,6 +25,7 @@ import java.util.List;
|
||||
|
||||
public class DatasourceImpl<T> implements Datasource<T>, DatasourceImplementation {
|
||||
protected DsContext dsContext;
|
||||
protected DataService dataservice;
|
||||
|
||||
private String id;
|
||||
protected MetaClass metaClass;
|
||||
@ -35,8 +37,13 @@ public class DatasourceImpl<T> implements Datasource<T>, DatasourceImplementatio
|
||||
|
||||
protected List<DatasourceListener> dsListeners = new ArrayList<DatasourceListener>();
|
||||
|
||||
public DatasourceImpl(DsContext dsContext, String id, MetaClass metaClass, String viewName) {
|
||||
public DatasourceImpl(
|
||||
DsContext dsContext, DataService dataservice,
|
||||
String id, MetaClass metaClass, String viewName)
|
||||
{
|
||||
this.dsContext = dsContext;
|
||||
this.dataservice = dataservice;
|
||||
|
||||
this.id = id;
|
||||
this.metaClass = metaClass;
|
||||
this.view = MetadataProvider.getViewRepository().getView(metaClass, viewName);
|
||||
@ -58,6 +65,10 @@ public class DatasourceImpl<T> implements Datasource<T>, DatasourceImplementatio
|
||||
return dsContext;
|
||||
}
|
||||
|
||||
public DataService getDataService() {
|
||||
return dataservice;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -9,10 +9,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.data.impl;
|
||||
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.Context;
|
||||
import com.haulmont.cuba.gui.data.ValueListener;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.gui.xml.ParametersHelper;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -22,6 +19,7 @@ import java.util.ArrayList;
|
||||
|
||||
public class DsContextImpl implements DsContext {
|
||||
private Context context;
|
||||
private DataService dataservice;
|
||||
|
||||
private Map<String, Datasource> datasourceMap =
|
||||
new HashMap<String, Datasource>();
|
||||
@ -29,6 +27,10 @@ public class DsContextImpl implements DsContext {
|
||||
private Map<String, Collection<Datasource>> contextListeners =
|
||||
new HashMap<String, Collection<Datasource>>();
|
||||
|
||||
public DsContextImpl(DataService dataservice) {
|
||||
this.dataservice = dataservice;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
@ -60,7 +62,11 @@ public class DsContextImpl implements DsContext {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public DataService getDataService() {
|
||||
return dataservice;
|
||||
}
|
||||
|
||||
public <T extends Datasource> T get(String id) {
|
||||
return (T) datasourceMap.get(id);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import com.haulmont.cuba.core.global.ViewProperty;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DatasourceListener;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.DataService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -62,6 +63,10 @@ public class PropertyDatasourceImpl<T> implements Datasource<T>, DatasourceImple
|
||||
return ds.getDsContext();
|
||||
}
|
||||
|
||||
public DataService getDataService() {
|
||||
return ds.getDataService();
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -23,14 +23,16 @@ import java.util.*;
|
||||
|
||||
public class DsContextLoader {
|
||||
private DatasourceFactory factory;
|
||||
private DataService dataservice;
|
||||
private DsContextImpl datasources;
|
||||
|
||||
public DsContextLoader(DatasourceFactory factory) {
|
||||
public DsContextLoader(DatasourceFactory factory, DataService dataservice) {
|
||||
this.factory = factory;
|
||||
this.dataservice = dataservice;
|
||||
}
|
||||
|
||||
public DsContext loadDatasources(Element element) {
|
||||
datasources = new DsContextImpl();
|
||||
datasources = new DsContextImpl(dataservice);
|
||||
|
||||
List<Element> elements = element.elements("datasource");
|
||||
for (Element ds : elements) {
|
||||
@ -52,7 +54,7 @@ public class DsContextLoader {
|
||||
final String viewName = element.attributeValue("view");
|
||||
|
||||
final Datasource datasource =
|
||||
factory.createDatasource(datasources, id, metaClass, viewName);
|
||||
factory.createDatasource(datasources, dataservice, id, metaClass, viewName);
|
||||
|
||||
String item = element.attributeValue("item");
|
||||
if (!StringUtils.isBlank(item)) {
|
||||
@ -136,7 +138,7 @@ public class DsContextLoader {
|
||||
final String viewName = element.attributeValue("view");
|
||||
|
||||
final CollectionDatasource datasource =
|
||||
factory.createCollectionDatasource(datasources, id, metaClass, viewName);
|
||||
factory.createCollectionDatasource(datasources, dataservice, id, metaClass, viewName);
|
||||
|
||||
final String query = element.elementText("query");
|
||||
if (!StringUtils.isBlank(query)) {
|
||||
|
@ -20,6 +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 frameLoaders = new LayoutLoaderConfig();
|
||||
|
||||
static {
|
||||
@ -29,6 +30,9 @@ public class LayoutLoaderConfig {
|
||||
editorLoaders.registerLoader("window", WindowLoader.Editor.class);
|
||||
registerComponents(editorLoaders);
|
||||
|
||||
lookupLoaders.registerLoader("window", WindowLoader.Lookup.class);
|
||||
registerComponents(lookupLoaders);
|
||||
|
||||
frameLoaders.registerLoader("frame", FrameLoader.class);
|
||||
registerComponents(frameLoaders);
|
||||
}
|
||||
@ -63,6 +67,10 @@ public class LayoutLoaderConfig {
|
||||
return frameLoaders;
|
||||
}
|
||||
|
||||
public static LayoutLoaderConfig getLookupLoaders() {
|
||||
return lookupLoaders;
|
||||
}
|
||||
|
||||
public Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader> getLoader(String name) {
|
||||
return loaders.get(name);
|
||||
}
|
||||
|
@ -49,4 +49,15 @@ public class WindowLoader extends FrameLoader implements ComponentLoader {
|
||||
return factory.createComponent("window.editor");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Lookup extends WindowLoader {
|
||||
public Lookup(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window createComponent(ComponentsFactory factory) throws InstantiationException, IllegalAccessException {
|
||||
return factory.createComponent("window.lookup");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 25.12.2008 11:51:01
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.data;
|
||||
|
||||
import com.haulmont.cuba.core.CubaTestCase;
|
||||
import com.haulmont.cuba.gui.data.impl.DatasourceFactoryImpl;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
import com.haulmont.cuba.security.entity.Profile;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
public class DatasourcesLoaderTest extends CubaTestCase {
|
||||
protected Element loadXml(String resource) {
|
||||
final InputStream stream = getClass().getResourceAsStream(resource);
|
||||
|
||||
SAXReader reader = new SAXReader();
|
||||
Document doc;
|
||||
try {
|
||||
doc = reader.read(stream);
|
||||
} catch (DocumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return doc.getRootElement();
|
||||
}
|
||||
|
||||
public void testDatasource1() {
|
||||
final DatasourceFactoryImpl factory = new DatasourceFactoryImpl();
|
||||
|
||||
final DsContextLoader loader = new DsContextLoader(factory);
|
||||
final DsContext dsContext = loader.loadDatasources(loadXml("/com/haulmont/cuba/gui/xml/data/server.xml"));
|
||||
System.out.println("datasources = " + dsContext);
|
||||
}
|
||||
|
||||
public void testDatasource2() {
|
||||
final DatasourceFactoryImpl factory = new DatasourceFactoryImpl();
|
||||
|
||||
final DsContextLoader loader = new DsContextLoader(factory);
|
||||
final DsContext dsContext = loader.loadDatasources(loadXml("/com/haulmont/cuba/gui/xml/data/security.xml"));
|
||||
|
||||
final Set<Profile> profiles = new HashSet<Profile>();
|
||||
profiles.add(new Profile());
|
||||
profiles.add(new Profile());
|
||||
|
||||
final User user = new User();
|
||||
user.setProfiles(profiles);
|
||||
|
||||
dsContext.setContext(new Context() {
|
||||
public <T> T getValue(String property) {
|
||||
if ("user".equals(property)) {
|
||||
return (T) user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue(String property, Object value) {}
|
||||
|
||||
public void addValueListener(ValueListener listener) {}
|
||||
|
||||
public void removeValueListener(ValueListener listener) {}
|
||||
});
|
||||
System.out.println("datasources = " + dsContext);
|
||||
System.out.println("((CollectionDatasource)datasources.get(\"profiles\")).getItemIds() = " + ((CollectionDatasource) dsContext.get("profiles")).getItemIds());
|
||||
}
|
||||
|
||||
public void testDatasource3() {
|
||||
final DatasourceFactoryImpl factory = new DatasourceFactoryImpl();
|
||||
|
||||
final DsContextLoader loader = new DsContextLoader(factory);
|
||||
final DsContext dsContext = loader.loadDatasources(loadXml("/com/haulmont/cuba/gui/xml/data/security2.xml"));
|
||||
|
||||
final Set<Profile> profiles = new HashSet<Profile>();
|
||||
profiles.add(new Profile());
|
||||
profiles.add(new Profile());
|
||||
|
||||
final User user = new User();
|
||||
user.setProfiles(profiles);
|
||||
|
||||
dsContext.setContext(new Context() {
|
||||
public <T> T getValue(String property) {
|
||||
if ("user".equals(property)) {
|
||||
return (T) user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue(String property, Object value) {}
|
||||
|
||||
public void addValueListener(ValueListener listener) {}
|
||||
|
||||
public void removeValueListener(ValueListener listener) {}
|
||||
});
|
||||
|
||||
final CollectionDatasource datasource = dsContext.get("profiles");
|
||||
|
||||
datasource.refresh();
|
||||
final Collection itemIds = datasource.getItemIds();
|
||||
|
||||
System.out.println("datasources = " + dsContext);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<datasources>
|
||||
<datasource id="user"
|
||||
class="com.haulmont.cuba.security.entity.User"
|
||||
view="UserView"
|
||||
item="${context:user}"
|
||||
>
|
||||
<collection-datasource id="profiles" property="profiles" inverseProperty="user"/>
|
||||
</datasource>
|
||||
</datasources>
|
@ -1,15 +0,0 @@
|
||||
<datasources>
|
||||
<datasource id="user"
|
||||
class="com.haulmont.cuba.security.entity.User"
|
||||
view="UserView"
|
||||
item="${context:user}"
|
||||
/>
|
||||
|
||||
<collection-datasource
|
||||
id="profiles"
|
||||
class="com.haulmont.cuba.security.entity.Profile"
|
||||
view="UserView"
|
||||
>
|
||||
<query>select p from Profile where user = ${ds:user}</query>
|
||||
</collection-datasource>
|
||||
</datasources>
|
@ -1,9 +0,0 @@
|
||||
<datasources>
|
||||
<datasource id="server"
|
||||
class="com.haulmont.cuba.core.entity.Server"
|
||||
view="ServerView"
|
||||
item="${context:server}"
|
||||
>
|
||||
<!--<collection-datasource id="termials" property="terminals" inverseProperty="airport"/>-->
|
||||
</datasource>
|
||||
</datasources>
|
@ -146,7 +146,7 @@ public class AppWindow extends Window
|
||||
App.getInstance().getScreenManager().openWindow(
|
||||
template,
|
||||
WindowManager.OpenType.NEW_TAB,
|
||||
Collections.singletonMap("caption", caption));
|
||||
Collections.<String, Object>singletonMap("caption", caption));
|
||||
} else {
|
||||
final String className = element.attributeValue("class");
|
||||
if (className != null) {
|
||||
@ -154,7 +154,7 @@ public class AppWindow extends Window
|
||||
App.getInstance().getScreenManager().openWindow(
|
||||
Class.forName(className),
|
||||
WindowManager.OpenType.NEW_TAB,
|
||||
Collections.singletonMap("caption", caption));
|
||||
Collections.<String, Object>singletonMap("caption", caption));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class Navigator extends Window
|
||||
App.getInstance().getScreenManager().openWindow(
|
||||
template,
|
||||
WindowManager.OpenType.NEW_TAB,
|
||||
Collections.singletonMap("caption", caption));
|
||||
Collections.<String, Object>singletonMap("caption", caption));
|
||||
parentWindow.removeWindow(Navigator.this);
|
||||
} else {
|
||||
final String className = element.attributeValue("class");
|
||||
@ -67,7 +67,7 @@ public class Navigator extends Window
|
||||
App.getInstance().getScreenManager().openWindow(
|
||||
Class.forName(className),
|
||||
WindowManager.OpenType.NEW_TAB,
|
||||
Collections.singletonMap("caption", caption));
|
||||
Collections.<String, Object>singletonMap("caption", caption));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -10,8 +10,13 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web;
|
||||
|
||||
import com.haulmont.cuba.core.Locator;
|
||||
import com.haulmont.cuba.core.app.BasicService;
|
||||
import com.haulmont.cuba.core.entity.BaseEntity;
|
||||
import com.haulmont.cuba.core.global.BasicInvocationContext;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.data.DataService;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.haulmont.cuba.web.ui.ScreenTitlePane;
|
||||
@ -22,10 +27,7 @@ import com.itmill.toolkit.ui.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.TabSheet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class ScreenManager extends WindowManager
|
||||
{
|
||||
@ -49,6 +51,11 @@ public class ScreenManager extends WindowManager
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected DataService createDefaultDataService() {
|
||||
return new BasicServiceWrapper();
|
||||
}
|
||||
|
||||
protected void showWindow(Window window, String caption, OpenType type) {
|
||||
if (OpenType.NEW_TAB.equals(type)) {
|
||||
ExpandLayout layout = new ExpandLayout();
|
||||
@ -118,4 +125,36 @@ public class ScreenManager extends WindowManager
|
||||
protected ComponentsFactory createComponentFactory() {
|
||||
return new WebComponentsFactory();
|
||||
}
|
||||
|
||||
private class BasicServiceWrapper implements DataService {
|
||||
protected BasicService service;
|
||||
|
||||
private BasicServiceWrapper() {
|
||||
service = Locator.lookupLocal(BasicService.JNDI_NAME);
|
||||
}
|
||||
|
||||
public <T> T create(T entity) {
|
||||
return (T)service.create((BaseEntity)entity);
|
||||
}
|
||||
|
||||
public <T> T update(T entity) {
|
||||
return (T) service.update((BaseEntity)entity);
|
||||
}
|
||||
|
||||
public void delete(BasicInvocationContext ctx) {
|
||||
service.delete(ctx);
|
||||
}
|
||||
|
||||
public <T> T get(BasicInvocationContext ctx) {
|
||||
return (T)service.get(ctx);
|
||||
}
|
||||
|
||||
public <T> T load(BasicInvocationContext ctx) {
|
||||
return (T)service.load(ctx);
|
||||
}
|
||||
|
||||
public <T> List<T> loadList(BasicInvocationContext ctx) {
|
||||
return (List)service.loadList(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import com.haulmont.cuba.web.ui.GenericEditorWindow;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class SecurityUserBrowser extends AbstractWindow {
|
||||
public class SecurityUserBrowser extends AbstractLookup {
|
||||
public SecurityUserBrowser(Window frame) {
|
||||
super(frame);
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
<window class="com.haulmont.cuba.web.app.ui.security.user.browse.SecurityUserBrowser">
|
||||
<window
|
||||
class="com.haulmont.cuba.web.app.ui.security.user.browse.SecurityUserBrowser"
|
||||
lookupComponent="users"
|
||||
>
|
||||
<metadataContext>
|
||||
<deployViews name="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.views.xml"/>
|
||||
</metadataContext>
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 05.02.2009 13:35:20
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.app.ui.security.user.edit;
|
||||
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class SecurityUserEditor extends AbstractEditor {
|
||||
public SecurityUserEditor(Window frame) {
|
||||
super(frame);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
Button button = getComponent("browse");
|
||||
button.setAction(new Action() {
|
||||
public String getCaption() {
|
||||
return "Browse...";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
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.
|
||||
}
|
||||
}, WindowManager.OpenType.THIS_TAB);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
<window
|
||||
resourceBundle="com.haulmont.cuba.web.app.ui.security.user.edit.security-user-edit"
|
||||
datasource="user"
|
||||
caption="Edit User '${item.name}'"
|
||||
caption="Edit User '${parameter$item.name}'"
|
||||
class="com.haulmont.cuba.web.app.ui.security.user.edit.SecurityUserEditor"
|
||||
>
|
||||
<metadataContext>
|
||||
<deployViews name="/com/haulmont/cuba/web/app/ui/security/user/edit/security-user-edit.views.xml"/>
|
||||
@ -40,7 +41,7 @@
|
||||
<label value="Login"/>
|
||||
<hbox>
|
||||
<text-field id="login" datasource="user" property="login"/>
|
||||
<button caption="Browse..."/>
|
||||
<button id="browse" caption="Browse..."/>
|
||||
</hbox>
|
||||
</row>
|
||||
</rows>
|
||||
|
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 05.02.2009 15:01:49
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.itmill.toolkit.ui.Component;
|
||||
|
||||
public interface ComponentEx extends Component {
|
||||
com.haulmont.cuba.gui.components.Component asComponent();
|
||||
}
|
@ -11,6 +11,7 @@ package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.itmill.toolkit.ui.Component;
|
||||
import com.itmill.toolkit.ui.ComponentContainer;
|
||||
import com.itmill.toolkit.ui.Form;
|
||||
import com.haulmont.cuba.gui.components.ValuePathHelper;
|
||||
|
||||
import java.util.Iterator;
|
||||
@ -20,6 +21,7 @@ import java.util.Arrays;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
public class ComponentsHelper {
|
||||
|
||||
public static Component unwrap(com.haulmont.cuba.gui.components.Component component) {
|
||||
Object comp = component;
|
||||
while (comp instanceof com.haulmont.cuba.gui.components.Component.Wrapper) {
|
||||
@ -32,7 +34,12 @@ public class ComponentsHelper {
|
||||
public static <T extends com.haulmont.cuba.gui.components.Component> T getComponent(
|
||||
com.haulmont.cuba.gui.components.Component.Container comp, String id)
|
||||
{
|
||||
final ComponentContainer container = (ComponentContainer) unwrap(comp);
|
||||
final Component unwrapedComponent = unwrap(comp);
|
||||
final ComponentContainer container =
|
||||
unwrapedComponent instanceof Form ?
|
||||
((Form)unwrapedComponent).getLayout() :
|
||||
(ComponentContainer) unwrapedComponent;
|
||||
|
||||
final String[] elements = ValuePathHelper.parse(id);
|
||||
if (elements.length == 1) {
|
||||
final com.haulmont.cuba.gui.components.Component component =
|
||||
@ -64,6 +71,18 @@ public class ComponentsHelper {
|
||||
if (c instanceof com.haulmont.cuba.gui.components.Component.Container) {
|
||||
component = ((com.haulmont.cuba.gui.components.Component.Container) c).getComponent(id);
|
||||
if (component != null) return (T) component;
|
||||
} else if (c instanceof ComponentEx) {
|
||||
component = ((ComponentEx) c).asComponent();
|
||||
if (component instanceof com.haulmont.cuba.gui.components.Component.Container) {
|
||||
component = ((com.haulmont.cuba.gui.components.Component.Container) component).getComponent(id);
|
||||
if (component != null) return (T) component;
|
||||
}
|
||||
} else if (c instanceof ComponentContainer) {
|
||||
component = getComponentByIterate(((ComponentContainer) c), id);
|
||||
if (component != null) return (T) component;
|
||||
} else if (c instanceof Form) {
|
||||
component = getComponentByIterate(((Form) c).getLayout(), id);
|
||||
if (component != null) return (T) component;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,19 +30,19 @@ public class IFrame extends AbstractPanel implements com.haulmont.cuba.gui.compo
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(descriptor, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(aclass, openType, params);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openEditor(descriptor, item, openType, params);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openEditor(aclass, item, openType, params);
|
||||
}
|
||||
|
||||
@ -61,4 +61,20 @@ public class IFrame extends AbstractPanel implements com.haulmont.cuba.gui.compo
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(aclass, openType);
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(String descriptor, Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(descriptor, handler, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(Class aclass, Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(aclass, handler, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(String descriptor, Window.Lookup.Handler handler, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(descriptor, handler, openType);
|
||||
}
|
||||
|
||||
public <T extends Window> T openLookup(Class aclass, Window.Lookup.Handler handler, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(aclass, handler, openType);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
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;
|
||||
@ -18,6 +19,8 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
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 java.util.*;
|
||||
@ -131,7 +134,31 @@ public class Table
|
||||
final CollectionDatasourceWrapper ds =
|
||||
new CollectionDatasourceWrapper(datasource);
|
||||
|
||||
for (MetaProperty metaProperty : (Collection<MetaProperty>)ds.getContainerPropertyIds()) {
|
||||
if (metaProperty.getRange().isClass()) {
|
||||
component.addGeneratedColumn(metaProperty, new com.itmill.toolkit.ui.Table.ColumnGenerator() {
|
||||
public com.itmill.toolkit.ui.Component generateCell(com.itmill.toolkit.ui.Table source, Object itemId, Object columnId) {
|
||||
Property property = source.getItem(itemId).getItemProperty(columnId);
|
||||
final Object value = property.getValue();
|
||||
|
||||
final com.itmill.toolkit.ui.Button component = new com.itmill.toolkit.ui.Button();
|
||||
component.setData(value);
|
||||
component.setCaption(value == null ? "" : value.toString());
|
||||
component.setStyleName("link");
|
||||
component.addListener(new com.itmill.toolkit.ui.Button.ClickListener() {
|
||||
public void buttonClick(Button.ClickEvent event) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
});
|
||||
|
||||
return component;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
component.setContainerDataSource(ds);
|
||||
|
||||
for (MetaProperty metaProperty : (Collection<MetaProperty>)ds.getContainerPropertyIds()) {
|
||||
component.setColumnHeader(metaProperty, StringUtils.capitalize(metaProperty.getName()));
|
||||
}
|
||||
|
@ -12,23 +12,46 @@ package com.haulmont.cuba.web.components;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.TabSheet;
|
||||
|
||||
import java.util.Collection;
|
||||
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
|
||||
com.haulmont.cuba.gui.components.Tabsheet, Component.Wrapper, Component.Container
|
||||
{
|
||||
public Tabsheet() {
|
||||
component = new TabSheet();
|
||||
component = new TabSheetEx(this);
|
||||
}
|
||||
|
||||
protected Map<String, Tab> tabs = new HashMap<String, Tab>();
|
||||
protected Map<Component, String> components = new HashMap<Component, String>();
|
||||
|
||||
public void add(Component component) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
for (Tab tab : tabs.values()) {
|
||||
if (tab.getComponent() instanceof Container) {
|
||||
final Component component = ComponentsHelper.getComponent((Container) tab.getComponent(), id);
|
||||
if (component != null) return (T) component;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
return ComponentsHelper.<T>getComponent(this, id);
|
||||
}
|
||||
|
||||
protected class Tab implements com.haulmont.cuba.gui.components.Tabsheet.Tab {
|
||||
private String name;
|
||||
private Component component;
|
||||
@ -97,4 +120,17 @@ public class Tabsheet
|
||||
public Collection<com.haulmont.cuba.gui.components.Tabsheet.Tab> getTabs() {
|
||||
return (Collection)tabs.values();
|
||||
}
|
||||
|
||||
private static class TabSheetEx extends TabSheet implements ComponentEx {
|
||||
private Component component;
|
||||
|
||||
private TabSheetEx(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public Component asComponent() {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,17 +17,16 @@ import com.haulmont.cuba.core.app.BasicService;
|
||||
import com.haulmont.cuba.core.entity.BaseEntity;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.LookupField;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.*;
|
||||
|
||||
public class Window implements com.haulmont.cuba.gui.components.Window, Component.Wrapper, Component.HasXmlDescriptor
|
||||
{
|
||||
@ -68,11 +67,11 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(descriptor, openType, params);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(aclass, openType, params);
|
||||
}
|
||||
|
||||
@ -84,11 +83,11 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
return App.getInstance().getScreenManager().<T>openWindow(aclass, openType);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String descriptor, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openEditor(descriptor, item, openType, params);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map params) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(Class aclass, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openEditor(aclass, item, openType, params);
|
||||
}
|
||||
|
||||
@ -100,7 +99,23 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
return App.getInstance().getScreenManager().<T>openEditor(aclass, item, openType);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(String descriptor, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(descriptor, handler, openType, params);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(Class aclass, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(aclass, handler, openType, params);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(String descriptor, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(descriptor, handler, openType);
|
||||
}
|
||||
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(Class aclass, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openLookup(aclass, handler, openType);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public DsContext getDsContext() {
|
||||
return dsContext;
|
||||
@ -216,6 +231,7 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
|
||||
public static class Editor extends Window implements com.haulmont.cuba.gui.components.Window.Editor {
|
||||
protected Object item;
|
||||
private Form form;
|
||||
|
||||
public Object getItem() {
|
||||
return item;
|
||||
@ -223,7 +239,9 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
|
||||
@Override
|
||||
protected com.itmill.toolkit.ui.Component createLayout() {
|
||||
final Form form = new Form();
|
||||
ExpandLayout layout = new ExpandLayout();
|
||||
|
||||
form = new Form();
|
||||
|
||||
Layout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
okbar.setHeight("25px");
|
||||
@ -231,14 +249,17 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
okbar.addComponent(new Button("OK", this, "commit"));
|
||||
okbar.addComponent(new Button("Cancel", this, "close"));
|
||||
|
||||
form.setFooter(okbar);
|
||||
layout.addComponent(form);
|
||||
layout.addComponent(okbar);
|
||||
|
||||
return form;
|
||||
layout.expand(form);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentContainer getContainer() {
|
||||
return ((Form) component).getLayout();
|
||||
return form.getLayout();
|
||||
}
|
||||
|
||||
public void setItem(Object item) {
|
||||
@ -279,7 +300,7 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
((Form) component).commit();
|
||||
form.commit();
|
||||
if (item instanceof Datasource) {
|
||||
final Datasource ds = (Datasource) item;
|
||||
ds.commit();
|
||||
@ -290,4 +311,74 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Lookup extends Window implements com.haulmont.cuba.gui.components.Window.Lookup {
|
||||
private Handler handler;
|
||||
|
||||
private Component lookupComponent;
|
||||
private ExpandLayout contaiter;
|
||||
|
||||
public com.haulmont.cuba.gui.components.Component getLookupComponent() {
|
||||
return lookupComponent;
|
||||
}
|
||||
|
||||
public void setLookupComponent(Component lookupComponent) {
|
||||
this.lookupComponent = lookupComponent;
|
||||
}
|
||||
|
||||
public Handler getLookupHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void setLookupHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentContainer getContainer() {
|
||||
return contaiter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected com.itmill.toolkit.ui.Component createLayout() {
|
||||
final ExpandLayout form = new ExpandLayout();
|
||||
|
||||
contaiter = new ExpandLayout();
|
||||
|
||||
OrderedLayout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
okbar.setHeight("25px");
|
||||
|
||||
final Button selectButton = new Button("Select");
|
||||
selectButton.addListener(new Button.ClickListener() {
|
||||
public void buttonClick(Button.ClickEvent event) {
|
||||
final com.haulmont.cuba.gui.components.Component lookupComponent = getLookupComponent();
|
||||
|
||||
if (lookupComponent instanceof com.haulmont.cuba.gui.components.Table ) {
|
||||
final Set selected = ((com.haulmont.cuba.gui.components.Table) lookupComponent).getSelected();
|
||||
handler.handleLookup(selected);
|
||||
} 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));
|
||||
} else if (lookupComponent instanceof LookupField) {
|
||||
final Object value = ((LookupField) lookupComponent).getValue();
|
||||
handler.handleLookup(Collections.singleton(value));
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final Button cancelButton = new Button("Cancel", this, "close");
|
||||
|
||||
okbar.addComponent(selectButton);
|
||||
okbar.addComponent(cancelButton);
|
||||
|
||||
form.addComponent(contaiter);
|
||||
form.addComponent(okbar);
|
||||
|
||||
form.expand(contaiter);
|
||||
|
||||
return form;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public class WebComponentsFactory implements ComponentsFactory {
|
||||
static {
|
||||
classes.put("window", Window.class);
|
||||
classes.put("window.editor", Window.Editor.class);
|
||||
classes.put("window.lookup", Window.Lookup.class);
|
||||
|
||||
classes.put("hbox", HBoxLayout.class);
|
||||
classes.put("vbox", VBoxLayout.class);
|
||||
|
Loading…
Reference in New Issue
Block a user