mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
generic edit screen
This commit is contained in:
parent
35c00c7d15
commit
3274de3710
@ -31,6 +31,7 @@ import org.dom4j.io.SAXReader;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class WindowManager {
|
||||
@ -40,61 +41,7 @@ public abstract class WindowManager {
|
||||
DIALOG
|
||||
}
|
||||
|
||||
protected abstract Window createWindow(String descriptor, Map params);
|
||||
protected abstract Window createWindow(Class aclass, Map params);
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params) {
|
||||
Window window = createWindow(descriptor, params);
|
||||
|
||||
String caption = getCaption(window, params);
|
||||
|
||||
showWindow(window, caption, openType);
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
protected <T extends Window> String getCaption(Window window, Map params) {
|
||||
String caption = (String) params.get("caption");
|
||||
if (StringUtils.isEmpty(caption)) {
|
||||
final ResourceBundle resourceBundle = window.getResourceBundle();
|
||||
if (resourceBundle != null) {
|
||||
try {
|
||||
caption = resourceBundle.getString("caption");
|
||||
} catch (MissingResourceException e) {
|
||||
caption = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (caption != null) {
|
||||
caption = TemplateHelper.processTemplate(caption, params);
|
||||
}
|
||||
|
||||
return caption;
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
Window window = createWindow(aclass, params);
|
||||
|
||||
String caption = getCaption(window, params);
|
||||
|
||||
showWindow(window, caption, openType);
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, OpenType openType) {
|
||||
return (T)openWindow(descriptor, openType, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, OpenType openType) {
|
||||
return (T)openWindow(aclass, openType, Collections.emptyMap());
|
||||
}
|
||||
|
||||
protected abstract void showWindow(Window window, String caption, OpenType openType);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
protected Window createWindowFromTemplate(String template, Map params) {
|
||||
protected Window createWindow(String template, Map params) {
|
||||
Document document = parseDescriptor(template, params);
|
||||
final Element rootElement = document.getRootElement();
|
||||
|
||||
@ -146,6 +93,79 @@ public abstract class WindowManager {
|
||||
return wrapByCustomClass(window, rootElement);
|
||||
}
|
||||
|
||||
protected Window createWindow(Class aclass, Map params) {
|
||||
try {
|
||||
final Window window = (Window) aclass.newInstance();
|
||||
try {
|
||||
invokeMethod(window, "init", params);
|
||||
} catch (NoSuchMethodException e) {
|
||||
invokeMethod(window, "init");
|
||||
}
|
||||
return window;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType, Map params) {
|
||||
Window window = createWindow(descriptor, params);
|
||||
|
||||
String caption = getCaption(window, params);
|
||||
|
||||
showWindow(window, caption, openType);
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
protected <T extends Window> String getCaption(Window window, Map params) {
|
||||
String caption = (String) params.get("caption");
|
||||
if (StringUtils.isEmpty(caption)) {
|
||||
final ResourceBundle resourceBundle = window.getResourceBundle();
|
||||
if (resourceBundle != null) {
|
||||
try {
|
||||
caption = resourceBundle.getString("caption");
|
||||
} catch (MissingResourceException e) {
|
||||
caption = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (caption != null) {
|
||||
caption = TemplateHelper.processTemplate(caption, params);
|
||||
} else {
|
||||
try {
|
||||
caption = invokeMethod(window, "getCaption");
|
||||
caption = TemplateHelper.processTemplate(caption, params);
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Do nothing
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return caption;
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
Window window = createWindow(aclass, params);
|
||||
|
||||
String caption = getCaption(window, params);
|
||||
|
||||
showWindow(window, caption, openType);
|
||||
return (T) window;
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, OpenType openType) {
|
||||
return (T)openWindow(descriptor, openType, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, OpenType openType) {
|
||||
return (T)openWindow(aclass, openType, Collections.emptyMap());
|
||||
}
|
||||
|
||||
protected abstract void showWindow(Window window, String caption, OpenType openType);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected abstract Locale getLocale();
|
||||
protected abstract ComponentsFactory createComponentFactory();
|
||||
|
||||
@ -202,13 +222,43 @@ public abstract class WindowManager {
|
||||
return document;
|
||||
}
|
||||
|
||||
protected <T> T invokeMethod(Window window, String name) {
|
||||
protected <T> T invokeMethod(Window window, String name) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
final Class<? extends Window> aClass = window.getClass();
|
||||
Method method;
|
||||
try {
|
||||
final Method method = window.getClass().getDeclaredMethod(name);
|
||||
method.setAccessible(true);
|
||||
return (T) method.invoke(window);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
method = aClass.getDeclaredMethod(name);
|
||||
} catch (NoSuchMethodException e) {
|
||||
method = aClass.getMethod(name);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return (T) method.invoke(window);
|
||||
}
|
||||
|
||||
protected <T> T invokeMethod(Window window, String name, Object...params) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
List<Class> paramClasses = new ArrayList<Class>();
|
||||
for (Object param : params) {
|
||||
if (param == null) throw new IllegalStateException("Null parameter");
|
||||
|
||||
final Class<? extends Object> aClass = param.getClass();
|
||||
if (List.class.isAssignableFrom(aClass)) {
|
||||
paramClasses.add(List.class);
|
||||
} else if (Set.class.isAssignableFrom(aClass)) {
|
||||
paramClasses.add(Set.class);
|
||||
} else if (Map.class.isAssignableFrom(aClass)) {
|
||||
paramClasses.add(Map.class);
|
||||
} else {
|
||||
paramClasses.add(aClass);
|
||||
}
|
||||
}
|
||||
|
||||
final Class<? extends Window> aClass = window.getClass();
|
||||
Method method;
|
||||
try {
|
||||
method = aClass.getDeclaredMethod(name, paramClasses.toArray(new Class<?>[]{}));
|
||||
} catch (NoSuchMethodException e) {
|
||||
method = aClass.getMethod(name, paramClasses.toArray(new Class<?>[]{}));
|
||||
}
|
||||
method.setAccessible(true);
|
||||
return (T) method.invoke(window, params);
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,12 @@ public class AbstractFrame implements IFrame, Component.Wrapper {
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType) {
|
||||
return frame.<T>openWindow(aclass, openType);
|
||||
}
|
||||
|
||||
public boolean close() {
|
||||
if (frame instanceof Window) {
|
||||
return ((Window) frame).close();
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,9 @@ import com.haulmont.cuba.gui.WindowManager;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Window extends IFrame {
|
||||
boolean close();
|
||||
|
||||
interface EditorWidow extends Window {
|
||||
void commit();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ public interface Datasource<T> {
|
||||
String getId();
|
||||
DsContext getDsContext();
|
||||
|
||||
void commit();
|
||||
|
||||
enum State {
|
||||
NOT_INITIALIZAED,
|
||||
INVALID,
|
||||
|
@ -58,6 +58,10 @@ public class DatasourceImpl<T> implements Datasource<T>, DatasourceImplementatio
|
||||
return dsContext;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public MetaClass getMetaClass() {
|
||||
return metaClass;
|
||||
}
|
||||
|
@ -62,6 +62,10 @@ public class PropertyDatasourceImpl<T> implements Datasource<T>, DatasourceImple
|
||||
return ds.getDsContext();
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ import com.itmill.toolkit.ui.TabSheet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScreenManager extends WindowManager
|
||||
{
|
||||
@ -49,20 +49,6 @@ public class ScreenManager extends WindowManager
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected Window createWindow(String descriptor, Map params) {
|
||||
return createWindowFromTemplate(descriptor, params);
|
||||
}
|
||||
|
||||
protected Window createWindow(Class aclass, Map params) {
|
||||
try {
|
||||
final Window window = (Window) aclass.newInstance();
|
||||
invokeMethod(window, "init");
|
||||
return window;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void showWindow(Window window, String caption, OpenType type) {
|
||||
if (OpenType.NEW_TAB.equals(type)) {
|
||||
ExpandLayout layout = new ExpandLayout();
|
||||
@ -114,9 +100,6 @@ public class ScreenManager extends WindowManager
|
||||
|
||||
Window window = tabInfo.screens.getLast();
|
||||
|
||||
final Object res = invokeMethod(window, "close");
|
||||
if (res != null && !Boolean.TRUE.equals(res)) { return; }
|
||||
|
||||
tabInfo.screens.removeLast();
|
||||
|
||||
layout.removeComponent(ComponentsHelper.unwrap(window));
|
||||
|
@ -10,25 +10,22 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.app.ui;
|
||||
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.ScreenOpenType;
|
||||
import com.haulmont.cuba.web.ui.Screen;
|
||||
import com.haulmont.cuba.web.ui.ScreenContext;
|
||||
import com.haulmont.cuba.web.ui.*;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
import com.itmill.toolkit.terminal.Sizeable;
|
||||
|
||||
public class DemoScreen extends Screen
|
||||
public class DemoScreen extends com.haulmont.cuba.web.ui.Window
|
||||
{
|
||||
public void init(ScreenContext context) {
|
||||
super.init(context);
|
||||
|
||||
getWindow().showNotification("Opening screen", Window.Notification.TYPE_TRAY_NOTIFICATION);
|
||||
layout.getWindow().showNotification("Opening screen", com.itmill.toolkit.ui.Window.Notification.TYPE_TRAY_NOTIFICATION);
|
||||
|
||||
final OrderedLayout vbox = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
|
||||
vbox.addComponent(createIFrame());
|
||||
vbox.addComponent(createVBox());
|
||||
|
||||
addComponent(vbox);
|
||||
layout.addComponent(vbox);
|
||||
}
|
||||
|
||||
private Component createVBox() {
|
||||
@ -84,7 +81,7 @@ public class DemoScreen extends Screen
|
||||
}
|
||||
|
||||
public boolean onClose() {
|
||||
getWindow().showNotification("Closing screen", Window.Notification.TYPE_TRAY_NOTIFICATION);
|
||||
layout.getWindow().showNotification("Closing screen", com.itmill.toolkit.ui.Window.Notification.TYPE_TRAY_NOTIFICATION);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
229
modules/web/src/com/haulmont/cuba/web/app/ui/GenericEditor.java
Normal file
229
modules/web/src/com/haulmont/cuba/web/app/ui/GenericEditor.java
Normal file
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 27.01.2009 11:06:56
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.app.ui;
|
||||
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.Range;
|
||||
import com.haulmont.chile.core.datatypes.Datatypes;
|
||||
import com.haulmont.chile.core.datatypes.Datatype;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.web.data.ItemWrapper;
|
||||
import com.haulmont.cuba.core.app.BasicService;
|
||||
import com.haulmont.cuba.core.Locator;
|
||||
import com.haulmont.cuba.core.entity.BaseEntity;
|
||||
import com.haulmont.cuba.core.global.BasicInvocationContext;
|
||||
import com.itmill.toolkit.data.Item;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.text.Format;
|
||||
import java.text.FieldPosition;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.ParseException;
|
||||
|
||||
public class GenericEditor
|
||||
extends
|
||||
com.haulmont.cuba.web.ui.Window
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.Window.EditorWidow
|
||||
{
|
||||
protected Object item;
|
||||
private Form form;
|
||||
private String caption;
|
||||
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
protected void init(Map params) {
|
||||
form = createForm();
|
||||
|
||||
layout.addComponent(form);
|
||||
layout.expand(form);
|
||||
|
||||
final Object item = params.get("item");
|
||||
if (item != null) {
|
||||
setItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected Form createForm() {
|
||||
final Form form = new Form();
|
||||
|
||||
Layout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
okbar.setHeight("25px");
|
||||
|
||||
okbar.addComponent(new Button("OK", this, "commit"));
|
||||
okbar.addComponent(new Button("Cancel", this, "close"));
|
||||
|
||||
// final Layout footer = form.getFooter();
|
||||
form.setFooter(okbar);
|
||||
// footer.addComponent(okbar);
|
||||
// if (footer instanceof Layout.AlignmentHandler) {
|
||||
// ((Layout.AlignmentHandler) footer).setComponentAlignment(okbar, Layout.AlignmentHandler.ALIGNMENT_RIGHT, Layout.AlignmentHandler.ALIGNMENT_VERTICAL_CENTER);
|
||||
// }
|
||||
form.setFieldFactory(new FieldFactory());
|
||||
form.setImmediate(true);
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
public Object getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Object item) {
|
||||
this.item = item;
|
||||
|
||||
final MetaClass metaClass = getMetaClass(item);
|
||||
setCaption("Edit " + metaClass.getName());
|
||||
|
||||
final Collection<MetaProperty> properties = getProperties(item);
|
||||
form.setItemDataSource(new ItemWrapper(item, properties));
|
||||
|
||||
for (MetaProperty metaProperty : properties) {
|
||||
final com.itmill.toolkit.ui.Field field = form.getField(metaProperty);
|
||||
if (field != null) {
|
||||
field.setRequired(metaProperty.isMandatory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<MetaProperty> getProperties(Object item) {
|
||||
final MetaClass metaClass = getMetaClass(item);
|
||||
|
||||
final List<MetaProperty> res = new ArrayList<MetaProperty>();
|
||||
|
||||
for (MetaProperty metaProperty : metaClass.getProperties()) {
|
||||
// TODO filter properties
|
||||
res.add(metaProperty);
|
||||
}
|
||||
|
||||
Collections.sort(res, new Comparator<MetaProperty>() {
|
||||
public int compare(MetaProperty o1, MetaProperty o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected MetaClass getMetaClass(Object item) {
|
||||
final MetaClass metaClass;
|
||||
if (item instanceof Datasource) {
|
||||
metaClass = ((Datasource) item).getMetaClass();
|
||||
} else {
|
||||
metaClass = ((Instance) item).getMetaClass();
|
||||
}
|
||||
return metaClass;
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
form.commit();
|
||||
if (item instanceof Datasource) {
|
||||
final Datasource ds = (Datasource) item;
|
||||
ds.commit();
|
||||
} else {
|
||||
BasicService service = Locator.lookupLocal(BasicService.JNDI_NAME);
|
||||
service.update((BaseEntity) item);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
private static class FieldFactory extends BaseFieldFactory {
|
||||
@Override
|
||||
public com.itmill.toolkit.ui.Field createField(Item item, Object propertyId, Component uiContext) {
|
||||
com.itmill.toolkit.ui.Field field = null;
|
||||
|
||||
MetaProperty metaProperty = (MetaProperty) propertyId;
|
||||
final Range range = metaProperty.getRange();
|
||||
|
||||
if (range != null) {
|
||||
final Range.Cardinality cardinality = range.getCardinality();
|
||||
|
||||
if (Range.Cardinality.ONE_TO_ONE.equals(cardinality)) {
|
||||
if (range.isDatatype()) {
|
||||
field = createField(range.asDatatype().getImplementationClass(), uiContext);
|
||||
} else if (range.isClass()) {
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (field != null) {
|
||||
final String caption = metaProperty.getCaption();
|
||||
field.setCaption(caption == null ? metaProperty.getName() : caption);
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.itmill.toolkit.ui.Field createField(final Class type, Component uiContext) {
|
||||
// Null typed properties can not be edited
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Date field
|
||||
if (Date.class.isAssignableFrom(type)) {
|
||||
final DateField df = new DateField();
|
||||
df.setResolution(DateField.RESOLUTION_DAY);
|
||||
return df;
|
||||
}
|
||||
|
||||
// Boolean field
|
||||
if (Boolean.class.isAssignableFrom(type)) {
|
||||
final Button button = new Button();
|
||||
button.setSwitchMode(true);
|
||||
button.setImmediate(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
// Nested form is used by default
|
||||
final Datatypes datatypes = Datatypes.getInstance();
|
||||
final TextField field = new TextField();
|
||||
final Datatype datatype = datatypes.get(type);
|
||||
|
||||
field.setFormat(new DatatypeFormat(datatype));
|
||||
return field;
|
||||
}
|
||||
|
||||
private static class DatatypeFormat extends Format {
|
||||
private final Datatype datatype;
|
||||
|
||||
public DatatypeFormat(Datatype datatype) {
|
||||
this.datatype = datatype;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
|
||||
return obj instanceof String ? toAppendTo.append(obj) : toAppendTo.append(datatype.format(obj));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object parseObject(String source, ParsePosition pos) {
|
||||
try {
|
||||
return datatype.parse(source);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,10 +9,10 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.app.ui;
|
||||
|
||||
import com.haulmont.cuba.web.ui.Screen;
|
||||
import com.haulmont.cuba.web.ui.Window;
|
||||
|
||||
public class TableDemoScreen extends Screen {
|
||||
public class TableDemoScreen extends Window {
|
||||
protected void init() {
|
||||
addComponent(new TableExample());
|
||||
layout.addComponent(new TableExample());
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.haulmont.cuba.web.app.ui.GenericEditor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
@ -39,10 +40,11 @@ public class SecurityUserBrowser extends AbstractFrame implements Window {
|
||||
final Set selected = table.getSelected();
|
||||
if (selected.size() == 1) {
|
||||
User user = (User) selected.iterator().next();
|
||||
openWindow(
|
||||
"/com/haulmont/cuba/web/app/ui/security/user/edit/security-user-edit.xml",
|
||||
WindowManager.OpenType.THIS_TAB,
|
||||
Collections.singletonMap("user", user));
|
||||
openWindow(GenericEditor.class, WindowManager.OpenType.THIS_TAB, Collections.singletonMap("item", user));
|
||||
// openWindow(
|
||||
// "/com/haulmont/cuba/web/app/ui/security/user/edit/security-user-edit.xml",
|
||||
// WindowManager.OpenType.THIS_TAB,
|
||||
// Collections.singletonMap("user", user));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -76,9 +78,9 @@ public class SecurityUserBrowser extends AbstractFrame implements Window {
|
||||
});
|
||||
}
|
||||
|
||||
protected boolean close() {
|
||||
public boolean close() {
|
||||
final com.itmill.toolkit.ui.Window window = ComponentsHelper.unwrap(this).getWindow();
|
||||
window.showNotification("Closing screen", com.itmill.toolkit.ui.Window.Notification.TYPE_TRAY_NOTIFICATION);
|
||||
return true;
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,12 @@ import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
public class ComponentsHelper {
|
||||
public static Component unwrap(com.haulmont.cuba.gui.components.Component component) {
|
||||
return (com.itmill.toolkit.ui.Component) (component instanceof com.haulmont.cuba.gui.components.Component.Wrapper ?
|
||||
((com.haulmont.cuba.gui.components.Component.Wrapper) component).getComponent() : component);
|
||||
Object comp = component;
|
||||
while (comp instanceof com.haulmont.cuba.gui.components.Component.Wrapper) {
|
||||
comp = ((com.haulmont.cuba.gui.components.Component.Wrapper) comp).getComponent();
|
||||
}
|
||||
|
||||
return (com.itmill.toolkit.ui.Component) comp;
|
||||
}
|
||||
|
||||
public static <T extends com.haulmont.cuba.gui.components.Component> T getComponent(
|
||||
|
@ -11,10 +11,13 @@ package com.haulmont.cuba.web.data;
|
||||
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.chile.core.model.Range;
|
||||
import com.haulmont.cuba.gui.MetadataHelper;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.itmill.toolkit.data.Property;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
public class PropertyWrapper implements Property{
|
||||
private boolean readOnly;
|
||||
private Object item;
|
||||
@ -44,7 +47,28 @@ public class PropertyWrapper implements Property{
|
||||
}
|
||||
|
||||
public void setValue(Object newValue) throws ReadOnlyException, ConversionException {
|
||||
getInstance().setValue(metaProperty.getName(), newValue);
|
||||
final Instance instance = getInstance();
|
||||
if (instance == null) throw new IllegalStateException("Instance is null");
|
||||
|
||||
instance.setValue(metaProperty.getName(), getValue(newValue));
|
||||
}
|
||||
|
||||
protected Object getValue(Object newValue) throws Property.ConversionException{
|
||||
final Range range = metaProperty.getRange();
|
||||
if (range == null) {
|
||||
return newValue;
|
||||
} else {
|
||||
if (range.isDatatype() && newValue instanceof String) {
|
||||
try {
|
||||
final Object value = range.asDatatype().parse((String) newValue);
|
||||
return value;
|
||||
} catch (ParseException e) {
|
||||
throw new Property.ConversionException(e);
|
||||
}
|
||||
} else {
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Class getType() {
|
||||
|
@ -12,16 +12,16 @@ package com.haulmont.cuba.web.ui;
|
||||
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.web.App;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.Layout;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Screen extends ExpandLayout implements Window
|
||||
public class Window implements com.haulmont.cuba.gui.components.Window, Component.Wrapper
|
||||
{
|
||||
protected ScreenContext screenContext;
|
||||
private String id;
|
||||
@ -29,10 +29,12 @@ public class Screen extends ExpandLayout implements Window
|
||||
private Map<String, Component> componentByIds = new HashMap<String, Component>();
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
public Screen() {
|
||||
super(ExpandLayout.ORIENTATION_VERTICAL);
|
||||
setMargin(true);
|
||||
setSpacing(true);
|
||||
protected ExpandLayout layout;
|
||||
|
||||
public Window() {
|
||||
layout = new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL);
|
||||
layout.setMargin(true);
|
||||
layout.setSpacing(true);
|
||||
}
|
||||
|
||||
public ResourceBundle getResourceBundle() {
|
||||
@ -43,31 +45,31 @@ public class Screen extends ExpandLayout implements Window
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
public <T extends 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 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 com.haulmont.cuba.gui.components.Window> T openWindow(Class aclass, WindowManager.OpenType openType, Map params) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(aclass, openType, params);
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(String descriptor, WindowManager.OpenType openType) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(String descriptor, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(descriptor, openType);
|
||||
}
|
||||
|
||||
public <T extends Window> T openWindow(Class aclass, WindowManager.OpenType openType) {
|
||||
public <T extends com.haulmont.cuba.gui.components.Window> T openWindow(Class aclass, WindowManager.OpenType openType) {
|
||||
return App.getInstance().getScreenManager().<T>openWindow(aclass, openType);
|
||||
}
|
||||
|
||||
public void add(Component component) {
|
||||
addComponent(ComponentsHelper.unwrap(component));
|
||||
layout.addComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.put(component.getId(), component);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
removeComponent(ComponentsHelper.unwrap(component));
|
||||
layout.removeComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.remove(component.getId());
|
||||
}
|
||||
@ -92,6 +94,30 @@ public class Screen extends ExpandLayout implements Window
|
||||
public void requestFocus() {
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return layout.getHeight();
|
||||
}
|
||||
|
||||
public int getHeightUnits() {
|
||||
return layout.getHeightUnits();
|
||||
}
|
||||
|
||||
public void setHeight(String height) {
|
||||
layout.setHeight(height);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return layout.getWidth();
|
||||
}
|
||||
|
||||
public int getWidthUnits() {
|
||||
return layout.getWidthUnits();
|
||||
}
|
||||
|
||||
public void setWidth(String width) {
|
||||
layout.setWidth(width);
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return (T) componentByIds.get(id);
|
||||
}
|
||||
@ -101,13 +127,13 @@ public class Screen extends ExpandLayout implements Window
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return ALIGNMENT_VERTICAL_CENTER;
|
||||
return Layout.AlignmentHandler.ALIGNMENT_VERTICAL_CENTER;
|
||||
}
|
||||
|
||||
public void setVerticalAlIlignment(int verticalAlIlignment) {}
|
||||
|
||||
public int getHorizontalAlIlignment() {
|
||||
return ALIGNMENT_HORIZONTAL_CENTER;
|
||||
return Layout.AlignmentHandler.ALIGNMENT_HORIZONTAL_CENTER;
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {}
|
||||
@ -115,4 +141,13 @@ public class Screen extends ExpandLayout implements Window
|
||||
public void expand(Component component, String height, String width) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public <T> T getComponent() {
|
||||
return (T) layout;
|
||||
}
|
||||
|
||||
public boolean close() {
|
||||
App.getInstance().getScreenManager().closeScreen();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ package com.haulmont.cuba.web.xml.layout;
|
||||
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.web.ui.Screen;
|
||||
import com.haulmont.cuba.web.ui.Window;
|
||||
import com.haulmont.cuba.web.components.*;
|
||||
|
||||
import java.util.Map;
|
||||
@ -22,7 +22,7 @@ public class WebComponentsFactory implements ComponentsFactory {
|
||||
private static Map<String, Class<? extends Component>> classes = new HashMap<String, Class<?extends Component>>();
|
||||
|
||||
static {
|
||||
classes.put("window", Screen.class);
|
||||
classes.put("window", Window.class);
|
||||
classes.put("hbox", HBox.class);
|
||||
classes.put("vbox", VBox.class);
|
||||
classes.put("expandable-hbox", ExpandableHBox.class);
|
||||
|
Loading…
Reference in New Issue
Block a user