generic browser

generic lookup
This commit is contained in:
Dmitry Abramov 2009-02-18 08:21:33 +00:00
parent 73d8c81b1e
commit 828b1b5fd3
15 changed files with 507 additions and 210 deletions

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 18.02.2009 9:55:51
* $Id$
*/
package com.haulmont.cuba.gui;
import com.haulmont.cuba.gui.data.Context;
import com.haulmont.cuba.gui.data.ValueListener;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.Component;
public class WindowContext implements Context {
private final Window window;
public WindowContext(Window window) {
this.window = window;
}
public <T> T getValue(String property) {
final Component component = window.getComponent(property);
if (component instanceof Component.Field) {
return ((Component.Field) component).<T>getValue();
} else {
return null;
}
}
public void setValue(String property, Object value) {
final Component component = window.getComponent(property);
if (component instanceof Component.Field) {
((Component.Field) component).setValue(value);
} else {
throw new UnsupportedOperationException();
}
}
public void addValueListener(ValueListener listener) {
}
public void removeValueListener(ValueListener listener) {
}
}

View File

@ -118,31 +118,7 @@ public abstract class WindowManager {
}
}
dsContext.setContext(new Context() {
public <T> T getValue(String property) {
final Component component = window.getComponent(property);
if (component instanceof Component.Field) {
return ((Component.Field) component).<T>getValue();
} else {
return null;
}
}
public void setValue(String property, Object value) {
final Component component = window.getComponent(property);
if (component instanceof Component.Field) {
((Component.Field) component).setValue(value);
} else {
throw new UnsupportedOperationException();
}
}
public void addValueListener(ValueListener listener) {
}
public void removeValueListener(ValueListener listener) {
}
});
dsContext.setContext(new WindowContext(window));
}
protected Window loadLayout(Element rootElement, ComponentLoader.Context context, LayoutLoaderConfig layoutConfig) {
@ -174,22 +150,22 @@ public abstract class WindowManager {
}
}
public <T extends Window> T openWindow(ScreenInfo screenInfo, WindowManager.OpenType openType, Map<String, Object> params)
public <T extends Window> T openWindow(ScreenInfo windowInfo, WindowManager.OpenType openType, Map<String, Object> params)
{
String template = screenInfo.getTemplate();
params = createParametersMap(windowInfo, params);
String template = windowInfo.getTemplate();
if (template != null) {
return (T) openWindow(template, openType, params);
}
else {
Class screenClass = screenInfo.getScreenClass();
return (T) __openWindow(template, openType, params);
} else {
Class screenClass = windowInfo.getScreenClass();
if (screenClass != null)
return (T) openWindow(screenClass, openType, params);
return (T) __openWindow(screenClass, openType, params);
else
return null;
}
}
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map<String, Object> params) {
protected <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);
@ -234,7 +210,7 @@ public abstract class WindowManager {
return caption;
}
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params) {
protected <T extends Window> T __openWindow(Class aclass, WindowManager.OpenType openType, Map<String, Object> params) {
Window window = createWindow(aclass, params);
String caption = loadCaption(window, params);
@ -243,21 +219,20 @@ public abstract class WindowManager {
return (T) window;
}
public <T extends Window> T openEditor(ScreenInfo screenInfo, Object item, OpenType openType, Map<String, Object> params) {
params = createParametersMap(params);
public <T extends Window> T openEditor(ScreenInfo windowInfo, Object item, OpenType openType, Map<String, Object> params) {
params = createParametersMap(windowInfo, params);
params.put("parameter$item", item instanceof Datasource ? ((Datasource) item).getItem() : item);
String template = screenInfo.getTemplate();
String template = windowInfo.getTemplate();
Window window;
if (template != null) {
window = createWindow(template, params, LayoutLoaderConfig.getEditorLoaders());
}
else {
Class screenClass = screenInfo.getScreenClass();
} else {
Class screenClass = windowInfo.getScreenClass();
if (screenClass != null)
window = createWindow(screenClass, params);
else
throw new IllegalStateException("Invalid ScreenInfo: " + screenInfo);
throw new IllegalStateException("Invalid ScreenInfo: " + windowInfo);
}
((Window.Editor) window).setItem(item);
@ -268,21 +243,21 @@ public abstract class WindowManager {
}
public <T extends Window> T openLookup(
ScreenInfo screenInfo, Window.Lookup.Handler handler,
ScreenInfo windowInfo, Window.Lookup.Handler handler,
OpenType openType, Map<String, Object> params)
{
params = createParametersMap(params);
params = createParametersMap(windowInfo, params);
String template = screenInfo.getTemplate();
String template = windowInfo.getTemplate();
Window window;
if (template != null) {
window = createWindow(template, params, LayoutLoaderConfig.getEditorLoaders());
} else {
Class screenClass = screenInfo.getScreenClass();
Class screenClass = windowInfo.getScreenClass();
if (screenClass != null)
window = createWindow(screenClass, params);
else
throw new IllegalStateException("Invalid ScreenInfo: " + screenInfo);
throw new IllegalStateException("Invalid ScreenInfo: " + windowInfo);
}
final Element element = ((Component.HasXmlDescriptor) window).getXmlDescriptor();
@ -296,11 +271,28 @@ public abstract class WindowManager {
String caption = loadCaption(window, params);
showWindow(window, caption, openType);
return (T) window;
}
protected Map<String, Object> createParametersMap(Map<String, Object> params) {
protected Map<String, Object> createParametersMap(ScreenInfo windowInfo, Map<String, Object> params) {
final Map<String, Object> map = new HashMap<String, Object>(params.size());
final Element element = windowInfo.getDescriptor();
if (element != null) {
final Element paramsElement = element.element("params");
if (paramsElement != null) {
final List<Element> paramElements = paramsElement.elements("param");
for (Element paramElement : paramElements) {
final String name = paramElement.attributeValue("name");
final String value = paramElement.attributeValue("value");
map.put("parameter$" + name, value);
}
}
}
for (Map.Entry<String, Object> entry : params.entrySet()) {
map.put("parameter$" + entry.getKey(), entry.getValue());
}
@ -308,33 +300,18 @@ public abstract class WindowManager {
return map;
}
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(ScreenInfo screenInfo, Object item, OpenType openType) {
return (T)openEditor(screenInfo, item, openType, Collections.<String, Object>emptyMap());
public <T extends Window> T openEditor(ScreenInfo windowInfo, Object item, OpenType openType) {
return (T)openEditor(windowInfo, item, openType, Collections.<String, Object>emptyMap());
}
public <T extends Window> T openWindow(ScreenInfo screenInfo, OpenType openType) {
return (T)openWindow(screenInfo, openType, Collections.<String, Object>emptyMap());
public <T extends Window> T openWindow(ScreenInfo windowInfo, OpenType openType) {
return (T)openWindow(windowInfo, openType, Collections.<String, Object>emptyMap());
}
public <T extends Window> T openLookup(ScreenInfo screenInfo, Window.Lookup.Handler handler, OpenType openType) {
return (T)openLookup(screenInfo, handler, openType, Collections.<String, Object>emptyMap());
public <T extends Window> T openLookup(ScreenInfo windowInfo, Window.Lookup.Handler handler, OpenType openType) {
return (T)openLookup(windowInfo, handler, openType, Collections.<String, Object>emptyMap());
}
protected abstract void showWindow(Window window, String caption, OpenType openType);
@ -508,4 +485,5 @@ public abstract class WindowManager {
}
}
}
}

View File

@ -20,23 +20,23 @@ public interface IFrame extends OrderedLayout, Component.Container {
void setResourceBundle(ResourceBundle resourceBundle);
<T extends Window> T openWindow(
String screenId, WindowManager.OpenType openType, Map<String, Object> params);
String windowAlias, WindowManager.OpenType openType, Map<String, Object> params);
<T extends Window> T openWindow(
String screenId, WindowManager.OpenType openType);
String windowAlias, WindowManager.OpenType openType);
<T extends Window> T openEditor(
String screenId, Object item,
String windowAlias, Object item,
WindowManager.OpenType openType, Map<String, Object> params);
<T extends Window> T openEditor(
String screenId, Object item, WindowManager.OpenType openType);
String windowAlias, Object item, WindowManager.OpenType openType);
<T extends Window> T openLookup(
String screenId, Window.Lookup.Handler handler,
String windowAlias, Window.Lookup.Handler handler,
WindowManager.OpenType openType, Map<String, Object> params);
<T extends Window> T openLookup(
String screenId, Window.Lookup.Handler handler, WindowManager.OpenType openType);
String windowAlias, Window.Lookup.Handler handler, WindowManager.OpenType openType);
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 16.02.2009 17:18:03
* $Id$
*/
package com.haulmont.cuba.gui.components;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.DataService;
import java.util.Set;
public class TableActionsHelper {
private IFrame frame;
private Table table;
public TableActionsHelper(IFrame frame, Table table) {
this.frame = frame;
this.table = table;
}
public Action createCreateAction() {
final AbstractAction action = new AbstractAction("create") {
public String getCaption() {
return "Create";
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
final CollectionDatasource datasource = table.getDatasource();
final DataService dataservice = datasource.getDataService();
final String windowID = datasource.getMetaClass().getName() + ".edit";
frame.openEditor(windowID, dataservice.<Entity>newInstance(datasource.getMetaClass()), WindowManager.OpenType.THIS_TAB);
}
};
table.addAction(action);
return action;
}
public Action createEditAction() {
final AbstractAction action = new AbstractAction("edit") {
public String getCaption() {
return "Edit";
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
final Set selected = table.getSelected();
if (selected.size() == 1) {
final CollectionDatasource datasource = table.getDatasource();
final String windowID = datasource.getMetaClass().getName() + ".edit";
frame.openEditor(windowID, datasource, WindowManager.OpenType.THIS_TAB);
}
}
};
table.addAction(action);
return action;
}
public Action createRefreshAction() {
final Action action = new AbstractAction("refresh") {
public String getCaption() {
return "Refresh";
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
table.getDatasource().refresh();
}
};
table.addAction(action);
return action;
}
}

View File

@ -41,6 +41,7 @@ public class ScreenInfo
throw new RuntimeException(e);
}
}
return screenClass;
}

View File

@ -177,26 +177,26 @@ public class CollectionDatasourceImpl<T extends Entity, K>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
protected Collection<T> getCollection() {
if (query == null) {
throw new IllegalStateException();
} else {
return collection;
}
return collection;
}
protected Collection<T> loadData() {
final DataServiceRemote.CollectionLoadContext context =
new DataServiceRemote.CollectionLoadContext(metaClass);
final Map<String, Object> parameters = getQueryParameters();
for (ParametersHelper.ParameterInfo info : queryParameters) {
if (ParametersHelper.ParameterInfo.Type.DATASOURCE.equals(info.getType())) {
final Object value = parameters.get(info.getFlatName());
if (value == null) return Collections.emptyList();
if (query != null && queryParameters != null) {
final Map<String, Object> parameters = getQueryParameters();
for (ParametersHelper.ParameterInfo info : queryParameters) {
if (ParametersHelper.ParameterInfo.Type.DATASOURCE.equals(info.getType())) {
final Object value = parameters.get(info.getFlatName());
if (value == null) return Collections.emptyList();
}
}
context.setQueryString(getJPQLQuery(this.query, parameters)).setParameters(parameters);
} else {
context.setQueryString("select e from " + metaClass.getName() + " e");
}
context.setQueryString(getJPQLQuery(this.query, parameters)).setParameters(parameters);
context.setView(view);
collection = (Collection) dataservice.loadList(context);

View File

@ -23,6 +23,8 @@ import com.haulmont.cuba.gui.data.Datasource;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
public class DatasourceImpl<T extends Entity>
extends
AbstractDataSource<T>
@ -48,7 +50,7 @@ public class DatasourceImpl<T extends Entity>
this.dataservice = dataservice;
this.metaClass = metaClass;
this.view = MetadataProvider.getViewRepository().getView(metaClass, viewName);
this.view = StringUtils.isEmpty(viewName) ? null : MetadataProvider.getViewRepository().getView(metaClass, viewName);
this.listener = new ItemListener();
}

View File

@ -3,8 +3,14 @@
<screen id="core$Server.browse"
class="com.haulmont.cuba.web.app.ui.TableDemoScreen"/>
<screen id="sec$User.browse"
template="/com/haulmont/cuba/web/app/ui/security/user/browse/user-browse.xml"/>
<!--<screen id="sec$User.browse"-->
<!--template="/com/haulmont/cuba/web/app/ui/security/user/browse/user-browse.xml"/>-->
<screen id="sec$User.browse" class="com.haulmont.cuba.web.ui.GenericBrowserWindow">
<params>
<param name="metaClass" value="sec$User"/>
</params>
</screen>
<screen id="sec$User.edit"
template="/com/haulmont/cuba/web/app/ui/security/user/edit/user-edit.xml"/>

View File

@ -9,15 +9,8 @@
*/
package com.haulmont.cuba.web.app.ui.security.user.browse;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.DataService;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.web.components.ComponentsHelper;
import com.haulmont.cuba.core.entity.Entity;
import java.util.Set;
public class UserBrowser extends AbstractLookup {
public UserBrowser(Window frame) {
@ -28,69 +21,12 @@ public class UserBrowser extends AbstractLookup {
final Button button = getComponent("filter.apply");
final Table table = getComponent("users");
table.addAction(new AbstractAction("create") {
public String getCaption() {
return "Create";
}
final TableActionsHelper helper = new TableActionsHelper(this, table);
helper.createCreateAction();
helper.createEditAction();
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
final CollectionDatasource ds = table.getDatasource();
final DataService dataservice = ds.getDataService();
openEditor("sec$User.edit", dataservice.<Entity>newInstance(ds.getMetaClass()), WindowManager.OpenType.THIS_TAB);
}
});
table.addAction(new AbstractAction("edit") {
public String getCaption() {
return "Edit";
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
final Set selected = table.getSelected();
if (selected.size() == 1) {
User user = (User) selected.iterator().next();
// openEditor(GenericEditorWindow.class, user, WindowManager.OpenType.THIS_TAB);
openEditor("sec$User.edit", table.getDatasource(), WindowManager.OpenType.THIS_TAB);
}
}
});
table.addAction(new AbstractAction("refresh") {
public String getCaption() {
return "Refresh";
}
public boolean isEnabled() {
final User user = table.getSingleSelected();
return user != null && user.getName().equals("Administrator");
}
public void actionPerform(Component component) {
table.getDatasource().refresh();
}
});
button.setAction(new AbstractAction("refresh") {
public String getCaption() {
return null;
}
public boolean isEnabled() {
return true;
}
public void actionPerform(Component component) {
table.getDatasource().refresh();
}
});
final Action refreshAction = helper.createRefreshAction();
button.setAction(refreshAction);
}
public boolean close() {

View File

@ -31,33 +31,33 @@ public class IFrame extends AbstractPanel implements com.haulmont.cuba.gui.compo
this.resourceBundle = resourceBundle;
}
public <T extends Window> T openWindow(String screenId, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
public <T extends Window> T openWindow(String windowAlias, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openWindow(screenInfo, openType, params);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String screenId, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openEditor(screenInfo, item, openType, params);
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String windowAlias, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openEditor(windowInfo, item, openType, params);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String screenId, Object item, WindowManager.OpenType openType) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openEditor(screenInfo, item, openType);
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String windowAlias, Object item, WindowManager.OpenType openType) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openEditor(windowInfo, item, openType);
}
public <T extends Window> T openWindow(String screenId, WindowManager.OpenType openType) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openWindow(screenInfo, openType);
public <T extends Window> T openWindow(String windowAlias, WindowManager.OpenType openType) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openWindow(windowInfo, openType);
}
public <T extends Window> T openLookup(String screenId, Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openLookup(screenInfo, handler, openType, params);
public <T extends Window> T openLookup(String windowAlias, Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openLookup(windowInfo, handler, openType, params);
}
public <T extends Window> T openLookup(String screenId, Window.Lookup.Handler handler, WindowManager.OpenType openType) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openLookup(screenInfo, handler, openType);
public <T extends Window> T openLookup(String windowAlias, Window.Lookup.Handler handler, WindowManager.OpenType openType) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openLookup(windowInfo, handler, openType);
}
}

View File

@ -58,6 +58,7 @@ public class CollectionDatasourceWrapper implements Container, Container.ItemSet
final MetaProperty metaProperty = metaClass.getProperty(name);
final Range range = metaProperty.getRange();
if (range == null) continue;
final Range.Cardinality cardinality = range.getCardinality();
if (Range.Cardinality.ONE_TO_ONE.equals(cardinality) ||
@ -69,6 +70,7 @@ public class CollectionDatasourceWrapper implements Container, Container.ItemSet
} else {
for (MetaProperty metaProperty : metaClass.getProperties()) {
final Range range = metaProperty.getRange();
if (range == null) continue;
final Range.Cardinality cardinality = range.getCardinality();
if (Range.Cardinality.ONE_TO_ONE.equals(cardinality) ||

View File

@ -0,0 +1,149 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 16.02.2009 17:27:55
* $Id$
*/
package com.haulmont.cuba.web.ui;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.cuba.core.global.MetadataProvider;
import com.haulmont.cuba.core.global.View;
import com.haulmont.cuba.gui.data.*;
import com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl;
import com.haulmont.cuba.gui.data.impl.DsContextImpl;
import com.haulmont.cuba.gui.data.impl.GenericDataService;
import com.haulmont.cuba.gui.WindowContext;
import com.haulmont.cuba.gui.components.TableActionsHelper;
import com.haulmont.cuba.gui.components.Action;
import com.haulmont.cuba.web.components.ComponentsHelper;
import com.haulmont.cuba.web.components.Table;
import com.haulmont.cuba.web.components.Button;
import com.itmill.toolkit.ui.Component;
import com.itmill.toolkit.ui.ExpandLayout;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Layout;
import java.util.Map;
import java.util.Collection;
public class GenericBrowserWindow extends Window
{
protected Table table;
protected Layout actionsToolbar;
@Override
protected Component createLayout() {
final ExpandLayout layout = new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL);
table = createTable();
actionsToolbar = createActionsToolbar(table);
final Component component = ComponentsHelper.unwrap(table);
final ExpandLayout componentContainer =
new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL);
componentContainer.addComponent(component);
componentContainer.expand(component);
layout.addComponent(actionsToolbar);
layout.addComponent(componentContainer);
layout.expand(componentContainer);
layout.setMargin(true);
layout.setSpacing(true);
return layout;
}
protected Table createTable() {
final Table table = new Table();
final TableActionsHelper helper = new TableActionsHelper(this, table);
helper.createCreateAction();
helper.createEditAction();
helper.createRefreshAction();
return table;
}
protected Layout createActionsToolbar(Table table) {
final OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
final Collection<Action> actions = table.getActions();
for (Action action : actions) {
final Button button = new Button();
button.setAction(action);
layout.addComponent(ComponentsHelper.unwrap(button));
}
return layout;
}
protected void init(Map<String,Object> params) {
MetaClass metaClass = getMetaClass(params);
View view = getView(params);
if (metaClass == null) throw new UnsupportedOperationException();
setCaption("Browse " + metaClass.getName());
final DsContextImpl context = createDsContext(metaClass, view);
setDsContext(context);
final CollectionDatasource ds = context.get(metaClass.getName());
ds.refresh();
table.setDatasource(ds);
}
protected View getView(Map<String, Object> params) {
final MetaClass metaClass = getMetaClass(params);
final Object o = params.get("parameter$view");
if (o == null) return null;
if (o instanceof View) {
return (View) o;
} else if (o instanceof String) {
return MetadataProvider.getViewRepository().getView(metaClass, (String)o);
} else {
throw new UnsupportedOperationException();
}
}
protected MetaClass getMetaClass(Map<String, Object> params) {
final Object o = params.get("parameter$metaClass");
if (o == null) return null;
if (o instanceof MetaClass) {
return (MetaClass) o;
} else if (o instanceof Class) {
return MetadataProvider.getSession().getClass((Class<?>) o);
} else if (o instanceof String) {
return MetadataProvider.getSession().getClass((String) o);
} else {
throw new UnsupportedOperationException();
}
}
protected DsContextImpl createDsContext(MetaClass metaClass, View view) {
final GenericDataService dataservice = new GenericDataService(false);
final DsContextImpl context = new DsContextImpl(dataservice);
context.setContext(new WindowContext(this));
final CollectionDatasource ds = createDatasource(context, metaClass, view);
context.register(ds);
return context;
}
protected CollectionDatasourceImpl createDatasource(DsContext context, MetaClass metaClass, View view) {
DataService dataservice = context.getDataService();
return new CollectionDatasourceImpl(context, dataservice, metaClass.getName(), metaClass, view == null ? null : view.getName());
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 18.02.2009 12:06:42
* $Id$
*/
package com.haulmont.cuba.web.ui;
import com.haulmont.cuba.gui.components.Component;
import com.itmill.toolkit.ui.Layout;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Button;
public class GenericLookupWindow extends GenericBrowserWindow implements com.haulmont.cuba.gui.components.Window.Lookup {
private Handler handler;
@Override
protected com.itmill.toolkit.ui.Component createLayout() {
final Layout layout = (Layout) super.createLayout();
OrderedLayout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
okbar.setHeight("25px");
final Button selectButton = new Button("Select");
selectButton.addListener(new SelectAction(this));
final Button cancelButton = new Button("Cancel", this, "close");
okbar.addComponent(selectButton);
okbar.addComponent(cancelButton);
layout.addComponent(okbar);
return layout;
}
public Component getLookupComponent() {
return table;
}
public void setLookupComponent(Component lookupComponent) {
throw new UnsupportedOperationException();
}
public Handler getLookupHandler() {
return handler;
}
public void setLookupHandler(Handler handler) {
this.handler = handler;
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
* Author: Dmitry Abramov
* Created: 18.02.2009 12:10:08
* $Id$
*/
package com.haulmont.cuba.web.ui;
import com.itmill.toolkit.ui.Button;
import com.haulmont.cuba.gui.components.*;
import java.util.Collection;
import java.util.Collections;
class SelectAction implements Button.ClickListener {
private com.haulmont.cuba.gui.components.Window.Lookup window;
SelectAction(com.haulmont.cuba.gui.components.Window.Lookup window) {
this.window = window;
}
public void buttonClick(Button.ClickEvent event) {
final com.haulmont.cuba.gui.components.Component lookupComponent = window.getLookupComponent();
Collection selected;
if (lookupComponent instanceof com.haulmont.cuba.gui.components.Table ) {
selected = ((com.haulmont.cuba.gui.components.Table) lookupComponent).getSelected();
} else if (lookupComponent instanceof com.haulmont.cuba.gui.components.Tree) {
selected = Collections.singleton(((com.haulmont.cuba.gui.components.Tree) lookupComponent).getSelected());
} else if (lookupComponent instanceof LookupField) {
selected = Collections.singleton(((LookupField) lookupComponent).getValue());
} else {
throw new UnsupportedOperationException();
}
final com.haulmont.cuba.gui.components.Window.Lookup.Handler lookupHandler = window.getLookupHandler();
window.close();
lookupHandler.handleLookup(selected);
}
}

View File

@ -68,33 +68,34 @@ 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<String, Object> params) {
return App.getInstance().getScreenManager().<T>openWindow(descriptor, openType, params);
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(String windowAlias, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openWindow(windowInfo, openType, params);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(String screenId, WindowManager.OpenType openType) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openWindow(screenInfo, openType);
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(String windowAlias, WindowManager.OpenType openType) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openWindow(windowInfo, openType);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String screenId, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openEditor(screenInfo, item, openType, params);
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String windowAlias, Object item, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openEditor(windowInfo, item, openType, params);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String screenId, Object item, WindowManager.OpenType openType) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openEditor(screenInfo, item, openType);
public <T extends com.haulmont.cuba.gui.components.Window> T openEditor(String windowAlias, Object item, WindowManager.OpenType openType) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openEditor(windowInfo, item, openType);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(String screenId, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openLookup(screenInfo, handler, openType, params);
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(String windowAlias, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType, Map<String, Object> params) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openLookup(windowInfo, handler, openType, params);
}
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(String screenId, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType) {
ScreenInfo screenInfo = App.getInstance().getScreenConfig().getScreenInfo(screenId);
return App.getInstance().getScreenManager().<T>openLookup(screenInfo, handler, openType);
public <T extends com.haulmont.cuba.gui.components.Window> T openLookup(String windowAlias, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, WindowManager.OpenType openType) {
ScreenInfo windowInfo = App.getInstance().getScreenConfig().getScreenInfo(windowAlias);
return App.getInstance().getScreenManager().<T>openLookup(windowInfo, handler, openType);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -369,25 +370,7 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
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();
Collection selected;
if (lookupComponent instanceof com.haulmont.cuba.gui.components.Table ) {
selected = ((com.haulmont.cuba.gui.components.Table) lookupComponent).getSelected();
} else if (lookupComponent instanceof com.haulmont.cuba.gui.components.Tree) {
selected = Collections.singleton(((com.haulmont.cuba.gui.components.Tree) lookupComponent).getSelected());
} else if (lookupComponent instanceof LookupField) {
selected = Collections.singleton(((LookupField) lookupComponent).getValue());
} else {
throw new UnsupportedOperationException();
}
close();
handler.handleLookup(selected);
}
});
selectButton.addListener(new SelectAction(this));
final Button cancelButton = new Button("Cancel", this, "close");