mirror of
https://gitee.com/jmix/cuba.git
synced 2024-11-30 18:27:56 +08:00
dependent grids
query templates
This commit is contained in:
parent
096e549498
commit
d97bc2c37e
15
build.xml
15
build.xml
@ -30,6 +30,7 @@
|
||||
<ext:install-lib name="commons-codec" version="${commons-codec.version}" toDir="${lib.common.dir}"/>
|
||||
<ext:install-lib name="commons-io" version="${commons-io.version}" toDir="${lib.common.dir}"/>
|
||||
<ext:install-jboss-lib name="log4j" version="${jboss.version}" toDir="${lib.common.dir}"/>
|
||||
<ext:install-lib name="freemarker" version="${freemarker.version}" toDir="${lib.common.dir}"/>
|
||||
<!-- server libs -->
|
||||
<ext:install-lib name="openjpa" version="${openjpa.version}" toDir="${lib.server.dir}"/>
|
||||
<ext:install-lib name="serp" version="${serp.version}" toDir="${lib.server.dir}"/>
|
||||
@ -80,4 +81,18 @@
|
||||
</target>
|
||||
|
||||
<target name="clean-build-deploy" depends="clean,build,deploy"/>
|
||||
|
||||
<target name="run">
|
||||
<exec dir="${root.dir}/jboss/bin" executable="cmd.exe">
|
||||
<arg line="/c start debug.bat"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="stop">
|
||||
<exec dir="${root.dir}/jboss/bin" executable="cmd.exe" spawn="true">
|
||||
<arg line="/c start shutdown.bat -S"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="clean-build-deploy-run" depends="clean,build,deploy,run"/>
|
||||
</project>
|
5
cuba.ipr
5
cuba.ipr
@ -5,7 +5,7 @@
|
||||
<buildFile url="file://$PROJECT_DIR$/build.xml">
|
||||
<additionalClassPath />
|
||||
<antReference projectDefault="true" />
|
||||
<customJdkName value="" />
|
||||
<customJdkName value="1.6" />
|
||||
<maximumHeapSize value="128" />
|
||||
<maximumStackSize value="32" />
|
||||
<properties />
|
||||
@ -933,7 +933,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/modules/web-war/web-war.iml" filepath="$PROJECT_DIR$/modules/web-war/web-war.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.5" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="ResourceManagerContainer">
|
||||
@ -1031,6 +1031,7 @@
|
||||
<root url="jar://$PROJECT_DIR$/../lib/common/google-collect-snapshot-20080820.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../lib/common/reflections-0.9.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../lib/common/commons-io-1.4.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../lib/common/freemarker-2.3.15.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
|
@ -194,6 +194,8 @@ alter table SEC_CONSTRAINT add constraint SEC_CONSTRAINT_GROUP foreign key (GROU
|
||||
|
||||
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME)
|
||||
values ('60885987-1b61-4247-94c7-dff348347f93', current_timestamp, 0, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator');
|
||||
insert into SEC_USER (ID, CREATE_TS, VERSION, LOGIN, PASSWORD, NAME)
|
||||
values ('40288137-1EF4-11C8-011E-F41247370001', current_timestamp, 0, 'abramov', '402881371EF411C8011EF411C8C50000', 'Dmitry Abramov');
|
||||
|
||||
insert into SEC_GROUP (ID, CREATE_TS, VERSION, NAME, PARENT_ID)
|
||||
values ('0fa2b1a5-1d68-4d69-9fbd-dff348347f93', current_timestamp, 0, 'Company', null);
|
||||
@ -201,11 +203,25 @@ values ('0fa2b1a5-1d68-4d69-9fbd-dff348347f93', current_timestamp, 0, 'Company',
|
||||
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, IS_DEFAULT, USER_ID, GROUP_ID)
|
||||
values ('bf83541f-f610-46f4-a268-dff348347f93', current_timestamp, 0, 'Default', 1, '60885987-1b61-4247-94c7-dff348347f93', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
|
||||
|
||||
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, IS_DEFAULT, USER_ID, GROUP_ID)
|
||||
values ('40288137-1EF4-11C8-011E-F4157FA70002', current_timestamp, 0, 'Default', 1, '40288137-1EF4-11C8-011E-F41247370001', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
|
||||
|
||||
insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, IS_DEFAULT, USER_ID, GROUP_ID)
|
||||
values ('40288137-1EF4-11C8-011E-F415E4FC0004', current_timestamp, 0, 'Administrator', 1, '40288137-1EF4-11C8-011E-F41247370001', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
|
||||
|
||||
--insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, IS_DEFAULT, USER_ID, GROUP_ID)
|
||||
--values ('cc1e0bc4-1062-4218-a09f-dff348347f93', current_timestamp, 0, 'Test', 0, '60885987-1b61-4247-94c7-dff348347f93', '0fa2b1a5-1d68-4d69-9fbd-dff348347f93');
|
||||
|
||||
insert into SEC_ROLE (ID, CREATE_TS, VERSION, NAME, IS_SUPER)
|
||||
values ('0c018061-b26f-4de2-a5be-dff348347f93', current_timestamp, 0, 'Administrators', 1);
|
||||
|
||||
insert into SEC_ROLE (ID, CREATE_TS, VERSION, NAME, IS_SUPER)
|
||||
values ('40288137-1EF4-11C8-011E-F416E4150005', current_timestamp, 0, 'Users', 1);
|
||||
|
||||
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
|
||||
values ('c838be0a-96d0-4ef4-a7c0-dff348347f93', current_timestamp, 0, 'bf83541f-f610-46f4-a268-dff348347f93', '0c018061-b26f-4de2-a5be-dff348347f93');
|
||||
|
||||
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
|
||||
values ('40288137-1EF4-11C8-011E-F41AAA740006', current_timestamp, 0, '40288137-1EF4-11C8-011E-F4157FA70002', '40288137-1EF4-11C8-011E-F416E4150005');
|
||||
insert into SEC_PROFILE_ROLE (ID, CREATE_TS, VERSION, PROFILE_ID, ROLE_ID)
|
||||
values ('40288137-1EF4-11C8-011E-F41AAA740007', current_timestamp, 0, '40288137-1EF4-11C8-011E-F415E4FC0004', '0c018061-b26f-4de2-a5be-dff348347f93');
|
||||
|
@ -2,6 +2,7 @@ jboss.version=5.0.0.GA-1
|
||||
jboss-embedded.version=beta3-1
|
||||
commons-codec.version=1.3
|
||||
commons-io.version=1.4
|
||||
freemarker.version=2.3.15
|
||||
openjpa.version=1.2.0
|
||||
itmill-toolkit.version=5.2.12
|
||||
jcifs.version=1.3.2
|
||||
|
@ -6,7 +6,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.5" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="chile" level="project" />
|
||||
<orderEntry type="library" name="test" level="project" />
|
||||
|
@ -72,8 +72,14 @@ public class BasicWorkerBean implements BasicWorker
|
||||
|
||||
Query query = em.createQuery(ctx.getQuery().getQueryString());
|
||||
SecurityProvider.applyConstraints(query, ctx.getMetaClass().getName());
|
||||
|
||||
final String queryString = ctx.getQuery().getQueryString();
|
||||
for (Map.Entry<String, Object> entry : ctx.getQuery().getParameters().entrySet()) {
|
||||
query.setParameter(entry.getKey(), entry.getValue());
|
||||
final String name = entry.getKey();
|
||||
if (queryString.contains(":" + name)) {
|
||||
final Object value = entry.getValue();
|
||||
query.setParameter(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx.getView() != null) {
|
||||
|
@ -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: 19.01.2009 10:21:02
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public class AbstractFrame implements IFrame, Component.Wrapper {
|
||||
protected IFrame frame;
|
||||
|
||||
public AbstractFrame(IFrame frame) {
|
||||
this.frame = frame;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return frame.getId();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
frame.setId(id);
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
frame.requestFocus();
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return frame.getHeight();
|
||||
}
|
||||
|
||||
public int getHeightUnits() {
|
||||
return frame.getHeightUnits();
|
||||
}
|
||||
|
||||
public void setHeight(String height) {
|
||||
frame.setHeight(height);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return frame.getWidth();
|
||||
}
|
||||
|
||||
public int getWidthUnits() {
|
||||
return frame.getWidthUnits();
|
||||
}
|
||||
|
||||
public void setWidth(String width) {
|
||||
frame.setWidth(width);
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return frame.getVerticalAlIlignment();
|
||||
}
|
||||
|
||||
public void setVerticalAlIlignment(int verticalAlIlignment) {
|
||||
frame.setVerticalAlIlignment(verticalAlIlignment);
|
||||
}
|
||||
|
||||
public int getHorizontalAlIlignment() {
|
||||
return frame.getHorizontalAlIlignment();
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {
|
||||
frame.setHorizontalAlIlignment(horizontalAlIlignment);
|
||||
}
|
||||
|
||||
public void add(Component component) {
|
||||
frame.add(component);
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
frame.remove(component);
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return frame.<T>getOwnComponent(id);
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
return frame.<T>getComponent(id);
|
||||
}
|
||||
|
||||
public <T> T getComponent() {
|
||||
return (T) frame;
|
||||
}
|
||||
|
||||
public void expand(Component component, String height, String width) {
|
||||
frame.expand(component, height, width);
|
||||
}
|
||||
}
|
17
modules/gui/src/com/haulmont/cuba/gui/components/Action.java
Normal file
17
modules/gui/src/com/haulmont/cuba/gui/components/Action.java
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 20.01.2009 11:33:34
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface Action {
|
||||
String getCaption();
|
||||
|
||||
boolean isEnabled();
|
||||
void actionPerform(Component component);
|
||||
}
|
@ -9,5 +9,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface Button extends Component, Component.HasCaption, Component.Sizable {
|
||||
public interface Button extends Component, Component.HasCaption {
|
||||
Action getAction();
|
||||
void setAction(Action action);
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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.01.2009 17:00:29
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface CheckBox extends Field {
|
||||
}
|
@ -25,6 +25,16 @@ public interface Component {
|
||||
String getId();
|
||||
void setId(String id);
|
||||
|
||||
void requestFocus();
|
||||
|
||||
int getHeight();
|
||||
int getHeightUnits();
|
||||
void setHeight(String height);
|
||||
|
||||
int getWidth();
|
||||
int getWidthUnits();
|
||||
void setWidth(String width);
|
||||
|
||||
int getVerticalAlIlignment();
|
||||
void setVerticalAlIlignment(int verticalAlIlignment);
|
||||
|
||||
@ -34,6 +44,9 @@ public interface Component {
|
||||
interface Container extends Component {
|
||||
void add(Component component);
|
||||
void remove(Component component);
|
||||
|
||||
<T extends Component> T getOwnComponent(String id);
|
||||
<T extends Component> T getComponent(String id);
|
||||
}
|
||||
|
||||
interface Wrapper {
|
||||
@ -50,11 +63,6 @@ public interface Component {
|
||||
void setValue(Object value);
|
||||
}
|
||||
|
||||
interface Sizable extends Component {
|
||||
boolean isFlexible();
|
||||
void setFlexible(boolean flexible);
|
||||
}
|
||||
|
||||
interface HasXmlDescriptor {
|
||||
Element getXmlDescriptor();
|
||||
void setXmlDescriptor(Element element);
|
||||
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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.01.2009 17:04:35
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface DateField extends Field {
|
||||
}
|
@ -4,14 +4,14 @@
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:10:30
|
||||
* Created: 16.01.2009 16:33:50
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
|
||||
public interface TextBox extends Component, Component.HasCaption, Component.Field, Component.Sizable {
|
||||
public interface Field extends Component, Component.HasCaption, Component.Field {
|
||||
Datasource getDatasource();
|
||||
String getProperty();
|
||||
|
@ -9,5 +9,5 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface IFrame extends Component, Component.Container, Component.Sizable {
|
||||
public interface IFrame extends OrderedLayout, Component.Container {
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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.01.2009 17:31:02
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface LookupField extends Field {
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 19.01.2009 13:39:01
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface OrderedLayout extends Component {
|
||||
void expand(Component component, String height, String width);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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.01.2009 17:25:26
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface ProgressBar extends Field {
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 20.01.2009 17:22:42
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface SplitPanel extends Component.Container {
|
||||
public static int ORIENTATION_VERTICAL = 0;
|
||||
public static int ORIENTATION_HORIZONTAL = 1;
|
||||
|
||||
int getOrientation();
|
||||
void setOrientation(int orientation);
|
||||
}
|
@ -12,15 +12,20 @@ package com.haulmont.cuba.gui.components;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface Table extends Component {
|
||||
<T> T getSingleSelected();
|
||||
List getSelected();
|
||||
Set getSelected();
|
||||
|
||||
void addAction(Action action);
|
||||
void removeAction(Action action);
|
||||
|
||||
List<Column> getColumns();
|
||||
void addColumn(Column column);
|
||||
void removeColumn(Column column);
|
||||
|
||||
CollectionDatasource getDatasource();
|
||||
void setDatasource(CollectionDatasource datasource);
|
||||
|
||||
public class Column {
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.01.2009 17:33:46
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Tabsheet extends Component {
|
||||
Tab getTab();
|
||||
void setTab(Tab tab);
|
||||
void setTab(String name);
|
||||
|
||||
List<Tab> getTabs();
|
||||
|
||||
interface Tab {
|
||||
String getName();
|
||||
void setName();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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.01.2009 17:01:37
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface TextArea extends Field {
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:10:30
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface TextField extends Field {
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 19.01.2009 11:31:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ValuePathHelper {
|
||||
public static String format(String[] elements) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
int i = 1;
|
||||
for (String element : elements) {
|
||||
buffer.append(element.contains(".") ? "[" + element + "]" : element);
|
||||
if (i != elements.length) buffer.append(".");
|
||||
i++;
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String[] parse(String path) {
|
||||
List<String> elements = new ArrayList<String>();
|
||||
|
||||
int breaketCount = 0;
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < path.length(); i++) {
|
||||
char c = path.charAt(i);
|
||||
if (c == '[')
|
||||
breaketCount++;
|
||||
if (c == ']')
|
||||
breaketCount--;
|
||||
|
||||
if ('.' != c || breaketCount > 0)
|
||||
buffer.append(c);
|
||||
|
||||
if ('.' == c && breaketCount == 0) {
|
||||
String element = buffer.toString();
|
||||
if (!StringUtils.isEmpty(element)) {
|
||||
elements.add(element);
|
||||
} else {
|
||||
throw new IllegalStateException("Wrong value path format");
|
||||
}
|
||||
buffer = new StringBuilder();
|
||||
}
|
||||
}
|
||||
elements.add(buffer.toString());
|
||||
|
||||
return elements.toArray(new String[]{});
|
||||
}
|
||||
}
|
@ -9,5 +9,5 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.components;
|
||||
|
||||
public interface Window extends Component, Component.Container, Component.HasCaption {
|
||||
public interface Window extends IFrame {
|
||||
}
|
||||
|
@ -9,6 +9,32 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface CollectionDatasourceListener<T> extends DatasourceListener<T> {
|
||||
// ??? something changed
|
||||
class CollectionOperation<T> {
|
||||
public enum Type {
|
||||
REFRESH,
|
||||
ADD,
|
||||
REMOVE
|
||||
}
|
||||
|
||||
protected Type type;
|
||||
protected Collection<T> items;
|
||||
|
||||
public CollectionOperation(Type type, Collection<T> items) {
|
||||
this.type = type;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Collection<T> getItems() {
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
void collectionChanged(Datasource<T> ds, CollectionOperation operation);
|
||||
}
|
||||
|
@ -10,6 +10,6 @@
|
||||
package com.haulmont.cuba.gui.data;
|
||||
|
||||
public interface DatasourceListener<T> extends ValueListener<T> {
|
||||
void currentChanged(Datasource<T> ds, T prevItem, T item);
|
||||
void itemChanged(Datasource<T> ds, T prevItem, T item);
|
||||
void stateChanged(Datasource<T> ds, Datasource.State prevState, Datasource.State state);
|
||||
}
|
||||
|
@ -10,15 +10,12 @@
|
||||
package com.haulmont.cuba.gui.data.impl;
|
||||
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.cuba.core.Locator;
|
||||
import com.haulmont.cuba.core.app.BasicService;
|
||||
import com.haulmont.cuba.core.global.BasicInvocationContext;
|
||||
import com.haulmont.cuba.core.global.BasicServiceRemote;
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DatasourceListener;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.gui.xml.ParametersHelper;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
@ -26,19 +23,26 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.io.StringWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.cache.StringTemplateLoader;
|
||||
|
||||
public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements CollectionDatasource<T, K> {
|
||||
private String query;
|
||||
private ParametersHelper.ParameterInfo[] queryParameters;
|
||||
private DatasourceListener parentDsListener;
|
||||
|
||||
private Collection<T> collection;
|
||||
private Collection<T> collection = Collections.emptyList();
|
||||
|
||||
public CollectionDatasourceImpl(DsContext context, String id, MetaClass metaClass, String viewName) {
|
||||
super(context, id, metaClass, viewName);
|
||||
parentDsListener = new DatasourceListener() {
|
||||
public void currentChanged(Datasource ds, Object prevItem, Object item) {
|
||||
invalidate();
|
||||
public void itemChanged(Datasource ds, Object prevItem, Object item) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void stateChanged(Datasource ds, State prevState, State state) {}
|
||||
@ -49,35 +53,68 @@ public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
this.collection = null;
|
||||
this.collection = Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(T item) {
|
||||
if (State.VALID.equals(state)) {
|
||||
Object prevItem = this.item;
|
||||
|
||||
if (!ObjectUtils.equals(prevItem, item)) {
|
||||
if (this.item != null) {
|
||||
detatchListener((Instance) this.item);
|
||||
}
|
||||
|
||||
if (item instanceof Instance) {
|
||||
final MetaClass aClass = ((Instance) item).getMetaClass();
|
||||
if (!aClass.equals(metaClass)) {
|
||||
throw new IllegalStateException(String.format("Invalid item metaClass"));
|
||||
}
|
||||
attachListener((Instance) item);
|
||||
}
|
||||
this.item = item;
|
||||
|
||||
forceItemChanged(prevItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void refresh() {
|
||||
collection = getCollection();
|
||||
invalidate();
|
||||
loadData();
|
||||
|
||||
State prevState = state;
|
||||
if (!prevState.equals(State.VALID)) {
|
||||
state = State.VALID;
|
||||
forceStateChanged(prevState);
|
||||
}
|
||||
|
||||
forceCollectionChanged(new CollectionDatasourceListener.CollectionOperation<T>(CollectionDatasourceListener.CollectionOperation.Type.REFRESH, null));
|
||||
}
|
||||
|
||||
public T getItem(K key) {
|
||||
if (State.VALID.equals(state)) {
|
||||
return (T) key;
|
||||
} else {
|
||||
if (State.NOT_INITIALIZAED.equals(state)) {
|
||||
throw new IllegalStateException("Invalid datasource state " + state);
|
||||
} else {
|
||||
return (T) key;
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<K> getItemIds() {
|
||||
if (State.VALID.equals(state)) {
|
||||
return (Collection<K>) getCollection();
|
||||
} else {
|
||||
if (State.NOT_INITIALIZAED.equals(state)) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return (Collection<K>) getCollection();
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
if (State.VALID.equals(state)) {
|
||||
return getCollection().size();
|
||||
} else {
|
||||
if (State.NOT_INITIALIZAED.equals(state)) {
|
||||
return 0;
|
||||
} else {
|
||||
return getCollection().size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,41 +167,58 @@ public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements
|
||||
if (query == null) {
|
||||
throw new IllegalStateException();
|
||||
} else {
|
||||
if (collection == null) {
|
||||
BasicServiceRemote service = Locator.lookupRemote(BasicService.JNDI_NAME);
|
||||
|
||||
final BasicInvocationContext ctx = new BasicInvocationContext();
|
||||
ctx.setEntityClass(metaClass);
|
||||
|
||||
final BasicInvocationContext.Query query = ctx.setQueryString(getJPQLQuery(this.query));
|
||||
query.setParameters(getQueryParameters());
|
||||
|
||||
ctx.setView(view);
|
||||
|
||||
collection = (Collection) service.loadList(ctx);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
||||
protected Collection<T> loadData() {
|
||||
BasicService service = Locator.lookupLocal(BasicService.JNDI_NAME);
|
||||
|
||||
final BasicInvocationContext ctx = new BasicInvocationContext();
|
||||
ctx.setEntityClass(metaClass);
|
||||
|
||||
final Map<String, Object> parameters = getQueryParameters();
|
||||
|
||||
final BasicInvocationContext.Query query = ctx.setQueryString(getJPQLQuery(this.query, parameters));
|
||||
query.setParameters(parameters);
|
||||
|
||||
ctx.setView(view);
|
||||
|
||||
collection = (Collection) service.loadList(ctx);
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
private Map<String, Object> getQueryParameters() {
|
||||
final Map<String, Object> map = new HashMap<String, Object>();
|
||||
for (ParametersHelper.ParameterInfo info : queryParameters) {
|
||||
String name = info.getType().getPrefix() + "." + info.getName();
|
||||
name = name.replaceAll("\\.", "_");
|
||||
|
||||
switch (info.getType()) {
|
||||
case DATASOURCE: {
|
||||
final Datasource datasource = dsContext.get(info.getName());
|
||||
map.put(info.getName(), datasource.getItem());
|
||||
if (Datasource.State.VALID.equals(datasource.getState())) {
|
||||
map.put(name, datasource.getItem());
|
||||
} else {
|
||||
map.put(name, null);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case CONTEXT: {
|
||||
final Object value = dsContext.getContext().getValue(info.getName());
|
||||
map.put(info.getName(), value);
|
||||
final Object value =
|
||||
dsContext.getContext() == null ?
|
||||
null : dsContext.getContext().getValue(info.getName());
|
||||
map.put(name, value);
|
||||
break;
|
||||
}
|
||||
case COMPONENT: {
|
||||
throw new UnsupportedOperationException();
|
||||
// break;
|
||||
final Object value =
|
||||
dsContext.getContext() == null ?
|
||||
null : dsContext.getContext().getValue(info.getName());
|
||||
map.put(name, value);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -175,14 +229,51 @@ public class CollectionDatasourceImpl<T, K> extends DatasourceImpl<T> implements
|
||||
return map;
|
||||
}
|
||||
|
||||
private String getJPQLQuery(String query) {
|
||||
private String getJPQLQuery(String query, Map<String, Object> parameterValues) {
|
||||
for (ParametersHelper.ParameterInfo info : queryParameters) {
|
||||
final String paramInfo = "\\$\\{" + info.getType().getPrefix() + "\\:" + info.getName() + "\\}";
|
||||
final String jpqlParamInfo = ":" + info.getType().getPrefix() + "_" + info.getName();
|
||||
|
||||
query = query.replaceAll(paramInfo, jpqlParamInfo);
|
||||
String paramName = info.getType().getPrefix() + "." + info.getName();
|
||||
paramName = paramName.replaceAll("\\.", "_");
|
||||
|
||||
query = query.replaceAll(paramInfo, paramName);
|
||||
}
|
||||
|
||||
query = processTemplate(query, parameterValues);
|
||||
|
||||
for (ParametersHelper.ParameterInfo info : queryParameters) {
|
||||
String paramName = info.getType().getPrefix() + "." + info.getName();
|
||||
paramName = paramName.replaceAll("\\.", "_");
|
||||
query = query.replaceAll(paramName, ":" + paramName);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
protected String processTemplate(String query, Map<String, Object> parameterValues) {
|
||||
final StringWriter writer = new StringWriter();
|
||||
|
||||
try {
|
||||
final Configuration configuration = new Configuration();
|
||||
|
||||
final StringTemplateLoader templateLoader = new StringTemplateLoader();
|
||||
templateLoader.putTemplate("query", query);
|
||||
configuration.setTemplateLoader(templateLoader);
|
||||
|
||||
final Template template = configuration.getTemplate("query");
|
||||
template.process(parameterValues, writer);
|
||||
|
||||
return writer.toString();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void forceCollectionChanged(CollectionDatasourceListener.CollectionOperation operation) {
|
||||
for (DatasourceListener dsListener : dsListeners) {
|
||||
if (dsListener instanceof CollectionDatasourceListener) {
|
||||
((CollectionDatasourceListener) dsListener).collectionChanged(this, operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,20 +9,20 @@
|
||||
*/
|
||||
package com.haulmont.cuba.gui.data.impl;
|
||||
|
||||
import com.haulmont.chile.core.common.ValueListener;
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
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.Datasource;
|
||||
import com.haulmont.cuba.gui.data.DatasourceListener;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.core.global.View;
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.chile.core.common.ValueListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DatasourceImpl<T> implements Datasource<T> {
|
||||
public class DatasourceImpl<T> implements Datasource<T>, DatasourceImplementation {
|
||||
protected DsContext dsContext;
|
||||
|
||||
private String id;
|
||||
@ -30,10 +30,10 @@ public class DatasourceImpl<T> implements Datasource<T> {
|
||||
protected View view;
|
||||
|
||||
protected State state = State.NOT_INITIALIZAED;
|
||||
private T item;
|
||||
protected T item;
|
||||
private ValueListener listener;
|
||||
|
||||
private List<DatasourceListener> dsListeners = new ArrayList<DatasourceListener>();
|
||||
protected List<DatasourceListener> dsListeners = new ArrayList<DatasourceListener>();
|
||||
|
||||
public DatasourceImpl(DsContext dsContext, String id, MetaClass metaClass, String viewName) {
|
||||
this.dsContext = dsContext;
|
||||
@ -99,9 +99,12 @@ public class DatasourceImpl<T> implements Datasource<T> {
|
||||
state = State.VALID;
|
||||
|
||||
forceStateChanged(prevStatus);
|
||||
forceItemChanged(prevItem);
|
||||
}
|
||||
|
||||
protected void forceItemChanged(Object prevItem) {
|
||||
for (DatasourceListener dsListener : dsListeners) {
|
||||
dsListener.currentChanged(this, prevItem, item);
|
||||
dsListener.itemChanged(this, prevItem, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,11 +122,11 @@ public class DatasourceImpl<T> implements Datasource<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private void attachListener(Instance item) {
|
||||
protected void attachListener(Instance item) {
|
||||
item.addListener(listener);
|
||||
}
|
||||
|
||||
private void detatchListener(Instance item) {
|
||||
protected void detatchListener(Instance item) {
|
||||
item.removeListener(listener);
|
||||
}
|
||||
|
||||
@ -148,4 +151,8 @@ public class DatasourceImpl<T> implements Datasource<T> {
|
||||
public void removeListener(DatasourceListener<T> listener) {
|
||||
dsListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void initialized() {
|
||||
state = State.INVALID;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 21.01.2009 19:31:49
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.data.impl;
|
||||
|
||||
public interface DatasourceImplementation {
|
||||
void initialized();
|
||||
}
|
@ -22,7 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class PropertyDatasourceImpl<T> implements Datasource<T> {
|
||||
public class PropertyDatasourceImpl<T> implements Datasource<T>, DatasourceImplementation {
|
||||
private String id;
|
||||
|
||||
protected Datasource ds;
|
||||
@ -93,4 +93,7 @@ public class PropertyDatasourceImpl<T> implements Datasource<T> {
|
||||
public void removeListener(DatasourceListener<T> listener) {
|
||||
dsListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void initialized() {
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.gui.data.impl.DsContextImpl;
|
||||
import com.haulmont.cuba.gui.data.impl.DatasourceImplementation;
|
||||
import com.haulmont.cuba.gui.xml.ParametersHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -15,31 +15,33 @@ import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LayoutLoaderConfig {
|
||||
private Map<String, Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader>> loaders = new HashMap<String, Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader>>();
|
||||
private Map<String, Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader>> loaders =
|
||||
new HashMap<String, Class<? extends com.haulmont.cuba.gui.xml.layout.ComponentLoader>>();
|
||||
|
||||
private static LayoutLoaderConfig windowLoaders = new LayoutLoaderConfig();
|
||||
private static LayoutLoaderConfig frameLoaders = new LayoutLoaderConfig();
|
||||
|
||||
static {
|
||||
windowLoaders.registerLoader("layout", WindowLoader.class);
|
||||
windowLoaders.registerLoader("hbox", HBoxLoader.class);
|
||||
windowLoaders.registerLoader("vbox", VBoxLoader.class);
|
||||
windowLoaders.registerLoader("button", ButtonLoader.class);
|
||||
windowLoaders.registerLoader("iframe", FrameLoader.class);
|
||||
windowLoaders.registerLoader("groupbox", GroupBoxLoader.class);
|
||||
windowLoaders.registerLoader("label", LabelLoader.class);
|
||||
windowLoaders.registerLoader("textbox", TextBoxLoader.class);
|
||||
windowLoaders.registerLoader("table", TableLoader.class);
|
||||
windowLoaders.registerLoader("window", WindowLoader.class);
|
||||
registerComponents(windowLoaders);
|
||||
|
||||
frameLoaders.registerLoader("layout", IFrameLoader.class);
|
||||
frameLoaders.registerLoader("hbox", HBoxLoader.class);
|
||||
frameLoaders.registerLoader("vbox", VBoxLoader.class);
|
||||
frameLoaders.registerLoader("button", ButtonLoader.class);
|
||||
frameLoaders.registerLoader("iframe", FrameLoader.class);
|
||||
frameLoaders.registerLoader("groupbox", GroupBoxLoader.class);
|
||||
frameLoaders.registerLoader("label", LabelLoader.class);
|
||||
frameLoaders.registerLoader("textbox", TextBoxLoader.class);
|
||||
frameLoaders.registerLoader("table", TableLoader.class);
|
||||
frameLoaders.registerLoader("frame", FrameLoader.class);
|
||||
registerComponents(frameLoaders);
|
||||
}
|
||||
|
||||
private static void registerComponents(LayoutLoaderConfig config) {
|
||||
config.registerLoader("hbox", HBoxLoader.class);
|
||||
config.registerLoader("vbox", VBoxLoader.class);
|
||||
config.registerLoader("button", ButtonLoader.class);
|
||||
config.registerLoader("group-box", GroupBoxLoader.class);
|
||||
config.registerLoader("label", LabelLoader.class);
|
||||
config.registerLoader("text-field", AbstractFieldLoader.class);
|
||||
config.registerLoader("text-area", AbstractFieldLoader.class);
|
||||
config.registerLoader("date-field", AbstractFieldLoader.class);
|
||||
config.registerLoader("lookup-field", AbstractFieldLoader.class);
|
||||
config.registerLoader("table", TableLoader.class);
|
||||
config.registerLoader("iframe", IFrameLoader.class);
|
||||
config.registerLoader("split", SplitPanelLoader.class);
|
||||
}
|
||||
|
||||
public static LayoutLoaderConfig getWindowLoaders() {
|
||||
|
@ -10,18 +10,20 @@
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.TextBox;
|
||||
import com.haulmont.cuba.gui.components.Field;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import org.dom4j.Element;
|
||||
|
||||
public class TextBoxLoader extends ComponentLoader {
|
||||
public class AbstractFieldLoader extends ComponentLoader {
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final TextBox textBox = factory.createComponent("textbox");
|
||||
final Field field = factory.createComponent(element.getName());
|
||||
|
||||
loadId(textBox, element);
|
||||
loadFlex(textBox, element);
|
||||
loadCaption(textBox, element);
|
||||
loadId(field, element);
|
||||
loadCaption(field, element);
|
||||
|
||||
return textBox;
|
||||
loadHeight(field, element);
|
||||
loadWidth(field, element);
|
||||
|
||||
return field;
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ public class ButtonLoader extends com.haulmont.cuba.gui.xml.layout.loaders.Compo
|
||||
final Button button = factory.createComponent("button");
|
||||
|
||||
loadId(button, element);
|
||||
loadFlex(button, element);
|
||||
loadCaption(button, element);
|
||||
|
||||
return button;
|
||||
|
@ -14,12 +14,6 @@ import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public abstract class ComponentLoader implements com.haulmont.cuba.gui.xml.layout.ComponentLoader {
|
||||
protected void loadFlex(Component.Sizable component, Element element) {
|
||||
final String flex = element.attributeValue("flex");
|
||||
if (!StringUtils.isBlank(flex)) {
|
||||
component.setFlexible(Integer.valueOf(flex) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadId(Component component, Element element) {
|
||||
final String id = element.attributeValue("id");
|
||||
@ -38,6 +32,20 @@ public abstract class ComponentLoader implements com.haulmont.cuba.gui.xml.layou
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadHeight(Component component, Element element) {
|
||||
final String height = element.attributeValue("height");
|
||||
if (!StringUtils.isBlank(height)) {
|
||||
component.setHeight(height);
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadWidth(Component component, Element element) {
|
||||
final String width = element.attributeValue("width");
|
||||
if (!StringUtils.isBlank(width)) {
|
||||
component.setWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
private int loadAlignment(String align, boolean horizontal) {
|
||||
if (!horizontal) {
|
||||
if ("start".equals(align)) {
|
||||
|
@ -10,14 +10,18 @@
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ContainerLoader extends ComponentLoader {
|
||||
protected ComponentsFactory factory;
|
||||
@ -30,14 +34,47 @@ public abstract class ContainerLoader extends ComponentLoader {
|
||||
this.dsContext = dsContext;
|
||||
}
|
||||
|
||||
protected void loadSubComponents(Component component, Element element, String ...exceptTags) {
|
||||
protected Collection<Component> loadSubComponents(Component component, Element element, String ...exceptTags) {
|
||||
final List<Component> res = new ArrayList<Component>();
|
||||
|
||||
final LayoutLoader loader = new LayoutLoader(factory, config, dsContext);
|
||||
for (Element subElement : (Collection<Element>)element.elements()) {
|
||||
final String name = subElement.getName();
|
||||
if (exceptTags != null && Arrays.binarySearch(exceptTags, name) < 0) {
|
||||
final Component subComponent = loader.loadComponent(subElement);
|
||||
((Component.Container) component).add(subComponent);
|
||||
res.add(subComponent);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void loadSubcomponentsAndExpand(OrderedLayout layout, Element element, String ...exceptTags) {
|
||||
final Collection<Component> components = loadSubComponents(layout, element, exceptTags);
|
||||
|
||||
final String expand = element.attributeValue("expand");
|
||||
if (!StringUtils.isEmpty(expand)) {
|
||||
final String[] parts = expand.split(";");
|
||||
final Component componentToExpand = ((Component.Container) layout).getComponent(parts[0]);
|
||||
|
||||
if (componentToExpand != null) {
|
||||
String height = find(parts, "height");
|
||||
String width = find(parts, "width");
|
||||
layout.expand(
|
||||
componentToExpand,
|
||||
height == null && width == null ? "100%" : height,
|
||||
height == null && width == null ? "100%" : width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String find(String[] parts, String name) {
|
||||
for (String part : parts) {
|
||||
if (part.trim().startsWith(name + "=")) {
|
||||
return part.trim().substring((name + "=").length()).trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.IFrame;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
@ -25,16 +24,11 @@ public class FrameLoader extends ContainerLoader implements ComponentLoader {
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final String src = element.attributeValue("src");
|
||||
final LayoutLoader loader = new LayoutLoader(factory, LayoutLoaderConfig.getFrameLoaders(), dsContext);
|
||||
final IFrame frame = factory.createComponent("iframe");
|
||||
|
||||
final IFrame frame = (IFrame) loader.loadComponent(getClass().getResource(src));
|
||||
loadAlign(frame, element);
|
||||
loadPack(frame, element);
|
||||
|
||||
loadFlex(frame, element);
|
||||
loadId(frame, element);
|
||||
loadSubcomponentsAndExpand(frame, element.element("layout"));
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
|
||||
@ -21,7 +22,7 @@ public class GroupBoxLoader extends ContainerLoader implements com.haulmont.cub
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Component component = factory.createComponent("groupbox");
|
||||
final OrderedLayout component = factory.createComponent("group-box");
|
||||
|
||||
final Element captionElement = element.element("caption");
|
||||
if (captionElement != null) {
|
||||
@ -32,7 +33,7 @@ public class GroupBoxLoader extends ContainerLoader implements com.haulmont.cub
|
||||
loadAlign(component, element);
|
||||
loadPack(component, element);
|
||||
|
||||
loadSubComponents(component, element, "caption");
|
||||
loadSubcomponentsAndExpand(component, element, "caption");
|
||||
|
||||
return component;
|
||||
}
|
||||
|
@ -12,9 +12,11 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class HBoxLoader extends ContainerLoader implements ComponentLoader {
|
||||
public HBoxLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
@ -22,13 +24,20 @@ public class HBoxLoader extends ContainerLoader implements ComponentLoader {
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Component component = factory.createComponent("hbox");
|
||||
final OrderedLayout component =
|
||||
StringUtils.isEmpty(element.attributeValue("expand")) ?
|
||||
factory.<OrderedLayout>createComponent("hbox") :
|
||||
factory.<OrderedLayout>createComponent("expandable-hbox");
|
||||
|
||||
loadId(component, element);
|
||||
loadAlign(component, element);
|
||||
loadPack(component, element);
|
||||
|
||||
loadSubComponents(component, element);
|
||||
|
||||
loadSubcomponentsAndExpand(component, element);
|
||||
|
||||
loadHeight(component, element);
|
||||
loadWidth(component, element);
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,9 @@ package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.IFrame;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
@ -24,10 +25,17 @@ public class IFrameLoader extends ContainerLoader implements ComponentLoader {
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final IFrame frame = factory.createComponent("iframe");
|
||||
final String src = element.attributeValue("src");
|
||||
final LayoutLoader loader = new LayoutLoader(factory, LayoutLoaderConfig.getFrameLoaders(), dsContext);
|
||||
|
||||
final IFrame frame = (IFrame) loader.loadComponent(getClass().getResource(src));
|
||||
|
||||
loadId(frame, element);
|
||||
loadSubComponents(frame, element);
|
||||
loadAlign(frame, element);
|
||||
loadPack(frame, element);
|
||||
|
||||
loadHeight(frame, element);
|
||||
loadWidth(frame, element);
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
@ -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: 20.01.2009 17:20:11
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.gui.xml.layout.loaders;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.SplitPanel;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class SplitPanelLoader extends ContainerLoader{
|
||||
public SplitPanelLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
super(config, factory, dsContext);
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final SplitPanel component = factory.createComponent("split");
|
||||
|
||||
loadId(component, element);
|
||||
loadSubComponents(component, element);
|
||||
|
||||
final String orientation = element.attributeValue("orientation");
|
||||
if (StringUtils.isEmpty(orientation)) {
|
||||
component.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
|
||||
} else if ("vertical".equalsIgnoreCase(orientation)) {
|
||||
component.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
|
||||
} else if ("horizontal".equalsIgnoreCase(orientation)) {
|
||||
component.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
@ -13,8 +13,10 @@ import com.haulmont.cuba.gui.xml.layout.ComponentLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import org.dom4j.Element;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class VBoxLoader extends ContainerLoader implements ComponentLoader {
|
||||
public VBoxLoader(LayoutLoaderConfig config, ComponentsFactory factory, DsContext dsContext) {
|
||||
@ -22,13 +24,20 @@ public class VBoxLoader extends ContainerLoader implements ComponentLoader {
|
||||
}
|
||||
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Component component = factory.createComponent("vbox");
|
||||
final OrderedLayout component =
|
||||
StringUtils.isEmpty(element.attributeValue("expand")) ?
|
||||
factory.<OrderedLayout>createComponent("vbox") :
|
||||
factory.<OrderedLayout>createComponent("expandable-vbox");
|
||||
|
||||
loadId(component, element);
|
||||
loadAlign(component, element);
|
||||
loadPack(component, element);
|
||||
|
||||
loadSubComponents(component, element);
|
||||
loadSubcomponentsAndExpand(component, element);
|
||||
|
||||
loadHeight(component, element);
|
||||
loadWidth(component, element);
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class WindowLoader extends ContainerLoader implements ComponentLoader {
|
||||
public Component loadComponent(ComponentsFactory factory, Element element) throws InstantiationException, IllegalAccessException {
|
||||
final Window window = factory.createComponent("window");
|
||||
|
||||
loadSubComponents(window, element);
|
||||
loadSubComponents(window, element.element("layout"));
|
||||
|
||||
return window;
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
|
||||
<action name="sec$User.browse" template="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.xml"/>
|
||||
|
||||
<action name="sec$Role.browse" class="com.haulmont.cuba.web.app.ui.DemoScreen"/>
|
||||
<action name="sec$Role.browse" class="com.haulmont.cuba.web.app.ui.TableDemoScreen"/>
|
||||
|
||||
</action-config>
|
@ -10,19 +10,25 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web;
|
||||
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.gui.config.Action;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.Context;
|
||||
import com.haulmont.cuba.gui.data.ValueListener;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.impl.DatasourceFactoryImpl;
|
||||
import com.haulmont.cuba.gui.data.impl.DatasourceImplementation;
|
||||
import com.haulmont.cuba.gui.xml.data.DsContextLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoader;
|
||||
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.haulmont.cuba.web.ui.Screen;
|
||||
import com.haulmont.cuba.web.ui.ScreenContext;
|
||||
import com.haulmont.cuba.web.ui.ScreenTitlePane;
|
||||
import com.haulmont.cuba.web.xml.layout.WebComponentsFactory;
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.itmill.toolkit.terminal.ExternalResource;
|
||||
import com.itmill.toolkit.ui.AbstractLayout;
|
||||
import com.itmill.toolkit.ui.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.TabSheet;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -32,17 +38,20 @@ import org.dom4j.Element;
|
||||
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.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScreenManager
|
||||
{
|
||||
private static class TabInfo
|
||||
{
|
||||
private ScreenTitlePane titlePane;
|
||||
private LinkedList<Screen> screens = new LinkedList<Screen>();
|
||||
private LinkedList<Window> screens = new LinkedList<Window>();
|
||||
|
||||
private TabInfo(ScreenTitlePane titlePane) {
|
||||
this.titlePane = titlePane;
|
||||
@ -57,18 +66,17 @@ public class ScreenManager
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public Screen openScreen(ScreenOpenType type, String actionName) {
|
||||
public Window openScreen(ScreenOpenType type, String actionName) {
|
||||
return openScreen(type, actionName, null);
|
||||
}
|
||||
|
||||
public Screen openScreen(ScreenOpenType type, String actionName, String tabCaption) {
|
||||
public Window openScreen(ScreenOpenType type, String actionName, String tabCaption) {
|
||||
app.getAppLog().debug("Opening screen " + actionName);
|
||||
Action action = app.getActionsConfig().getAction(actionName);
|
||||
if (tabCaption == null)
|
||||
tabCaption = action.getCaption();
|
||||
|
||||
Screen screen = createScreen(action);
|
||||
screen.setSizeFull();
|
||||
Window window = createScreen(action);
|
||||
|
||||
if (ScreenOpenType.NEW_TAB.equals(type)) {
|
||||
ExpandLayout layout = new ExpandLayout();
|
||||
@ -77,20 +85,20 @@ public class ScreenManager
|
||||
titlePane.addCaption(action.getCaption());
|
||||
layout.addComponent(titlePane);
|
||||
|
||||
layout.addComponent(screen);
|
||||
layout.expand(screen);
|
||||
final Component component = ComponentsHelper.unwrap(window);
|
||||
layout.addComponent(component);
|
||||
layout.expand(component);
|
||||
|
||||
TabSheet tabSheet = app.getAppWindow().getTabSheet();
|
||||
tabSheet.addTab(layout, tabCaption, null);
|
||||
tabSheet.setSelectedTab(layout);
|
||||
|
||||
TabInfo tabInfo = new TabInfo(titlePane);
|
||||
tabInfo.screens.add(screen);
|
||||
tabInfo.screens.add(window);
|
||||
tabs.put(layout, tabInfo);
|
||||
|
||||
screen.init(new ScreenContext(layout, titlePane));
|
||||
}
|
||||
else if (ScreenOpenType.THIS_TAB.equals(type)) {
|
||||
// window.init(new ScreenContext(layout, titlePane));
|
||||
} else if (ScreenOpenType.THIS_TAB.equals(type)) {
|
||||
TabSheet tabSheet = app.getAppWindow().getTabSheet();
|
||||
ExpandLayout layout = (ExpandLayout) tabSheet.getSelectedTab();
|
||||
|
||||
@ -98,19 +106,18 @@ public class ScreenManager
|
||||
if (tabInfo == null)
|
||||
throw new IllegalStateException("Current tab not found");
|
||||
|
||||
layout.removeComponent(tabInfo.screens.getLast());
|
||||
layout.addComponent(screen);
|
||||
layout.expand(screen);
|
||||
layout.removeComponent(ComponentsHelper.unwrap(tabInfo.screens.getLast()));
|
||||
layout.addComponent(ComponentsHelper.unwrap(window));
|
||||
layout.expand(ComponentsHelper.unwrap(window));
|
||||
|
||||
tabInfo.titlePane.addCaption(action.getCaption());
|
||||
tabInfo.screens.add(screen);
|
||||
tabInfo.screens.add(window);
|
||||
|
||||
screen.init(new ScreenContext(layout, tabInfo.titlePane));
|
||||
}
|
||||
else
|
||||
// window.init(new ScreenContext(layout, tabInfo.titlePane));
|
||||
} else
|
||||
throw new UnsupportedOperationException("Opening type not supported: " + type);
|
||||
|
||||
return screen;
|
||||
return window;
|
||||
}
|
||||
|
||||
public void closeScreen() {
|
||||
@ -121,23 +128,23 @@ public class ScreenManager
|
||||
if (tabInfo == null)
|
||||
throw new IllegalStateException("Unable to close screen: current tab not found");
|
||||
|
||||
Screen screen = tabInfo.screens.getLast();
|
||||
if (!screen.onClose()) {
|
||||
return;
|
||||
}
|
||||
Window window = tabInfo.screens.getLast();
|
||||
|
||||
final Object res = invokeMethod(window, "close");
|
||||
if (res != null && !Boolean.TRUE.equals(res)) { return; }
|
||||
|
||||
tabInfo.screens.removeLast();
|
||||
|
||||
layout.removeComponent(screen);
|
||||
layout.removeComponent(ComponentsHelper.unwrap(window));
|
||||
if (tabInfo.screens.isEmpty()) {
|
||||
tabSheet.removeComponent(layout);
|
||||
tabs.remove(layout);
|
||||
app.getMainWindow().open(new ExternalResource(app.getURL())); // TODO fix TabSheet repaint
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tabInfo.titlePane.removeCaption();
|
||||
Screen prevScreen = tabInfo.screens.getLast();
|
||||
layout.addComponent(prevScreen);
|
||||
layout.expand(prevScreen);
|
||||
Window prevScreen = tabInfo.screens.getLast();
|
||||
layout.addComponent(ComponentsHelper.unwrap(prevScreen));
|
||||
layout.expand(ComponentsHelper.unwrap(prevScreen));
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,30 +177,99 @@ public class ScreenManager
|
||||
return document;
|
||||
}
|
||||
|
||||
private Screen createScreen(Action action) {
|
||||
private Window createScreen(Action action) {
|
||||
final Element descriptor = action.getDescriptor();
|
||||
String className = descriptor.attributeValue("class");
|
||||
|
||||
if (StringUtils.isBlank(className)) {
|
||||
final String template = descriptor.attributeValue("template");
|
||||
|
||||
Document document = parseDescriptor(template);
|
||||
final Element rootElement = document.getRootElement();
|
||||
|
||||
final DsContextLoader dsContextLoader = new DsContextLoader(new DatasourceFactoryImpl());
|
||||
final DsContext dsContext = dsContextLoader.loadDatasources(rootElement.element("dsContext"));
|
||||
|
||||
final LayoutLoader layoutLoader = new LayoutLoader(new WebComponentsFactory(), LayoutLoaderConfig.getWindowLoaders(), dsContext);
|
||||
final Screen screen = (Screen) layoutLoader.loadComponent(rootElement.element("layout"));
|
||||
|
||||
return screen;
|
||||
return createWindowFromTemplate(descriptor);
|
||||
} else {
|
||||
try {
|
||||
Class c = Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
return (Screen) c.newInstance();
|
||||
final Window window = (Window) c.newInstance();
|
||||
invokeMethod(window, "init");
|
||||
return window;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Window createWindowFromTemplate(Element descriptor) {
|
||||
final String template = descriptor.attributeValue("template");
|
||||
|
||||
Document document = parseDescriptor(template);
|
||||
final Element rootElement = document.getRootElement();
|
||||
|
||||
final DsContextLoader dsContextLoader = new DsContextLoader(new DatasourceFactoryImpl());
|
||||
final DsContext dsContext = dsContextLoader.loadDatasources(rootElement.element("dsContext"));
|
||||
|
||||
final LayoutLoader layoutLoader = new LayoutLoader(new WebComponentsFactory(), LayoutLoaderConfig.getWindowLoaders(), dsContext);
|
||||
final Window window = (Screen) layoutLoader.loadComponent(rootElement);
|
||||
|
||||
|
||||
for (Datasource ds : dsContext.getAll()) {
|
||||
if (ds instanceof DatasourceImplementation) {
|
||||
((DatasourceImplementation) ds).initialized();
|
||||
}
|
||||
}
|
||||
|
||||
dsContext.setContext(new Context() {
|
||||
public <T> T getValue(String property) {
|
||||
final com.haulmont.cuba.gui.components.Component component = window.getComponent(property);
|
||||
if (component instanceof com.haulmont.cuba.gui.components.Component.Field) {
|
||||
return ((com.haulmont.cuba.gui.components.Component.Field) component).<T>getValue();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setValue(String property, Object value) {
|
||||
final com.haulmont.cuba.gui.components.Component component = window.getComponent(property);
|
||||
if (component instanceof com.haulmont.cuba.gui.components.Component.Field) {
|
||||
((com.haulmont.cuba.gui.components.Component.Field) component).setValue(value);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void addValueListener(ValueListener listener) {
|
||||
}
|
||||
|
||||
public void removeValueListener(ValueListener listener) {
|
||||
}
|
||||
});
|
||||
|
||||
return wrapByCustomClass(window, rootElement);
|
||||
}
|
||||
|
||||
protected Window wrapByCustomClass(Window window, Element element) {
|
||||
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(Screen.class);
|
||||
res = (Window) constructor.newInstance(window);
|
||||
|
||||
invokeMethod(res, "init");
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return res;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
protected <T> T invokeMethod(Window window, String name) {
|
||||
try {
|
||||
final Method method = window.getClass().getDeclaredMethod(name);
|
||||
method.setAccessible(true);
|
||||
return (T) method.invoke(window);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 21.01.2009 18:54:56
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.app.ui;
|
||||
|
||||
import com.haulmont.cuba.web.ui.Screen;
|
||||
|
||||
public class TableDemoScreen extends Screen {
|
||||
protected void init() {
|
||||
addComponent(new TableExample());
|
||||
}
|
||||
}
|
301
modules/web/src/com/haulmont/cuba/web/app/ui/TableExample.java
Normal file
301
modules/web/src/com/haulmont/cuba/web/app/ui/TableExample.java
Normal file
@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright 2008 IT Mill Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.web.app.ui;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.itmill.toolkit.data.Item;
|
||||
import com.itmill.toolkit.data.Property;
|
||||
import com.itmill.toolkit.event.Action;
|
||||
import com.itmill.toolkit.ui.Button;
|
||||
import com.itmill.toolkit.ui.CheckBox;
|
||||
import com.itmill.toolkit.ui.CustomComponent;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.Table;
|
||||
import com.itmill.toolkit.ui.Button.ClickEvent;
|
||||
|
||||
/**
|
||||
* Table example.
|
||||
*
|
||||
* @author IT Mill Ltd.
|
||||
*/
|
||||
public class TableExample extends CustomComponent implements Action.Handler,
|
||||
Button.ClickListener {
|
||||
|
||||
// Actions
|
||||
private static final Action ACTION_SAVE = new Action("Save");
|
||||
private static final Action ACTION_DELETE = new Action("Delete");
|
||||
private static final Action ACTION_HIRE = new Action("Hire");
|
||||
// Action sets
|
||||
private static final Action[] ACTIONS_NOHIRE = new Action[] { ACTION_SAVE,
|
||||
ACTION_DELETE };
|
||||
private static final Action[] ACTIONS_HIRE = new Action[] { ACTION_HIRE,
|
||||
ACTION_SAVE, ACTION_DELETE };
|
||||
// Properties
|
||||
private static final Object PROPERTY_SPECIES = "Species";
|
||||
private static final Object PROPERTY_TYPE = "Type";
|
||||
private static final Object PROPERTY_KIND = "Kind";
|
||||
private static final Object PROPERTY_HIRED = "Hired";
|
||||
|
||||
// "global" components
|
||||
Table source;
|
||||
Table saved;
|
||||
Button saveSelected;
|
||||
Button hireSelected;
|
||||
Button deleteSelected;
|
||||
Button deselect;
|
||||
|
||||
public TableExample() {
|
||||
// main layout
|
||||
final OrderedLayout main = new OrderedLayout();
|
||||
main.setMargin(true);
|
||||
setCompositionRoot(main);
|
||||
|
||||
// "source" table with bells & whistlesenabled
|
||||
source = new Table("All creatures");
|
||||
source.setPageLength(7);
|
||||
source.setWidth(550);
|
||||
source.setColumnCollapsingAllowed(true);
|
||||
source.setColumnReorderingAllowed(true);
|
||||
|
||||
source.setSelectable(true);
|
||||
source.setMultiSelect(false);
|
||||
source.setImmediate(true);
|
||||
source.setNullSelectionAllowed(false);
|
||||
|
||||
source.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
|
||||
fillTable(source);
|
||||
source.addActionHandler(this);
|
||||
main.addComponent(source);
|
||||
|
||||
// x-selected button row
|
||||
final OrderedLayout horiz = new OrderedLayout(
|
||||
OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
horiz.setMargin(false, false, true, false);
|
||||
main.addComponent(horiz);
|
||||
saveSelected = new Button("Save selected");
|
||||
saveSelected.setStyleName(Button.STYLE_LINK);
|
||||
saveSelected.addListener(this);
|
||||
horiz.addComponent(saveSelected);
|
||||
hireSelected = new Button("Hire selected");
|
||||
hireSelected.setStyleName(Button.STYLE_LINK);
|
||||
hireSelected.addListener(this);
|
||||
horiz.addComponent(hireSelected);
|
||||
deleteSelected = new Button("Delete selected");
|
||||
deleteSelected.setStyleName(Button.STYLE_LINK);
|
||||
deleteSelected.addListener(this);
|
||||
horiz.addComponent(deleteSelected);
|
||||
deselect = new Button("Deselect all");
|
||||
deselect.setStyleName(Button.STYLE_LINK);
|
||||
deselect.addListener(this);
|
||||
horiz.addComponent(deselect);
|
||||
final CheckBox editmode = new CheckBox("Editmode ");
|
||||
editmode.addListener(new CheckBox.ClickListener() {
|
||||
public void buttonClick(ClickEvent event) {
|
||||
source.setEditable(((Boolean) event.getButton().getValue())
|
||||
.booleanValue());
|
||||
}
|
||||
});
|
||||
editmode.setImmediate(true);
|
||||
horiz.addComponent(editmode);
|
||||
|
||||
// "saved" table, minimalistic
|
||||
saved = new Table("Saved creatures");
|
||||
saved.setPageLength(5);
|
||||
saved.setWidth(550);
|
||||
saved.setSelectable(false);
|
||||
saved.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
|
||||
saved.setRowHeaderMode(Table.ROW_HEADER_MODE_ID);
|
||||
initProperties(saved);
|
||||
saved.addActionHandler(this);
|
||||
main.addComponent(saved);
|
||||
|
||||
final CheckBox b = new CheckBox("Modify saved creatures");
|
||||
b.addListener(new CheckBox.ClickListener() {
|
||||
public void buttonClick(ClickEvent event) {
|
||||
saved.setEditable(((Boolean) event.getButton().getValue())
|
||||
.booleanValue());
|
||||
}
|
||||
});
|
||||
b.setImmediate(true);
|
||||
main.addComponent(b);
|
||||
|
||||
}
|
||||
|
||||
// set up the properties (columns)
|
||||
private void initProperties(Table table) {
|
||||
table.addContainerProperty(PROPERTY_SPECIES, String.class, "");
|
||||
table.addContainerProperty(PROPERTY_TYPE, String.class, "");
|
||||
table.addContainerProperty(PROPERTY_KIND, String.class, "");
|
||||
table
|
||||
.addContainerProperty(PROPERTY_HIRED, Boolean.class,
|
||||
Boolean.FALSE);
|
||||
}
|
||||
|
||||
// fill the table with some random data
|
||||
private void fillTable(Table table) {
|
||||
initProperties(table);
|
||||
|
||||
final String[] sp = new String[] { "Fox", "Dog", "Cat", "Moose",
|
||||
"Penguin", "Cow" };
|
||||
final String[] ty = new String[] { "Quick", "Lazy", "Sleepy",
|
||||
"Fidgety", "Crazy", "Kewl" };
|
||||
final String[] ki = new String[] { "Jumping", "Walking", "Sleeping",
|
||||
"Skipping", "Dancing" };
|
||||
|
||||
Random r = new Random(5);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
final String s = sp[(int) (r.nextDouble() * sp.length)];
|
||||
final String t = ty[(int) (r.nextDouble() * ty.length)];
|
||||
final String k = ki[(int) (r.nextDouble() * ki.length)];
|
||||
table.addItem(new Object[] { s, t, k, Boolean.FALSE }, new Integer(
|
||||
i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Called for each item (row), returns valid actions for that item
|
||||
public Action[] getActions(Object target, Object sender) {
|
||||
if (sender == source) {
|
||||
final Item item = source.getItem(target);
|
||||
// save, delete, and hire if not already hired
|
||||
if (item != null
|
||||
&& item.getItemProperty(PROPERTY_HIRED).getValue() == Boolean.FALSE) {
|
||||
return ACTIONS_HIRE;
|
||||
} else {
|
||||
return ACTIONS_NOHIRE;
|
||||
}
|
||||
} else {
|
||||
// "saved" table only has one action
|
||||
return new Action[] { ACTION_DELETE };
|
||||
}
|
||||
}
|
||||
|
||||
// called when an action is invoked on an item (row)
|
||||
public void handleAction(Action action, Object sender, Object target) {
|
||||
if (sender == source) {
|
||||
Item item = source.getItem(target);
|
||||
if (action == ACTION_HIRE) {
|
||||
// set HIRED property to true
|
||||
item.getItemProperty(PROPERTY_HIRED).setValue(Boolean.TRUE);
|
||||
if (saved.containsId(target)) {
|
||||
item = saved.getItem(target);
|
||||
item.getItemProperty(PROPERTY_HIRED).setValue(Boolean.TRUE);
|
||||
}
|
||||
getWindow().showNotification("Hired", "" + item);
|
||||
|
||||
} else if (action == ACTION_SAVE) {
|
||||
if (saved.containsId(target)) {
|
||||
// let's not save twice
|
||||
getWindow().showNotification("Already saved", "" + item);
|
||||
return;
|
||||
}
|
||||
// "manual" copy of the item properties we want
|
||||
final Item added = saved.addItem(target);
|
||||
Property p = added.getItemProperty(PROPERTY_SPECIES);
|
||||
p.setValue(item.getItemProperty(PROPERTY_SPECIES).getValue());
|
||||
p = added.getItemProperty(PROPERTY_TYPE);
|
||||
p.setValue(item.getItemProperty(PROPERTY_TYPE).getValue());
|
||||
p = added.getItemProperty(PROPERTY_KIND);
|
||||
p.setValue(item.getItemProperty(PROPERTY_KIND).getValue());
|
||||
p = added.getItemProperty(PROPERTY_HIRED);
|
||||
p.setValue(item.getItemProperty(PROPERTY_HIRED).getValue());
|
||||
getWindow().showNotification("Saved", "" + item);
|
||||
} else {
|
||||
// ACTION_DELETE
|
||||
getWindow().showNotification("Deleted ", "" + item);
|
||||
source.removeItem(target);
|
||||
}
|
||||
|
||||
} else {
|
||||
// sender==saved
|
||||
if (action == ACTION_DELETE) {
|
||||
final Item item = saved.getItem(target);
|
||||
getWindow().showNotification("Deleted", "" + item);
|
||||
saved.removeItem(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonClick(ClickEvent event) {
|
||||
final Button b = event.getButton();
|
||||
if (b == deselect) {
|
||||
source.setValue(null);
|
||||
} else if (b == saveSelected) {
|
||||
// loop each selected and copy to "saved" table
|
||||
final Set selected = (Set) source.getValue();
|
||||
int s = 0;
|
||||
for (final Iterator it = selected.iterator(); it.hasNext();) {
|
||||
final Object id = it.next();
|
||||
if (!saved.containsId(id)) {
|
||||
final Item item = source.getItem(id);
|
||||
final Item added = saved.addItem(id);
|
||||
// "manual" copy of the properties we want
|
||||
Property p = added.getItemProperty(PROPERTY_SPECIES);
|
||||
p.setValue(item.getItemProperty(PROPERTY_SPECIES)
|
||||
.getValue());
|
||||
p = added.getItemProperty(PROPERTY_TYPE);
|
||||
p.setValue(item.getItemProperty(PROPERTY_TYPE).getValue());
|
||||
p = added.getItemProperty(PROPERTY_KIND);
|
||||
p.setValue(item.getItemProperty(PROPERTY_KIND).getValue());
|
||||
p = added.getItemProperty(PROPERTY_HIRED);
|
||||
p.setValue(item.getItemProperty(PROPERTY_HIRED).getValue());
|
||||
s++;
|
||||
}
|
||||
}
|
||||
getWindow().showNotification("Saved " + s);
|
||||
|
||||
} else if (b == hireSelected) {
|
||||
// loop each selected and set property HIRED to true
|
||||
int s = 0;
|
||||
final Set selected = (Set) source.getValue();
|
||||
for (final Iterator it = selected.iterator(); it.hasNext();) {
|
||||
final Object id = it.next();
|
||||
Item item = source.getItem(id);
|
||||
final Property p = item.getItemProperty(PROPERTY_HIRED);
|
||||
if (p.getValue() == Boolean.FALSE) {
|
||||
p.setValue(Boolean.TRUE);
|
||||
s++;
|
||||
}
|
||||
if (saved.containsId(id)) {
|
||||
// also update "saved" table
|
||||
item = saved.getItem(id);
|
||||
item.getItemProperty(PROPERTY_HIRED).setValue(Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
getWindow().showNotification("Hired " + s);
|
||||
|
||||
} else {
|
||||
// loop trough selected and delete
|
||||
int s = 0;
|
||||
final Set selected = (Set) source.getValue();
|
||||
for (final Iterator it = selected.iterator(); it.hasNext();) {
|
||||
final Object id = it.next();
|
||||
if (source.containsId(id)) {
|
||||
s++;
|
||||
source.removeItem(id);
|
||||
}
|
||||
}
|
||||
getWindow().showNotification("Deleted " + s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 19.01.2009 10:15:26
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.app.ui.security.user.browse;
|
||||
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.web.ui.Screen;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
|
||||
public class SecurityUserBrowser extends AbstractFrame implements Window {
|
||||
public SecurityUserBrowser(Screen frame) {
|
||||
super(frame);
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
final Button button = getComponent("filter.apply");
|
||||
final Table table = getComponent("users");
|
||||
|
||||
table.addAction(new Action() {
|
||||
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 Action() {
|
||||
public String getCaption() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
table.getDatasource().refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected 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;
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
<window>
|
||||
<vbox>
|
||||
<groupbox>
|
||||
<caption label="Filter"/>
|
||||
<hbox flex="1">
|
||||
<label control="name" value="Name:"/>
|
||||
<textbox id="name" flex="1"/>
|
||||
<frame>
|
||||
<layout>
|
||||
<vbox id="filter-pane" width="100%">
|
||||
<group-box>
|
||||
<caption label="Filter"/>
|
||||
<hbox id="group-box">
|
||||
<label control="name" value="Name:"/>
|
||||
<text-field id="name" width="100%"/>
|
||||
</hbox>
|
||||
</group-box>
|
||||
<hbox align="end" width="500px">
|
||||
<button id="clear" caption="Clear"/>
|
||||
<button id="apply" caption="Apply"/>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
<hbox align="end">
|
||||
|
||||
<button id="Clear" caption="Clear"/>
|
||||
<button id="Apply" caption="Apply"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
</vbox>
|
||||
</layout>
|
||||
</frame>
|
@ -3,4 +3,8 @@
|
||||
<property name="name"/>
|
||||
<property name="login"/>
|
||||
</view>
|
||||
<view entity="sec$Profile" name="browse">
|
||||
<property name="name"/>
|
||||
<property name="defaultProfile"/>
|
||||
</view>
|
||||
</views>
|
@ -1,4 +1,4 @@
|
||||
<screen>
|
||||
<window class="com.haulmont.cuba.web.app.ui.security.user.browse.SecurityUserBrowser">
|
||||
<metadataContext>
|
||||
<deployViews name="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse.views.xml"/>
|
||||
</metadataContext>
|
||||
@ -9,20 +9,45 @@
|
||||
class="com.haulmont.cuba.security.entity.User"
|
||||
view="browse"
|
||||
>
|
||||
<query>select u from sec$User u</query>
|
||||
<query>
|
||||
<![CDATA[select u from sec$User u where u.name like <#if ${component:filter.name}?has_content>${component:filter.name}<#else>'%'</#if>]]>
|
||||
</query>
|
||||
</collection-datasource>
|
||||
|
||||
<collection-datasource
|
||||
id="profiles"
|
||||
class="com.haulmont.cuba.security.entity.Profile"
|
||||
view="browse"
|
||||
>
|
||||
<query>select p from sec$Profile p where p.user = ${ds:users}</query>
|
||||
</collection-datasource>
|
||||
</dsContext>
|
||||
|
||||
<layout>
|
||||
<hbox>
|
||||
<vbox>
|
||||
<table>
|
||||
<columns>
|
||||
<column id="name" label="Name"/>
|
||||
</columns>
|
||||
<rows datasource="users"/>
|
||||
</table>
|
||||
</vbox>
|
||||
</hbox>
|
||||
<vbox expand="table-panel">
|
||||
<iframe id="filter" src="/com/haulmont/cuba/web/app/ui/security/user/browse/security-user-browse-filter.xml"/>
|
||||
|
||||
<hbox id="table-panel" expand="table">
|
||||
<split orientation="horizontal">
|
||||
<vbox expand="users">
|
||||
<table id="users">
|
||||
<columns>
|
||||
<column id="name" label="Name"/>
|
||||
</columns>
|
||||
<rows datasource="users"/>
|
||||
</table>
|
||||
</vbox>
|
||||
<vbox expand="profiles">
|
||||
<table id="profiles">
|
||||
<columns>
|
||||
<column id="name" label="Name"/>
|
||||
<column id="defaultProfile" label="Default"/>
|
||||
</columns>
|
||||
<rows datasource="profiles"/>
|
||||
</table>
|
||||
</vbox>
|
||||
</split>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</layout>
|
||||
</screen>
|
||||
</window>
|
||||
|
@ -25,6 +25,37 @@ class AbstractComponent<T extends com.itmill.toolkit.ui.Component> implements Co
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
component.setDebugId(id);
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
if (component instanceof com.itmill.toolkit.ui.Component.Focusable) {
|
||||
((com.itmill.toolkit.ui.Component.Focusable) component).focus();
|
||||
}
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return component.getHeight();
|
||||
}
|
||||
|
||||
public int getHeightUnits() {
|
||||
return component.getHeightUnits();
|
||||
}
|
||||
|
||||
public void setHeight(String height) {
|
||||
component.setHeight(height);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return component.getWidth();
|
||||
}
|
||||
|
||||
public int getWidthUnits() {
|
||||
return component.getWidthUnits();
|
||||
}
|
||||
|
||||
public void setWidth(String width) {
|
||||
component.setWidth(width);
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
|
@ -9,13 +9,19 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.ValuePathHelper;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
|
||||
class AbstractContainer extends OrderedLayout implements Component, Component.Container {
|
||||
import java.util.*;
|
||||
|
||||
class AbstractContainer extends OrderedLayout implements Component.Container {
|
||||
private int verticalAlIlignment = AlignmentHandler.ALIGNMENT_TOP;
|
||||
private int horizontalAlIlignment = AlignmentHandler.ALIGNMENT_LEFT;
|
||||
private String id;
|
||||
|
||||
protected String id;
|
||||
protected Map<String, Component> componentByIds = new HashMap<String, Component>();
|
||||
|
||||
public AbstractContainer(int orientation) {
|
||||
super(orientation);
|
||||
@ -26,10 +32,25 @@ class AbstractContainer extends OrderedLayout implements Component, Component.Co
|
||||
|
||||
addComponent(itmillComponent);
|
||||
setComponentAlignment(itmillComponent, component.getHorizontalAlIlignment(), component.getVerticalAlIlignment());
|
||||
|
||||
if (component.getId() != null) {
|
||||
componentByIds.put(component.getId(), component);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
removeComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.remove(component.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return (T) componentByIds.get(id);
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
return ComponentsHelper.<T>getComponent(this, id);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@ -38,6 +59,10 @@ class AbstractContainer extends OrderedLayout implements Component, Component.Co
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
setDebugId(id);
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 23.12.2008 11:46:42
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.ValuePathHelper;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.Layout;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
class AbstractExpandableContainer extends ExpandLayout implements Component, Component.Container {
|
||||
private int verticalAlIlignment = Layout.AlignmentHandler.ALIGNMENT_TOP;
|
||||
private int horizontalAlIlignment = Layout.AlignmentHandler.ALIGNMENT_LEFT;
|
||||
|
||||
protected String id;
|
||||
protected Map<String, Component> componentByIds = new HashMap<String, Component>();
|
||||
|
||||
public AbstractExpandableContainer(int orientation) {
|
||||
super(orientation);
|
||||
}
|
||||
|
||||
public void add(Component component) {
|
||||
final com.itmill.toolkit.ui.Component itmillComponent = ComponentsHelper.unwrap(component);
|
||||
|
||||
addComponent(itmillComponent);
|
||||
setComponentAlignment(itmillComponent, component.getHorizontalAlIlignment(), component.getVerticalAlIlignment());
|
||||
|
||||
if (component.getId() != null) {
|
||||
componentByIds.put(component.getId(), component);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
removeComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.remove(component.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return (T) componentByIds.get(id);
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
return ComponentsHelper.<T>getComponent(this, id);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return verticalAlIlignment;
|
||||
}
|
||||
|
||||
public void setVerticalAlIlignment(int verticalAlIlignment) {
|
||||
this.verticalAlIlignment = verticalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof AlignmentHandler) {
|
||||
((AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHorizontalAlIlignment() {
|
||||
return horizontalAlIlignment;
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {
|
||||
this.horizontalAlIlignment = horizontalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof AlignmentHandler) {
|
||||
((AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void expand(Component component, String height, String width) {
|
||||
final com.itmill.toolkit.ui.Component expandedComponent = ComponentsHelper.unwrap(component);
|
||||
expand(expandedComponent);
|
||||
|
||||
if (!StringUtils.isEmpty(height)) {
|
||||
expandedComponent.setHeight(height);
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(width)) {
|
||||
expandedComponent.setWidth(width);
|
||||
}
|
||||
}
|
||||
}
|
@ -34,4 +34,20 @@ public class AbstractField<T extends com.itmill.toolkit.ui.Field> extends Abstra
|
||||
final ItemWrapper wrapper = new ItemWrapper(datasource, metaClass.getProperties());
|
||||
component.setPropertyDataSource(wrapper.getItemProperty(metaClass.getProperty(property)));
|
||||
}
|
||||
|
||||
public <T> T getValue() {
|
||||
return (T) component.getValue();
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
component.setValue(value);
|
||||
}
|
||||
|
||||
public String getCaption() {
|
||||
return component.getCaption();
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
component.setCaption(caption);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 20.01.2009 10:27:00
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.Layout;
|
||||
import com.itmill.toolkit.ui.Panel;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class AbstractPanel extends Panel implements com.haulmont.cuba.gui.components.OrderedLayout, Component.Container {
|
||||
private int verticalAlIlignment = Layout.AlignmentHandler.ALIGNMENT_TOP;
|
||||
private int horizontalAlIlignment = Layout.AlignmentHandler.ALIGNMENT_LEFT;
|
||||
|
||||
private String id;
|
||||
private Component component;
|
||||
|
||||
public void add(Component component) {
|
||||
final com.itmill.toolkit.ui.Component comp = ComponentsHelper.unwrap(component);
|
||||
if (comp instanceof Layout) {
|
||||
setLayout(((Layout) comp));
|
||||
this.component = component;
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
if (getLayout() == ComponentsHelper.unwrap(component)) {
|
||||
setLayout(null);
|
||||
this.component = null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
if (getComponentIterator().hasNext()) {
|
||||
com.itmill.toolkit.ui.Component component = (com.itmill.toolkit.ui.Component) getComponentIterator().next();
|
||||
if (component instanceof Focusable) {
|
||||
((Focusable) component).focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return component != null && ObjectUtils.equals(component.getId(), id) ? (T) component : null;
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
final Layout layout = getLayout();
|
||||
if (layout instanceof Container) {
|
||||
final com.haulmont.cuba.gui.components.Component component = ((Container) layout).getOwnComponent(id);
|
||||
|
||||
if (component == null) {
|
||||
return ComponentsHelper.<T>getComponentByIterate(layout, id);
|
||||
} else {
|
||||
return (T) component;
|
||||
}
|
||||
} else {
|
||||
return ComponentsHelper.<T>getComponentByIterate(layout, id);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return verticalAlIlignment;
|
||||
}
|
||||
|
||||
public void setVerticalAlIlignment(int verticalAlIlignment) {
|
||||
this.verticalAlIlignment = verticalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof Layout.AlignmentHandler) {
|
||||
((Layout.AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHorizontalAlIlignment() {
|
||||
return horizontalAlIlignment;
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {
|
||||
this.horizontalAlIlignment = horizontalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof Layout.AlignmentHandler) {
|
||||
((Layout.AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public void expand(Component component, String height, String width) {
|
||||
final com.itmill.toolkit.ui.Component expandedComponent = ComponentsHelper.unwrap(component);
|
||||
if (getLayout() instanceof ExpandLayout) {
|
||||
((ExpandLayout) getLayout()).expand(expandedComponent);
|
||||
|
||||
if (!StringUtils.isEmpty(height)) {
|
||||
expandedComponent.setHeight(height);
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(width)) {
|
||||
expandedComponent.setWidth(width);
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Action;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class Button
|
||||
extends
|
||||
@ -17,10 +19,17 @@ public class Button
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.Button, Component.Wrapper
|
||||
{
|
||||
private boolean flexible;
|
||||
private Action action;
|
||||
|
||||
public Button() {
|
||||
component = new com.itmill.toolkit.ui.Button();
|
||||
component.addListener(new com.itmill.toolkit.ui.Button.ClickListener() {
|
||||
public void buttonClick(com.itmill.toolkit.ui.Button.ClickEvent event) {
|
||||
if (action != null) {
|
||||
action.actionPerform(Button.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getCaption() {
|
||||
@ -31,12 +40,16 @@ public class Button
|
||||
component.setCaption(caption);
|
||||
}
|
||||
|
||||
public boolean isFlexible() {
|
||||
return flexible;
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setFlexible(boolean flexible) {
|
||||
this.flexible = flexible;
|
||||
component.setWidth("100%");
|
||||
public void setAction(Action action) {
|
||||
this.action = action;
|
||||
|
||||
final String caption = action.getCaption();
|
||||
if (!StringUtils.isEmpty(caption)) {
|
||||
component.setCaption(caption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:12:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
|
||||
public class CheckBox
|
||||
extends
|
||||
AbstractField<com.itmill.toolkit.ui.CheckBox>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.CheckBox, Component.Wrapper {
|
||||
|
||||
public CheckBox() {
|
||||
this.component = new com.itmill.toolkit.ui.CheckBox();
|
||||
}
|
||||
}
|
@ -10,10 +10,59 @@
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.itmill.toolkit.ui.Component;
|
||||
import com.itmill.toolkit.ui.ComponentContainer;
|
||||
import com.haulmont.cuba.gui.components.ValuePathHelper;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 String[] elements = ValuePathHelper.parse(id);
|
||||
if (elements.length == 1) {
|
||||
final com.haulmont.cuba.gui.components.Component component =
|
||||
comp.<com.haulmont.cuba.gui.components.Component>getOwnComponent(id);
|
||||
|
||||
if (component == null) {
|
||||
return (T)getComponentByIterate(container, id);
|
||||
} else {
|
||||
return (T) component;
|
||||
}
|
||||
} else {
|
||||
com.haulmont.cuba.gui.components.Component component = comp.getOwnComponent(elements[0]);
|
||||
if (component == null) {
|
||||
return (T)getComponentByIterate(container, id);
|
||||
} else {
|
||||
final List<String> subpath = Arrays.asList(elements).subList(1, elements.length);
|
||||
return ((com.haulmont.cuba.gui.components.Component.Container) component).<T>getComponent(
|
||||
ValuePathHelper.format(subpath.toArray(new String[]{})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T extends com.haulmont.cuba.gui.components.Component> T getComponentByIterate(ComponentContainer container, String id) {
|
||||
com.haulmont.cuba.gui.components.Component component;
|
||||
final Iterator iterator = container.getComponentIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Component c = (Component) iterator.next();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:12:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
|
||||
public class DateField
|
||||
extends
|
||||
AbstractField<com.itmill.toolkit.ui.DateField>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.DateField, Component.Wrapper {
|
||||
|
||||
public DateField() {
|
||||
this.component = new com.itmill.toolkit.ui.DateField();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 19.12.2008 17:20:39
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class ExpandableHBox extends AbstractExpandableContainer implements com.haulmont.cuba.gui.components.OrderedLayout {
|
||||
public ExpandableHBox() {
|
||||
super(ExpandLayout.ORIENTATION_HORIZONTAL);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 19.12.2008 17:20:39
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class ExpandableVBox extends AbstractExpandableContainer implements com.haulmont.cuba.gui.components.OrderedLayout {
|
||||
|
||||
public ExpandableVBox() {
|
||||
super(ExpandLayout.ORIENTATION_VERTICAL);
|
||||
}
|
||||
}
|
@ -13,62 +13,16 @@ import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.Layout;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.Panel;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
|
||||
public class GroupBox extends Panel implements Component, Component.Container, Component.HasCaption {
|
||||
private int verticalAlIlignment = Layout.AlignmentHandler.ALIGNMENT_TOP;
|
||||
private int horizontalAlIlignment = Layout.AlignmentHandler.ALIGNMENT_LEFT;
|
||||
private String id;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class GroupBox extends AbstractPanel implements Component.HasCaption {
|
||||
|
||||
public GroupBox() {
|
||||
setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL));
|
||||
}
|
||||
|
||||
public void add(Component component) {
|
||||
final com.itmill.toolkit.ui.Component itmillComponent = ComponentsHelper.unwrap(component);
|
||||
|
||||
final Layout layout = getLayout();
|
||||
layout.addComponent(itmillComponent);
|
||||
if (layout instanceof Layout.AlignmentHandler) {
|
||||
((Layout.AlignmentHandler) getLayout()).setComponentAlignment(
|
||||
itmillComponent,
|
||||
component.getHorizontalAlIlignment(),
|
||||
component.getVerticalAlIlignment());
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
getLayout().removeComponent(ComponentsHelper.unwrap(component));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return verticalAlIlignment;
|
||||
}
|
||||
|
||||
public void setVerticalAlIlignment(int verticalAlIlignment) {
|
||||
this.verticalAlIlignment = verticalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof Layout.AlignmentHandler) {
|
||||
((Layout.AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHorizontalAlIlignment() {
|
||||
return horizontalAlIlignment;
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {
|
||||
this.horizontalAlIlignment = horizontalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof Layout.AlignmentHandler) {
|
||||
((Layout.AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
setLayout(new ExpandLayout(OrderedLayout.ORIENTATION_VERTICAL));
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,13 @@ package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.Layout;
|
||||
|
||||
public class HBox extends AbstractContainer {
|
||||
public class HBox extends AbstractContainer implements com.haulmont.cuba.gui.components.OrderedLayout {
|
||||
public HBox() {
|
||||
super(ExpandLayout.ORIENTATION_HORIZONTAL);
|
||||
}
|
||||
|
||||
public void expand(Component component, String height, String width) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
@ -9,23 +9,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
|
||||
public class IFrame extends AbstractContainer implements com.haulmont.cuba.gui.components.IFrame {
|
||||
private boolean flexible;
|
||||
|
||||
public class IFrame extends AbstractPanel implements com.haulmont.cuba.gui.components.IFrame {
|
||||
public IFrame() {
|
||||
super(ExpandLayout.ORIENTATION_VERTICAL);
|
||||
}
|
||||
|
||||
public boolean isFlexible() {
|
||||
return flexible;
|
||||
}
|
||||
|
||||
public void setFlexible(boolean flexible) {
|
||||
this.flexible = flexible;
|
||||
setWidth("100%");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:12:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.Select;
|
||||
|
||||
public class LookupField
|
||||
extends
|
||||
AbstractField<Select>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.LookupField, Component.Wrapper {
|
||||
|
||||
public LookupField() {
|
||||
this.component = new Select();
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 20.01.2009 17:09:40
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SplitPanel extends com.itmill.toolkit.ui.SplitPanel implements com.haulmont.cuba.gui.components.SplitPanel {
|
||||
private int verticalAlIlignment = AlignmentHandler.ALIGNMENT_TOP;
|
||||
private int horizontalAlIlignment = AlignmentHandler.ALIGNMENT_LEFT;
|
||||
|
||||
protected String id;
|
||||
protected Map<String, Component> componentByIds = new HashMap<String, Component>();
|
||||
|
||||
public void add(Component component) {
|
||||
final com.itmill.toolkit.ui.Component itmillComponent = ComponentsHelper.unwrap(component);
|
||||
|
||||
addComponent(itmillComponent);
|
||||
|
||||
if (component.getId() != null) {
|
||||
componentByIds.put(component.getId(), component);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
removeComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.remove(component.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return (T) componentByIds.get(id);
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
return ComponentsHelper.<T>getComponent(this, id);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
setDebugId(id);
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return verticalAlIlignment;
|
||||
}
|
||||
|
||||
public void setVerticalAlIlignment(int verticalAlIlignment) {
|
||||
this.verticalAlIlignment = verticalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof AlignmentHandler) {
|
||||
((AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public int getHorizontalAlIlignment() {
|
||||
return horizontalAlIlignment;
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {
|
||||
this.horizontalAlIlignment = horizontalAlIlignment;
|
||||
final com.itmill.toolkit.ui.Component component = getParent();
|
||||
if (component instanceof AlignmentHandler) {
|
||||
((AlignmentHandler) component).setComponentAlignment(this, horizontalAlIlignment, verticalAlIlignment);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,33 +9,95 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.Action;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.web.data.CollectionDatasourceWrapper;
|
||||
import com.haulmont.chile.core.model.MetaProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
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 org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Table
|
||||
extends
|
||||
AbstractComponent<com.itmill.toolkit.ui.Table>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.Table, Component.Wrapper
|
||||
{
|
||||
protected CollectionDatasource datasource;
|
||||
|
||||
protected List<Action> actionsOrder = new LinkedList<Action>();
|
||||
protected BiMap<Action, com.itmill.toolkit.event.Action> actions =
|
||||
new HashBiMap<Action,com.itmill.toolkit.event.Action>();
|
||||
|
||||
public Table() {
|
||||
component = new com.itmill.toolkit.ui.Table();
|
||||
|
||||
component.setSelectable(true);
|
||||
component.setMultiSelect(false);
|
||||
component.setNullSelectionAllowed(false);
|
||||
component.setImmediate(true);
|
||||
|
||||
component.addActionHandler(new ActionsAdapter());
|
||||
component.addListener(new Property.ValueChangeListener() {
|
||||
public void valueChange(Property.ValueChangeEvent event) {
|
||||
final Set<Object> itemIds = getSelecetdItemIds();
|
||||
if (itemIds == null || itemIds.isEmpty()) {
|
||||
datasource.setItem(null);
|
||||
} else if (itemIds.size() == 1) {
|
||||
final Object id = itemIds.iterator().next();
|
||||
datasource.setItem(datasource.getItem(id));
|
||||
} else {
|
||||
datasource.setItem(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public <T> T getSingleSelected() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
final Set selected = getSelecetdItemIds();
|
||||
return selected == null || selected.isEmpty() ?
|
||||
null : (T) datasource.getItem(selected.iterator().next());
|
||||
}
|
||||
|
||||
public List getSelected() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
public Set getSelected() {
|
||||
final Set<Object> itemIds = getSelecetdItemIds();
|
||||
|
||||
if (itemIds != null) {
|
||||
final HashSet<Object> res = new HashSet<Object>();
|
||||
for (Object id : itemIds) {
|
||||
final Object o = datasource.getItem(id);
|
||||
res.add(o);
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAction(final Action action) {
|
||||
actions.put(action, new ActionWrapper(action));
|
||||
actionsOrder.add(action);
|
||||
}
|
||||
|
||||
public void removeAction(Action action) {
|
||||
actions.remove(action);
|
||||
actionsOrder.remove(action);
|
||||
}
|
||||
|
||||
protected Set<Object> getSelecetdItemIds() {
|
||||
final Object value = component.getValue();
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else if (value instanceof Collection) {
|
||||
return (Set) component.getValue();
|
||||
} else {
|
||||
return Collections.singleton(value);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Column> getColumns() {
|
||||
@ -60,7 +122,12 @@ public class Table
|
||||
component.removeContainerProperty(column.getId());
|
||||
}
|
||||
|
||||
public CollectionDatasource getDatasource() {
|
||||
return datasource;
|
||||
}
|
||||
|
||||
public void setDatasource(CollectionDatasource datasource) {
|
||||
this.datasource = datasource;
|
||||
final CollectionDatasourceWrapper ds =
|
||||
new CollectionDatasourceWrapper(datasource);
|
||||
|
||||
@ -69,4 +136,37 @@ public class Table
|
||||
component.setColumnHeader(metaProperty, StringUtils.capitalize(metaProperty.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
private class ActionsAdapter implements com.itmill.toolkit.event.Action.Handler {
|
||||
public com.itmill.toolkit.event.Action[] getActions(Object target, Object sender) {
|
||||
final List<com.itmill.toolkit.event.Action> res = new ArrayList();
|
||||
for (Action action : actionsOrder) {
|
||||
// if (action.isEnabled()) {
|
||||
res.add(actions.get(action));
|
||||
// }
|
||||
}
|
||||
return res.toArray(new com.itmill.toolkit.event.Action[]{});
|
||||
}
|
||||
|
||||
public void handleAction(com.itmill.toolkit.event.Action tableAction, Object sender, Object target) {
|
||||
final Action action = actions.inverse().get(tableAction);
|
||||
if (action != null) {
|
||||
action.actionPerform(Table.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ActionWrapper extends com.itmill.toolkit.event.Action {
|
||||
private final Action action;
|
||||
|
||||
public ActionWrapper(Action action) {
|
||||
super(action.getCaption());
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCaption() {
|
||||
return action.getCaption();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:12:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.RichTextArea;
|
||||
|
||||
public class TextArea
|
||||
extends
|
||||
AbstractField<RichTextArea>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.TextArea, Component.Wrapper {
|
||||
|
||||
public TextArea() {
|
||||
this.component = new RichTextArea();
|
||||
}
|
||||
}
|
@ -1,51 +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: 22.12.2008 18:12:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.TextField;
|
||||
|
||||
public class TextBox
|
||||
extends
|
||||
AbstractField<TextField>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.TextBox, Component.Wrapper {
|
||||
|
||||
private boolean flexible;
|
||||
|
||||
public TextBox() {
|
||||
this.component = new TextField();
|
||||
}
|
||||
|
||||
public <T> T getValue() {
|
||||
return (T) component.getValue();
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
component.setValue(value);
|
||||
}
|
||||
|
||||
public String getCaption() {
|
||||
return component.getCaption();
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
component.setCaption(caption);
|
||||
}
|
||||
|
||||
public boolean isFlexible() {
|
||||
return flexible;
|
||||
}
|
||||
|
||||
public void setFlexible(boolean flexible) {
|
||||
this.flexible = flexible;
|
||||
component.setWidth("100%");
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved.
|
||||
* Haulmont Technology proprietary and confidential.
|
||||
* Use is subject to license terms.
|
||||
|
||||
* Author: Dmitry Abramov
|
||||
* Created: 22.12.2008 18:12:13
|
||||
* $Id$
|
||||
*/
|
||||
package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
|
||||
public class TextField
|
||||
extends
|
||||
AbstractField<com.itmill.toolkit.ui.TextField>
|
||||
implements
|
||||
com.haulmont.cuba.gui.components.TextField, Component.Wrapper {
|
||||
|
||||
public TextField() {
|
||||
this.component = new com.itmill.toolkit.ui.TextField();
|
||||
}
|
||||
}
|
@ -11,12 +11,14 @@ package com.haulmont.cuba.web.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
|
||||
public class VBox extends AbstractContainer {
|
||||
public class VBox extends AbstractContainer implements com.haulmont.cuba.gui.components.OrderedLayout {
|
||||
|
||||
public VBox() {
|
||||
super(ExpandLayout.ORIENTATION_VERTICAL);
|
||||
}
|
||||
|
||||
public void expand(Component component, String height, String width) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
@ -63,13 +63,17 @@ public class CollectionDatasourceWrapper implements Container, Container.ItemSet
|
||||
}
|
||||
|
||||
datasource.addListener(new CollectionDatasourceListener() {
|
||||
public void currentChanged(Datasource ds, Object prevItem, Object item) {}
|
||||
public void itemChanged(Datasource ds, Object prevItem, Object item) {}
|
||||
|
||||
public void stateChanged(Datasource ds, Datasource.State prevState, Datasource.State state) {
|
||||
fireItemSetChanged();
|
||||
}
|
||||
|
||||
public void valueChanged(Object source, String property, Object prevValue, Object value) {}
|
||||
|
||||
public void collectionChanged(Datasource ds, CollectionOperation operation) {
|
||||
fireItemSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -43,4 +43,12 @@ public class PropertyWrapper implements Property{
|
||||
public void setReadOnly(boolean newStatus) {
|
||||
readOnly = newStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final Object value = getValue();
|
||||
return metaProperty.getRange().isDatatype() ?
|
||||
metaProperty.getRange().asDatatype().format(value) :
|
||||
value == null ? null : value.toString();
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,16 @@ import com.haulmont.cuba.gui.components.Window;
|
||||
import com.haulmont.cuba.web.components.ComponentsHelper;
|
||||
import com.itmill.toolkit.ui.ExpandLayout;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Screen extends ExpandLayout implements Window
|
||||
{
|
||||
protected ScreenContext screenContext;
|
||||
private String id;
|
||||
|
||||
private Map<String, Component> componentByIds = new HashMap<String, Component>();
|
||||
|
||||
public Screen() {
|
||||
super(ExpandLayout.ORIENTATION_VERTICAL);
|
||||
setMargin(true);
|
||||
@ -28,10 +33,16 @@ public class Screen extends ExpandLayout implements Window
|
||||
|
||||
public void add(Component component) {
|
||||
addComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.put(component.getId(), component);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Component component) {
|
||||
removeComponent(ComponentsHelper.unwrap(component));
|
||||
if (component.getId() != null) {
|
||||
componentByIds.remove(component.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void init(ScreenContext context) {
|
||||
@ -50,6 +61,17 @@ public class Screen extends ExpandLayout implements Window
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
}
|
||||
|
||||
public <T extends Component> T getOwnComponent(String id) {
|
||||
return (T) componentByIds.get(id);
|
||||
}
|
||||
|
||||
public <T extends Component> T getComponent(String id) {
|
||||
return ComponentsHelper.<T>getComponent(this, id);
|
||||
}
|
||||
|
||||
public int getVerticalAlIlignment() {
|
||||
return ALIGNMENT_VERTICAL_CENTER;
|
||||
}
|
||||
@ -61,4 +83,8 @@ public class Screen extends ExpandLayout implements Window
|
||||
}
|
||||
|
||||
public void setHorizontalAlIlignment(int horizontalAlIlignment) {}
|
||||
|
||||
public void expand(Component component, String height, String width) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
@ -25,16 +25,25 @@ public class WebComponentsFactory implements ComponentsFactory {
|
||||
classes.put("window", Screen.class);
|
||||
classes.put("hbox", HBox.class);
|
||||
classes.put("vbox", VBox.class);
|
||||
classes.put("expandable-hbox", ExpandableHBox.class);
|
||||
classes.put("expandable-vbox", ExpandableVBox.class);
|
||||
classes.put("button", Button.class);
|
||||
classes.put("label", Label.class);
|
||||
classes.put("groupbox", GroupBox.class);
|
||||
classes.put("textbox", TextBox.class);
|
||||
classes.put("group-box", GroupBox.class);
|
||||
classes.put("text-field", TextField.class);
|
||||
classes.put("text-area", TextArea.class);
|
||||
classes.put("iframe", IFrame.class);
|
||||
classes.put("table", Table.class);
|
||||
classes.put("date-field", DateField.class);
|
||||
classes.put("lookup-field", LookupField.class);
|
||||
classes.put("split", SplitPanel.class);
|
||||
}
|
||||
|
||||
public <T extends Component> T createComponent(String name) throws InstantiationException, IllegalAccessException {
|
||||
final Class<Component> componentClass = (Class<Component>) classes.get(name);
|
||||
if (componentClass == null) {
|
||||
throw new IllegalStateException(String.format("Can't find component class for '%s'", name));
|
||||
}
|
||||
return (T) componentClass.newInstance();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.5" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="chile" level="project" />
|
||||
<orderEntry type="module" module-name="core" />
|
||||
|
2
root.iml
2
root.iml
@ -5,7 +5,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="1.5" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
Loading…
Reference in New Issue
Block a user