diff --git a/.classpath b/.classpath index 0564845..ce15ddb 100644 --- a/.classpath +++ b/.classpath @@ -5,9 +5,7 @@ - - diff --git a/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch b/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch new file mode 100644 index 0000000..6ef634c --- /dev/null +++ b/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.mymetadata b/.mymetadata index d053dbb..0054d57 100644 --- a/.mymetadata +++ b/.mymetadata @@ -7,7 +7,7 @@ j2ee-spec="5.0" archive="com.idcanet.vasc.war"> - + diff --git a/.project b/.project index e26af5a..4848137 100644 --- a/.project +++ b/.project @@ -25,6 +25,16 @@ + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch + + + org.eclipse.wst.validation.validationbuilder diff --git a/.settings/com.genuitec.eclipse.core.prefs b/.settings/com.genuitec.eclipse.core.prefs new file mode 100644 index 0000000..fc7c45b --- /dev/null +++ b/.settings/com.genuitec.eclipse.core.prefs @@ -0,0 +1,4 @@ +#Thu Jan 08 18:05:54 CET 2009 +eclipse.preferences.version=1 +validator.Checked=target +validator.Unchecked= diff --git a/.settings/com.genuitec.eclipse.j2eedt.core.prefs b/.settings/com.genuitec.eclipse.j2eedt.core.prefs new file mode 100644 index 0000000..80cf3e4 --- /dev/null +++ b/.settings/com.genuitec.eclipse.j2eedt.core.prefs @@ -0,0 +1,4 @@ +#Thu Jan 15 07:20:11 CET 2009 +defaultTldInfo=f\=http\://java.sun.com/jsf/core;http\://java.sun.com/jsf/html\=h;http\://struts.apache.org/tags-bean\=bean;http\://java.sun.com/jsp/jstl/fmt\=fmt;bean\=http\://struts.apache.org/tags-bean;nested\=http\://struts.apache.org/tags-nested;http\://java.sun.com/jsp/jstl/sql\=sql;fmt\=http\://java.sun.com/jsp/jstl/fmt;c\=http\://java.sun.com/jsp/jstl/core;http\://struts.apache.org/tags-logic\=logic;http\://java.sun.com/jsp/jstl/xml\=x;http\://java.sun.com/jsp/jstl/core\=c;logic\=http\://struts.apache.org/tags-logic;h\=http\://java.sun.com/jsf/html;http\://struts.apache.org/tags-tiles\=tiles;http\://java.sun.com/jsp/jstl/functions\=fn;tiles\=http\://struts.apache.org/tags-tiles;sql\=http\://java.sun.com/jsp/jstl/sql;http\://struts.apache.org/tags-html\=html;html\=http\://struts.apache.org/tags-html;http\://struts.apache.org/tags-nested\=nested;http\://java.sun.com/jsf/core\=f;fn\=http\://java.sun.com/jsp/jstl/functions;x\=http\://java.sun.com/jsp/jstl/xml +eclipse.preferences.version=1 +j2ee.deployment.web.archive_dependent_projects=always diff --git a/.settings/com.genuitec.eclipse.ws.blue.prefs b/.settings/com.genuitec.eclipse.ws.blue.prefs new file mode 100644 index 0000000..284916e --- /dev/null +++ b/.settings/com.genuitec.eclipse.ws.blue.prefs @@ -0,0 +1,4 @@ +#Thu Jan 15 07:20:11 CET 2009 +blue.framework.id= +blue.target.server= +eclipse.preferences.version=1 diff --git a/doc/TODO.txt b/doc/TODO.txt index 2a18ce6..97cff65 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -1,25 +1,30 @@ + +- (30%) X4O client/server config - fix frontend event system - make event channels work +- config prefix (and rest of default in finalizer) +- (10%) update SWT frontend +- create JSF frontend +- Make annotations work. +- Multiple SelectItems for addable null's etc. - make sorting work - make searching work - made options work +- auto text converts + - Plugin validation - Plugin Role Parser - Finalizer plugins -- X4O client/server config - Check user roles in frontend - Default/Full Table and templating - Ckeck all validators -- Make annotations work. - Bind to x18n - MetaQuery support -- config prefix (and rest of default in finalizer) -- update SWT frontend -- create JSF frontend - create JSF-extJS frontend - create XML-RPC frontend - +- export interface + exports +- graphs of numeric value columns === DONE === diff --git a/pom.xml b/pom.xml index 639f4dc..b9743d7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,8 @@ 4.0.0 com.idcanet.vasc vasc-main +0.3-SNAPSHOT jar -0.8-SNAPSHOT vasc Simple crud'ing for all. http://www.x4o.org/vasc @@ -75,12 +75,12 @@ 0.8-SNAPSHOT - com.idcanet.serv5 serv5-main 0.6-SNAPSHOT + compile @@ -88,6 +88,7 @@ com.idcanet.xtes xtes-main 0.6-SNAPSHOT + compile @@ -95,6 +96,7 @@ com.idcanet.fff fff-main 0.8-SNAPSHOT + compile @@ -102,6 +104,7 @@ com.novell.ldap jldap 4.3 + compile @@ -109,13 +112,64 @@ com.michaelbaranov microba 0.4.4.1 + compile + - org.eclipse - swt + org.eclipse.swt.gtk.linux + x86 3.3.0-v3346 + provided + + + + org.eclipse + jface + 3.3.0-I20070606-0010 + provided + + + + + + org.apache.openejb + javaee-api + 5.0-1 + provided + + + javax.faces + jsf-api + 1.2_04 + provided + + + javax.servlet + jstl + 1.2 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + javax.faces + jsf-impl + 1.2_04 + provided + + + + + org.apache.myfaces.tomahawk + tomahawk12 + 1.1.8 + compile @@ -123,9 +177,19 @@ org.testng testng 5.8 - test jdk15 + test + + + + + + de.odysseus.juel + juel + 2.1.0 + provided + @@ -184,6 +248,17 @@ + + + maven-source-plugin + + + attach-sources + jar + + + + maven-site-plugin diff --git a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java index c9afc1e..b9d7032 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java @@ -62,61 +62,165 @@ public class VascAnnotationParser { * @param property The property for the ToolTip * @return The i18n key for an ToolTip */ - public String getVascDescriptionKey(Class beanClass,String property) { - return (String)getValue(beanClass,VascDescription.class,property); + public String getVascI18nDescription(Class beanClass,String property) { + return (String)getValue(beanClass,VascI18n.class,property,"description"); } - public String getVascDescriptionKey(Class beanClass) { - return (String)getValue(beanClass,VascDescription.class,null); + public String getVascI18nDescription(Class beanClass) { + return (String)getValue(beanClass,VascI18n.class,null,"description"); + } + + public String getVascI18nName(Class beanClass,String property) { + return (String)getValue(beanClass,VascI18n.class,property,"name"); + } + + public String getVascI18nName(Class beanClass) { + return (String)getValue(beanClass,VascI18n.class,null,"name"); + } + + public String getVascI18nHelpId(Class beanClass,String property) { + return (String)getValue(beanClass,VascI18n.class,property,"helpId"); + } + + public String getVascI18nHelpId(Class beanClass) { + return (String)getValue(beanClass,VascI18n.class,null,"helpId"); + } + + public String getVascI18nImage(Class beanClass,String property) { + return (String)getValue(beanClass,VascI18n.class,property,"image"); + } + + public String getVascI18nImage(Class beanClass) { + return (String)getValue(beanClass,VascI18n.class,null,"image"); + } + + public Integer getVascOrderIndex(Class beanClass,String property) { + return (Integer)getValue(beanClass,VascFieldOrder.class,property,"orderIndex"); + } + + + public Integer getVascStyleSizeList(Class beanClass,String property) { + return (Integer)getValue(beanClass,VascStyle.class,property,"sizeList"); + } + public Integer getVascStyleSizeEdit(Class beanClass,String property) { + return (Integer)getValue(beanClass,VascStyle.class,property,"sizeEdit"); + } + public String getVascStyleStyleList(Class beanClass,String property) { + return (String)getValue(beanClass,VascStyle.class,property,"styleList"); + } + public String getVascStyleStyleEdit(Class beanClass,String property) { + return (String)getValue(beanClass,VascStyle.class,property,"styleEdit"); + } + + + public String getVascFieldBackendName(Class beanClass,String property) { + return (String)getValue(beanClass,VascField.class,property,"backendName"); + } + public Boolean getVascFieldCreate(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"create"); + } + public Boolean getVascFieldEdit(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"edit"); + } + public Boolean getVascFieldEditReadOnly(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"editReadOnly"); + } + public Boolean getVascFieldEditBlank(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"editBlank"); + } + public Boolean getVascFieldList(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"list"); + } + public Boolean getVascFieldView(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"view"); + } + public Boolean getVascFieldOptional(Class beanClass,String property) { + return (Boolean)getValue(beanClass,VascField.class,property,"optional"); + } + + + public String getVascFieldType(Class beanClass,String property) { + return (String)getValue(beanClass,VascFieldType.class,property,"type"); + } + public String[] getVascFieldTypeProperties(Class beanClass,String property) { + return (String[])getValue(beanClass,VascFieldType.class,property,"properties"); + } + + + public String getVascRolesCreate(Class beanClass,String property) { + return (String)getValue(beanClass,VascRoles.class,property,"rolesCreate"); + } + public String getVascRolesEdit(Class beanClass,String property) { + return (String)getValue(beanClass,VascRoles.class,property,"rolesEdit"); + } + public String getVascRolesEditReadOnly(Class beanClass,String property) { + return (String)getValue(beanClass,VascRoles.class,property,"rolesEditReadOnly"); + } + public String getVascRolesList(Class beanClass,String property) { + return (String)getValue(beanClass,VascRoles.class,property,"rolesList"); } /** - * Gets the key of the VascName key for the property of the class - * @param beanClass The class to search for the property - * @param property The property for the Labe - * @return The i18n key for an Label + * TODO: change this, because we need differnce between key and value instance + * @param beanClass + * @param property + * @return */ - public String getVascNameKey(Class beanClass,String property) { - return (String)getValue(beanClass,VascName.class,property); - } - - public String getVascNameKey(Class beanClass) { - return (String)getValue(beanClass,VascName.class,null); - } - - - public Object getVascColumnWidth(Class beanClass,String property) { - return getValue(beanClass,VascColumnWidth.class,property); - } - - public Object getVascColumnWidth(Class beanClass) { - return getValue(beanClass,VascColumnWidth.class,null); - } - - public String getVascHelpId(Class beanClass,String property) { - return (String)getValue(beanClass,VascHelpId.class,property); - } - - public String getVascHelpId(Class beanClass) { - return (String)getValue(beanClass,VascHelpId.class,null); - } - public Object getVascDefaultValue(Class beanClass,String property) { - return getValue(beanClass,VascDefaultValue.class,property); + return getValue(beanClass,VascDefaultValue.class,property,null); } public Object getVascDefaultValue(Class beanClass) { - return getValue(beanClass,VascDefaultValue.class,null); - } - - public String getVascImage(Class beanClass,String property) { - return (String)getValue(beanClass,VascImage.class,property); - } - - public String getVascImage(Class beanClass) { - return (String)getValue(beanClass,VascImage.class,null); + return getValue(beanClass,VascDefaultValue.class,null,null); } + public String getVascDisplayName(Class beanClass) { + for (Method method:beanClass.getMethods()) { + if(method.getName().startsWith("get")==false) { //a bit durty + continue; + } + Annotation anno = method.getAnnotation(VascDisplayName.class); + if (anno==null) { + continue; + } + return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get + } + return null; + } + public String getVascDisplayName(Class beanClass,String property) { + for (Method method:beanClass.getMethods()) { + if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty + continue; + } + VascI18nModelReference mt = method.getAnnotation(VascI18nModelReference.class); + if (mt==null) { + String result = (String)getValue(beanClass,VascField.class,property,"displayName"); + return result; + } + Class typeClass = mt.type(); + if (Object.class==mt.type()) { + typeClass = method.getReturnType(); + } + String name = getVascDisplayName(typeClass); + return name; + } + return null; + } + + public String getVascPrimaryKey(Class beanClass) { + for (Method method:beanClass.getMethods()) { + if(method.getName().startsWith("get")==false) { //a bit durty + continue; + } + Annotation anno = method.getAnnotation(VascPrimaryKey.class); + if (anno==null) { + continue; + } + return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get + } + return null; + } + /** * No oop code here...refactor at some point in time @@ -128,12 +232,16 @@ public class VascAnnotationParser { * @return */ @SuppressWarnings("unchecked") - private Object getValue(Class beanClass,Class annotationType,String property) { + private Object getValue(Class beanClass,Class annotationType,String property,String field) { if(beanClass==null) { throw new NullPointerException("beanClass may not be null"); } if(annotationType==null){ throw new NullPointerException("annotationType may not be null"); } Object result = null; - if(property==null) { + if (property==null) { + String def = beanClass.getName()+"."+annotationType.getSimpleName(); + if (field!=null) { + def = def+"."+field; + } Annotation anno = beanClass.getAnnotation(annotationType); if (anno==null) { // no annotation == no default @@ -146,7 +254,7 @@ public class VascAnnotationParser { return null; } } else { - result = doAnnotation(anno); + result = doAnnotation(anno,def,field); if(result!=null) { return result; } @@ -154,31 +262,35 @@ public class VascAnnotationParser { return null; } } - return beanClass.getName()+"."+annotationType.getSimpleName(); + return def; } String propRest = null; int index = property.indexOf("."); - if(index>0) { + if (index>0) { propRest = property.substring(index+1); property = property.substring(0,index); } - for(Method method:beanClass.getMethods()) { - if(method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty + String def = beanClass.getName()+"."+property+"."+annotationType.getSimpleName(); + if (field!=null) { + def = def+"."+field; + } + for (Method method:beanClass.getMethods()) { + if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty continue; } //logger.finer("Found property: "+property); - VascModelReference mt = method.getAnnotation(VascModelReference.class); - if(mt!=null) { + VascI18nModelReference mt = method.getAnnotation(VascI18nModelReference.class); + if (mt!=null && annotationType.equals(VascI18n.class)) { Class typeClass = mt.type(); - if(Object.class==mt.type()) { + if (Object.class==mt.type()) { typeClass = method.getReturnType(); //return returnType.getName()+"."+annotationType.toString(); } // recursif function: - return getValue(typeClass,annotationType,propRest); + return getValue(typeClass,annotationType,propRest,field); } Annotation anno = method.getAnnotation(annotationType); @@ -186,7 +298,7 @@ public class VascAnnotationParser { if (anno==null && annotationType.equals(VascDefaultValue.class)) { return null; } - result = doAnnotation(anno); + result = doAnnotation(anno,def,field); if(result!=null) { return result; } @@ -195,62 +307,202 @@ public class VascAnnotationParser { } break; // return default } - return beanClass.getName()+"."+property+"."+annotationType.getSimpleName(); + + if (annotationType.equals(VascField.class)) { + try { + if ("backendName".equals(field)) { + return VascField.class.getMethod("backendName").getDefaultValue(); + } + if ("displayName".equals(field)) { + return VascField.class.getMethod("displayName").getDefaultValue(); + } + if ("create".equals(field)) { + return VascField.class.getMethod("create").getDefaultValue(); + } + if ("edit".equals(field)) { + return VascField.class.getMethod("edit").getDefaultValue(); + } + if ("editReadOnly".equals(field)) { + return VascField.class.getMethod("editReadOnly").getDefaultValue(); + } + if ("editBlank".equals(field)) { + return VascField.class.getMethod("editBlank").getDefaultValue(); + } + if ("list".equals(field)) { + return VascField.class.getMethod("list").getDefaultValue(); + } + if ("view".equals(field)) { + return VascField.class.getMethod("view").getDefaultValue(); + } + if ("optional".equals(field)) { + return VascField.class.getMethod("optional").getDefaultValue(); + } + // This are the default value then.... + return null; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + if (annotationType.equals(VascFieldType.class)) { + return null; + } + if (annotationType.equals(VascStyle.class)) { + return null; + } + if (annotationType.equals(VascRoles.class)) { + return null; + } + if (annotationType.equals(VascFieldOrder.class)) { + int indexOrder = 0; + for (Method method:beanClass.getMethods()) { + if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty + indexOrder = indexOrder + 100; + continue; + } + return indexOrder; + } + return null; + } + return def; } - private Object doAnnotation(Annotation b) { + private Object doAnnotation(Annotation b,String def,String field) { if (b==null) { return null; } Class a = b.annotationType(); - if (a.equals(VascName.class)) { - VascName l = (VascName)b; - if("".equals(l.key()) | "null".equals(l.key())) { - return null; - } - return l.key(); + if (a.equals(VascI18n.class)) { + VascI18n l = (VascI18n)b; + String val = null; + + if ("name".equals(field)) { + val = l.name(); + } + if ("description".equals(field)) { + val = l.description(); + } + if ("image".equals(field)) { + val = l.image(); + } + if ("helpId".equals(field)) { + val = l.helpId(); + } + if (val==null) { + val = ""; + } + if ("".equals(val)) { + return def; + } + return val; } - if (a.equals(VascDescription.class)) { - VascDescription t = (VascDescription)b; - if("".equals(t.key()) | "null".equals(t.key())) { - return null; - } - return t.key(); - } - if (a.equals(VascHelpId.class)) { - VascHelpId h = (VascHelpId)b; - if("".equals(h.helpId()) | "null".equals(h.helpId())) { - return null; - } - return h.helpId(); + if (a.equals(VascFieldOrder.class)) { + VascFieldOrder v = (VascFieldOrder)b; + return v.orderIndex(); } if (a.equals(VascDefaultValue.class)) { VascDefaultValue v = (VascDefaultValue)b; - - if(v.defaultValue().equals(Object.class)==false) { - try { - //return v.defaultValue().newInstance(); - } catch (Exception e) { - throw new NullPointerException("Could not init defaultValueClass error: "+e.getMessage()); - } - } if ("null".equals(v.defaultValue())) { return ""; } return v.defaultValue(); } - if (a.equals(VascColumnWidth.class)) { - VascColumnWidth c = (VascColumnWidth)b; - return c.width(); - } - if (a.equals(VascImage.class)) { - VascImage c = (VascImage)b; - if("".equals(c.image()) | "null".equals(c.image())) { - return null; + if (a.equals(VascStyle.class)) { + VascStyle c = (VascStyle)b; + if ("sizeList".equals(field)) { + return c.sizeList(); } - return c.image(); + if ("sizeEdit".equals(field)) { + return c.sizeEdit(); + } + if ("styleList".equals(field)) { + return c.styleList(); + } + if ("styleEdit".equals(field)) { + return c.styleEdit(); + } + return null; } + + if (a.equals(VascField.class)) { + VascField c = (VascField)b; + if ("backendName".equals(field)) { + if ("".equals(c.backendName())) { + return null; + } + return c.backendName(); + } + if ("displayName".equals(field)) { + if ("".equals(c.displayName())) { + return null; + } + return c.displayName(); + } + if ("create".equals(field)) { + return c.create(); + } + if ("edit".equals(field)) { + return c.edit(); + } + if ("editReadOnly".equals(field)) { + return c.editReadOnly(); + } + if ("editBlank".equals(field)) { + return c.editBlank(); + } + if ("list".equals(field)) { + return c.list(); + } + if ("view".equals(field)) { + return c.view(); + } + if ("optional".equals(field)) { + return c.optional(); + } + return null; + } + if (a.equals(VascFieldType.class)) { + VascFieldType c = (VascFieldType)b; + if ("type".equals(field)) { + if ("".equals(c.type())) { + return null; + } + return c.type(); + } + if ("properties".equals(field)) { + return c.properties(); + } + } + if (a.equals(VascRoles.class)) { + VascRoles c = (VascRoles)b; + if ("rolesCreate".equals(field)) { + if ("".equals(c.rolesCreate())) { + return null; + } + return c.rolesCreate(); + } + if ("rolesEdit".equals(field)) { + if ("".equals(c.rolesEdit())) { + return null; + } + return c.rolesEdit(); + } + if ("rolesEditReadOnly".equals(field)) { + if ("".equals(c.rolesEditReadOnly())) { + return null; + } + return c.rolesEditReadOnly(); + } + if ("rolesList".equals(field)) { + if ("".equals(c.rolesList())) { + return null; + } + return c.rolesList(); + } + return null; + } + return null; } diff --git a/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java b/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java new file mode 100644 index 0000000..49177b5 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java @@ -0,0 +1,231 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.annotations; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; + +/** + * Parses the Vasc annotations and generates all i18n keys for you. + * + * @author Willem Cazander + * @version 1.0 Mar 23, 2009 + */ +public class VascBundleKeyGenerator { + + private List> models = null; + private Map keys = null; + private boolean generateName = true; + private boolean generateDescription = true; + private boolean generateImage = true; + private boolean generateHelpId = true; + + public VascBundleKeyGenerator() { + models = new ArrayList>(30); + keys = new HashMap(300); + } + + public void addModelClass(Class model) { + models.add(model); + } + + public List> getModelClasses() { + return models; + } + + + public void generateMissingKeys(StringBuffer buffer,ResourceBundle bundle) { + if (keys.isEmpty()==false) { + keys.clear(); + } + for (Class modelClass:models) { + generatorI18nKeys(modelClass); + } + + List keys2 = new ArrayList(keys.keySet()); + keys2.removeAll(bundle.keySet()); + Collections.sort(keys2); + for (String key:keys2) { + String value = keys.get(key); + buffer.append(key); + buffer.append(" = "); + buffer.append(value); + buffer.append('\n'); + } + } + + public void generateRemoveKeys(StringBuffer buffer,ResourceBundle bundle,String excludeRegex) { + if (keys.isEmpty()==false) { + keys.clear(); + } + for (Class modelClass:models) { + generatorI18nKeys(modelClass); + } + + List keys2 = new ArrayList(bundle.keySet()); + keys2.removeAll(keys.keySet()); + Collections.sort(keys2); + for (String key:keys2) { + // exlude code and user keys + if (excludeRegex!=null && key.matches(excludeRegex)) { + continue; + } + buffer.append(key); + buffer.append('\n'); + } + } + + public void generateKeys(StringBuffer buffer) { + if (keys.isEmpty()==false) { + keys.clear(); + } + for (Class modelClass:models) { + generatorI18nKeys(modelClass); + } + List keys2 = new ArrayList(keys.keySet()); + Collections.sort(keys2); + for (String key:keys2) { + String value = keys.get(key); + buffer.append(key); + buffer.append(" = "); + buffer.append(value); + buffer.append('\n'); + } + } + + private void generatorI18nKeys(Class bean) { + VascAnnotationParser vap = new VascAnnotationParser(); + + String prop1 = bean.getName().substring(bean.getName().lastIndexOf('.')+1); + if (isGenerateName()) { + appendKey(vap.getVascI18nName(bean),prop1); + } + if (isGenerateDescription()) { + appendKey(vap.getVascI18nDescription(bean),prop1); + } + if (isGenerateImage()) { + appendKey(vap.getVascI18nImage(bean),"resources/images/models/"+prop1+".png"); + } + if (isGenerateHelpId()) { + appendKey(vap.getVascI18nHelpId(bean),prop1); + } + + + for (Method method:bean.getMethods()) { + if (method.getName().startsWith("get")==false) { //a bit durty + continue; + } + if (method.getName().equals("getClass")==true) { + continue; + } + String prop = method.getName().substring(3); + prop = prop.substring(0,1).toLowerCase()+prop.substring(1); + + + if (isGenerateName()) { + appendKey(vap.getVascI18nName(bean, prop),prop); + } + if (isGenerateDescription()) { + appendKey(vap.getVascI18nDescription(bean, prop),prop); + } + if (isGenerateImage()) { + appendKey(vap.getVascI18nImage(bean, prop),"resources/images/models/"+prop1+"-"+prop+".png"); + } + if (isGenerateHelpId()) { + appendKey(vap.getVascI18nHelpId(bean),prop); + } + } + } + + private void appendKey(String key,String value) { + if (keys.containsKey(key)) { + return; + } + keys.put(key, value); + } + + /** + * @return the generateName + */ + public boolean isGenerateName() { + return generateName; + } + + /** + * @param generateName the generateName to set + */ + public void setGenerateName(boolean generateName) { + this.generateName = generateName; + } + + /** + * @return the generateDescription + */ + public boolean isGenerateDescription() { + return generateDescription; + } + + /** + * @param generateDescription the generateDescription to set + */ + public void setGenerateDescription(boolean generateDescription) { + this.generateDescription = generateDescription; + } + + /** + * @return the generateImage + */ + public boolean isGenerateImage() { + return generateImage; + } + + /** + * @param generateImage the generateImage to set + */ + public void setGenerateImage(boolean generateImage) { + this.generateImage = generateImage; + } + + /** + * @return the generateHelpId + */ + public boolean isGenerateHelpId() { + return generateHelpId; + } + + /** + * @param generateHelpId the generateHelpId to set + */ + public void setGenerateHelpId(boolean generateHelpId) { + this.generateHelpId = generateHelpId; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascChoices.java b/src/main/java/com/idcanet/vasc/annotations/VascChoices.java index 55c8170..4ed5dfb 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascChoices.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascChoices.java @@ -35,6 +35,8 @@ import java.lang.annotation.Target; /** * Some choises options * + * make also the field type to list + * * @author Willem Cazander * @version 1.0 Aug 19, 2008 */ @@ -42,9 +44,9 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) public @interface VascChoices { - String[] choisesKeys(); + String[] choisesKeys() default {}; String[] choisesNames(); - boolean editAsRadio() default true; + boolean choisesAsRadio() default false; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascDefaultValue.java b/src/main/java/com/idcanet/vasc/annotations/VascDefaultValue.java index 4830ab0..86dd7e4 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascDefaultValue.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascDefaultValue.java @@ -42,12 +42,11 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) public @interface VascDefaultValue { - String key() default "null"; + //String key() default ""; + /** + * Note: special value for default, because else we can not set empty. + * @return + */ String defaultValue() default "null"; - - /** - * The defaultValue of the method - */ - //Class defaultValueClass() default Object.class; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascDisplayName.java b/src/main/java/com/idcanet/vasc/annotations/VascDisplayName.java index 6bdd008..0d879ea 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascDisplayName.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascDisplayName.java @@ -41,13 +41,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface VascDisplayName { - - /** - * The field or fields which are the display name. - * If used on method then field may be left out. - * - */ - String fields() default "null"; - - String format() default "null"; + } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascAdmin.java b/src/main/java/com/idcanet/vasc/annotations/VascEntry.java similarity index 83% rename from src/main/java/com/idcanet/vasc/annotations/VascAdmin.java rename to src/main/java/com/idcanet/vasc/annotations/VascEntry.java index dca021b..fe18002 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascAdmin.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascEntry.java @@ -40,13 +40,24 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface VascAdmin { +public @interface VascEntry { - boolean list() default true; + String id() default ""; + + String headerName() default ""; + + String headerDescription() default ""; + + String headerImage() default ""; + + String helpId() default ""; + + + boolean vascAdminList() default true; - boolean create() default true; + boolean vascAdminCreate() default true; - boolean update() default true; + boolean vascAdminEdit() default true; - boolean delete() default true; + boolean vascAdminDelete() default true; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascEventChannel.java b/src/main/java/com/idcanet/vasc/annotations/VascEventChannel.java index 19a7780..2a843a8 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascEventChannel.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascEventChannel.java @@ -39,7 +39,7 @@ import java.lang.annotation.Target; * @version 1.0 Aug 15, 2008 */ @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) +@Target(ElementType.TYPE) public @interface VascEventChannel { /** diff --git a/src/main/java/com/idcanet/vasc/annotations/VascFieldOptions.java b/src/main/java/com/idcanet/vasc/annotations/VascField.java similarity index 84% rename from src/main/java/com/idcanet/vasc/annotations/VascFieldOptions.java rename to src/main/java/com/idcanet/vasc/annotations/VascField.java index 0bf2716..9a20897 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascFieldOptions.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascField.java @@ -40,17 +40,23 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface VascFieldOptions { - - /** - * - */ - boolean blank() default false; - - /** - * - */ - String choises() default "null"; // + radio admin - - boolean editable() default true; +public @interface VascField { + + String backendName() default ""; + + String displayName() default ""; + + boolean create() default true; + + boolean edit() default true; + + boolean editReadOnly() default false; + + boolean editBlank() default false; + + boolean list() default true; + + boolean view() default true; + + boolean optional() default false; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascHelpId.java b/src/main/java/com/idcanet/vasc/annotations/VascFieldOrder.java similarity index 89% rename from src/main/java/com/idcanet/vasc/annotations/VascHelpId.java rename to src/main/java/com/idcanet/vasc/annotations/VascFieldOrder.java index a1659d9..1bdd4a6 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascHelpId.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascFieldOrder.java @@ -33,17 +33,18 @@ import java.lang.annotation.Target; /** - * Sets the helpId + * Lets you order the fields to better UI bahaivur. * * @author Willem Cazander - * @version 1.0 Mar 28, 2007 + * @version 1.0 Apr 6, 2009 */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD,ElementType.TYPE}) -public @interface VascHelpId { +@Target(ElementType.METHOD) +public @interface VascFieldOrder { /** - * The defaultValue of the method + * The editor of the method/field */ - String helpId() default "null"; + int orderIndex() default 0; + } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascEditorType.java b/src/main/java/com/idcanet/vasc/annotations/VascFieldType.java similarity index 95% rename from src/main/java/com/idcanet/vasc/annotations/VascEditorType.java rename to src/main/java/com/idcanet/vasc/annotations/VascFieldType.java index d65a1fb..9340839 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascEditorType.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascFieldType.java @@ -40,15 +40,15 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface VascEditorType { +public @interface VascFieldType { /** * The editor of the method/field */ - String type() default "null"; + String type() default ""; /** * Hints for the choosen editor */ - String hints() default "null"; + String[] properties() default {}; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascName.java b/src/main/java/com/idcanet/vasc/annotations/VascI18n.java similarity index 92% rename from src/main/java/com/idcanet/vasc/annotations/VascName.java rename to src/main/java/com/idcanet/vasc/annotations/VascI18n.java index 99237b6..4cd3fd7 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascName.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascI18n.java @@ -40,12 +40,18 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD,ElementType.TYPE}) -public @interface VascName { +public @interface VascI18n { /** * The key of the Label default to "null" * @see com.idcanet.i18n.I18nAnnotationParser#getI18nLabelKey(Class, String) * @return The key of the ToolTip */ - String key() default "null"; + String name() default ""; + + String description() default ""; + + String image() default ""; + + String helpId() default ""; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascModelReference.java b/src/main/java/com/idcanet/vasc/annotations/VascI18nModelReference.java similarity index 96% rename from src/main/java/com/idcanet/vasc/annotations/VascModelReference.java rename to src/main/java/com/idcanet/vasc/annotations/VascI18nModelReference.java index 14bcd5f..cf60047 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascModelReference.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascI18nModelReference.java @@ -40,9 +40,7 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface VascModelReference { - - boolean editAsRadio() default true; - +public @interface VascI18nModelReference { + Class type() default Object.class; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascImage.java b/src/main/java/com/idcanet/vasc/annotations/VascImage.java deleted file mode 100644 index 8369e05..0000000 --- a/src/main/java/com/idcanet/vasc/annotations/VascImage.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2004-2006 IDCA. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and - * the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions - * and the following disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the authors and - * should not be interpreted as representing official policies, either expressed or implied, of IDCA. - */ - -package com.idcanet.vasc.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * Sets the VascImage property - * - * @author Willem Cazander - * @version 1.0 May 27, 2006 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD,ElementType.TYPE}) -public @interface VascImage { - - /** - * The resource or key of the Image, default to "null" - * @see com.idcanet.i18n.I18nAnnotationParser#getI18nLabelKey(Class, String) - * @return The key of the ToolTip - */ - String image() default "null"; -} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascUserRoles.java b/src/main/java/com/idcanet/vasc/annotations/VascRoles.java similarity index 91% rename from src/main/java/com/idcanet/vasc/annotations/VascUserRoles.java rename to src/main/java/com/idcanet/vasc/annotations/VascRoles.java index f289edc..418014f 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascUserRoles.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascRoles.java @@ -40,20 +40,23 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface VascUserRoles { +public @interface VascRoles { /** * */ - String list() default "null"; + String rolesCreate() default ""; /** * */ - String edit() default "null"; + String rolesEdit() default ""; /** * */ - String editViewOnly() default "null"; + String rolesEditReadOnly() default ""; + + + String rolesList() default ""; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/annotations/VascColumnWidth.java b/src/main/java/com/idcanet/vasc/annotations/VascStyle.java similarity index 92% rename from src/main/java/com/idcanet/vasc/annotations/VascColumnWidth.java rename to src/main/java/com/idcanet/vasc/annotations/VascStyle.java index 047216e..75c36f9 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascColumnWidth.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascStyle.java @@ -40,7 +40,10 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface VascColumnWidth { +public @interface VascStyle { - int width() default 150; + int sizeList() default 0; + int sizeEdit() default 0; + String styleList() default ""; + String styleEdit() default ""; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcConnectionProvider.java b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcConnectionProvider.java index 8522f32..6dbae00 100644 --- a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcConnectionProvider.java +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcConnectionProvider.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.backends.jdbc; import java.sql.Connection; +import java.sql.SQLException; /** @@ -36,5 +37,5 @@ import java.sql.Connection; */ public interface JdbcConnectionProvider { - public Connection getJdbcConnection(); + public Connection getJdbcConnection() throws SQLException; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcVascBackend.java index 45bad93..8757fc7 100644 --- a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcVascBackend.java @@ -26,11 +26,18 @@ package com.idcanet.vasc.backends.jdbc; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.idcanet.vasc.core.AbstractVascBackend; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; @@ -42,6 +49,11 @@ import com.idcanet.vasc.core.entry.VascEntryRecordCreator; public class JdbcVascBackend extends AbstractVascBackend { private JdbcConnectionProvider jdbcConnectionProvider = null; + private String sqlList = null; + private String idColumn = null; + private String sqlDelete = null; + private String sqlUpdate = null; + private String sqlInsert = null; /** * @return the JdbcConnectionProvider @@ -57,14 +69,33 @@ public class JdbcVascBackend extends AbstractVascBackend { this.jdbcConnectionProvider = jdbcConnectionProvider; } - - - /** * @see com.idcanet.vasc.core.VascBackend#execute() */ public List execute() throws Exception { - return null; + JdbcConnectionProvider prov = getJdbcConnectionProvider(); + Connection connection = prov.getJdbcConnection(); + List result = new ArrayList(50); + try { + Statement s = connection.createStatement(); + s.execute(getSqlList()); + ResultSet rs = s.getResultSet(); + int cols = rs.getMetaData().getColumnCount(); + while (rs.next()) { + Map map = new HashMap(cols); + for (int i=1;i<=cols;i++) { + String columnName = rs.getMetaData().getColumnName(i); + Object columnObject = rs.getObject(i); + map.put(columnName, columnObject); + } + result.add(map); + } + } finally { + if (connection!=null) { + connection.close(); + } + } + return result; } /** @@ -90,13 +121,59 @@ public class JdbcVascBackend extends AbstractVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - return null; + VascEntryFieldValue result = new VascEntryFieldValue() { + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public Object getValue(VascEntryField field, Object record) throws VascException { + Map map = (Map)record; + Object o = map.get(field.getBackendName()); + return o; + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public void setValue(VascEntryField field, Object record,Object value) throws VascException { + Map map = (Map)record; + map.put(field.getBackendName(), value); + } + }; + return result; } /** * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return null; + return new VascEntryRecordCreator() { + + public Class getObjectClass() { + return Map.class; + } + + public Object newRecord(VascEntry entry) throws Exception { + return new HashMap(10); + } + }; } + + /** + * @return the sqlList + */ + public String getSqlList() { + return sqlList; + } + + /** + * @param sqlList the sqlList to set + */ + public void setSqlList(String sqlList) { + this.sqlList = sqlList; + } + + + } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java index 0ceba81..36eda1d 100644 --- a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcXpqlVascBackend.java @@ -37,6 +37,7 @@ import java.util.Map; import com.idcanet.vasc.core.AbstractVascBackend; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; import com.idcanet.xtes.xpql.query.QueryParameterValue; @@ -65,33 +66,54 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend { public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) { this.jdbcConnectionProvider = jdbcConnectionProvider; } + + /** + * @return the query + */ + public com.idcanet.xtes.xpql.query.Query getQuery() { + return query; + } + + /** + * @param query the query to set + */ + public void setQuery(com.idcanet.xtes.xpql.query.Query query) { + this.query = query; + } /** * @see com.idcanet.vasc.core.VascBackend#execute() */ public List execute() throws Exception { + // Copy parameters + for (String key:getDataParameterKeys()) { + Object value = getDataParameter(key); + query.setQueryParameter(key, value); + } Connection c = getJdbcConnectionProvider().getJdbcConnection(); try { PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query)); List values = query.getOrderQueryParameterValues(); - int i = 0; + int ii = 1; for (QueryParameterValue value:values) { - q.setObject(i,value.getValue()); - i++; + q.setObject(ii,value.getValue()); + ii++; } q.execute(); ResultSet rs = q.getResultSet(); - - List data = new ArrayList(100); - do { - Map obj = new HashMap(10); - for (i=0;i result = new ArrayList(50); + while (rs.next()) { + Map map = new HashMap(cols); + for (int i=1;i<=cols;i++) { + String columnName = rs.getMetaData().getColumnName(i); + Object columnObject = rs.getObject(i); + map.put(columnName, columnObject); + } + result.add(map); + } + return result; } finally { if (c!=null) { c.close(); @@ -122,13 +144,42 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - return null; + VascEntryFieldValue result = new VascEntryFieldValue() { + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public Object getValue(VascEntryField field, Object record) throws VascException { + Map map = (Map)record; + Object o = map.get(field.getBackendName()); + return o; + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) + */ + @SuppressWarnings("unchecked") + public void setValue(VascEntryField field, Object record,Object value) throws VascException { + Map map = (Map)record; + map.put(field.getBackendName(), value); + } + }; + return result; } /** * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return null; + return new VascEntryRecordCreator() { + + public Class getObjectClass() { + return Map.class; + } + + public Object newRecord(VascEntry entry) throws Exception { + return new HashMap(10); + } + }; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java b/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java new file mode 100644 index 0000000..0679f86 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java @@ -0,0 +1,112 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.backends.jdbc; + +import java.sql.Connection; +import java.sql.SQLException; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.sql.DataSource; + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 15, 2009 + */ +public class JdniDataSourceJdbcConnectionProvider implements JdbcConnectionProvider { + + /** The context in which database data sources are found. */ + private String dataSourceContext = "java:comp/env/jdbc/"; + + private String dataSourceName = null; + + /** + * @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection() + */ + public Connection getJdbcConnection() throws SQLException { + Connection connection = getDataSource(dataSourceName).getConnection(); + return connection; + } + + + /** + * Gets a DataSource out of the JNDI context. + *

+ * @param name The name of the data source in the JDNI context. + * @return The data source. + */ + private DataSource getDataSource(String name) throws SQLException { + + try { + Context initialContext = new InitialContext(); + if ( initialContext == null ) { + throw new SQLException("Cannot get Initial Context"); + } + DataSource datasource = (DataSource)initialContext.lookup(dataSourceContext+name); + if ( datasource == null ) { + throw new SQLException("Cannot lookup datasource: "+name); + } + return datasource; + } catch ( NamingException e ) { + throw new SQLException("Cannot get connection " + e,e); + } + } + + + /** + * @return the dataSourceContext + */ + public String getDataSourceContext() { + return dataSourceContext; + } + + + /** + * @param dataSourceContext the dataSourceContext to set + */ + public void setDataSourceContext(String dataSourceContext) { + this.dataSourceContext = dataSourceContext; + } + + + /** + * @return the dataSourceName + */ + public String getDataSourceName() { + return dataSourceName; + } + + + /** + * @param dataSourceName the dataSourceName to set + */ + public void setDataSourceName(String dataSourceName) { + this.dataSourceName = dataSourceName; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/SimpleJdbcConnectionProvider.java b/src/main/java/com/idcanet/vasc/backends/jdbc/SimpleJdbcConnectionProvider.java new file mode 100644 index 0000000..317477f --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/SimpleJdbcConnectionProvider.java @@ -0,0 +1,121 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.backends.jdbc; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + + +/** + * + * @author Willem Cazander + * @version 1.0 Mar 15, 2009 + */ +public class SimpleJdbcConnectionProvider implements JdbcConnectionProvider { + + private String driverClassName = null; + private String dbUrl = null; + private String dbUser = null; + private String dbPassword = null; + private boolean loadedDriver = false; + + /** + * @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection() + */ + public Connection getJdbcConnection() throws SQLException { + if (loadedDriver==false) { + try { + Class.forName(driverClassName); + loadedDriver = true; + } catch (ClassNotFoundException e) { + throw new SQLException("Could not load driver: "+driverClassName+" error: "+e.getMessage(),e); + } + } + Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword); + return connection; + } + + /** + * @return the driverClassName + */ + public String getDriverClassName() { + return driverClassName; + } + + /** + * @param driverClassName the driverClassName to set + */ + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + /** + * @return the dbUrl + */ + public String getDbUrl() { + return dbUrl; + } + + /** + * @param dbUrl the dbUrl to set + */ + public void setDbUrl(String dbUrl) { + this.dbUrl = dbUrl; + } + + /** + * @return the dbUser + */ + public String getDbUser() { + return dbUser; + } + + /** + * @param dbUser the dbUser to set + */ + public void setDbUser(String dbUser) { + this.dbUser = dbUser; + } + + /** + * @return the dbPassword + */ + public String getDbPassword() { + return dbPassword; + } + + /** + * @param dbPassword the dbPassword to set + */ + public void setDbPassword(String dbPassword) { + this.dbPassword = dbPassword; + } + + + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java index c2242df..3e50c35 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java @@ -37,19 +37,17 @@ import com.idcanet.vasc.core.AbstractVascBackend; */ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend { - /** - * Provides a hibernate session which is closed !! when transaction is compleeted. - * @return - */ abstract EntityManager getEntityManager(); public void persist(Object object) throws Exception { EntityManager s = getEntityManager(); try { + s.getTransaction().begin(); s.persist(object); + s.getTransaction().commit(); } finally { if (s!=null) { - s.close(); + //s.close(); } } } @@ -57,10 +55,13 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend public Object merge(Object object) throws Exception { EntityManager s = getEntityManager(); try { - return s.merge(object); + s.getTransaction().begin(); + Object result = s.merge(object); + s.getTransaction().commit(); + return result; } finally { if (s!=null) { - s.close(); + //s.close(); } } } @@ -68,11 +69,13 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend public void delete(Object object) throws Exception { EntityManager s = getEntityManager(); try { + s.getTransaction().begin(); Object newObject = s.merge(object); s.remove(newObject); + s.getTransaction().commit(); } finally { if (s!=null) { - s.close(); + //s.close(); } } } diff --git a/src/main/java/com/idcanet/vasc/validators/VascValidatorField.java b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java similarity index 78% rename from src/main/java/com/idcanet/vasc/validators/VascValidatorField.java rename to src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java index b4893f2..ccb5933 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascValidatorField.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 IDCA. All rights reserved. + * Copyright 2004-2007 IDCA. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the * following conditions are met: @@ -24,24 +24,17 @@ * should not be interpreted as representing official policies, either expressed or implied, of IDCA. */ -package com.idcanet.vasc.validators; +package com.idcanet.vasc.backends.jpa; + +import javax.persistence.EntityManager; /** - * The VascValidator interface * * @author Willem Cazander - * @version 1.0 Sep 5, 2008 + * @version 1.0 Mar 21, 2009 */ -public class VascValidatorField { - - final private String propertyName = null; - final private String message = null; - final private Object value = null; - final private Class beanClass = null; - final private Object beanObject = null; +public interface EntityManagerProvider { - public VascValidatorField() { - - } + public EntityManager getEntityManager(); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java index bcf3b8f..06ae566 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java @@ -64,11 +64,16 @@ public class Serv5XpqlHibernateVascBackend extends AbstractHibernateVascBackend @SuppressWarnings("unchecked") public List execute() throws Exception { + // Copy parameters + for (String key:getDataParameterKeys()) { + Object value = getDataParameter(key); + query.setQueryParameter(key, value); + } Session s = getHibernateSession(); try { Query q = s.createQuery(query.toPreparedSQL(query)); List values = query.getOrderQueryParameterValues(); - int i = 0; + int i = 1; for (QueryParameterValue value:values) { q.setParameter(i,value.getValue()); i++; diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java new file mode 100644 index 0000000..57d045f --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java @@ -0,0 +1,250 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.backends.jpa; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.vasc.core.entry.VascEntryRecordCreator; +import com.idcanet.x4o.element.ElementParameterHelper; +import com.idcanet.x4o.impl.DefaultElementParameterHelper; +import com.idcanet.xtes.xpql.query.QueryParameterValue; + +/** + * Manages persistance with xpql queries + * + * @author Willem Cazander + * @version 1.0 Mar 17, 2009 + */ +public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend { + + private EntityManagerProvider entityManagerProvider = null; + + private com.idcanet.xtes.xpql.query.Query query = null; + + private com.idcanet.xtes.xpql.query.Query queryTotal = null; + + private Class resultClass = null; + + public XpqlPersistanceVascBackend() { + } + + /** + * @see com.idcanet.vasc.backends.jpa.AbstractPersistenceVascBackend#getEntityManager() + */ + @Override + EntityManager getEntityManager() { + return entityManagerProvider.getEntityManager(); + } + + + + @SuppressWarnings("unchecked") + public List execute() throws Exception { + + // Copy parameters + for (String key:getDataParameterKeys()) { + Object value = getDataParameter(key); + query.setQueryParameter(key, value); + if (queryTotal!=null) { + queryTotal.setQueryParameter(key, value); + } + } + + //if (isPageable()) { + //query.setQueryParameter("offset", getPageIndex()); + //query.setQueryParameter("limit", getPageSize()); + //} + + EntityManager em = getEntityManager(); + try { + if (queryTotal!=null) { + Query q = em.createQuery(queryTotal.toPreparedSQL(queryTotal)); + List values = queryTotal.getOrderQueryParameterValues(); + int i = 1; + for (QueryParameterValue value:values) { + q.setParameter(i,value.getValue()); + i++; + } + Long resultTotal = (Long)q.getSingleResult(); + setPagesTotalRecords(resultTotal); + } + + Query q = em.createQuery(query.toPreparedSQL(query)); + List values = query.getOrderQueryParameterValues(); + int i = 1; + for (QueryParameterValue value:values) { + q.setParameter(i,value.getValue()); + i++; + } + if (isPageable()) { + q.setFirstResult(getPageIndex()); + q.setMaxResults(getPageSize()); + } + List data = q.getResultList(); + if (queryTotal==null) { + setPagesTotalRecords(data.size()); + } + return data; + } finally { + if (em!=null) { + //em.close(); + } + } + } + + /** + * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) + */ + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + VascEntryFieldValue result = new VascEntryFieldValue() { + + private ElementParameterHelper bean = new DefaultElementParameterHelper(); + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + public Object getValue(VascEntryField field, Object record) throws VascException { + try { + Object o = bean.getParameter(record,field.getBackendName()); + return o; + } catch (Exception e) { + throw new VascException(e); + } + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) + */ + public void setValue(VascEntryField field, Object record,Object value) throws VascException { + try { + bean.setParameter(record, field.getBackendName(), value); + } catch (Exception e) { + throw new VascException(e); + } + } + }; + return result; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) + */ + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new VascEntryRecordCreator() { + + public Class getObjectClass() { + return resultClass; + } + + public Object newRecord(VascEntry entry) throws Exception { + return resultClass.newInstance(); + } + }; + } + + /** + * @return the query + */ + public com.idcanet.xtes.xpql.query.Query getQuery() { + return query; + } + + /** + * @param query the query to set + */ + public void setQuery(com.idcanet.xtes.xpql.query.Query query) { + this.query = query; + } + + /** + * @return the queryTotal + */ + public com.idcanet.xtes.xpql.query.Query getQueryTotal() { + return queryTotal; + } + + /** + * @param queryTotal the queryTotal to set + */ + public void setQueryTotal(com.idcanet.xtes.xpql.query.Query queryTotal) { + this.queryTotal = queryTotal; + } + + /** + * @return the resultClass + */ + public Class getResultClass() { + return resultClass; + } + + /** + * @param resultClass the resultClass to set + */ + public void setResultClass(Class resultClass) { + this.resultClass = resultClass; + } + + /** + * @return the entityManagerProvider + */ + public EntityManagerProvider getEntityManagerProvider() { + return entityManagerProvider; + } + + /** + * @param entityManagerProvider the entityManagerProvider to set + */ + public void setEntityManagerProvider(EntityManagerProvider entityManagerProvider) { + this.entityManagerProvider = entityManagerProvider; + } + + /** + * @see com.idcanet.vasc.core.AbstractVascBackend#isPageable() + */ + @Override + public boolean isPageable() { + if (queryTotal==null) { + return false; + } + /* + if (query.getQueryParameterValue("offset")==null) { + return false; + } + if (query.getQueryParameterValue("limit")==null) { + return false; + } + */ + return true; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/ldap/LdapVascBackend.java b/src/main/java/com/idcanet/vasc/backends/ldap/LdapVascBackend.java index bab81e4..97df14c 100644 --- a/src/main/java/com/idcanet/vasc/backends/ldap/LdapVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/ldap/LdapVascBackend.java @@ -27,7 +27,6 @@ package com.idcanet.vasc.backends.ldap; import java.util.ArrayList; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -94,7 +93,7 @@ public class LdapVascBackend extends AbstractVascBackend { int searchScope = LDAPConnection.SCOPE_ONE; String searchBase = baseDN; - System.out.println("\n\tReading object :" + searchBase + " with filter: " + ldapFilter); + //System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter); LDAPSearchResults searchResults = connection.search( searchBase, // object to read searchScope, // scope - read single object @@ -102,18 +101,15 @@ public class LdapVascBackend extends AbstractVascBackend { null, // return all attributes false); // return attrs and values - System.out.println("Got object :" + searchResults.getCount()); while (searchResults.hasMore()) { LDAPEntry entry = searchResults.next(); - System.out.println("We found "+entry.getDN()); Map map = new HashMap(10); LDAPAttributeSet attributeSet = entry.getAttributeSet(); - Iterator i = attributeSet.iterator(); + Iterator i = attributeSet.iterator(); while (i.hasNext()) { - LDAPAttribute attr = (LDAPAttribute)i.next(); - System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue()); - + LDAPAttribute attr = i.next(); + //System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue()); map.put(attr.getName(), attr.getStringValueArray()); } result.add(map); diff --git a/src/main/java/com/idcanet/vasc/backends/meta/MetaModelVascBackend.java b/src/main/java/com/idcanet/vasc/backends/meta/MetaModelVascBackend.java new file mode 100644 index 0000000..e87ed6f --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/meta/MetaModelVascBackend.java @@ -0,0 +1,75 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.backends.meta; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import com.idcanet.vasc.core.AbstractVascBackend; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.vasc.core.entry.VascEntryRecordCreator; + +import dk.eobjects.metamodel.query.Query; + +/** + * + * @author Willem Cazander + * @version 1.0 Dec 19, 2008 + */ +public class MetaModelVascBackend extends AbstractVascBackend { + + private Query listQuery = null; + + // interface + + public void delete(Object object) throws Exception { + } + + public List execute() throws Exception { + return null; + } + + public Object merge(Object object) throws Exception { + return null; + } + + public void persist(Object object) throws Exception { + } + + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return null; + } + + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java b/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java index e1e84df..bf2158b 100644 --- a/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java @@ -26,7 +26,9 @@ package com.idcanet.vasc.core; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -44,6 +46,7 @@ abstract public class AbstractVascBackend implements VascBackend { private String sortField = null; private String searchString = null; private boolean ascending = true; + private long pagesTotalRecords = 0; public AbstractVascBackend() { parameters = new HashMap(10); @@ -97,7 +100,13 @@ abstract public class AbstractVascBackend implements VascBackend { * @see com.idcanet.vasc.core.VascBackend#setPageIndex(int) */ public void setPageIndex(int pageIndex) { - this.pageIndex=pageIndex; + if (pageIndex<1) { + pageIndex = 0; + } + if (pageIndex>(getPagesTotalRecords()/getPageSize())) { + pageIndex = new Long(getPagesTotalRecords()/getPageSize()).intValue(); + } + this.pageIndex=pageIndex; } /** @@ -115,20 +124,39 @@ abstract public class AbstractVascBackend implements VascBackend { } /** - * @see com.idcanet.vasc.core.VascBackend#getPagesTotal() + * Returns the total amount of pages + * @return */ - public int getPagesTotal() { - return 0; + public List getVascBackendPageNumbers() { + int pages = new Long(getPagesTotalRecords()/getPageSize()).intValue(); + List result = new ArrayList(pages); + int counter = 0; + for (int i=0;i<=pages;i++) { + VascBackendPageNumber pn = new VascBackendPageNumber(i); + if (getPageIndex()==i) { + pn.setSelected(true); + } + result.add(pn); + + counter++; + if (counter>45) { + break; + } + } + return result; } + /** * @see com.idcanet.vasc.core.VascBackend#getPagesTotalRecords() */ - public int getPagesTotalRecords() { - return 0; + public long getPagesTotalRecords() { + return pagesTotalRecords; } - + protected void setPagesTotalRecords(long pagesTotalRecords) { + this.pagesTotalRecords=pagesTotalRecords; + } /** diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java b/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java new file mode 100644 index 0000000..77fc045 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java @@ -0,0 +1,233 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.core; + +import java.util.List; +import java.util.Set; + +import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.vasc.core.entry.VascEntryRecordCreator; + +/** + * + * @author Willem Cazander + * @version 1.0 Apr 1, 2009 + */ +abstract public class AbstractVascBackendProxy implements VascBackend { + + protected VascBackend backend = null; + + public AbstractVascBackendProxy(VascBackend backend) { + if (backend==null) { + throw new NullPointerException("backend object mey not be null."); + } + this.backend=backend; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getPagesTotalRecords() + */ + public long getPagesTotalRecords() { + return backend.getPagesTotalRecords(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isSortable() + */ + public boolean isSortable() { + return backend.isSortable(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isSortAscending() + */ + public boolean isSortAscending() { + return backend.isSortAscending(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setSortAscending(boolean) + */ + public void setSortAscending(boolean ascending) { + backend.setSortAscending(ascending); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getSortField() + */ + public String getSortField() { + return backend.getSortField(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setSortField(java.lang.String) + */ + public void setSortField(String name) { + backend.setSortField(name); + } + + /** + * @throws Exception + * @see com.idcanet.vasc.core.VascBackend#execute() + */ + public List execute() throws Exception { + return backend.execute(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object) + */ + public void delete(Object object) throws Exception { + backend.delete(object); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getDataParameter(java.lang.String) + */ + public Object getDataParameter(String key) { + return backend.getDataParameter(key); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getDataParameterKeys() + */ + public Set getDataParameterKeys() { + return backend.getDataParameterKeys(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getVascBackendPageNumbers() + */ + public List getVascBackendPageNumbers() { + return backend.getVascBackendPageNumbers(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isPageable() + */ + public boolean isPageable() { + return backend.isPageable(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isSearchable() + */ + public boolean isSearchable() { + return backend.isSearchable(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object) + */ + public Object merge(Object object) throws Exception { + return backend.merge(object); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object) + */ + public void persist(Object object) throws Exception { + backend.persist(object); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) + */ + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return backend.provideVascEntryFieldValue(field); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) + */ + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return backend.provideVascEntryRecordCreator(vascEntry); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setDataParameter(java.lang.String, java.lang.Object) + */ + public void setDataParameter(String key, Object data) { + backend.setDataParameter(key, data); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getId() + */ + public String getId() { + return backend.getId(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setId(java.lang.String) + */ + public void setId(String id) { + backend.setId(id); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getPageIndex() + */ + public int getPageIndex() { + return backend.getPageIndex(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setPageIndex(int) + */ + public void setPageIndex(int index) { + backend.setPageIndex(index); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getPageSize() + */ + public int getPageSize() { + return backend.getPageSize(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setPageSize(int) + */ + public void setPageSize(int size) { + backend.setPageSize(size); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#getSearchString() + */ + public String getSearchString() { + return backend.getSearchString(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#setSearchString(java.lang.String) + */ + public void setSearchString(String searchString) { + backend.setSearchString(searchString); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascEntryFieldType.java b/src/main/java/com/idcanet/vasc/core/AbstractVascEntryFieldType.java index 89ab19d..1c75f07 100644 --- a/src/main/java/com/idcanet/vasc/core/AbstractVascEntryFieldType.java +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascEntryFieldType.java @@ -42,20 +42,26 @@ import com.idcanet.vasc.validators.VascValidator; */ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { - private String id = null; - private Class autoDetectClass = null; - private List vascValidators = null; - private Map properties = null; + protected String id = null; + protected Class autoDetectClass = null; + protected List vascValidators = null; + protected Map properties = null; - private Object dataObject = null; - private String uiComponentId = null; - private String inputMask = null; + protected Object dataObject = null; + protected String uiComponentId = null; + protected String inputMask = null; public AbstractVascEntryFieldType() { vascValidators = new ArrayList(4); properties = new HashMap(); } + /** + * @see java.lang.Object#clone() + */ + @Override + abstract public VascEntryFieldType clone() throws CloneNotSupportedException; + /** * @see com.idcanet.vasc.core.VascEntryFieldType#getId() */ diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java b/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java index 625e54f..78425b2 100644 --- a/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascFrontend.java @@ -40,7 +40,7 @@ abstract public class AbstractVascFrontend implements VascFrontend { return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params); } - protected VascEntry getVascEntry() { + public VascEntry getVascEntry() { return entry; } diff --git a/src/main/java/com/idcanet/vasc/core/VascBackend.java b/src/main/java/com/idcanet/vasc/core/VascBackend.java index abbad39..398bb1f 100644 --- a/src/main/java/com/idcanet/vasc/core/VascBackend.java +++ b/src/main/java/com/idcanet/vasc/core/VascBackend.java @@ -81,9 +81,13 @@ public interface VascBackend { * Returns the total amount of pages * @return */ - public int getPagesTotal(); + public List getVascBackendPageNumbers(); - public int getPagesTotalRecords(); + /** + * Returns the total amount of records. + * @return + */ + public long getPagesTotalRecords(); public void setPageSize(int size); diff --git a/src/main/java/com/idcanet/vasc/annotations/VascDescription.java b/src/main/java/com/idcanet/vasc/core/VascBackendPageNumber.java similarity index 67% rename from src/main/java/com/idcanet/vasc/annotations/VascDescription.java rename to src/main/java/com/idcanet/vasc/core/VascBackendPageNumber.java index ba9e9de..c86e947 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascDescription.java +++ b/src/main/java/com/idcanet/vasc/core/VascBackendPageNumber.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006 IDCA. All rights reserved. + * Copyright 2004-2007 IDCA. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the * following conditions are met: @@ -24,28 +24,25 @@ * should not be interpreted as representing official policies, either expressed or implied, of IDCA. */ -package com.idcanet.vasc.annotations; +package com.idcanet.vasc.core; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import java.io.Serializable; /** - * Sets the I18nToolTip(non default) an a Class property + * Small class to wrap page number and the selected page number. + * note: this can be removed when JSF has the combined EL. * * @author Willem Cazander - * @version 1.0 May 27, 2006 + * @version 1.0 Apr 25, 2006 */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD,ElementType.TYPE}) -public @interface VascDescription { - - /** - * The key of the ToolTip default to "null" - * @see com.idcanet.i18n.I18nAnnotationParser#getI18nToolTipKey(Class, String) - * @return The key of the ToolTip - */ - String key() default "null"; +public class VascBackendPageNumber implements Serializable { + private static final long serialVersionUID = 1L; + private Integer pageNumber = null; + private Boolean selected = false; + public VascBackendPageNumber(Integer pageNumber) { this.pageNumber=pageNumber; } + public Integer getPageNumber() { return pageNumber; } + public Boolean getSelected() { return selected; } + public Boolean getNotSelected() { return !selected; } + public void setSelected(Boolean selected) { this.selected=selected; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascEntry.java b/src/main/java/com/idcanet/vasc/core/VascEntry.java index 17c0cdd..0bda42a 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntry.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntry.java @@ -31,13 +31,13 @@ import java.util.List; import com.idcanet.vasc.core.actions.ColumnVascAction; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; /** * * TODO: * private List userOptions = null; * private List listeners = null; - * private Map vascLinks = null; * private Map vascFunctions = null; * * @@ -56,26 +56,6 @@ public interface VascEntry extends Cloneable { */ public void setId(String id); - /** - * @return the name - */ - public String getName(); - - /** - * @param name the name to set - */ - public void setName(String name); - - /** - * @return the description - */ - public String getDescription(); - - /** - * @param description the description to set - */ - public void setDescription(String description); - /** * @return the helpId */ @@ -147,44 +127,44 @@ public interface VascEntry extends Cloneable { public void setDisplayNameFieldId(String displayNameField); /** - * @return the vascAdmimList + * @return the vascAdminList */ - public boolean isVascAdmimList(); + public boolean isVascAdminList(); /** - * @param vascAdmimList the vascAdmimList to set + * @param vascAdminList the vascAdminList to set */ - public void setVascAdmimList(boolean vascAdmimList); + public void setVascAdminList(boolean vascAdminList); /** - * @return the vascAdmimEdit + * @return the vascAdminEdit */ - public boolean isVascAdmimEdit(); + public boolean isVascAdminEdit(); /** - * @param vascAdmimEdit the vascAdmimEdit to set + * @param vascAdminEdit the vascAdminEdit to set */ - public void setVascAdmimEdit(boolean vascAdmimEdit); + public void setVascAdminEdit(boolean vascAdminEdit); /** - * @return the vascAdmimCreate + * @return the vascAdminCreate */ - public boolean isVascAdmimCreate(); + public boolean isVascAdminCreate(); /** - * @param vascAdmimCreate the vascAdmimCreate to set + * @param vascAdminCreate the vascAdminCreate to set */ - public void setVascAdmimCreate(boolean vascAdmimCreate); + public void setVascAdminCreate(boolean vascAdminCreate); /** - * @return the vascAdmimDelete + * @return the vascAdminDelete */ - public boolean isVascAdmimDelete(); + public boolean isVascAdminDelete(); /** - * @param vascAdmimDelete the vascAdmimDelete to set + * @param vascAdminDelete the vascAdminDelete to set */ - public void setVascAdmimDelete(boolean vascAdmimDelete); + public void setVascAdminDelete(boolean vascAdminDelete); /** * @return the vascFields @@ -290,4 +270,34 @@ public interface VascEntry extends Cloneable { public String getBackendId(); public void setBackendId(String backendId); + + + + /** + * @return the vascDisplayOnly + */ + public boolean isVascDisplayOnly(); + + /** + * @param vascDisplayOnly the vascDisplayOnly to set + */ + public void setVascDisplayOnly(boolean vascDisplayOnly); + + + /** + * @return the vascEntryFieldEventChannel + */ + public VascEntryFieldEventChannel getVascEntryFieldEventChannel(); + + /** + * @param vascEntryFieldEventChannel the vascEntryFieldEventChannel to set + */ + public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel); + + /** + * Force impl to have public clone methode + * @return + * @throws CloneNotSupportedException + */ + public VascEntry clone() throws CloneNotSupportedException; } diff --git a/src/main/java/com/idcanet/vasc/core/VascEntryField.java b/src/main/java/com/idcanet/vasc/core/VascEntryField.java index e243a68..08cb59f 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntryField.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntryField.java @@ -28,7 +28,6 @@ package com.idcanet.vasc.core; import java.util.List; -import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.validators.VascValidator; @@ -40,7 +39,7 @@ import com.idcanet.vasc.validators.VascValidator; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascEntryField { +public interface VascEntryField extends Cloneable { /** * @return the VascEntry @@ -91,17 +90,7 @@ public interface VascEntryField { * @param vascEntryFieldValue the vascEntryFieldValue to set */ public void setVascEntryFieldValue(VascEntryFieldValue vascEntryFieldValue); - - /** - * @return the vascEntryFieldEventChannel - */ - public VascEntryFieldEventChannel getVascEntryFieldEventChannel(); - - /** - * @param vascEntryFieldEventChannel the vascEntryFieldEventChannel to set - */ - public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel); - + /** * @return the vascValidators */ @@ -220,62 +209,62 @@ public interface VascEntryField { /** * @return the view */ - public boolean isView(); + public Boolean getView(); /** * @param view the view to set */ - public void setView(boolean view); + public void setView(Boolean view); /** * @return the optional */ - public boolean isOptional(); + public Boolean getOptional(); /** * @param optional the optional to set */ - public void setOptional(boolean optional); + public void setOptional(Boolean optional); /** * @return the create */ - public boolean isCreate(); + public Boolean getCreate(); /** * @param create the create to set */ - public void setCreate(boolean create); + public void setCreate(Boolean create); /** * @return the edit */ - public boolean isEdit(); + public Boolean getEdit(); /** * @param edit the edit to set */ - public void setEdit(boolean edit); + public void setEdit(Boolean edit); /** * @return the editReadOnly */ - public boolean isEditReadOnly(); + public Boolean getEditReadOnly(); /** * @param editReadOnly the editReadOnly to set */ - public void setEditReadOnly(boolean editReadOnly); + public void setEditReadOnly(Boolean editReadOnly); /** * @return the list */ - public boolean isList(); + public Boolean getList(); /** * @param list the list to set */ - public void setList(boolean list); + public void setList(Boolean list); /** * @return the rolesCreate @@ -316,4 +305,82 @@ public interface VascEntryField { * @param rolesList the rolesList to set */ public void setRolesList(String rolesList); + + + /** + * @return the choicesAsRadio + */ + public Boolean getChoicesAsRadio(); + + /** + * @param choicesAsRadio the choicesAsRadio to set + */ + public void setChoicesAsRadio(Boolean choicesAsRadio); + + /** + * @return the editBlank + */ + public Boolean getEditBlank(); + + /** + * @param editBlank the editBlank to set + */ + public void setEditBlank(Boolean editBlank); + + /** + * @return the displayName + */ + public String getDisplayName(); + + /** + * @param displayName the displayName to set + */ + public void setDisplayName(String displayName); + + /** + * @return the orderIndex + */ + public Integer getOrderIndex(); + + /** + * @param orderIndex the orderIndex to set + */ + public void setOrderIndex(Integer orderIndex); + + /** + * @return the sortable + */ + public Boolean getSortable(); + + /** + * @param sortable the sortable to set + */ + public void setSortable(Boolean sortable); + + /** + * @return the sumable + */ + public Boolean getSumable(); + + /** + * @param sumable the sumable to set + */ + public void setSumable(Boolean sumable); + + /** + * @return the graphable + */ + public Boolean getGraphable(); + + /** + * @param graphable the graphable to set + */ + public void setGraphable(Boolean graphable); + + /** + * Force impl to have public clone methode + * @return + * @throws CloneNotSupportedException + */ + public VascEntryField clone() throws CloneNotSupportedException; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascEntryFieldSet.java b/src/main/java/com/idcanet/vasc/core/VascEntryFieldSet.java index 9dc146c..3fce41f 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntryFieldSet.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntryFieldSet.java @@ -36,7 +36,7 @@ import java.util.List; * @author Willem Cazander * @version 1.0 Sep 56, 2008 */ -public interface VascEntryFieldSet { +public interface VascEntryFieldSet extends Cloneable { /** * @return the id @@ -144,4 +144,11 @@ public interface VascEntryFieldSet { * @param vascEntryFieldIds the vascEntryFieldIds to remove */ public void removeVascEntryFieldId(String vascEntryFieldId); + + /** + * Force impl to have public clone methode + * @return + * @throws CloneNotSupportedException + */ + public VascEntryFieldSet clone() throws CloneNotSupportedException; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java b/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java index 069506a..9ee5814 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java @@ -67,4 +67,11 @@ public interface VascEntryFieldType { public VascUIComponent provideLabelUIComponent(int index,VascEntryField entryField) throws VascException; public VascUIComponent provideEditorUIComponent(int index,VascEntryField entryField) throws VascException; public VascValueModel provideEditorVascValueModel(int index,VascEntryField entryField) throws VascException; + + /** + * Force impl to have public clone methode + * @return + * @throws CloneNotSupportedException + */ + public VascEntryFieldType clone() throws CloneNotSupportedException; } diff --git a/src/main/java/com/idcanet/vasc/core/VascEntryFieldTypeControllerLocal.java b/src/main/java/com/idcanet/vasc/core/VascEntryFieldTypeControllerLocal.java new file mode 100644 index 0000000..d019818 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/core/VascEntryFieldTypeControllerLocal.java @@ -0,0 +1,38 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.core; + + +/** + * + * @author Willem Cazander + * @version 1.0 Dec 19, 2008 + */ +public interface VascEntryFieldTypeControllerLocal extends VascEntryFieldTypeController { + + public void addVascEntryFieldType(VascEntryFieldType vascEntryFieldType); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascEventChannelController.java b/src/main/java/com/idcanet/vasc/core/VascEventChannelController.java index 2e3bf54..58b6dc5 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEventChannelController.java +++ b/src/main/java/com/idcanet/vasc/core/VascEventChannelController.java @@ -34,5 +34,5 @@ package com.idcanet.vasc.core; */ public interface VascEventChannelController { - + public void publishEntryEvent(String entryId); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascEventChannelControllerLocal.java b/src/main/java/com/idcanet/vasc/core/VascEventChannelControllerLocal.java new file mode 100644 index 0000000..16691c4 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/core/VascEventChannelControllerLocal.java @@ -0,0 +1,38 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.core; + + +/** + * + * @author Willem Cazander + * @version 1.0 Dec 19, 2008 + */ +public interface VascEventChannelControllerLocal extends VascEventChannelController { + + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascFrontendData.java b/src/main/java/com/idcanet/vasc/core/VascFrontendData.java index 245281f..1d612e2 100644 --- a/src/main/java/com/idcanet/vasc/core/VascFrontendData.java +++ b/src/main/java/com/idcanet/vasc/core/VascFrontendData.java @@ -102,4 +102,14 @@ public interface VascFrontendData { public void addFieldVascUIComponents(VascEntryField field,VascUIComponent uiComponent,Object editor); public VascUIComponent getFieldVascUIComponent(VascEntryField field); public Object getFieldRealRenderer(VascEntryField field); + + /** + * @return the vascBackend + */ + public VascBackend getVascBackend(); + + /** + * @param vascBackend the vascBackend to set + */ + public void setVascBackend(VascBackend vascBackend); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java b/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java index abcea90..f2dd751 100644 --- a/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core; +import com.idcanet.vasc.core.actions.GlobalVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.entry.VascEntryEventListener; @@ -36,6 +38,14 @@ import com.idcanet.vasc.core.entry.VascEntryEventListener; */ public interface VascFrontendHelper { + public boolean renderView(VascEntryField field); + public boolean renderList(VascEntryField field); + public boolean renderEdit(VascEntryField field); + public boolean renderEditReadOnly(VascEntryField field); + public boolean renderCreate(VascEntryField field); + public boolean renderGlobalVascAction(GlobalVascAction action); + public boolean renderRowVascAction(RowVascAction action); + public Integer getTotalColumnsWidth(VascEntry table); public void refreshData(VascEntry table) throws Exception; diff --git a/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java b/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java index b925d7b..4433b11 100644 --- a/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java +++ b/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java @@ -32,9 +32,34 @@ package com.idcanet.vasc.core; * @author Willem Cazander * @version 1.0 Sep 7, 2008 */ -public interface VascLinkEntry { +public interface VascLinkEntry extends Cloneable { - public String getVascEntryName(); - public void setVascEntryName(String vascEntryName); + public String getId(); + public void setId(String id); + public String getVascEntryId(); + public void setVascEntryId(String vascEntryId); + + public String getParameterName(); + public void setParameterName(String parameterName); + + public String getValueFieldId(); + public void setValueFieldId(String valueFieldId); + + /** + * @return the viewAsDetail + */ + public Boolean getViewAsDetail(); + + /** + * @param viewAsDetail the viewAsDetail to set + */ + public void setViewAsDetail(Boolean viewAsDetail); + + /** + * Force impl to have public clone methode + * @return + * @throws CloneNotSupportedException + */ + public VascLinkEntry clone() throws CloneNotSupportedException; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascUserRoleController.java b/src/main/java/com/idcanet/vasc/core/VascUserRoleController.java index c963f00..93cca4e 100644 --- a/src/main/java/com/idcanet/vasc/core/VascUserRoleController.java +++ b/src/main/java/com/idcanet/vasc/core/VascUserRoleController.java @@ -41,4 +41,6 @@ public interface VascUserRoleController { public String getUserName(); public List getUserRoles(); + + public boolean hasRole(String roles); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/actions/AbstractVascAction.java b/src/main/java/com/idcanet/vasc/core/actions/AbstractVascAction.java index 8655a71..36d198d 100644 --- a/src/main/java/com/idcanet/vasc/core/actions/AbstractVascAction.java +++ b/src/main/java/com/idcanet/vasc/core/actions/AbstractVascAction.java @@ -35,29 +35,63 @@ package com.idcanet.vasc.core.actions; */ abstract public class AbstractVascAction implements VascAction { + private String id = null; private String name = null; private String toolTip = null; private String image = null; private String helpId = null; + + public VascAction clone() throws CloneNotSupportedException { + VascAction action; + try { + action = this.getClass().newInstance(); + } catch (Exception e) { + throw new CloneNotSupportedException("Could not create action from myClass: "+e.getMessage()); + } + action.setId(id); + action.setName(name); + action.setToolTip(toolTip); + action.setImage(image); + action.setHelpId(helpId); + return action; + } + + /** + * @see com.idcanet.vasc.core.actions.VascAction#getId() + */ + public String getId() { + return id; + } + + /** + * @see com.idcanet.vasc.core.actions.VascAction#setId(java.lang.String) + */ + public void setId(String id) { + this.id=id; + } + /** * @return the name */ public String getName() { return name; } + /** * @param name the name to set */ public void setName(String name) { this.name = name; } + /** * @return the toolTip */ public String getToolTip() { return toolTip; } + /** * @param toolTip the toolTip to set */ diff --git a/src/main/java/com/idcanet/vasc/core/actions/RowVascAction.java b/src/main/java/com/idcanet/vasc/core/actions/RowVascAction.java index add03d4..2c4ee09 100644 --- a/src/main/java/com/idcanet/vasc/core/actions/RowVascAction.java +++ b/src/main/java/com/idcanet/vasc/core/actions/RowVascAction.java @@ -35,5 +35,7 @@ import com.idcanet.vasc.core.VascEntry; */ public interface RowVascAction extends VascAction { + public boolean isMultiRowAction(); + public void doRowAction(VascEntry vascEntry,Object rowObject) throws Exception; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/actions/VascAction.java b/src/main/java/com/idcanet/vasc/core/actions/VascAction.java index 6012d2b..77a70e2 100644 --- a/src/main/java/com/idcanet/vasc/core/actions/VascAction.java +++ b/src/main/java/com/idcanet/vasc/core/actions/VascAction.java @@ -31,7 +31,11 @@ package com.idcanet.vasc.core.actions; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascAction { +public interface VascAction extends Cloneable { + + public String getId(); + + public void setId(String id); public String getName(); @@ -48,4 +52,11 @@ public interface VascAction { public String getHelpId(); public void setHelpId(String helpId); + + /** + * Force impl to have public clone methode + * @return + * @throws CloneNotSupportedException + */ + public VascAction clone() throws CloneNotSupportedException; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/entry/VascEntryExporter.java b/src/main/java/com/idcanet/vasc/core/entry/VascEntryExporter.java index 0947e23..3ec81bb 100644 --- a/src/main/java/com/idcanet/vasc/core/entry/VascEntryExporter.java +++ b/src/main/java/com/idcanet/vasc/core/entry/VascEntryExporter.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.core.entry; import java.io.OutputStream; +import java.io.Serializable; import com.idcanet.vasc.core.VascEntry; @@ -36,7 +37,7 @@ import com.idcanet.vasc.core.VascEntry; * @author Willem Cazander * @version 1.0 May 19, 2007 */ -public interface VascEntryExporter { +public interface VascEntryExporter extends Serializable { public void doExport(OutputStream out,VascEntry vascEntry) throws Exception; diff --git a/src/main/java/com/idcanet/vasc/core/ui/VascSelectItem.java b/src/main/java/com/idcanet/vasc/core/ui/VascSelectItem.java index dc7e1b2..e15e079 100644 --- a/src/main/java/com/idcanet/vasc/core/ui/VascSelectItem.java +++ b/src/main/java/com/idcanet/vasc/core/ui/VascSelectItem.java @@ -35,6 +35,8 @@ public class VascSelectItem { private String label = null; private Object value = null; + private String keyValue = null; + private boolean disabled = false; public VascSelectItem() { @@ -43,7 +45,11 @@ public class VascSelectItem { setLabel(label); setValue(value); } - + public VascSelectItem(String label,Object value,String keyValue) { + setLabel(label); + setValue(value); + setKeyValue(keyValue); + } /** * @return the label @@ -72,4 +78,32 @@ public class VascSelectItem { public void setValue(Object value) { this.value = value; } + + /** + * @return the keyValue + */ + public String getKeyValue() { + return keyValue; + } + + /** + * @param keyValue the keyValue to set + */ + public void setKeyValue(String keyValue) { + this.keyValue = keyValue; + } + + /** + * @return the disabled + */ + public boolean isDisabled() { + return disabled; + } + + /** + * @param disabled the disabled to set + */ + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } } diff --git a/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java b/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java index cdfd72c..61976df 100644 --- a/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java +++ b/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java @@ -28,6 +28,9 @@ package com.idcanet.vasc.core.ui; import java.util.List; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascException; + /** * * @author Willem Cazander @@ -35,5 +38,5 @@ import java.util.List; */ public interface VascSelectItemModel { - public List getVascSelectItems(); + public List getVascSelectItems(VascEntry entry) throws VascException; } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java b/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java index f638935..16676dd 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java +++ b/src/main/java/com/idcanet/vasc/frontends/swing/SwingVascFrontend.java @@ -114,7 +114,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { // optional UI components vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwingBoolean.class.getName()); - vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwingDate.class.getName()); + //vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwingDate.class.getName()); vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwingTextArea.class.getName()); vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwingColorChooser.class.getName()); } @@ -172,13 +172,13 @@ public class SwingVascFrontend extends AbstractVascFrontend { public void renderDelete(Object rowBean) throws Exception { String beanValue = rowBean.toString(); - if (entry.getDisplayNameFieldId()!=null) { - VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId()); - beanValue = ""+v.getVascEntryFieldValue().getValue(v, rowBean); - if (beanValue.length()>30) { - beanValue=beanValue.substring(0, 30); - } + + VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId()); + beanValue = ""+v.getVascEntryFieldValue().getValue(v, rowBean); + if (beanValue.length()>30) { + beanValue=beanValue.substring(0, 30); } + int response = JOptionPane.showOptionDialog( parent // Center in window. , i18n("vasc.dialog.delete.message",beanValue) // Message @@ -190,7 +190,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { , null // Default button's label ); if (response==JOptionPane.YES_OPTION) { - entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).delete(rowBean); + entry.getVascFrontendData().getVascBackend().delete(rowBean); entry.getVascFrontendData().getEntryDataList().remove(rowBean); entry.getVascFrontendData().setEntryDataObject(null); //entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); @@ -261,7 +261,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { int column = 0; for (VascEntryField c:entry.getVascEntryFields()) { entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean); - if (c.isEdit()==false) { + if (c.getEdit()==false) { continue; } @@ -466,7 +466,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { TableCellRenderer renderer = new JComponentTableHeaderCellRenderer(); int counter=0; for(VascEntryField c:entry.getVascEntryFields()) { - if (c.isList()==false) { + if (c.getList()==false) { continue; } TableColumn t = new TableColumn(); @@ -619,7 +619,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { public int getColumnCount() { int result = 0; for(VascEntryField c:entry.getVascEntryFields()) { - if (c.isList()==false) { + if (c.getList()==false) { continue; } result++; @@ -647,7 +647,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { // TODO: this is slowing.... List list = new ArrayList(); for(VascEntryField c:entry.getVascEntryFields()) { - if (c.isList()==false) { + if (c.getList()==false) { continue; } diff --git a/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingDate.java b/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingDate.java index 870a350..0f44ccc 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingDate.java +++ b/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingDate.java @@ -50,7 +50,7 @@ public class SwingDate implements VascUIComponent { private DatePicker datePicker = null; private Color orgBackgroundColor = null; - + public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { datePicker = new DatePicker(); orgBackgroundColor = datePicker.getBackground(); diff --git a/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingList.java b/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingList.java index 2666160..dfd5da7 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingList.java +++ b/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingList.java @@ -60,7 +60,7 @@ public class SwingList implements VascUIComponent { if (items==null) { comboBox = new JComboBox(); } else { - comboBox = new JComboBox(items.getVascSelectItems().toArray()); + comboBox = new JComboBox(items.getVascSelectItems(table).toArray()); } orgBackgroundColor = comboBox.getBackground(); ((JComponent)gui).add(comboBox); diff --git a/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingTextArea.java b/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingTextArea.java index c5318c8..7d7f6fe 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingTextArea.java +++ b/src/main/java/com/idcanet/vasc/frontends/swing/ui/SwingTextArea.java @@ -28,6 +28,7 @@ package com.idcanet.vasc.frontends.swing.ui; import java.awt.Color; +import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JTextArea; import javax.swing.event.DocumentEvent; @@ -51,6 +52,8 @@ public class SwingTextArea implements VascUIComponent { public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { textArea = new JTextArea(); + textArea.setBorder(BorderFactory.createEtchedBorder()); + textArea.setRows(8); //entryField.getVascEntryFieldType().getProperty(name) diff --git a/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java b/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java index 7908e5e..d038304 100644 --- a/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java +++ b/src/main/java/com/idcanet/vasc/frontends/swt/SwtVascFrontend.java @@ -70,10 +70,14 @@ import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.entry.VascEntryExporter; +import com.idcanet.vasc.core.ui.VascColumnValueModelListener; import com.idcanet.vasc.core.ui.VascUIComponent; -import com.idcanet.vasc.frontends.swing.ui.SwingLabel; -import com.idcanet.vasc.frontends.swing.ui.SwingList; -import com.idcanet.vasc.frontends.swing.ui.SwingText; +import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.swt.ui.SwtBoolean; +import com.idcanet.vasc.frontends.swt.ui.SwtButton; +import com.idcanet.vasc.frontends.swt.ui.SwtLabel; +import com.idcanet.vasc.frontends.swt.ui.SwtText; +import com.idcanet.vasc.frontends.swt.ui.SwtTextArea; /** * @@ -97,15 +101,15 @@ public class SwtVascFrontend extends AbstractVascFrontend { VascFrontendData vfd = getVascEntry().getVascFrontendData(); // required UI components - vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwingLabel.class.getName()); - vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwingText.class.getName()); - vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwingList.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwtLabel.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwtText.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwtButton.class.getName()); // optional UI components - //vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwingBoolean.class.getName()); - //vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwingDate.class.getName()); - //vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwingTextArea.class.getName()); - //vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwingColorChooser.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwtBoolean.class.getName()); + //vfd.putVascUIComponent(VascUIComponent.VASC_DATE , SwtDate.class.getName()); + vfd.putVascUIComponent(VascUIComponent.VASC_TEXTAREA, SwtTextArea.class.getName()); + //vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwtColorChooser.class.getName()); } @@ -143,7 +147,8 @@ public class SwtVascFrontend extends AbstractVascFrontend { public void renderEdit(Object object) throws Exception { logger.fine("Rending Edit View"); - entry.getVascFrontendData().getVascFrontendHelper().initEditObject(entry, object); + + object = entry.getVascFrontendData().getVascFrontendHelper().initEditObject(entry, object); SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),object,"Vasc Edit","Edit"); Object result = dialog.open(); @@ -237,7 +242,12 @@ public class SwtVascFrontend extends AbstractVascFrontend { footer.setLayoutData(new GridData(SWT.NONE)); //createHeader(header); - createBody(body); + try { + createBody(body); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } //createFooter(footer); // should be last @@ -257,45 +267,35 @@ public class SwtVascFrontend extends AbstractVascFrontend { return result; } - public void createBody(Composite body) { + public void createBody(Composite body) throws Exception { body.setLayout(new GridLayout(2, true)); body.setLayoutData(new GridData(GridData.FILL_BOTH)); - for(VascEntryField c:entry.getVascEntryFields()) { - Label l = new Label(body, SWT.WRAP); - l.setText(i18n(c.getName())); - - if(c.getDescription()!=null) { - l.setToolTipText(i18n(c.getDescription())); - } - - try { - entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean); - - //if(c.getVascColumnEditor()==null) { - Label valueLabel = new Label(body, SWT.WRAP); - valueLabel.setText(""+c.getVascEntryFieldValue().getValue(c, bean)); - //c.setColumnEditor(valueLabel); - /* - } else { - c.setColumnEditor(c.getVascColumnEditor().createColumnEditor(c,bean,body)); - } - */ - } catch (Exception e) { - logger.log(Level.WARNING,"Error making column editor: '"+c.getVascEntryFieldValue()+"' error: "+e.getMessage(),e); - } - - /* - if(c.getColumnEditor() instanceof Control) { - Control editor = (Control)c.getColumnEditor(); - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - editor.setLayoutData(gridData); - } - */ + + for (VascEntryField c:entry.getVascEntryFields()) { + entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean); + if (c.getEdit()==false) { + continue; + } + //if (c.isEditReadOnly()==true) { + + for (int i=0;i values = new HashMap(10); + + + /** + * @return the searchString + */ + public String getSearchString() { + return searchString; + } + + /** + * @param searchString the searchString to set + */ + public void setSearchString(String searchString) { + this.searchString = searchString; + } + + /** + * @return the values + */ + public Map getValues() { + return values; + } +} diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java new file mode 100644 index 0000000..5147796 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java @@ -0,0 +1,161 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.faces.FactoryFinder; +import javax.faces.component.UIViewRoot; +import javax.faces.context.FacesContext; +import javax.faces.context.FacesContextFactory; +import javax.faces.lifecycle.Lifecycle; +import javax.faces.lifecycle.LifecycleFactory; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Parses the Request info path info 3 vasc attributes an dispatches the request to the templateFile. + * + * @author Willem Cazander + * @version 1.0 Mar 21, 2009 + */ +public class VascRequestFacesFilter implements Filter { + + private static final long serialVersionUID = 10l; + private Logger logger = null; + private String templateFile = null; + private ServletContext servletContext = null; + + /** + * @see javax.servlet.Filter#destroy() + */ + public void destroy() { + } + + + + /** + * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) + */ + public void init(FilterConfig config) throws ServletException { + logger = Logger.getLogger(VascRequestFacesFilter.class.getName()); + templateFile=config.getInitParameter("templateFile"); + if (templateFile==null) { + throw new ServletException("No templateFile init-param found."); + } + servletContext=config.getServletContext(); + } + + /** + * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) + */ + public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain chain) throws IOException, ServletException { + + HttpServletRequest request = (HttpServletRequest)servletRequest; + HttpServletResponse response = (HttpServletResponse)servletResponse; + + // request info + String path = request.getRequestURI(); + String v = "/vasc/"; + if (path.contains(v)) { + path = path.substring(path.indexOf(v)+v.length()); + } + + // stuff to fill + String entityName = null; + String actionName = null; + String actionRecordId = null; + + // parse request info + //path = path.substring(1); // rm / + int index = path.indexOf("/"); // check next / + String actionString = null; + if (index>0) { + actionString = path.substring(index+1); + entityName = path.substring(0,index); + } else { + entityName = path; + } + + if (actionString!=null) { + index = actionString.indexOf("/"); + String recordString = null; + if (index>0) { + recordString = actionString.substring(index+1); + actionName = actionString.substring(0,index); + } else { + actionName = actionString; + } + if (recordString!=null) { + actionRecordId = recordString; + } + } + + //log + if (logger.isLoggable(Level.INFO)) { + logger.log(Level.INFO,"entityName="+entityName+" actionName="+actionName+" actionRecordId="+actionRecordId); + } + + // add to response + request.setAttribute("requestScopeVascEntityName", entityName); + request.setAttribute("requestScopeVascActionName", actionName); + request.setAttribute("requestScopeVascRecordId" , actionRecordId); + + // Acquire the FacesContext instance for this request + FacesContext facesContext = FacesContext.getCurrentInstance(); + if (facesContext == null) { + logger.info("Creating new context"); + FacesContextFactory facesContextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); + LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); + Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); + + facesContext = facesContextFactory.getFacesContext(servletContext, request, response, lifecycle); + ProtectedFacesContext.setFacesContextAsCurrentInstance(facesContext); + + + UIViewRoot viewRoot = facesContext.getApplication().getViewHandler().createView(facesContext,entityName+actionName); + facesContext.setViewRoot(viewRoot); + logger.info("view Root: "+viewRoot); + } + request.getRequestDispatcher(templateFile).include(request, response); + // done + } + private abstract static class ProtectedFacesContext extends FacesContext { + protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) { + FacesContext.setCurrentInstance(facesContext); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java index 747460c..7781871 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java @@ -27,82 +27,1402 @@ package com.idcanet.vasc.frontends.web.jsf; import java.io.IOException; -import java.util.Date; +import java.io.Serializable; +import java.util.List; import javax.el.ValueExpression; +import javax.faces.application.Application; +import javax.faces.component.UIColumn; import javax.faces.component.UIComponent; import javax.faces.component.UIComponentBase; +import javax.faces.component.UIInput; +import javax.faces.component.UIOutput; +import javax.faces.component.UIPanel; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlCommandButton; import javax.faces.component.html.HtmlInputText; +import javax.faces.component.html.HtmlMessage; +import javax.faces.component.html.HtmlOutputText; +import javax.faces.component.html.HtmlDataTable; +import javax.faces.component.html.HtmlCommandLink; +import javax.faces.component.html.HtmlPanelGrid; +import javax.faces.component.html.HtmlPanelGroup; import javax.faces.context.FacesContext; -import javax.faces.context.ResponseWriter; +import javax.faces.event.ActionEvent; +import javax.faces.event.ActionListener; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.myfaces.custom.datalist.HtmlDataList; + +import com.idcanet.vasc.core.AbstractVascFrontend; +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascController; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascFrontendData; +import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.actions.GlobalVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.entry.VascEntryExporter; +import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFBoolean; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFLabel; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFList; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFText; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFTextArea; +import com.idcanet.vasc.impl.VascBackendProxyPaged; +import com.idcanet.vasc.impl.VascBackendProxySearch; +import com.idcanet.vasc.impl.VascBackendProxySort; /** + * Renders an JSF vasc entry views. * + * This is a bit hacky because I'm not a JSF guro. * * @author Willem Cazander * @version 1.0 Nov 16, 2008 */ public class VascUIComponent extends UIComponentBase { - public static final String COMPONENT_TYPE = "vasc-jsf"; - //public static final String RENDERER_TYPE = "com.idcanet.vasc.frontends.web.jsf.VascUIComponentRenderer"; - + public static final String COMPONENT_TYPE = "com.idcanet.vasc.frontends.web.jsf.VascUIComponent"; private Object[] state = null; - protected String bar; + private ValueExpression vascController = null; + private ValueExpression vascFrontendData = null; + private ValueExpression entryName = null; + private String viewId = null; + private String editId = null; + private String exportId = null; + private String deleteId = null; + private String entryNameRealId = null; + private boolean defaultRenderView = false; + private JSFFrontendRenderer renderer = null; + private DataModel tableDataModel = null; + private DataModel pagesDataModel = null; + private String selectedRecordName = "selectedRecord"; + public VascEntryExporter exporter = null; + public String entryNameOldId = null; - public VascUIComponent() { - //setRendererType(RENDERER_TYPE); + public void resetViews() { + UIPanel panel = getPanel("viewId"); + panel.setRendered(false); + panel = getPanel("editId"); + panel.setRendered(false); + panel = getPanel("exportId"); + panel.setRendered(false); + panel = getPanel("deleteId"); + panel.setRendered(false); } + public UIPanel getPanel(String panel) { + if ("viewId".equals(panel)) { + return findUIPanel(viewId); + } + if ("editId".equals(panel)) { + return findUIPanel(editId); + } + if ("exportId".equals(panel)) { + return findUIPanel(exportId); + } + if ("deleteId".equals(panel)) { + return findUIPanel(deleteId); + } + throw new IllegalArgumentException("ID field unknow."); + } + + private UIPanel findUIPanel(String panelId) { + for (UIComponent c:this.getChildren()) { + if (panelId.equals(c.getId())) { + return (UIPanel)c; + } + } + return null; + } + + protected String i18n(String key,Object...params) { + // TODO change thus + VascEntry entry = getVascEntry(); + return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params); + } + + public VascEntry getVascEntry() { + return renderer.getVascEntry(); + } + + + public VascEntry createClonedVascEntry() { + if (vascController==null) { + throw new NullPointerException("vascController is not set."); + } + if (entryName==null) { + throw new NullPointerException("entryName is not set."); + } + String vascEntityName = null; + VascController vascControllerObj = null; + + if (vascController.isLiteralText()) { + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), vascController.getExpressionString(), VascController.class); + vascControllerObj = (VascController)ve2.getValue(FacesContext.getCurrentInstance().getELContext()); + } else { + vascControllerObj = (VascController)vascController.getValue(FacesContext.getCurrentInstance().getELContext()); + } + + if (entryName.isLiteralText()) { + if (entryName.getExpressionString().startsWith("#") | entryName.getExpressionString().startsWith("$")) { + ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), entryName.getExpressionString(), String.class); + String res = (String)ve3.getValue(FacesContext.getCurrentInstance().getELContext()); + vascEntityName = res; + } else { + vascEntityName = entryName.getExpressionString(); + } + } else { + vascEntityName = (String)entryName.getValue(FacesContext.getCurrentInstance().getELContext()); + } + + if ("".equals(vascEntityName)) { + // this is hackie because faces post back to the included page thats why we loose the requestScope of the vasc servlet + vascEntityName = entryNameRealId; + } + + VascEntry entry = vascControllerObj.getVascEntryControllerResolver().getVascEntryController().getVascEntryById(vascEntityName); + if (entry==null) { + throw new NullPointerException("Could not locate '"+vascEntityName+"' from : "+vascControllerObj+" ("+entryName.getExpressionString()+")"); + } + + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), vascFrontendData.getExpressionString(), VascFrontendData.class); + VascFrontendData frontendData = (VascFrontendData)ve2.getValue(FacesContext.getCurrentInstance().getELContext()); + + frontendData.setVascController(vascControllerObj); + entry.setVascFrontendData(frontendData); + + VascBackend backend = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()); + if (backend.isSearchable()==false) { + backend = new VascBackendProxySearch(backend,entry); + } + if (backend.isPageable()==false) { + backend = new VascBackendProxyPaged(backend,entry); + } + if (backend.isSortable()==false) { + backend = new VascBackendProxySort(backend,entry); + } + frontendData.setVascBackend(backend); + + return entry; + } + + static public VascUIComponent findVascParent(UIComponent comp) { + if (comp==null) { + return null; + } + if (comp instanceof VascUIComponent) { + return (VascUIComponent)comp; + } + return findVascParent(comp.getParent()); + } + + static public VascUIComponent findVascChild(UIComponent comp,String entryId) { + if (comp==null) { + return null; + } + //System.out.println("Checking object: "+comp); + if (comp instanceof VascUIComponent) { + VascUIComponent ui = (VascUIComponent)comp; + if (entryId.equals(ui.getVascEntry().getId())) { + return ui; + } + return null; // this is a other entry on this view + } + for (UIComponent c:comp.getChildren()) { + Object res = findVascChild(c,entryId); + if (res!=null) { + return (VascUIComponent)res; // found + } + } + return null; + } + + // ==== JSF Stuff + public String getFamily () { return COMPONENT_TYPE; } - public String getBar() { - if (null != this.bar) { - return this.bar; + public void restoreState(FacesContext context, Object stateObject) { + state = (Object[])stateObject; + vascController=(ValueExpression)state[0]; + entryName=(ValueExpression)state[1]; + viewId=(String)state[2]; + editId=(String)state[3]; + exportId=(String)state[4]; + deleteId=(String)state[5]; + entryNameRealId=(String)state[6]; + renderer=(JSFFrontendRenderer)state[7]; + tableDataModel=(DataModel)state[8]; + pagesDataModel=(DataModel)state[9]; + vascFrontendData=(ValueExpression)state[10]; + exporter=(VascEntryExporter)state[11]; + entryNameOldId=(String)state[12]; + } + + public Object saveState(FacesContext context) { + state = new Object[13]; + state[0]=vascController; + state[1]=entryName; + state[2]=viewId; + state[3]=editId; + state[4]=exportId; + state[5]=deleteId; + state[6]=entryNameRealId; + state[7]=renderer; + state[8]=tableDataModel; + state[9]=pagesDataModel; + state[10]=vascFrontendData; + state[11]=exporter; + state[12]=entryNameOldId; + return state; + } + + protected void init() { + try { + //System.out.println("Real init of component of vasc."); + + if (renderer!=null) { + return; + } + + VascEntry entry = createClonedVascEntry(); + tableDataModel = new ListDataModel(); + pagesDataModel = new ListDataModel(); + + // lets load data; + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + List data = entry.getVascFrontendData().getEntryDataList(); + tableDataModel.setWrappedData(data); + pagesDataModel.setWrappedData(entry.getVascFrontendData().getVascBackend().getVascBackendPageNumbers()); + + renderer = new JSFFrontendRenderer(); + renderer.initEntry(entry); + + viewId = createView(entry); + editId = createEdit(entry); + exportId = createExport(entry); + deleteId = createDelete(entry); + entryNameRealId = getVascEntry().getId(); + + defaultRenderView = true; + } catch (Exception e) { + e.printStackTrace(); } - ValueExpression ve = getValueExpression("bar"); - return (ve != null) ? (String) ve.getValue(getFacesContext().getELContext()) : null; - } + } + protected void initGoto(String name,String paraName,Object paraValue) { + try { + //System.out.println("GOTO init Entry: "+name); + + this.getChildren().clear(); + + entryNameOldId = entryNameRealId; + entryNameRealId = name; + VascEntry entry = createClonedVascEntry(); + + if (paraName!=null) { + VascBackend b = entry.getVascFrontendData().getVascBackend(); + b.setDataParameter(paraName, paraValue); + } else { + entryNameOldId = null; // removed back link. + } + + // lets load data; + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + List data = entry.getVascFrontendData().getEntryDataList(); + tableDataModel.setWrappedData(data); + pagesDataModel.setWrappedData(entry.getVascFrontendData().getVascBackend().getVascBackendPageNumbers()); + + renderer = new JSFFrontendRenderer(); + renderer.initEntry(entry); + + viewId = createView(entry); + editId = createEdit(entry); + exportId = createExport(entry); + deleteId = createDelete(entry); + entryNameRealId = getVascEntry().getId(); - public void encodeBegin(FacesContext context) throws IOException { - ResponseWriter writer = context.getResponseWriter(); - - writer.append("

"); - writer.append(" Today is: " + new Date()); - writer.append("

"); - - - HtmlInputText inputText = new HtmlInputText(); - inputText.setParent(this); - // inputText.setId(this.getId() + ":_text1"); - inputText.encodeBegin(context); - inputText.encodeEnd(context); - - if (inputText.getRendersChildren()) { - for (UIComponent child:inputText.getChildren()) { - child.encodeBegin(context); - child.encodeEnd(context); - } - } - + defaultRenderView = true; + } catch (Exception e) { + e.printStackTrace(); + } } - public void restoreState(FacesContext context, Object state) { - this.state = (Object[]) state; - super.restoreState(context, this.state[0]); - bar = (String) this.state[1]; - } + /** + * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext) + */ + @Override + public void encodeBegin(FacesContext context) throws IOException { + super.encodeBegin(context); + + if (defaultRenderView) { + VascEntry entry = getVascEntry(); + JSFFrontendRenderer r = (JSFFrontendRenderer)entry.getVascFrontendData().getVascFrontend(); + if (r==null) { + return; + } + //System.out.println("defaultRenderView = true"); + try { + r.renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + /** + * @return the vascController + */ + public ValueExpression getVascController() { + return vascController; + } + + /** + * @param vascController the vascController to set + */ + public void setVascController(ValueExpression vascController) { + this.vascController = vascController; + } + + /** + * @return the entryName + */ + public ValueExpression getEntryName() { + return entryName; + } + + /** + * @param entryName the entryName to set + */ + public void setEntryName(ValueExpression entryName) { + this.entryName = entryName; + } + + /** + * @return the vascFrontendData + */ + public ValueExpression getVascFrontendData() { + return vascFrontendData; + } + + /** + * @param vascFrontendData the vascFrontendData to set + */ + public void setVascFrontendData(ValueExpression vascFrontendData) { + this.vascFrontendData = vascFrontendData; + } - public Object saveState(FacesContext context) { - if (state == null) { - state = new Object[2]; - } - state[0] = super.saveState(context); - state[1] = bar; - return state; - } + /** + * @return the selectedRecordName + */ + public String getSelectedRecordName() { + return selectedRecordName; + } + + /** + * @param selectedRecordName the selectedRecordName to set + */ + public void setSelectedRecordName(String selectedRecordName) { + this.selectedRecordName = selectedRecordName; + } + + public String createDelete(VascEntry entry) throws Exception { + + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + + UIPanel panelDelete = (UIPanel)application.createComponent(UIPanel.COMPONENT_TYPE); + panelDelete.setId(viewRoot.createUniqueId()); + + HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + title.setId(viewRoot.createUniqueId()); + title.setValue(entry.getHeaderName()); + title.setStyleClass("style_header1"); + panelDelete.getChildren().add(title); + + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("

"); + br.setEscape(false); + panelDelete.getChildren().add(br); + + HtmlOutputText header = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + header.setId(viewRoot.createUniqueId()); + header.setValue(entry.getHeaderDescription()); + panelDelete.getChildren().add(header); + + HtmlOutputText br2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br2.setId(viewRoot.createUniqueId()); + br2.setValue("
Weet je wel zeker dat je deze wilt verwijderen ?
"); + br2.setEscape(false); + panelDelete.getChildren().add(br2); + + + // this is hacky because IT only works on BEANS !! + VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId()); + String beanValue = "."+v.getBackendName(); + HtmlOutputText text = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + text.setId(viewRoot.createUniqueId()); + panelDelete.getChildren().add(text); + ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+getSelectedRecordName()+beanValue+"}", Object.class); + text.setValueExpression("value", ve7); + + br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("
"); + br.setEscape(false); + panelDelete.getChildren().add(br); + + HtmlCommandButton save = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE); + save.setId(viewRoot.createUniqueId()); + save.addActionListener(new DeleteActionListener()); + save.setValue("Delete"); + panelDelete.getChildren().add(save); + + HtmlOutputText space = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + space.setId(viewRoot.createUniqueId()); + space.setValue(" "); + space.setEscape(false); + panelDelete.getChildren().add(space); + + HtmlCommandButton cancel = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE); + cancel.setId(viewRoot.createUniqueId()); + cancel.addActionListener(new BackActionListener()); + cancel.setValue("Cancel"); + panelDelete.getChildren().add(cancel); + + this.getChildren().add(panelDelete); + return panelDelete.getId(); + } + + public String createEdit(VascEntry entry) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + + UIPanel panelEdit = (UIPanel)application.createComponent(UIPanel.COMPONENT_TYPE); + panelEdit.setId(viewRoot.createUniqueId()); + + HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + title.setId(viewRoot.createUniqueId()); + title.setValue(entry.getHeaderName()); + title.setStyleClass("style_header1"); + panelEdit.getChildren().add(title); + + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("

"); + br.setEscape(false); + panelEdit.getChildren().add(br); + + HtmlOutputText header = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + header.setId(viewRoot.createUniqueId()); + header.setValue(entry.getHeaderDescription()); + panelEdit.getChildren().add(header); + + HtmlOutputText br2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br2.setId(viewRoot.createUniqueId()); + br2.setValue("

"); + br2.setEscape(false); + panelEdit.getChildren().add(br2); + + HtmlPanelGrid grid = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); + grid.setId(viewRoot.createUniqueId()); + grid.setColumns(3); + grid.setHeaderClass("style_tableHeader1"); + grid.setColumnClasses("style_tableDarkGray_dub, style_tableLightGray_dub, style_tableLightGray_dub"); + panelEdit.getChildren().add(grid); + + HtmlOutputText gridHeaderText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText.setId(viewRoot.createUniqueId()); + gridHeaderText.setValue("Edit"); + grid.getFacets().put("header", gridHeaderText); + + int column = 0; + for (VascEntryField c:entry.getVascEntryFields()) { + //entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean); + if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) { + continue; + } + + for (int i=0;i"); + br.setEscape(false); + panelEdit.getChildren().add(br); + + HtmlCommandButton save = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE); + save.setId(viewRoot.createUniqueId()); + save.addActionListener(new SaveActionListener()); + save.setValue("Save"); + panelEdit.getChildren().add(save); + + HtmlOutputText space = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + space.setId(viewRoot.createUniqueId()); + space.setValue(" "); + space.setEscape(false); + panelEdit.getChildren().add(space); + + HtmlCommandButton cancel = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE); + cancel.setId(viewRoot.createUniqueId()); + cancel.addActionListener(new BackActionListener()); + cancel.setValue("Cancel"); + panelEdit.getChildren().add(cancel); + + this.getChildren().add(panelEdit); + return panelEdit.getId(); + } + + + public String createExport(VascEntry entry) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + + UIPanel panelExport = (UIPanel)application.createComponent(UIPanel.COMPONENT_TYPE); + panelExport.setId(viewRoot.createUniqueId()); + + HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + title.setId(viewRoot.createUniqueId()); + title.setValue(entry.getHeaderName()); + title.setStyleClass("style_header1"); + panelExport.getChildren().add(title); + + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("

"); + br.setEscape(false); + panelExport.getChildren().add(br); + + HtmlOutputText header = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + header.setId(viewRoot.createUniqueId()); + header.setValue(entry.getHeaderDescription()); + panelExport.getChildren().add(header); + + HtmlOutputText br2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br2.setId(viewRoot.createUniqueId()); + br2.setValue("

"); + br2.setEscape(false); + panelExport.getChildren().add(br2); + + + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.addActionListener(new BackActionListener()); + + + HtmlCommandLink linkExport = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + linkExport.setId(viewRoot.createUniqueId()); + linkExport.addActionListener(new ExportActionListener()); + linkExport.setValue("Download"); + panelExport.getChildren().add(linkExport); + + br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("

"); + br.setEscape(false); + panelExport.getChildren().add(br); + + HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out.setId(viewRoot.createUniqueId()); + out.setValue("Back"); + + link.getChildren().add(out); + panelExport.getChildren().add(link); + + + + this.getChildren().add(panelExport); + return panelExport.getId(); + } + + @SuppressWarnings("serial") + class ExportActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + VascEntryExporter ex = comp.exporter; + + FacesContext fc = FacesContext.getCurrentInstance(); + HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse(); + String filename = "export-list."+ex.getType(); + response.setHeader("Content-disposition", "attachment; filename=" + filename); + String contentType = ex.getMineType(); + response.setContentType(contentType); + ServletOutputStream out = response.getOutputStream(); + + + ex.doExport(out, entry); + out.close(); + + fc.responseComplete(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + @SuppressWarnings("serial") + class BackActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().setEntryDataObject(null); + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @SuppressWarnings("serial") + class DeleteActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + Object rowObject = entry.getVascFrontendData().getEntryDataObject(); + entry.getVascFrontendData().getVascBackend().delete(rowObject); + entry.getVascFrontendData().getEntryDataList().remove(rowObject); + entry.getVascFrontendData().setEntryDataObject(null); + //entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); + + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + @SuppressWarnings("serial") + class SaveActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + Object rowObject = entry.getVascFrontendData().getEntryDataObject(); + entry.getVascFrontendData().getEntryDataList().remove(rowObject); + Object newObject = entry.getVascFrontendData().getVascBackend().merge(rowObject); + entry.getVascFrontendData().getEntryDataList().add(newObject); + entry.getVascFrontendData().setEntryDataObject(null); + //entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); + + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + @SuppressWarnings("serial") + class PageLinkActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + Integer pageIndex = (Integer)((HtmlCommandLink)event.getComponent()).getValue(); + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().getVascBackend().setPageIndex(pageIndex); + //entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); + + // lets load data; + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + List data = entry.getVascFrontendData().getEntryDataList(); + comp.getDataModel().setWrappedData(data); + + pagesDataModel.setWrappedData(entry.getVascFrontendData().getVascBackend().getVascBackendPageNumbers()); + + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + @SuppressWarnings("serial") + class SortActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + String fieldIdString = ((HtmlCommandLink)event.getComponent()).getType(); + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + VascEntryField field = entry.getVascEntryFieldById(fieldIdString); + String curSort = entry.getVascFrontendData().getVascBackend().getSortField(); + + if (field.getBackendName().equals(curSort)) { + entry.getVascFrontendData().getVascBackend().setSortAscending(!entry.getVascFrontendData().getVascBackend().isSortAscending()); + } + String sortID = field.getBackendName(); + entry.getVascFrontendData().getVascBackend().setSortField(sortID); + //entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean); + + entry.getVascFrontendData().getVascBackend().setPageIndex(0); + + // lets load data; + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + List data = entry.getVascFrontendData().getEntryDataList(); + comp.getDataModel().setWrappedData(data); + + ValueExpression ren2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['sortOrder']}", Boolean.class); + ValueExpression ren3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['sortField']}", String.class); + ren2.setValue(FacesContext.getCurrentInstance().getELContext(), entry.getVascFrontendData().getVascBackend().isSortAscending()); + ren3.setValue(FacesContext.getCurrentInstance().getELContext(), field.getId()); + + pagesDataModel.setWrappedData(entry.getVascFrontendData().getVascBackend().getVascBackendPageNumbers()); + + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + @SuppressWarnings("serial") + class SearchActionListener implements ActionListener,Serializable { + public void processAction(ActionEvent event) { + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + + + ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.searchString}", String.class); + String ss = (String)ve3.getValue(FacesContext.getCurrentInstance().getELContext()); + + entry.getVascFrontendData().getVascBackend().setSearchString(ss); + entry.getVascFrontendData().getVascBackend().setSortField(null); + entry.getVascFrontendData().getVascBackend().setPageIndex(0); + + // lets load data; + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + List data = entry.getVascFrontendData().getEntryDataList(); + comp.getDataModel().setWrappedData(data); + + pagesDataModel.setWrappedData(entry.getVascFrontendData().getVascBackend().getVascBackendPageNumbers()); + + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + public String createView(VascEntry entry) throws Exception { + + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + + UIPanel panelView = (UIPanel)application.createComponent(UIPanel.COMPONENT_TYPE); + panelView.setId(viewRoot.createUniqueId()); + + HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + title.setId(viewRoot.createUniqueId()); + title.setValue(i18n(entry.getHeaderName())); + title.setStyleClass("style_header1"); + panelView.getChildren().add(title); + + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("

"); + br.setEscape(false); + panelView.getChildren().add(br); + + HtmlOutputText header = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + header.setId(viewRoot.createUniqueId()); + header.setValue(i18n(entry.getHeaderDescription())); + panelView.getChildren().add(header); + + br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("

"); + br.setEscape(false); + panelView.getChildren().add(br); + + HtmlPanelGrid grid = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); + grid.setId(viewRoot.createUniqueId()); + grid.setColumns(2); + grid.setHeaderClass("style_tableHeader1"); + grid.setColumnClasses(", style_tableDarkGray_dub"); + panelView.getChildren().add(grid); + + HtmlOutputText gridHeaderText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText.setId(viewRoot.createUniqueId()); + gridHeaderText.setValue("Options"); + grid.getFacets().put("header", gridHeaderText); + + HtmlPanelGroup options = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE); + options.setId(viewRoot.createUniqueId()); + grid.getChildren().add(options); + + HtmlCommandButton search = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE); + search.setId(viewRoot.createUniqueId()); + search.addActionListener(new SearchActionListener()); + search.setValue("Search"); + grid.getChildren().add(search); + + HtmlPanelGrid gridOption = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); + gridOption.setId(viewRoot.createUniqueId()); + gridOption.setColumns(1); + gridOption.setColumnClasses("style_tableDarkGray_dub"); + options.getChildren().add(gridOption); + + HtmlPanelGroup gridOptionGroup = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE); + gridOptionGroup.setId(viewRoot.createUniqueId()); + gridOption.getChildren().add(gridOptionGroup); + + HtmlOutputText searchText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + searchText.setId(viewRoot.createUniqueId()); + searchText.setValue("Search: "); + gridOptionGroup.getChildren().add(searchText); + + HtmlInputText searchInput = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE); + searchInput.setId(viewRoot.createUniqueId()); + searchInput.setSize(20); + + ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.searchString}", String.class); + searchInput.setValueExpression("value", ve3); + gridOptionGroup.getChildren().add(searchInput); + + HtmlOutputText gridHeaderText2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText2.setId(viewRoot.createUniqueId()); + gridHeaderText2.setValue("Results "); // Results 101 - 200 of 217 rows + panelView.getChildren().add(gridHeaderText2); + + HtmlOutputText gridHeaderText3 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText3.setId(viewRoot.createUniqueId()); + ValueExpression renH3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalPageResults']}", Integer.class); + gridHeaderText3.setValueExpression("value", renH3); + panelView.getChildren().add(gridHeaderText3); + + HtmlOutputText gridHeaderText4 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText4.setId(viewRoot.createUniqueId()); + gridHeaderText4.setValue(" of "); + panelView.getChildren().add(gridHeaderText4); + + HtmlOutputText gridHeaderText5 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText5.setId(viewRoot.createUniqueId()); + ValueExpression renH5 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalResults']}", Integer.class); + gridHeaderText5.setValueExpression("value", renH5); + panelView.getChildren().add(gridHeaderText5); + + HtmlOutputText gridHeaderText6 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gridHeaderText6.setId(viewRoot.createUniqueId()); + gridHeaderText6.setValue(" total rows."); + panelView.getChildren().add(gridHeaderText6); + + if (entryNameOldId!=null) { + + br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + br.setId(viewRoot.createUniqueId()); + br.setValue("
"); + br.setEscape(false); + panelView.getChildren().add(br); + + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.addActionListener(new VascLinkBackActionListener(entryNameOldId)); + link.setValue("Back"); + + panelView.getChildren().add(link); + } + + + HtmlPanelGrid gridHeader = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); + gridHeader.setId(viewRoot.createUniqueId()); + gridHeader.setColumns(3); + gridHeader.setColumnClasses(" , , style_tableHeader1"); + gridHeader.setWidth("90%"); + panelView.getChildren().add(gridHeader); + + HtmlPanelGroup gotoGroup = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE); + gotoGroup.setId(viewRoot.createUniqueId()); + gridHeader.getChildren().add(gotoGroup); + + VascBackend backend = entry.getVascFrontendData().getVascBackend(); + // create pageing + if (backend.isPageable()) { + + HtmlOutputText gotoText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + gotoText.setId(viewRoot.createUniqueId()); + gotoText.setValue("Goto page: "); + gotoGroup.getChildren().add(gotoText); + + HtmlDataList table = (HtmlDataList)application.createComponent(HtmlDataList.COMPONENT_TYPE); + table.setVar("vascPage"); + table.setId(viewRoot.createUniqueId()); + table.setValue(pagesDataModel); + table.setLayout("simple"); + gotoGroup.getChildren().add(table); + + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascPage.pageNumber}", Integer.class); + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.addActionListener(new PageLinkActionListener()); + link.setValueExpression("value", ve2); + ValueExpression ren2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascPage.selected?'style_header1':''}", String.class); + link.setValueExpression("styleClass", ren2); + + //HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + //out.setId(viewRoot.createUniqueId()); + //out.setValueExpression("value", ve2); + //ValueExpression ren = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascPage.notSelected}", Boolean.class); + //out.setValueExpression("rendered", ren); + + //HtmlOutputText out2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + //out2.setId(viewRoot.createUniqueId()); + //out2.setStyleClass("style_header1"); + //out2.setValueExpression("value", ve2); + //ValueExpression ren2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascPage.selected}", Boolean.class); + //out2.setValueExpression("rendered", ren2); + + //link.getChildren().add(out); + //link.getChildren().add(out2); + table.getChildren().add(link); + + HtmlOutputText space2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + space2.setId(viewRoot.createUniqueId()); + space2.setValue(" "); + space2.setEscape(false); + table.getChildren().add(space2); + } + + HtmlOutputText space2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + space2.setId(viewRoot.createUniqueId()); + space2.setValue(" "); + space2.setEscape(false); + gridHeader.getChildren().add(space2); + + HtmlPanelGroup actionGroup = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE); + actionGroup.setId(viewRoot.createUniqueId()); + gridHeader.getChildren().add(actionGroup); + + for (GlobalVascAction action:entry.getGlobalActions()) { + if (entry.getVascFrontendData().getVascFrontendHelper().renderGlobalVascAction(action)==false) { + continue; + } + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.setType(action.getId()); + link.addActionListener(new VascGlobalActionListener(action.getId())); + + HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out.setId(viewRoot.createUniqueId()); + out.setValue(i18n(action.getName())); + + link.getChildren().add(out); + actionGroup.getChildren().add(link); + + HtmlOutputText space = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + space.setId(viewRoot.createUniqueId()); + space.setValue(" "); + space.setEscape(false); + actionGroup.getChildren().add(space); + } + + // keep add button seperate + for (RowVascAction action:entry.getRowActions()) { + if ("addRowAction".equals(action.getId())==false) { + continue; + } + if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) { + continue; + } + HtmlOutputText space = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + space.setId(viewRoot.createUniqueId()); + space.setValue("     "); + space.setEscape(false); + actionGroup.getChildren().add(space); + + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.addActionListener(new VascRowActionListener(action.getId())); + + HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out.setId(viewRoot.createUniqueId()); + out.setValue(i18n(action.getName())); + + link.getChildren().add(out); + actionGroup.getChildren().add(link); + } + + + + HtmlDataTable table = (HtmlDataTable)application.createComponent(HtmlDataTable.COMPONENT_TYPE); + table.setVar("vascRecord"); + table.setId(viewRoot.createUniqueId()); + table.setWidth("90%"); + table.setRowClasses("style_tableRowType1,style_tableRowType2"); + table.setHeaderClass("style_tableHeader1"); + table.setValue(tableDataModel); + panelView.getChildren().add(table); + + for (VascEntryField c:entry.getVascEntryFields()) { + if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) { + continue; + } + UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE); + col.setId(viewRoot.createUniqueId()); + + + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.setType(c.getId()); + link.addActionListener(new SortActionListener()); + + HtmlOutputText out2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out2.setId(viewRoot.createUniqueId()); + out2.setEscape(false); + out2.setValue(i18n(c.getName())+" "); + + HtmlOutputText orderUp = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + orderUp.setId(viewRoot.createUniqueId()); + orderUp.setEscape(false); + orderUp.setValue("↑"); // ↑ + ValueExpression ren2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['sortOrder']==true and vascActionBean.values['sortField']=='"+c.getId()+"'}", Boolean.class); + orderUp.setValueExpression("rendered", ren2); + + HtmlOutputText orderDown = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + orderDown.setId(viewRoot.createUniqueId()); + orderDown.setEscape(false); + orderDown.setValue("↓"); // ↓ + ValueExpression ren3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['sortOrder']==false and vascActionBean.values['sortField']=='"+c.getId()+"'}", Boolean.class); + orderDown.setValueExpression("rendered", ren3); + + + link.getChildren().add(out2); + link.getChildren().add(orderUp); + link.getChildren().add(orderDown); + col.setHeader(link); + + HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out.setId(viewRoot.createUniqueId()); + String valueId = "#{vascRecord."+c.getBackendName()+"}"; + if (c.getDisplayName()!=null && "".equals(c.getDisplayName())==false) { + valueId = "#{vascRecord."+c.getDisplayName()+"}"; + } + //System.out.println("ValueException fieldId: "+c.getId()+" back: "+c.getBackendName()+" dis: "+c.getDisplayName()+" val: "+valueId); + ValueExpression ve1 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(),valueId,Object.class); + out.setValueExpression("value", ve1); + + col.getChildren().add(out); + table.getChildren().add(col); + } + + for (VascLinkEntry vascLink:entry.getVascLinkEntries()) { + + UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE); + col.setId(viewRoot.createUniqueId()); + + UIOutput colHeader = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE); + colHeader.setId(viewRoot.createUniqueId()); + colHeader.setValue("link"); + col.setHeader(colHeader); + + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.addActionListener(new VascLinkActionListener(vascLink.getId())); + + // rm this , bacause of unneeded copy, should add name to link + VascEntry ve = entry.getVascFrontendData().getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById(vascLink.getVascEntryId()); + + HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out.setId(viewRoot.createUniqueId()); + out.setValue(i18n(ve.getHeaderName())); + + link.getChildren().add(out); + col.getChildren().add(link); + + table.getChildren().add(col); + } + + + for (RowVascAction action:entry.getRowActions()) { + if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) { + continue; + } + if ("addRowAction".equals(action.getId())) { + continue; + } + + UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE); + col.setId(viewRoot.createUniqueId()); + + UIOutput colHeader = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE); + colHeader.setId(viewRoot.createUniqueId()); + colHeader.setValue(i18n(action.getName())); + col.setHeader(colHeader); + + HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE); + link.setId(viewRoot.createUniqueId()); + link.addActionListener(new VascRowActionListener(action.getId())); + + HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + out.setId(viewRoot.createUniqueId()); + out.setValue(i18n(action.getName())); + + link.getChildren().add(out); + col.getChildren().add(link); + + table.getChildren().add(col); + } + + this.getChildren().add(panelView); + return panelView.getId(); + } + + public DataModel getDataModel() { + return tableDataModel; + } +} + +class JSFFrontendRenderer extends AbstractVascFrontend implements Serializable { + + private static final long serialVersionUID = 1L; + + // Frontend Stuff + + protected void addUiComponents() { + VascFrontendData vfd = getVascEntry().getVascFrontendData(); + + // required UI components + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_LABEL,JSFLabel.class.getName()); + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_TEXT, JSFText.class.getName()); + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_LIST, JSFList.class.getName()); + //vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_BUTTON, JSFButton.class.getName()); + + // optional UI components + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_BOOLEAN , JSFBoolean.class.getName()); + //vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_DATE , JSFDate.class.getName()); + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_TEXTAREA , JSFTextArea.class.getName()); + //vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_COLOR , JSFColorChooser.class.getName()); + + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderDelete(java.lang.Object) + */ + public void renderDelete(Object rowBean) throws Exception { + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.resetViews(); + UIPanel panel = comp.getPanel("deleteId"); + panel.setRendered(true); + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderEdit(java.lang.Object) + */ + public void renderEdit(Object rowBean) throws Exception { + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.resetViews(); + UIPanel panel = comp.getPanel("editId"); + panel.setRendered(true); + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderExport(com.idcanet.vasc.core.entry.VascEntryExporter) + */ + public void renderExport(VascEntryExporter exporter) throws Exception { + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.resetViews(); + UIPanel panel = comp.getPanel("exportId"); + panel.setRendered(true); + + comp.exporter=exporter; + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderView() + */ + public void renderView() throws Exception { + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.resetViews(); + UIPanel panel = comp.getPanel("viewId"); + panel.setRendered(true); + + + // ui value + ValueExpression ren3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalPageResults']}", Integer.class); + ren3.setValue(FacesContext.getCurrentInstance().getELContext(), getVascEntry().getVascFrontendData().getEntryDataList().size()); + ValueExpression ren4 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalResults']}", Integer.class); + ren4.setValue(FacesContext.getCurrentInstance().getELContext(), getVascEntry().getVascFrontendData().getVascBackend().getPagesTotalRecords()); + } +} + +@SuppressWarnings("serial") +class VascGlobalActionListener implements ActionListener,Serializable { + private String actionId = null; + public VascGlobalActionListener(String actionId) { + this.actionId=actionId; + } + public void processAction(ActionEvent event) { + //System.out.println("Doing action link for global: "+actionId); + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + for (GlobalVascAction action:entry.getGlobalActions()) { + if (action.getId().equals(actionId)) { + try { + //System.out.println("Do Gloabel action on entry: "+entry); + action.doGlobalAction(entry); + } catch (Exception e) { + e.printStackTrace(); + //entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry); + } + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} +@SuppressWarnings("serial") +class VascRowActionListener implements ActionListener,Serializable { + private String actionId = null; + public VascRowActionListener(String actionId) { + this.actionId=actionId; + } + public void processAction(ActionEvent event) { + //System.out.println("Doing action link for row: "+actionId); + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + + for (RowVascAction action:entry.getRowActions()) { + if (action.getId().equals(actionId)) { + try { + //System.out.println("Do Row action"); + + + if ("addRowAction".equals(actionId)) { + Object selectedNew = entry.getVascFrontendData().getVascFrontendHelper().initEditObject(entry, null); + + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+comp.getSelectedRecordName()+"}", Object.class); + ve2.setValue(FacesContext.getCurrentInstance().getELContext(), selectedNew); + ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).setAttribute(comp.getSelectedRecordName(), selectedNew); + + //System.out.println("Do Row action NEW selected: "+selectedNew+" entry: "+entry); + entry.getVascFrontendData().setEntryDataObject(selectedNew); + action.doRowAction(entry, selectedNew); + return; + } + + + DataModel dm = comp.getDataModel(); + Object selected = dm.getRowData(); + + + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+comp.getSelectedRecordName()+"}", Object.class); + ve2.setValue(FacesContext.getCurrentInstance().getELContext(), selected); + ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).setAttribute(comp.getSelectedRecordName(), selected); + + entry.getVascFrontendData().setEntryDataObject(selected); + //System.out.println("Do Row action selected: "+selected+" entry: "+entry); + action.doRowAction(entry, selected); + } catch (Exception e) { + e.printStackTrace(); + //entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry); + } + return; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} +@SuppressWarnings("serial") +class VascLinkActionListener implements ActionListener,Serializable { + private String linkId = null; + public VascLinkActionListener(String linkId) { + this.linkId=linkId; + } + public void processAction(ActionEvent event) { + //System.out.println("Doing action link for vascLink: "+linkId); + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + for (VascLinkEntry l:entry.getVascLinkEntries()) { + if (l.getId().equals(linkId)) { + try { + //System.out.println("Do Link action"); + DataModel dm = comp.getDataModel(); + Object selected = dm.getRowData(); + VascEntryField v = entry.getVascEntryFieldById(l.getValueFieldId()); + Object selectedValue = v.getVascEntryFieldValue().getValue(v, selected); + //System.out.println("Do Link action value: "+selectedValue+" from: "+selected); + comp.initGoto(l.getVascEntryId(), l.getParameterName(), selectedValue); + } catch (Exception e) { + e.printStackTrace(); + //entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry); + } + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} +@SuppressWarnings("serial") +class VascLinkBackActionListener implements ActionListener,Serializable { + private String linkId = null; + public VascLinkBackActionListener(String linkId) { + this.linkId=linkId; + } + public void processAction(ActionEvent event) { + try { + VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + comp.initGoto(linkId, null, null); + } catch (Exception e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java index 4383c47..85320d5 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java @@ -26,13 +26,11 @@ package com.idcanet.vasc.frontends.web.jsf; + import javax.el.ValueExpression; import javax.faces.component.UIComponent; -import javax.faces.component.UIComponentBase; -import javax.faces.context.FacesContext; -import javax.faces.context.ResponseWriter; -import javax.faces.render.Renderer; -import javax.faces.webapp.UIComponentTag; +import javax.faces.webapp.UIComponentELTag; +import javax.servlet.jsp.JspException; /** * @@ -40,40 +38,113 @@ import javax.faces.webapp.UIComponentTag; * @author Willem Cazander * @version 1.0 Nov 16, 2008 */ -public class VascUIComponentTag extends UIComponentTag { +public class VascUIComponentTag extends UIComponentELTag { - protected ValueExpression bar; + private ValueExpression vascController = null; + private ValueExpression vascFrontendData = null; + private ValueExpression entryName = null; + private ValueExpression bundleName = null; + private ValueExpression locale = null; + /** + * @see javax.faces.webapp.UIComponentELTag#setProperties(javax.faces.component.UIComponent) + */ + @Override + protected void setProperties(UIComponent comp) { + super.setProperties(comp); + VascUIComponent component = (VascUIComponent)comp; + component.setVascController(vascController); + component.setEntryName(entryName); + component.setVascFrontendData(vascFrontendData); + component.init(); + } + + /** + * @see javax.faces.webapp.UIComponentClassicTagBase#doStartTag() + */ + @Override + public int doStartTag() throws JspException { + int result = super.doStartTag(); + return result; + } + + @Override public String getComponentType() { return VascUIComponent.COMPONENT_TYPE; } + @Override public String getRendererType() { - return VascUIComponent.COMPONENT_TYPE; + return null; } - public ValueExpression getBar() { - return bar; - } - - protected void setProperties(UIComponent component) { - super.setProperties(component); - VascUIComponent download = null; - try { - //foo = (VascUIComponent) component; - } catch (ClassCastException cce) { - throw new IllegalStateException("Component " + component.toString() + - " not expected type. Expected: com.foo.Foo. Perhaps you're missing a tag?"); - } - - if (bar != null) { - //foo.setValueExpression("bar", bar); - } - } - - public void release() { - super.release(); - bar = null; + /** + * @return the vascController + */ + public ValueExpression getVascController() { + return vascController; } + /** + * @param vascController the vascController to set + */ + public void setVascController(ValueExpression vascController) { + this.vascController = vascController; + } + + /** + * @return the entryName + */ + public ValueExpression getEntryName() { + return entryName; + } + + /** + * @param entryName the entryName to set + */ + public void setEntryName(ValueExpression entryName) { + this.entryName = entryName; + } + + /** + * @return the bundleName + */ + public ValueExpression getBundleName() { + return bundleName; + } + + /** + * @param bundleName the bundleName to set + */ + public void setBundleName(ValueExpression bundleName) { + this.bundleName = bundleName; + } + + /** + * @return the locale + */ + public ValueExpression getLocale() { + return locale; + } + + /** + * @param locale the locale to set + */ + public void setLocale(ValueExpression locale) { + this.locale = locale; + } + + /** + * @return the vascFrontendData + */ + public ValueExpression getVascFrontendData() { + return vascFrontendData; + } + + /** + * @param vascFrontendData the vascFrontendData to set + */ + public void setVascFrontendData(ValueExpression vascFrontendData) { + this.vascFrontendData = vascFrontendData; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java new file mode 100644 index 0000000..4f95a91 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java @@ -0,0 +1,75 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf.ui; + +import javax.faces.application.Application; +import javax.faces.component.UIComponent; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlSelectBooleanCheckbox; +import javax.faces.context.FacesContext; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 28, 2009 + */ +public class JSFBoolean implements VascUIComponent { + + private HtmlSelectBooleanCheckbox component = null; + + public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + component = (HtmlSelectBooleanCheckbox)application.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE); + component.setId(viewRoot.createUniqueId()); + if (entryField.getEditReadOnly()) { + component.setDisabled(true); + } + ((UIComponent)gui).getChildren().add(component); + return component; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + return ""; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFLabel.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFLabel.java new file mode 100644 index 0000000..4b51b78 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFLabel.java @@ -0,0 +1,73 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf.ui; + +import javax.faces.application.Application; +import javax.faces.component.UIComponent; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlOutputText; +import javax.faces.context.FacesContext; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 25, 2009 + */ +public class JSFLabel implements VascUIComponent { + + private HtmlOutputText component = null; + + public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + component = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + component.setId(viewRoot.createUniqueId()); + component.setValue(""+model.getValue()); + ((UIComponent)gui).getChildren().add(component); + return component; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + return ""; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java new file mode 100644 index 0000000..6518391 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java @@ -0,0 +1,167 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf.ui; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.faces.application.Application; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.component.UISelectItems; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlSelectOneMenu; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.model.SelectItem; +import javax.servlet.http.HttpSession; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.ui.VascSelectItem; +import com.idcanet.vasc.core.ui.VascSelectItemModel; +import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 28, 2009 + */ +public class JSFList implements VascUIComponent { + + private HtmlSelectOneMenu component = null; + + public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + component = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE); + component.setId(viewRoot.createUniqueId()); + if (entryField.getEditReadOnly()) { + component.setDisabled(true); + } + + VascSelectItemModel itemModel = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject(); + List items = itemModel.getVascSelectItems(entry); + + String id = entry.getId()+"_"+entryField.getId(); + ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).setAttribute(id, items); + component.setConverter(new VascConverter(id)); + + List value = new ArrayList(50); + for (VascSelectItem v:items) { + SelectItem si = new SelectItem(); + si.setLabel(v.getLabel()); + si.setValue(v.getValue()); + si.setDisabled(v.isDisabled()); + value.add(si); + } + UISelectItems item = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE); + item.setId(viewRoot.createUniqueId()); + item.setValue(value); + component.getChildren().add(item); + + ((UIComponent)gui).getChildren().add(component); + return component; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + return ""; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (text==null) { + return; + } + FacesMessage message = new FacesMessage(text); + message.setSeverity(FacesMessage.SEVERITY_ERROR); + FacesContext.getCurrentInstance().addMessage(component.getId(),message); + } +} +class VascConverter implements Converter,Serializable { + + private static final long serialVersionUID = 6198813637409531713L; + private String id = null; + + public VascConverter(String id) { + this.id=id; + } + + + /** + * Convert an ID to an Object + */ + public Object getAsObject(FacesContext context,UIComponent component,String value) throws ConverterException { + //System.out.println("getAsObject: "+component+" value: "+value); + if (context == null) { throw new NullPointerException("context may not be null"); } + if (component == null) { throw new NullPointerException("component may not be null"); } + if (value == null) { return null; } + if ((value=value.trim()).length() == 0) { return null; } + + List items = (List)((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getAttribute(id); + for (VascSelectItem v:items) { + //System.out.println("Check: "+value+" key: "+v.getKeyValue()); + if (value.equals(v.getKeyValue())) { + //System.out.println("FOUND VALUE"); + return v.getValue(); + } + } + throw new ConverterException("Could not convert value: "+value); + } + + /** + * Converts an Object to an ID. + */ + public String getAsString(FacesContext context,UIComponent component,Object value) throws ConverterException { + //System.out.println("getAsString: "+component+" value: "+value); + if (context == null) { throw new NullPointerException("context may not be null"); } + if (component == null) { throw new NullPointerException("component may not be null"); } + if (value == null) { return ""; } + + List items = (List)((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getAttribute(id); + for (VascSelectItem v:items) { + //System.out.println("Check: "+value+" key: "+v.getKeyValue()); + if (value.equals(v.getValue())) { + //System.out.println("FOUND"); + return v.getKeyValue(); + } + } + throw new ConverterException("Could not convert value: "+value); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java new file mode 100644 index 0000000..0c10ac9 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java @@ -0,0 +1,86 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf.ui; + +import javax.faces.application.Application; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlInputText; +import javax.faces.context.FacesContext; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 25, 2009 + */ +public class JSFText implements VascUIComponent { + + private HtmlInputText component = null; + + public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + component = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE); + component.setId(viewRoot.createUniqueId()); + Integer sizeEdit = entryField.getSizeEdit(); + if (sizeEdit!=null) { + component.setSize(sizeEdit); + } + if (entryField.getEditReadOnly()) { + component.setDisabled(true); + } + ((UIComponent)gui).getChildren().add(component); + return component; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + return ""; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (text==null) { + return; + } + FacesMessage message = new FacesMessage(text); + message.setSeverity(FacesMessage.SEVERITY_ERROR); + FacesContext.getCurrentInstance().addMessage(component.getId(),message); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java new file mode 100644 index 0000000..2539498 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java @@ -0,0 +1,90 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf.ui; + +import javax.faces.application.Application; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlInputTextarea; +import javax.faces.context.FacesContext; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.core.ui.VascValueModel; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 25, 2009 + */ +public class JSFTextArea implements VascUIComponent { + + private HtmlInputTextarea component = null; + + public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + component = (HtmlInputTextarea)application.createComponent(HtmlInputTextarea.COMPONENT_TYPE); + component.setId(viewRoot.createUniqueId()); + if (entryField.getEditReadOnly()) { + component.setDisabled(true); + } + String cols = entryField.getVascEntryFieldType().getProperty("editor.columns"); + if (cols!=null && "".equals(cols)==false) { + component.setCols(new Integer(cols)); + } + String rows = entryField.getVascEntryFieldType().getProperty("editor.rows"); + if (rows!=null && "".equals(rows)==false) { + component.setRows(new Integer(rows)); + } + ((UIComponent)gui).getChildren().add(component); + return component; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText() + */ + public String getErrorText() { + return ""; + } + + /** + * @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String) + */ + public void setErrorText(String text) { + if (text==null) { + return; + } + FacesMessage message = new FacesMessage(text); + message.setSeverity(FacesMessage.SEVERITY_ERROR); + FacesContext.getCurrentInstance().addMessage(component.getId(),message); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java index eb8576c..fa62369 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java @@ -26,6 +26,9 @@ package com.idcanet.vasc.impl; +import java.util.Collections; +import java.util.Comparator; + import com.idcanet.vasc.core.VascBackend; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; @@ -89,12 +92,6 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { } // entry fields - if (entry.getName()==null) { - entry.setName("vasc.entry."+id+".name"); - } - if (entry.getDescription()==null) { - entry.setDescription("vasc.entry."+id+".description"); - } if (entry.getImage()==null) { entry.setImage("vasc.entry."+id+".image"); } @@ -150,6 +147,7 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { // Check fields + int orderIndex = 0; for (VascEntryField vef:entry.getVascEntryFields()) { String vid = vef.getId(); @@ -161,6 +159,12 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { vef.setVascEntry(entry); } + //System.out.println("Field: "+vef.getId()+" order: "+vef.getOrderIndex()+" else: "+orderIndex); + if (vef.getOrderIndex()==null) { + vef.setOrderIndex(orderIndex); + } + orderIndex = orderIndex+100; + // fill up properties if (vef.getName()==null) { vef.setName("vasc.entry."+id+"."+vid+".name"); @@ -185,10 +189,6 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { // vef.setDefaultValue("vasc.entry."+id+"."+vid+".defaultValue"); //} - - if (vef.getVascEntryFieldEventChannel()==null) { - //vef.setStyleList("vasc.entry."+id+"."+vid+".styleEdit"); - } if (vef.getVascEntryFieldValue()==null) { VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() ); vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef)); @@ -217,11 +217,33 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { //for (VascValidator vv:vef.getVascValidators()) { //} } + Collections.sort(entry.getVascEntryFields(),new Comparator() { + public int compare(Object o1, Object o2) { + VascEntryField v1 = (VascEntryField)o1; + VascEntryField v2 = (VascEntryField)o2; + return v1.getOrderIndex().compareTo(v2.getOrderIndex()); + } + }); + // place primary key in front + int index = 0; + for (VascEntryField vef:entry.getVascEntryFields()) { + if (entry.getPrimaryKeyFieldId().equals(vef.getId())) { + break; + } + index++; + } + VascEntryField idField = entry.getVascEntryFields().remove(index); + entry.getVascEntryFields().add(0, idField); // Check if link entries excists for (VascLinkEntry vle:entry.getVascLinkEntries()) { - vle.getVascEntryName(); + + // check id + String vid = vle.getId(); + if (vid==null) { + throw new IllegalArgumentException("All VascLinkEntry need an id"); + } } diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackendController.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackendController.java index 451a031..97b9db8 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackendController.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackendController.java @@ -49,7 +49,7 @@ public class DefaultVascBackendController implements VascBackendControllerLocal /** * @see com.idcanet.vasc.core.VascBackendController#getVascBackendById(java.lang.String) */ - public VascBackend getVascBackendById(String id) { + public VascBackend getVascBackendById(String id) { return backends.get(id); } diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascController.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascController.java index 39281ad..28291d8 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascController.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascController.java @@ -57,8 +57,7 @@ public class DefaultVascController implements VascController { /** * @param vascEventChannelControllerResolver the vascEventChannelControllerResolver to set */ - public void setVascEventChannelControllerResolver( - VascEventChannelControllerResolver vascEventChannelControllerResolver) { + public void setVascEventChannelControllerResolver(VascEventChannelControllerResolver vascEventChannelControllerResolver) { this.vascEventChannelControllerResolver = vascEventChannelControllerResolver; } @@ -114,8 +113,7 @@ public class DefaultVascController implements VascController { /** * @param vascUserRoleControllerResolver the vascUserRoleControllerResolver to set */ - public void setVascUserRoleControllerResolver( - VascUserRoleControllerResolver vascUserRoleControllerResolver) { + public void setVascUserRoleControllerResolver(VascUserRoleControllerResolver vascUserRoleControllerResolver) { this.vascUserRoleControllerResolver = vascUserRoleControllerResolver; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java index a4fe605..02ef6ca 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntry.java @@ -39,6 +39,8 @@ import com.idcanet.vasc.core.VascLinkEntry; import com.idcanet.vasc.core.actions.ColumnVascAction; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.actions.VascAction; +import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; /** * VascEntry @@ -50,8 +52,6 @@ public class DefaultVascEntry implements VascEntry { private String id = null; - private String name = null; - private String description = null; private String helpId = null; private String image = null; @@ -62,10 +62,11 @@ public class DefaultVascEntry implements VascEntry { private String primaryKeyFieldId = null; private String displayNameFieldId = null; - private boolean vascAdmimList = true; - private boolean vascAdmimEdit = true; - private boolean vascAdmimCreate = true; - private boolean vascAdmimDelete = true; + private boolean vascDisplayOnly = false; + private boolean vascAdminList = true; + private boolean vascAdminEdit = true; + private boolean vascAdminCreate = true; + private boolean vascAdminDelete = true; private List vascFields = null; @@ -76,6 +77,7 @@ public class DefaultVascEntry implements VascEntry { private List vascEntryFieldSets = null; private List vascLinkEntries = null; private Map entryParameters = null; + private VascEntryFieldEventChannel vascEntryFieldEventChannel = null; private String backendId = null; private VascFrontendData vascFrontendData = null; @@ -99,8 +101,53 @@ public class DefaultVascEntry implements VascEntry { * @see java.lang.Object#clone() */ @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + public VascEntry clone() throws CloneNotSupportedException { + + DefaultVascEntry result = new DefaultVascEntry(); + result.id=id; + result.helpId=helpId; + result.image=image; + result.headerName=headerName; + result.headerDescription=headerDescription; + result.headerImage=headerImage; + result.primaryKeyFieldId=primaryKeyFieldId; + result.displayNameFieldId=displayNameFieldId; + result.vascDisplayOnly=vascDisplayOnly; + result.vascAdminList=vascAdminList; + result.vascAdminCreate=vascAdminCreate; + result.vascAdminEdit=vascAdminEdit; + result.vascAdminDelete=vascAdminDelete; + result.backendId=backendId; + result.vascEntryFieldEventChannel=vascEntryFieldEventChannel; + // skipping 'vascFrontendData' because it should always be null when cloning happens. + + for (VascEntryField f:vascFields) { + VascEntryField ff = f.clone(); + ff.setVascEntry(result); // mmm remove this ? + result.vascFields.add(ff); + } + for (VascAction a:rowActions) { + result.rowActions.add((RowVascAction)a.clone()); + } + for (VascAction a:columnActions) { + result.columnActions.add((ColumnVascAction)a.clone()); + } + for (VascAction a:globalActions) { + result.globalActions.add((GlobalVascAction)a.clone()); + } + for (VascEntryFieldSet s:vascEntryFieldSets) { + result.vascEntryFieldSets.add(s.clone()); + } + for (VascLinkEntry l:vascLinkEntries) { + result.vascLinkEntries.add(l.clone()); + } + + // no cloning of the values here ? + for (String key:entryParameters.keySet()) { + Object value = entryParameters.get(key); + result.setEntryParameter(key, value); + } + return result; } @@ -120,34 +167,6 @@ public class DefaultVascEntry implements VascEntry { this.id = id; } - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - /** * @return the helpId */ @@ -247,59 +266,59 @@ public class DefaultVascEntry implements VascEntry { } /** - * @return the vascAdmimList + * @return the vascAdminList */ - public boolean isVascAdmimList() { - return vascAdmimList; + public boolean isVascAdminList() { + return vascAdminList; } /** - * @param vascAdmimList the vascAdmimList to set + * @param vascAdminList the vascAdminList to set */ - public void setVascAdmimList(boolean vascAdmimList) { - this.vascAdmimList = vascAdmimList; + public void setVascAdminList(boolean vascAdminList) { + this.vascAdminList = vascAdminList; } /** - * @return the vascAdmimEdit + * @return the vascAdminEdit */ - public boolean isVascAdmimEdit() { - return vascAdmimEdit; + public boolean isVascAdminEdit() { + return vascAdminEdit; } /** - * @param vascAdmimEdit the vascAdmimEdit to set + * @param vascAdminEdit the vascAdminEdit to set */ - public void setVascAdmimEdit(boolean vascAdmimEdit) { - this.vascAdmimEdit = vascAdmimEdit; + public void setVascAdminEdit(boolean vascAdminEdit) { + this.vascAdminEdit = vascAdminEdit; } /** - * @return the vascAdmimCreate + * @return the vascAdminCreate */ - public boolean isVascAdmimCreate() { - return vascAdmimCreate; + public boolean isVascAdminCreate() { + return vascAdminCreate; } /** - * @param vascAdmimCreate the vascAdmimCreate to set + * @param vascAdminCreate the vascAdminCreate to set */ - public void setVascAdmimCreate(boolean vascAdmimCreate) { - this.vascAdmimCreate = vascAdmimCreate; + public void setVascAdminCreate(boolean vascAdminCreate) { + this.vascAdminCreate = vascAdminCreate; } /** - * @return the vascAdmimDelete + * @return the vascAdminDelete */ - public boolean isVascAdmimDelete() { - return vascAdmimDelete; + public boolean isVascAdminDelete() { + return vascAdminDelete; } /** - * @param vascAdmimDelete the vascAdmimDelete to set + * @param vascAdminDelete the vascAdminDelete to set */ - public void setVascAdmimDelete(boolean vascAdmimDelete) { - this.vascAdmimDelete = vascAdmimDelete; + public void setVascAdminDelete(boolean vascAdminDelete) { + this.vascAdminDelete = vascAdminDelete; } /** @@ -332,7 +351,7 @@ public class DefaultVascEntry implements VascEntry { return v; } } - throw new IllegalArgumentException("Id not found as field"); + return null; } /** @@ -488,4 +507,32 @@ public class DefaultVascEntry implements VascEntry { public void setBackendId(String backendId) { this.backendId = backendId; } + + /** + * @return the vascDisplayOnly + */ + public boolean isVascDisplayOnly() { + return vascDisplayOnly; + } + + /** + * @param vascDisplayOnly the vascDisplayOnly to set + */ + public void setVascDisplayOnly(boolean vascDisplayOnly) { + this.vascDisplayOnly = vascDisplayOnly; + } + + /** + * @return the vascEntryFieldEventChannel + */ + public VascEntryFieldEventChannel getVascEntryFieldEventChannel() { + return vascEntryFieldEventChannel; + } + + /** + * @param vascEntryFieldEventChannel the vascEntryFieldEventChannel to set + */ + public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel) { + this.vascEntryFieldEventChannel = vascEntryFieldEventChannel; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryController.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryController.java index 39367fe..34c6601 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryController.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryController.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.impl; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,14 +61,27 @@ public class DefaultVascEntryController implements VascEntryControllerLocal { * @see com.idcanet.vasc.core.VascEntryController#getVascEntryById(java.lang.String) */ public VascEntry getVascEntryById(String id) { - return entries.get(id); + VascEntry entry = entries.get(id); + try { + return entry.clone(); + } catch (CloneNotSupportedException e) { + throw new NullPointerException("Could not clone entry: "+e.getMessage()); + } } + + public VascEntry getRealVascEntryById(String id) { + VascEntry entry = entries.get(id); + return entry; + } + /** * @see com.idcanet.vasc.core.VascEntryController#getVascEntryIds() */ public List getVascEntryIds() { - return new ArrayList(entries.keySet()); + List result = new ArrayList(entries.keySet()); + Collections.sort(result); // lets do abc for consistance behauvior. + return result; } /** @@ -76,10 +90,11 @@ public class DefaultVascEntryController implements VascEntryControllerLocal { public List getVascEntryAdminIds() { List adminIds = new ArrayList(30); for (VascEntry e:entries.values()) { - if (Boolean.TRUE.equals(e.isVascAdmimList())) { + if (Boolean.TRUE.equals(e.isVascAdminList())) { adminIds.add(e.getId()); } } + Collections.sort(adminIds); // lets do abc for consistance behauvior. return adminIds; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java index 108d830..a2b1b40 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java @@ -32,7 +32,6 @@ import java.util.List; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryFieldType; -import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.validators.VascValidator; @@ -45,44 +44,40 @@ import com.idcanet.vasc.validators.VascValidator; public class DefaultVascEntryField implements VascEntryField { private VascEntry vascEntry = null; - - /** The vasc id for this field */ - private String id = null; - - /** The vasc Field Type for this field entry. */ - private VascEntryFieldType vascEntryFieldType = null; - - /** The backendName, default to the name. **/ - private String backendName = null; + private String id = null; + private String backendName = null; + private String displayName = null; + + private VascEntryFieldType vascEntryFieldType = null; private VascEntryFieldValue vascEntryFieldValue = null; - - private VascEntryFieldEventChannel vascEntryFieldEventChannel = null; - private List vascValidators = null; - /** Some VascField fields**/ private String name = null; private String description = null; private String helpId = null; private String image = null; + private Integer orderIndex = null; private Object defaultValue = null; + private Integer sizeList = null; private Integer sizeEdit = null; private String styleList = null; private String styleEdit = null; private String choices = null; + private Boolean choicesAsRadio = null; /** Defines if this columns is used in interface list,create,edit **/ - private boolean view = true; - private boolean optional = false; + private Boolean view = null; + private Boolean optional = null; /** Defines per view state of this field **/ - private boolean create = true; - private boolean edit = true; - private boolean editReadOnly = false; - private boolean list = true; + private Boolean create = null; + private Boolean edit = null; + private Boolean editReadOnly = null; + private Boolean editBlank = null; + private Boolean list = null; /** Defines the roles stuff if all up is true **/ private String rolesCreate = null; @@ -90,6 +85,10 @@ public class DefaultVascEntryField implements VascEntryField { private String rolesEditReadOnly = null; private String rolesList = null; + private Boolean sortable = null; + private Boolean sumable = null; + private Boolean graphable = null; + public DefaultVascEntryField() { vascValidators = new ArrayList(5); } @@ -99,6 +98,52 @@ public class DefaultVascEntryField implements VascEntryField { setId(id); } + /** + * @see java.lang.Object#clone() + */ + @Override + public VascEntryField clone() throws CloneNotSupportedException { + DefaultVascEntryField result = new DefaultVascEntryField(); + result.id=id; + result.backendName=backendName; + result.displayName=displayName; + result.vascEntryFieldType=vascEntryFieldType; + result.name=name; + result.description=description; + result.helpId=helpId; + result.image=image; + result.defaultValue=defaultValue; + result.orderIndex=orderIndex; + result.sizeList=sizeList; + result.sizeEdit=sizeEdit; + result.styleList=styleList; + result.styleEdit=styleEdit; + result.choices=choices; + result.choicesAsRadio=choicesAsRadio; + result.view=view; + result.optional=optional; + result.create=create; + result.edit=edit; + result.editReadOnly=editReadOnly; + result.editBlank=editBlank; + result.list=list; + + result.rolesCreate=rolesCreate; + result.rolesEdit=rolesEdit; + result.rolesEditReadOnly=rolesEditReadOnly; + result.rolesList=rolesList; + + result.sortable=sortable; + result.sumable=sumable; + result.graphable=graphable; + + result.vascEntryFieldValue=vascEntryFieldValue; + + result.vascValidators.addAll(vascValidators); + + return result; + } + public VascEntry getVascEntry() { return vascEntry; } @@ -162,21 +207,7 @@ public class DefaultVascEntryField implements VascEntryField { public void setVascEntryFieldValue(VascEntryFieldValue vascEntryFieldValue) { this.vascEntryFieldValue = vascEntryFieldValue; } - - /** - * @return the vascEntryFieldEventChannel - */ - public VascEntryFieldEventChannel getVascEntryFieldEventChannel() { - return vascEntryFieldEventChannel; - } - - /** - * @param vascEntryFieldEventChannel the vascEntryFieldEventChannel to set - */ - public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel) { - this.vascEntryFieldEventChannel = vascEntryFieldEventChannel; - } - + /** * @return the vascValidators */ @@ -341,84 +372,84 @@ public class DefaultVascEntryField implements VascEntryField { /** * @return the view */ - public boolean isView() { + public Boolean getView() { return view; } /** * @param view the view to set */ - public void setView(boolean view) { + public void setView(Boolean view) { this.view = view; } /** * @return the optional */ - public boolean isOptional() { + public Boolean getOptional() { return optional; } /** * @param optional the optional to set */ - public void setOptional(boolean optional) { + public void setOptional(Boolean optional) { this.optional = optional; } /** * @return the create */ - public boolean isCreate() { + public Boolean getCreate() { return create; } /** * @param create the create to set */ - public void setCreate(boolean create) { + public void setCreate(Boolean create) { this.create = create; } /** * @return the edit */ - public boolean isEdit() { + public Boolean getEdit() { return edit; } /** * @param edit the edit to set */ - public void setEdit(boolean edit) { + public void setEdit(Boolean edit) { this.edit = edit; } /** * @return the editReadOnly */ - public boolean isEditReadOnly() { + public Boolean getEditReadOnly() { return editReadOnly; } /** * @param editReadOnly the editReadOnly to set */ - public void setEditReadOnly(boolean editReadOnly) { + public void setEditReadOnly(Boolean editReadOnly) { this.editReadOnly = editReadOnly; } /** * @return the list */ - public boolean isList() { + public Boolean getList() { return list; } /** * @param list the list to set */ - public void setList(boolean list) { + public void setList(Boolean list) { this.list = list; } @@ -477,4 +508,102 @@ public class DefaultVascEntryField implements VascEntryField { public void setRolesList(String rolesList) { this.rolesList = rolesList; } + + /** + * @return the choicesAsRadio + */ + public Boolean getChoicesAsRadio() { + return choicesAsRadio; + } + + /** + * @param choicesAsRadio the choicesAsRadio to set + */ + public void setChoicesAsRadio(Boolean choicesAsRadio) { + this.choicesAsRadio = choicesAsRadio; + } + + /** + * @return the editBlank + */ + public Boolean getEditBlank() { + return editBlank; + } + + /** + * @param editBlank the editBlank to set + */ + public void setEditBlank(Boolean editBlank) { + this.editBlank = editBlank; + } + + /** + * @return the displayName + */ + public String getDisplayName() { + return displayName; + } + + /** + * @param displayName the displayName to set + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * @return the orderIndex + */ + public Integer getOrderIndex() { + return orderIndex; + } + + /** + * @param orderIndex the orderIndex to set + */ + public void setOrderIndex(Integer orderIndex) { + this.orderIndex = orderIndex; + } + + /** + * @return the sortable + */ + public Boolean getSortable() { + return sortable; + } + + /** + * @param sortable the sortable to set + */ + public void setSortable(Boolean sortable) { + this.sortable = sortable; + } + + /** + * @return the sumable + */ + public Boolean getSumable() { + return sumable; + } + + /** + * @param sumable the sumable to set + */ + public void setSumable(Boolean sumable) { + this.sumable = sumable; + } + + /** + * @return the graphable + */ + public Boolean getGraphable() { + return graphable; + } + + /** + * @param graphable the graphable to set + */ + public void setGraphable(Boolean graphable) { + this.graphable = graphable; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java index 918bf1a..fbd1b06 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryFieldSet.java @@ -57,6 +57,26 @@ public class DefaultVascEntryFieldSet implements VascEntryFieldSet { vascEntryFieldIds = new ArrayList(10); } + /** + * @see java.lang.Object#clone() + */ + @Override + public VascEntryFieldSet clone() throws CloneNotSupportedException { + DefaultVascEntryFieldSet result = new DefaultVascEntryFieldSet(); + result.id=id; + result.name=name; + result.description=description; + result.helpId=helpId; + result.image=image; + result.styleList=styleList; + result.styleEdit=styleEdit; + result.collapsed=collapsed; + result.optional=optional; + result.vascEntryFieldIds.addAll(vascEntryFieldIds); + return result; + } + + /** * @return the id */ diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java index 26c9fa1..1c07e74 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendData.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.idcanet.vasc.core.VascBackend; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryFinalizer; @@ -52,6 +53,7 @@ public class DefaultVascFrontendData implements VascFrontendData { private List entryDataList = null; private Object entryDataObject = null; private VascFrontend vascFrontend = null; + private VascBackend vascBackend = null; private VascEntryFinalizer vascEntryFinalizer = null; private VascFrontendHelper vascFrontendHelper = null; private VascEntryResourceResolver vascEntryResourceResolver = null; @@ -160,6 +162,12 @@ public class DefaultVascFrontendData implements VascFrontendData { cl = rendererId.getClass().getClassLoader(); // fallback } String componentClass = getVascUIComponentClass(rendererId); + if (componentClass==null) { + + // TODO: auto wire text <-> object converts + + componentClass = getVascUIComponentClass(VascUIComponent.VASC_TEXT); + } if (componentClass==null) { throw new VascException("No component Class found for frontend UIComponent: "+rendererId); } @@ -219,4 +227,18 @@ public class DefaultVascFrontendData implements VascFrontendData { public VascUIComponent getFieldVascUIComponent(VascEntryField field) { return fieldComps.get(field); } + + /** + * @return the vascBackend + */ + public VascBackend getVascBackend() { + return vascBackend; + } + + /** + * @param vascBackend the vascBackend to set + */ + public void setVascBackend(VascBackend vascBackend) { + this.vascBackend = vascBackend; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java index 099742f..9ec39d6 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java @@ -32,6 +32,9 @@ import java.util.logging.Logger; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascFrontendHelper; +import com.idcanet.vasc.core.VascUserRoleController; +import com.idcanet.vasc.core.actions.GlobalVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; import com.idcanet.vasc.core.ui.VascUIComponent; @@ -55,6 +58,98 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { //exceptionListeners = new ArrayList(2); } + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderView(com.idcanet.vasc.core.VascEntryField) + */ + public boolean renderView(VascEntryField field) { + if (field.getView()==false) { + return false; + } + return true; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderCreate(com.idcanet.vasc.core.VascEntryField) + */ + public boolean renderCreate(VascEntryField field) { + if (renderView(field)==false) { + return false; + } + VascUserRoleController u = field.getVascEntry().getVascFrontendData().getVascController().getVascUserRoleControllerResolver().getVascUserRoleController(); + if (field.getRolesCreate()!=null && u.hasRole(field.getRolesCreate())) { + return true; + } + if (field.getCreate()) { + return true; + } + return false; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderEdit(com.idcanet.vasc.core.VascEntryField) + */ + public boolean renderEdit(VascEntryField field) { + if (renderView(field)==false) { + return false; + } + VascUserRoleController u = field.getVascEntry().getVascFrontendData().getVascController().getVascUserRoleControllerResolver().getVascUserRoleController(); + if (field.getRolesEdit()!=null && u.hasRole(field.getRolesEdit())) { + return true; + } + if (field.getEdit()) { + return true; + } + return false; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderEditReadOnly(com.idcanet.vasc.core.VascEntryField) + */ + public boolean renderEditReadOnly(VascEntryField field) { + if (renderView(field)==false) { + return false; + } + VascUserRoleController u = field.getVascEntry().getVascFrontendData().getVascController().getVascUserRoleControllerResolver().getVascUserRoleController(); + if (field.getRolesEditReadOnly()!=null && u.hasRole(field.getRolesEditReadOnly())) { + return true; + } + if (field.getEditReadOnly()) { + return true; + } + return false; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderList(com.idcanet.vasc.core.VascEntryField) + */ + public boolean renderList(VascEntryField field) { + if (renderView(field)==false) { + return false; + } + VascUserRoleController u = field.getVascEntry().getVascFrontendData().getVascController().getVascUserRoleControllerResolver().getVascUserRoleController(); + if (field.getRolesList()!=null && u.hasRole(field.getRolesList())) { + return true; + } + if (field.getList()) { + return true; + } + return false; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderGlobalVascAction(com.idcanet.vasc.core.actions.GlobalVascAction) + */ + public boolean renderGlobalVascAction(GlobalVascAction action) { + return true; + } + + /** + * @see com.idcanet.vasc.core.VascFrontendHelper#renderRowVascAction(com.idcanet.vasc.core.actions.RowVascAction) + */ + public boolean renderRowVascAction(RowVascAction action) { + return true; + } + /** * @see com.idcanet.vasc.core.VascFrontendHelper#addEventListener(com.idcanet.vasc.core.entry.VascEntryEventListener) */ @@ -119,7 +214,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { if (object!=null) { return object; } - object = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).provideVascEntryRecordCreator(entry).newRecord(entry); + object = entry.getVascFrontendData().getVascBackend().provideVascEntryRecordCreator(entry).newRecord(entry); //fireVascEvent(VascEventListener.VascEventType.BEAN_INIT, object); return object; } @@ -145,7 +240,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { public Object mergeObject(VascEntry entry, Object object) { Object result = null; try { - object = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).merge(object); + object = entry.getVascFrontendData().getVascBackend().merge(object); //fireVascEvent(VascEventListener.VascEventType.BEAN_MERGE,object); // todo: make faster // add to table at position old old object @@ -164,7 +259,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { */ public void refreshData(VascEntry entry) throws Exception { entry.getVascFrontendData().setEntryDataObject(null); - entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()).execute()); + entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascBackend().execute()); //fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, null); } @@ -189,7 +284,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { */ public boolean setUIComponentsBeanErrors(VascEntry entry, Object bean) { boolean error = false; - if(bean==null) { + if (bean==null) { logger.finest("No bean to check."); return true; // nothing to check } @@ -198,7 +293,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { //InvalidValue[] ival = val.getInvalidValues(bean); //logger.fine("Got invaliled value: "+ival.length); - for(VascEntryField col:entry.getVascEntryFields()) { + for (VascEntryField col:entry.getVascEntryFields()) { try { Object object = col.getVascEntryFieldValue().getValue(col, bean); @@ -256,57 +351,8 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } */ - /* - public void finalizeVascColumns(VascTable table) throws Exception { - VascAnnotationParser vap = new VascAnnotationParser(); - - for(VascTableColumn c:table.getTableColumns()) { - if (c instanceof VascAnnotationTableColumn) { - VascAnnotationTableColumn column = (VascAnnotationTableColumn)c; - - if (c.getName()==null) { - c.setName(vap.getVascNameKey(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); - } - if (c.getToolTip()==null) { - c.setToolTip(vap.getVascToolTipKey(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); - } - if (c.getDefaultValue()==null) { - c.setDefaultValue(vap.getVascDefaultValue(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); - } - if (c.getWidth()==null) { - Object obj = vap.getVascColumnWidth(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty()); - if (obj instanceof Integer) { - c.setWidth((Integer)obj); - } - c.setWidth(100); - // get KEY - } - if (c.getHelpId()==null) { - c.setHelpId(vap.getVascHelpId(table.getVascRecordCreator().getObjectClass(), column.getBeanProperty())); - } - if (c.getVascColumnValue()==null) { - c.setVascColumnValue(new BeanPropertyVascColumnValue(column.getBeanProperty())); - } - if (c.getImage()==null) { - c.setImage(vap.getVascImage(table.getVascRecordCreator().getObjectClass(),column.getBeanProperty())); - } - } - if (c.getVascUIComponent()==null) { - if (c.getDefaultValue() instanceof Boolean) { - c.setVascUIComponent(new VascToggle()); - } else if (c.getDefaultValue() instanceof Date) { - c.setVascUIComponent(new VascDate()); - } else { - c.setVascUIComponent(new VascTextField()); - } - } - if (c.getVascColumnRenderer()==null) { - //c.setVascColumnRenderer(new DefaultVascColumnRenderer()); - } - } - } - +/* public void addEventListener(VascEventListener e) { eventListeners.add(e); } diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java index 607b829..2fe1769 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java @@ -36,20 +36,94 @@ import com.idcanet.vasc.core.VascLinkEntry; * @version 1.0 Oct 27, 2007 */ public class DefaultVascLinkEntry implements VascLinkEntry { - - private String vascEntryName = null; + + private String id; + private String vascEntryId = null; + private String parameterName = null; + private String valueFieldId = null; + private Boolean viewAsDetail = null; /** - * @return the vascEntryName + * @return the id */ - public String getVascEntryName() { - return vascEntryName; + public String getId() { + return id; } /** - * @param vascEntryName the vascEntryName to set + * @param id the id to set */ - public void setVascEntryName(String vascEntryName) { - this.vascEntryName = vascEntryName; + public void setId(String id) { + this.id = id; + } + + /** + * @return the parameterName + */ + public String getParameterName() { + return parameterName; + } + + /** + * @param parameterName the parameterName to set + */ + public void setParameterName(String parameterName) { + this.parameterName = parameterName; + } + + /** + * @return the valueFieldId + */ + public String getValueFieldId() { + return valueFieldId; + } + + /** + * @param valueFieldId the valueFieldId to set + */ + public void setValueFieldId(String valueFieldId) { + this.valueFieldId = valueFieldId; + } + + /** + * @return the vascEntryId + */ + public String getVascEntryId() { + return vascEntryId; + } + + /** + * @param vascEntryId the vascEntryId to set + */ + public void setVascEntryId(String vascEntryId) { + this.vascEntryId = vascEntryId; + } + + /** + * @return the viewAsDetail + */ + public Boolean getViewAsDetail() { + return viewAsDetail; + } + + /** + * @param viewAsDetail the viewAsDetail to set + */ + public void setViewAsDetail(Boolean viewAsDetail) { + this.viewAsDetail = viewAsDetail; + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public VascLinkEntry clone() throws CloneNotSupportedException { + DefaultVascLinkEntry result = new DefaultVascLinkEntry(); + result.viewAsDetail=viewAsDetail; + result.vascEntryId=vascEntryId; + result.parameterName=parameterName; + result.valueFieldId=valueFieldId; + result.id=id; + return result; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java new file mode 100644 index 0000000..c8de797 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java @@ -0,0 +1,126 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and +* the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions +* and the following disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the authors and +* should not be interpreted as representing official policies, either expressed or implied, of IDCA. +*/ + +package com.idcanet.vasc.impl; + +import java.util.ArrayList; +import java.util.List; + +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.ui.VascSelectItem; +import com.idcanet.vasc.core.ui.VascSelectItemModel; + + +/** +* The DefaultVascLinkEntry +* +* @author Willem Cazander +* @version 1.0 Oct 27, 2007 +*/ +public class DefaultVascSelectItemModel implements VascSelectItemModel { + + private String entryId = null; + private String keyFieldId = null; + private String displayFieldId = null; + + /** + * @see com.idcanet.vasc.core.ui.VascSelectItemModel#getVascSelectItems(com.idcanet.vasc.core.VascEntry) + */ + public List getVascSelectItems(VascEntry entry) throws VascException { + List result = new ArrayList(100); + VascEntry ve = entry.getVascFrontendData().getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById(entryId); + VascEntryField key = ve.getVascEntryFieldById(keyFieldId); + VascEntryField dis = ve.getVascEntryFieldById(displayFieldId); + if (key==null) { + throw new VascException("Could not find: "+keyFieldId+" from: "+ve.getId()); + } + if (dis==null) { + throw new VascException("Could not find: "+displayFieldId+" from: "+ve.getId()); + } + + VascBackend back = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(ve.getBackendId()); + try { + for (Object o:back.execute()) { + String keyId = ""+key.getVascEntryFieldValue().getValue(key, o); + // hackje + if (dis.getDisplayName()!=null && "".equals(dis.getDisplayName())==false) { + dis.setBackendName(dis.getDisplayName()); + } + String nameId = ""+dis.getVascEntryFieldValue().getValue(dis, o); + VascSelectItem item = new VascSelectItem(nameId,o,keyId); + result.add(item); + } + } catch (Exception e) { + throw new VascException(e); + } + return result; + } + + /** + * @return the entryId + */ + public String getEntryId() { + return entryId; + } + + /** + * @param entryId the entryId to set + */ + public void setEntryId(String entryId) { + this.entryId = entryId; + } + + /** + * @return the keyFieldId + */ + public String getKeyFieldId() { + return keyFieldId; + } + + /** + * @param keyFieldId the keyFieldId to set + */ + public void setKeyFieldId(String keyFieldId) { + this.keyFieldId = keyFieldId; + } + + /** + * @return the displayFieldId + */ + public String getDisplayFieldId() { + return displayFieldId; + } + + /** + * @param displayFieldId the displayFieldId to set + */ + public void setDisplayFieldId(String displayFieldId) { + this.displayFieldId = displayFieldId; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleController.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleController.java new file mode 100644 index 0000000..631c303 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleController.java @@ -0,0 +1,106 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl; + +import java.util.ArrayList; +import java.util.List; + +import com.idcanet.vasc.core.VascUserRoleController; + +/** + * Simple default user controller for wrapping user info into vasc + * + * + * @author Willem Cazander + * @version 1.0 Mar 13, 2009 + */ +public class DefaultVascUserRoleController implements VascUserRoleController { + + private Long userId = null; + private String userName = null; + private List userRoles = null; + + + public DefaultVascUserRoleController(Long userId,String userName) { + if (userId==null) { + throw new NullPointerException("userId may not be null."); + } + if (userName==null) { + throw new NullPointerException("userName may not be null"); + } + this.userId=userId; + this.userName=userName; + userRoles = new ArrayList(10); + } + + public DefaultVascUserRoleController(Long userId,String userName,String...roles) { + this(userId,userName); + for (String role:roles) { + userRoles.add(role); + } + } + + + /** + * @see com.idcanet.vasc.core.VascUserRoleController#getUserId() + */ + public Long getUserId() { + return userId; + } + + /** + * @see com.idcanet.vasc.core.VascUserRoleController#getUserName() + */ + public String getUserName() { + return userName; + } + + /** + * @see com.idcanet.vasc.core.VascUserRoleController#getUserRoles() + */ + public List getUserRoles() { + return userRoles; + } + + /** + * @see com.idcanet.vasc.core.VascUserRoleController#hasRole(java.lang.String) + */ + public boolean hasRole(String roles) { + if (roles==null) { + return false; + } + // input: admin|superAdmin + // input: (admin|superAdmin)&login + String[] r = roles.split("|"); + for (String rr:r) { + if (userRoles.contains(rr)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleControllerResolver.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleControllerResolver.java index 08a4714..edc6c31 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleControllerResolver.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascUserRoleControllerResolver.java @@ -48,8 +48,7 @@ public class DefaultVascUserRoleControllerResolver implements VascUserRoleContro /** * @param vascUserRoleController the vascUserRoleController to set */ - public void setVascUserRoleController( - VascUserRoleController vascUserRoleController) { + public void setVascUserRoleController(VascUserRoleController vascUserRoleController) { this.vascUserRoleController = vascUserRoleController; } -} \ No newline at end of file +} diff --git a/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java b/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java new file mode 100644 index 0000000..f2b5d88 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java @@ -0,0 +1,83 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and +* the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions +* and the following disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the authors and +* should not be interpreted as representing official policies, either expressed or implied, of IDCA. +*/ + +package com.idcanet.vasc.impl; + +import java.util.ArrayList; +import java.util.List; + +import com.idcanet.vasc.core.AbstractVascBackendProxy; +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascEntry; + + +/** +* Simulates a real pages backend. +* +* @author Willem Cazander +* @version 1.0 Oct 27, 2007 +*/ +public class VascBackendProxyPaged extends AbstractVascBackendProxy { + + private long records = 0; + + public VascBackendProxyPaged(VascBackend backend,VascEntry entry) { + super(backend); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isPageable() + */ + @Override + public boolean isPageable() { + return true; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#execute() + */ + @Override + public List execute() throws Exception { + List allData = backend.execute(); + List paged = new ArrayList(getPageSize()); + int off = getPageIndex()*getPageSize(); + int offMax = off+getPageSize(); + for (int i=off;i=allData.size()) { + break; + } + Object o = allData.get(i); + paged.add(o); + } + records = allData.size(); + return paged; + } + + @Override + public long getPagesTotalRecords() { + return records; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/VascBackendProxySearch.java b/src/main/java/com/idcanet/vasc/impl/VascBackendProxySearch.java new file mode 100644 index 0000000..371cc5d --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/VascBackendProxySearch.java @@ -0,0 +1,125 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and +* the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions +* and the following disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the authors and +* should not be interpreted as representing official policies, either expressed or implied, of IDCA. +*/ + +package com.idcanet.vasc.impl; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.idcanet.vasc.core.AbstractVascBackendProxy; +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascBackendPageNumber; +import com.idcanet.vasc.core.VascEntry; + + +/** +* Simple text search +* +* @author Willem Cazander +* @version 1.0 Oct 27, 2007 +*/ +public class VascBackendProxySearch extends AbstractVascBackendProxy { + + private long records = 0; + + public VascBackendProxySearch(VascBackend backend,VascEntry entry) { + super(backend); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isSearchable() + */ + @Override + public boolean isSearchable() { + return true; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#execute() + */ + @Override + public List execute() throws Exception { + List result = backend.execute(); + if (getSearchString()==null) { + records = backend.getPagesTotalRecords(); + return result; + } + String searchString = getSearchString().toLowerCase(); + List search = new ArrayList(result.size()/4); + for (Object o:result) { + for (Method method:o.getClass().getMethods()) { + if (method.getName().startsWith("get")==false) { //a bit durty + continue; + } + if (method.getName().equals("getClass")) { + continue; + } + if (method.getReturnType().isAssignableFrom(Collection.class)) { + continue; + } + if (method.getReturnType().isAssignableFrom(List.class)) { + continue; + } + if (method.getReturnType().isAssignableFrom(Set.class)) { + continue; + } + if (method.getReturnType().isAssignableFrom(Map.class)) { + continue; + } + Object res = method.invoke(o,null); + if (res==null) { + continue; + } + String r = res.toString().toLowerCase(); + if (r.contains(searchString)) { + search.add(o); + break; + } + } + } + records = search.size(); + return search; + } + + @Override + public long getPagesTotalRecords() { + return records; + } + @Override + public List getVascBackendPageNumbers() { + if (getSearchString()==null) { + return backend.getVascBackendPageNumbers(); + } + // limit the pages to the number of search results. + List r = backend.getVascBackendPageNumbers(); + int pages = new Long(getPagesTotalRecords()/getPageSize()).intValue(); + return r.subList(0, pages); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java b/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java new file mode 100644 index 0000000..292d7d8 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java @@ -0,0 +1,88 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and +* the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions +* and the following disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the authors and +* should not be interpreted as representing official policies, either expressed or implied, of IDCA. +*/ + +package com.idcanet.vasc.impl; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import com.idcanet.vasc.core.AbstractVascBackendProxy; +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; + + +/** +* Add an sortware sort an a backend +* +* @author Willem Cazander +* @version 1.0 Oct 27, 2007 +*/ +public class VascBackendProxySort extends AbstractVascBackendProxy { + + private VascEntry entry = null; + + public VascBackendProxySort(VascBackend backend,VascEntry entry) { + super(backend); + this.entry=entry; + } + + // sort stuff + + /** + * @see com.idcanet.vasc.core.VascBackend#execute() + */ + @SuppressWarnings("unchecked") + @Override + public List execute() throws Exception { + List result = backend.execute(); + if (getSortField()==null) { + return result; + } + final VascEntryField field = entry.getVascEntryFieldById(getSortField()); + final VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field); + Collections.sort(result, new Comparator() { + public int compare(Object o1, Object o2) { + try { + Comparable c1 = (Comparable)fieldValue.getValue(field, o1); + Comparable c2 = (Comparable)fieldValue.getValue(field, o2); + if (isSortAscending()) { + return c1.compareTo(c2); + } else { + return c2.compareTo(c1); + } + } catch (VascException e) { + e.printStackTrace(); + return 0; + } + } + }); + return result; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/actions/AddRowAction.java b/src/main/java/com/idcanet/vasc/impl/actions/AddRowAction.java index 7798e26..004f486 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/AddRowAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/AddRowAction.java @@ -38,6 +38,7 @@ import com.idcanet.vasc.core.actions.RowVascAction; public class AddRowAction extends AbstractVascAction implements RowVascAction { public AddRowAction() { + setId("addRowAction"); setName("vasc.action.add.name"); setToolTip("vasc.action.add.tooltip"); setImage("vasc.action.add.image"); @@ -46,4 +47,11 @@ public class AddRowAction extends AbstractVascAction implements RowVascAction { public void doRowAction(VascEntry enty,Object rowObject) throws Exception { enty.getVascFrontendData().getVascFrontend().renderEdit(null); } + + /** + * @see com.idcanet.vasc.core.actions.RowVascAction#isMultiRowAction() + */ + public boolean isMultiRowAction() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java b/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java index 8ed2cd7..4eaaadd 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java @@ -43,6 +43,7 @@ import com.idcanet.vasc.core.actions.GlobalVascAction; public class CSVExportGlobalAction extends AbstractVascAction implements GlobalVascAction,VascEntryExporter { public CSVExportGlobalAction() { + setId("CSVExportGlobalAction"); setName("vasc.action.csv.name"); setToolTip("vasc.action.csv.tooltip"); setImage("vasc.action.csv.image"); @@ -71,7 +72,7 @@ public class CSVExportGlobalAction extends AbstractVascAction implements GlobalV } public String getMineType() { - return "csv"; + return "text/csv"; } public String getType() { diff --git a/src/main/java/com/idcanet/vasc/impl/actions/DeleteRowAction.java b/src/main/java/com/idcanet/vasc/impl/actions/DeleteRowAction.java index 9518584..ff5a441 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/DeleteRowAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/DeleteRowAction.java @@ -38,6 +38,7 @@ import com.idcanet.vasc.core.actions.RowVascAction; public class DeleteRowAction extends AbstractVascAction implements RowVascAction { public DeleteRowAction() { + setId("deleteRowAction"); setName("vasc.action.del.name"); setToolTip("vasc.action.del.tooltip"); setImage("vasc.action.del.image"); @@ -49,4 +50,11 @@ public class DeleteRowAction extends AbstractVascAction implements RowVascAction } entry.getVascFrontendData().getVascFrontend().renderDelete(rowObject); } + + /** + * @see com.idcanet.vasc.core.actions.RowVascAction#isMultiRowAction() + */ + public boolean isMultiRowAction() { + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java b/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java index b643870..7c50e3b 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/EditRowAction.java @@ -38,6 +38,7 @@ import com.idcanet.vasc.core.actions.RowVascAction; public class EditRowAction extends AbstractVascAction implements RowVascAction { public EditRowAction() { + setId("editRowAction"); setName("vasc.action.edit.name"); setToolTip("vasc.action.edit.tooltip"); setImage("vasc.action.edit.image"); @@ -50,4 +51,12 @@ public class EditRowAction extends AbstractVascAction implements RowVascAction { } entry.getVascFrontendData().getVascFrontend().renderEdit(rowObject); } + + + /** + * @see com.idcanet.vasc.core.actions.RowVascAction#isMultiRowAction() + */ + public boolean isMultiRowAction() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java b/src/main/java/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java index ba20974..d8d4515 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/RefreshDataGlobalAction.java @@ -38,6 +38,7 @@ import com.idcanet.vasc.core.actions.GlobalVascAction; public class RefreshDataGlobalAction extends AbstractVascAction implements GlobalVascAction { public RefreshDataGlobalAction() { + setId("refreshDataGlobalAction"); setName("vasc.action.refresh.name"); setToolTip("vasc.action.refresh.tooltip"); setImage("vasc.action.refresh.image"); diff --git a/src/main/java/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java b/src/main/java/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java index 3ff0bec..b50e910 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/XMLExportGlobalAction.java @@ -43,6 +43,7 @@ import com.idcanet.vasc.core.entry.VascEntryExporter; public class XMLExportGlobalAction extends AbstractVascAction implements GlobalVascAction,VascEntryExporter { public XMLExportGlobalAction() { + setId("XMLExportGlobalAction"); setName("vasc.action.xml.name"); setToolTip("vasc.action.xml.tooltip"); setImage("vasc.action.xml.image"); @@ -58,9 +59,9 @@ public class XMLExportGlobalAction extends AbstractVascAction implements GlobalV p.write("\n"); for (Object o:entry.getVascFrontendData().getEntryDataList()) { for (VascEntryField c:entry.getVascEntryFields()) { - p.write(""); + p.write("\n"); + p.write("]]>\n"); } p.flush(); } diff --git a/src/main/java/com/idcanet/vasc/impl/entry/DefaultVascEntryResourceResolver.java b/src/main/java/com/idcanet/vasc/impl/entry/DefaultVascEntryResourceResolver.java index 7290869..ae6012f 100644 --- a/src/main/java/com/idcanet/vasc/impl/entry/DefaultVascEntryResourceResolver.java +++ b/src/main/java/com/idcanet/vasc/impl/entry/DefaultVascEntryResourceResolver.java @@ -26,6 +26,11 @@ package com.idcanet.vasc.impl.entry; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + import com.idcanet.vasc.core.entry.VascEntryResourceResolver; /** @@ -35,11 +40,56 @@ import com.idcanet.vasc.core.entry.VascEntryResourceResolver; */ public class DefaultVascEntryResourceResolver implements VascEntryResourceResolver { + protected ResourceBundle resourceBundle = null; + + + public DefaultVascEntryResourceResolver() { + } + + public DefaultVascEntryResourceResolver(ResourceBundle resourceBundle) { + setResourceBundle(resourceBundle); + } + + public DefaultVascEntryResourceResolver(String baseName,Locale locale) { + this(ResourceBundle.getBundle(baseName, locale)); + } + public String getKeyMapping(String key) { - return key; + if (resourceBundle==null) { + return key; + } else { + return resourceBundle.getString(key); + } } public String getTextValue(String text,Object...params) { - return text; + if (resourceBundle==null) { + return text; + } else { + String textValue = null; + try { + textValue = resourceBundle.getString(text); + } catch (MissingResourceException mre) { + return text; + } + if (params.length>0) { + textValue = MessageFormat.format(textValue, params); + } + return textValue; + } + } + + /** + * @return the resourceBundle + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * @param resourceBundle the resourceBundle to set + */ + public void setResourceBundle(ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldType.java b/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldType.java index 831d482..cf2d3a7 100644 --- a/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldType.java +++ b/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldType.java @@ -28,12 +28,29 @@ package com.idcanet.vasc.impl.type; import com.idcanet.vasc.core.AbstractVascEntryFieldType; +import com.idcanet.vasc.core.VascEntryFieldType; /** + * Only knows how to clone its self. + * * * @author Willem Cazander * @version 1.0 Sep 8, 2008 */ -public class DefaultVascEntryFieldType extends AbstractVascEntryFieldType { +public class DefaultVascEntryFieldType extends AbstractVascEntryFieldType { + @Override + public VascEntryFieldType clone() throws CloneNotSupportedException { + DefaultVascEntryFieldType clone = new DefaultVascEntryFieldType(); + clone.id=id; + clone.autoDetectClass=autoDetectClass; + clone.uiComponentId=uiComponentId; + clone.inputMask=inputMask; + for (String key:properties.keySet()) { + clone.properties.put(key,properties.get(key)); + } + // mmm + clone.vascValidators.addAll(vascValidators); + return clone; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldTypeController.java b/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldTypeController.java index 0d65e86..452a941 100644 --- a/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldTypeController.java +++ b/src/main/java/com/idcanet/vasc/impl/type/DefaultVascEntryFieldTypeController.java @@ -27,46 +27,80 @@ package com.idcanet.vasc.impl.type; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.idcanet.vasc.core.VascEntryFieldType; -import com.idcanet.vasc.core.VascEntryFieldTypeController; +import com.idcanet.vasc.core.VascEntryFieldTypeControllerLocal; +import com.idcanet.vasc.core.VascException; /** * * @author Willem Cazander * @version 1.0 Sep 14, 2008 */ -public class DefaultVascEntryFieldTypeController implements VascEntryFieldTypeController { +public class DefaultVascEntryFieldTypeController implements VascEntryFieldTypeControllerLocal { - FieldTypeParser parser = null; + private Map vascEntryFieldTypes = null; - public DefaultVascEntryFieldTypeController() throws Exception { - parser = new FieldTypeParser(); - parser.parseVascFieldTypes(); + public DefaultVascEntryFieldTypeController() throws VascException { + try { + FieldTypeParser parser = new FieldTypeParser(); + parser.parseVascFieldTypes(); + + vascEntryFieldTypes = new HashMap(35); + for(VascEntryFieldType v:parser.getTypes()) { + vascEntryFieldTypes.put(v.getId(),v); + } + } catch (Exception e) { + throw new VascException(e); + } } - + /** + * + */ + public void addVascEntryFieldType(VascEntryFieldType vascEntryFieldType) { + if (vascEntryFieldType==null) { + throw new NullPointerException("Can't add null vascEntryFieldType."); + } + vascEntryFieldTypes.put(vascEntryFieldType.getId(),vascEntryFieldType); + } + /** * @see com.idcanet.vasc.core.VascEntryFieldTypeController#getVascEntryFieldTypeById(java.lang.String) */ - public VascEntryFieldType getVascEntryFieldTypeById(String name) { - for(VascEntryFieldType v:parser.getTypes()) { - if (v.getId().equals(name)) { - return v; - } + public VascEntryFieldType getVascEntryFieldTypeById(String id) { + VascEntryFieldType result = vascEntryFieldTypes.get(id); + if (result==null) { + throw new IllegalArgumentException("Field not found: "+id); + } + try { + return result.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalArgumentException("FieldType not clonable: "+e.getMessage()); } - throw new IllegalArgumentException("Field not found: "+name); } + + public VascEntryFieldType getRealVascEntryFieldTypeById(String id) { + VascEntryFieldType result = vascEntryFieldTypes.get(id); + if (result==null) { + throw new IllegalArgumentException("Field not found: "+id); + } + return result; + } + + /** * @see com.idcanet.vasc.core.VascEntryFieldTypeController#getVascEntryFieldTypeIds() */ public List getVascEntryFieldTypeIds() { List result = new ArrayList(5); - for(VascEntryFieldType v:parser.getTypes()) { - result.add(v.getId()); - } + result.addAll(vascEntryFieldTypes.keySet()); + Collections.sort(result); // lets do abc for consistance behauvior. return result; } } diff --git a/src/main/java/com/idcanet/vasc/impl/type/FieldTypeParser.java b/src/main/java/com/idcanet/vasc/impl/type/FieldTypeParser.java index 044ee88..117763d 100644 --- a/src/main/java/com/idcanet/vasc/impl/type/FieldTypeParser.java +++ b/src/main/java/com/idcanet/vasc/impl/type/FieldTypeParser.java @@ -28,6 +28,7 @@ package com.idcanet.vasc.impl.type; import java.io.IOException; import java.util.ArrayList; +import java.util.InvalidPropertiesFormatException; import java.util.List; import javax.xml.parsers.ParserConfigurationException; @@ -51,9 +52,11 @@ public class FieldTypeParser extends X4OParser { /** * * @param language + * @throws IOException + * @throws InvalidPropertiesFormatException * @throws Exception */ - public FieldTypeParser() throws Exception { + public FieldTypeParser() throws InvalidPropertiesFormatException, IOException { super(FIELD_TYPE_LANGUAGE); } @@ -63,7 +66,7 @@ public class FieldTypeParser extends X4OParser { public List getTypes() { List result = new ArrayList(4); - for (Element e:getElementContext().getRootElements()) { + for (Element e:getElementContext().getRootElement().getChilderen()) { VascEntryFieldType a = (VascEntryFieldType)e.getElementObject(); result.add(a); } diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java b/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java new file mode 100644 index 0000000..9debb45 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/x4o/AnnotationParserElement.java @@ -0,0 +1,318 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.x4o; + +import java.io.IOException; +import java.io.StringReader; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import com.idcanet.vasc.annotations.VascAnnotationParser; +import com.idcanet.vasc.core.VascController; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascEntryFieldType; +import com.idcanet.vasc.impl.DefaultVascEntryField; +import com.idcanet.vasc.validators.VascValidator; +import com.idcanet.vasc.validators.VascValidatorClassParser; + +import com.idcanet.x4o.core.X4OParser; +import com.idcanet.x4o.element.AbstractElement; +import com.idcanet.x4o.element.ElementException; + + +/** + * Parses the xml element for auto adding field or defaults of fields. + * + * @author Willem Cazander + * @version 1.0 Mar 24, 2009 + */ +public class AnnotationParserElement extends AbstractElement { + + /** + * @see com.idcanet.x4o.element.AbstractElement#doElementRun() + */ + @Override + public void doElementRun() throws ElementException { + try { + String className = getAttributes().get("className"); + String addFields = getAttributes().get("addFields"); + Object parentObject = getParent().getElementObject(); + + Class modelClass; + try { + modelClass = X4OParser.loadClass(className); + } catch (ClassNotFoundException e) { + throw new ElementException(e); + } + VascAnnotationParser parser = new VascAnnotationParser(); + + if (parentObject instanceof VascEntry) { + VascEntry entry = (VascEntry)parentObject; + if (addFields!=null && "false".equals(addFields)) { + // when false we don't add the fields. + } else { + addFields(entry,modelClass); + } + for (VascEntryField field:entry.getVascEntryFields()) { + fillField(field,modelClass,parser); + } + entry.setDisplayNameFieldId(parser.getVascDisplayName(modelClass)); + entry.setPrimaryKeyFieldId(parser.getVascPrimaryKey(modelClass)); + + } else if (parentObject instanceof VascEntryField) { + VascEntryField field = (VascEntryField)parentObject; + fillField(field,modelClass,parser); + } else { + throw new ElementException("Unknow parent object type: "+parentObject); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new ElementException(e); + } + } + + private void fillEntry(VascEntry entry,Class modelClass,VascAnnotationParser parser) { + + + if (entry.getId()==null) { + + } + if (entry.getHeaderName()==null) { + + } + if (entry.getHeaderDescription()==null) { + + } + if (entry.getHeaderImage()==null) { + + } + + + } + + private void fillField(VascEntryField field,Class modelClass,VascAnnotationParser parser) { + String value = null; + value = parser.getVascFieldBackendName(modelClass, field.getId()); + if (value!=null && "".equals(value)==false) { + field.setBackendName(value); + } + + + if (field.getDisplayName()==null) { + field.setDisplayName( parser.getVascDisplayName (modelClass, field.getId())); + } + if (field.getName()==null) { + field.setName( parser.getVascI18nName (modelClass, field.getId())); + } + if (field.getDescription()==null) { + field.setDescription( parser.getVascI18nDescription (modelClass, field.getId())); + } + if (field.getImage()==null) { + field.setImage( parser.getVascI18nImage (modelClass, field.getId())); + } + if (field.getHelpId()==null) { + field.setHelpId( parser.getVascI18nHelpId (modelClass, field.getId())); + } + if (field.getOrderIndex()==null) { + field.setOrderIndex( parser.getVascOrderIndex (modelClass, field.getId())); + } + if (field.getCreate()==null) { + field.setCreate( parser.getVascFieldCreate (modelClass, field.getId())); + } + if (field.getEdit()==null) { + field.setEdit( parser.getVascFieldEdit (modelClass, field.getId())); + } + if (field.getEditReadOnly()==null) { + field.setEditReadOnly( parser.getVascFieldEditReadOnly (modelClass, field.getId())); + } + if (field.getEditBlank()==null) { + field.setEditBlank( parser.getVascFieldEditBlank (modelClass, field.getId())); + } + if (field.getList()==null) { + field.setList( parser.getVascFieldList (modelClass, field.getId())); + } + if (field.getView()==null) { + field.setView( parser.getVascFieldView (modelClass, field.getId())); + } + if (field.getOptional()==null) { + field.setOptional( parser.getVascFieldOptional (modelClass, field.getId())); + } + + + if (field.getRolesCreate()==null) { + field.setRolesCreate( parser.getVascRolesCreate (modelClass, field.getId())); + } + if (field.getRolesEdit()==null) { + field.setRolesEdit( parser.getVascRolesEdit (modelClass, field.getId())); + } + if (field.getRolesEditReadOnly()==null) { + field.setRolesEditReadOnly(parser.getVascRolesEditReadOnly (modelClass, field.getId())); + } + if (field.getRolesList()==null) { + field.setRolesList( parser.getVascRolesList (modelClass, field.getId())); + } + + + if (field.getSizeEdit()==null) { + field.setSizeEdit( parser.getVascStyleSizeEdit (modelClass, field.getId())); + } + if (field.getSizeList()==null) { + field.setSizeList( parser.getVascStyleSizeList (modelClass, field.getId())); + } + if (field.getStyleEdit()==null) { + field.setStyleEdit( parser.getVascStyleStyleEdit (modelClass, field.getId())); + } + if (field.getStyleList()==null) { + field.setStyleList( parser.getVascStyleStyleList (modelClass, field.getId())); + } + + VascValidatorClassParser validatorParser = new VascValidatorClassParser(); + List val = validatorParser.getValidatorsByPropertyName(modelClass, field.getId()); + for (VascValidator v:val) { + field.addVascValidator(v); + } + + VascController vascController = VascParser.getVascController(this.getElementContext()); + if (field.getVascEntryFieldType()==null) { + String fieldType = parser.getVascFieldType (modelClass, field.getId()); + if (fieldType!=null) { + VascEntryFieldType type = vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById(fieldType); + field.setVascEntryFieldType(type); + + // copy properties + String[] prop = parser.getVascFieldTypeProperties (modelClass, field.getId()); + if (prop!=null) { + Properties properties = new Properties(); + for (String p:prop) { + try { + // let properties class parse the key=value pairs. + properties.load(new StringReader(p)); + } catch (IOException e) { + e.printStackTrace(); + } + } + for (Object key:properties.keySet()) { + type.setProperty((String)key, (String)properties.get(key)); + } + } + } + } + + if (field.getVascEntryFieldType()==null) { + + Method methodCall = null; + // note: model references properties are not resolved yet. + + // search for method on bean. + for (Method method:modelClass.getMethods()) { + if (method.getName().startsWith("get")==false) { //a bit durty + continue; + } + if (method.getName().equals("getClass")) { + continue; + } + if (field.getBackendName()==null) { + if (method.getName().equalsIgnoreCase("get"+field.getId())) { + methodCall = method; + break; + } + } else { + if (method.getName().equalsIgnoreCase("get"+field.getBackendName())) { + methodCall = method; + break; + } + } + } + // System.out.println("Found method: "+methodCall); + + // search for type + if (methodCall!=null) { + Class retType = methodCall.getReturnType(); + + for (String typeId: vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeIds()) { + VascEntryFieldType type = vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById(typeId); + + //String auto = ""; + //if (type.getAutoDetectClass()!=null) { + // auto = type.getAutoDetectClass().getName(); + //} + //System.out.println("Check ret: "+retType.getName()+" type: "+type.getId()+" auto: "+auto); + + + if (type.getAutoDetectClass()!=null) { + if (type.getAutoDetectClass().isAssignableFrom(retType)) { + field.setVascEntryFieldType(type); + break; + } + } + } + } + } + } + + private void addFields(VascEntry entry,Class modelClass) { + for (Method method:modelClass.getMethods()) { + if (method.getName().startsWith("get")==false) { //a bit durty + continue; + } + if (method.getName().equals("getClass")) { + continue; + } + if (method.getReturnType().isAssignableFrom(Collection.class)) { + continue; + } + if (method.getReturnType().isAssignableFrom(List.class)) { + continue; + } + if (method.getReturnType().isAssignableFrom(Set.class)) { + continue; + } + if (method.getReturnType().isAssignableFrom(Map.class)) { + continue; + } + + String fieldId = method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); + VascEntryField field = new DefaultVascEntryField(); + field.setId(fieldId); + if (method.getName().equals("getId")) { + field.setEditReadOnly(true); + } + + if (entry.getVascEntryFieldById(fieldId)==null) { + entry.addVascEntryField(field); + } else { + continue; // already set in xml + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java b/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java new file mode 100644 index 0000000..143f39f --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java @@ -0,0 +1,75 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.x4o; + +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascEntryFieldType; +import com.idcanet.vasc.core.ui.VascSelectItemModel; +import com.idcanet.x4o.element.AbstractElementBindingHandler; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementBindingException; + +/** + * Binds SelectItems + * + * + * @author Willem Cazander + * @version 1.0 Apr 02, 2009 + */ +public class SelectItemModelBindingHandler extends AbstractElementBindingHandler { + + /** + * @see com.idcanet.x4o.element.ElementBindingHandler#canBind(com.idcanet.x4o.element.Element) + */ + public boolean canBind(Element element) { + if (element.getParent()==null) { + return false; + } + Object parent = element.getParent().getElementObject(); + Object child = element.getElementObject(); + boolean p = false; + boolean c = false; + if (parent instanceof VascEntryField) { p=true; } + if (child instanceof VascSelectItemModel) { c=true; } + if (p&c) { return true; } else { return false; } + } + + /** + * @see com.idcanet.x4o.element.ElementBindingHandler#doBind(com.idcanet.x4o.element.Element) + */ + public void doBind(Element element) throws ElementBindingException { + Object child = element.getElementObject(); + Object parentObject = element.getParent().getElementObject(); + if (parentObject instanceof VascEntryField) { + VascEntryField parent = (VascEntryField)parentObject; + if (child instanceof VascSelectItemModel) { + VascEntryFieldType type = parent.getVascEntryFieldType(); + type.setDataObject(child); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/SetParameterElement.java b/src/main/java/com/idcanet/vasc/impl/x4o/SetParameterElement.java new file mode 100644 index 0000000..ae73da9 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/x4o/SetParameterElement.java @@ -0,0 +1,96 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.x4o; + +import java.util.logging.Logger; + +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascController; + +import com.idcanet.x4o.element.AbstractElement; +import com.idcanet.x4o.element.ElementException; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 24, 2009 + */ +public class SetParameterElement extends AbstractElement { + + private Logger logger = Logger.getLogger(SetParameterElement.class.getName()); + + /** + * @see com.idcanet.x4o.element.AbstractElement#doElementRun() + */ + @Override + public void doElementRun() throws ElementException { + String name = getAttributes().get("name"); + String value = getAttributes().get("value"); + String type = getAttributes().get("type"); + VascBackend back = (VascBackend)getParent().getElementObject(); + VascController cont = VascParser.getVascController(getElementContext()); + + logger.info("Setting parameter name: "+name+" value: "+value+" type: "+type); + + if ("setUserParameter".equals(getElementClass().getTag())) { + if (value==null) { + value="id"; + } + if ("id".equals(value)) { + if ("int".equals(type)) { + Long userId = cont.getVascUserRoleControllerResolver().getVascUserRoleController().getUserId(); + back.setDataParameter(name, userId.intValue()); + } else { + Long userId = cont.getVascUserRoleControllerResolver().getVascUserRoleController().getUserId(); + back.setDataParameter(name, userId); + } + } else { + String userName = cont.getVascUserRoleControllerResolver().getVascUserRoleController().getUserName(); + back.setDataParameter(name, userName); + } + return; + } + + if (type==null) { + back.setDataParameter(name, value); + return; + } + + if ("long".equalsIgnoreCase(type)) { + back.setDataParameter(name, new Long(value)); + return; + } + if ("int".equalsIgnoreCase(type)) { + back.setDataParameter(name, new Integer(value)); + return; + } + + throw new ElementException("Could not set dataParameter: "+name+" with type: "+type); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java index 6fa28a7..c38c732 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascBackendElementConfigurator.java @@ -43,12 +43,11 @@ import com.idcanet.x4o.element.ElementConfiguratorException; * @version 1.0 Nov 16, 2008 */ public class VascBackendElementConfigurator extends AbstractElementConfigurator { - + /** * @see com.idcanet.x4o.element.AbstractElementConfigurator#doConfigEndTag(com.idcanet.x4o.element.Element) */ - @Override - public void doConfigEndTag(Element element) throws ElementConfiguratorException { + public void doConfigElement(Element element) throws ElementConfiguratorException { VascBackend backend = (VascBackend)element.getElementObject(); diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java index 93fde9c..7974323 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryElementConfigurator.java @@ -43,12 +43,11 @@ import com.idcanet.x4o.element.ElementConfiguratorException; * @version 1.0 Nov 16, 2008 */ public class VascEntryElementConfigurator extends AbstractElementConfigurator { - + /** * @see com.idcanet.x4o.element.AbstractElementConfigurator#doConfigEndTag(com.idcanet.x4o.element.Element) */ - @Override - public void doConfigEndTag(Element element) throws ElementConfiguratorException { + public void doConfigElement(Element element) throws ElementConfiguratorException { VascEntry entry = (VascEntry)element.getElementObject(); diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldElement.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldElement.java new file mode 100644 index 0000000..cb70b5b --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldElement.java @@ -0,0 +1,66 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.x4o; + +import java.util.logging.Logger; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; + +import com.idcanet.x4o.element.AbstractElement; +import com.idcanet.x4o.element.ElementException; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 27, 2009 + */ +public class VascEntryFieldElement extends AbstractElement { + + private Logger logger = Logger.getLogger(VascEntryFieldElement.class.getName()); + + + /** + * @see com.idcanet.x4o.element.AbstractElement#doElementRun() + */ + @Override + public void doElementRun() throws ElementException { + String id = getAttributes().get("id"); + VascEntry back = (VascEntry)getParent().getElementObject(); + VascEntryField field = back.getVascEntryFieldById(id); + if (field==null) { + return; + } + if (field==getElementObject()) { + return; // is the same object + } + logger.fine("ReSetting elementObject: "+field.getId()); + setElementObject(field); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java index 60655b6..f840c8a 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java @@ -43,7 +43,6 @@ public class VascEntryFieldSetParameterConverter extends AbstractElementParamete /** * @see com.idcanet.x4o.element.AbstractElementParameterConverter#doConvertParameter(com.idcanet.x4o.element.Element, java.lang.Object) */ - @Override public Object doConvertParameter(Element element, Object parameterValue) throws ElementParameterConverterException { if (parameterValue==null) { diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeElement.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeElement.java new file mode 100644 index 0000000..18b4d25 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeElement.java @@ -0,0 +1,64 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.impl.x4o; + +import java.util.logging.Logger; + +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascEntryFieldType; + +import com.idcanet.x4o.core.X4OPhase; +import com.idcanet.x4o.element.AbstractElement; +import com.idcanet.x4o.element.ElementException; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 27, 2009 + */ +public class VascEntryFieldTypeElement extends AbstractElement { + + private Logger logger = Logger.getLogger(VascEntryFieldTypeElement.class.getName()); + + + /** + * @see com.idcanet.x4o.element.AbstractElement#doElementRun() + */ + @Override + public void doElementRun() throws ElementException { + if (getElementObject()!=null) { + return; // already done. + } + VascEntryField field = (VascEntryField)getParent().getElementObject(); + VascEntryFieldType type = field.getVascEntryFieldType(); + setElementObject(type); + logger.info("Readding the element for reparsing"); + getElementContext().addDirtyElement(this, X4OPhase.startX4OPhase); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java index 1e60f03..f495b4f 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java @@ -43,7 +43,6 @@ public class VascEntryFieldTypeParameterConverter extends AbstractElementParamet /** * @see com.idcanet.x4o.element.AbstractElementParameterConverter#doConvertParameter(com.idcanet.x4o.element.Element, java.lang.Object) */ - @Override public Object doConvertParameter(Element element, Object parameterValue) throws ElementParameterConverterException { if (parameterValue==null) { diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascParser.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascParser.java index b796ea9..468659f 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascParser.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascParser.java @@ -26,13 +26,15 @@ package com.idcanet.vasc.impl.x4o; -import java.io.IOException; import javax.el.ValueExpression; -import javax.xml.parsers.ParserConfigurationException; -import org.xml.sax.SAXException; import com.idcanet.vasc.core.VascController; +import com.idcanet.x4o.core.AbstractX4OPhaseHandler; import com.idcanet.x4o.core.X4OParser; +import com.idcanet.x4o.core.X4OPhaseException; +import com.idcanet.x4o.core.X4OPhaseHandler; +import com.idcanet.x4o.core.X4OPhase; +import com.idcanet.x4o.element.Element; import com.idcanet.x4o.element.ElementContext; /** @@ -69,11 +71,26 @@ public class VascParser extends X4OParser { return con; } - protected void preStartParsing() throws ParserConfigurationException,SAXException,IOException { - super.preStartParsing(); - - // Add the controller to EL - ValueExpression ee = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${vascController}", VascController.class); - ee.setValue(getElementContext().getELContext(), vascController); + /** + * + */ + @Override + protected X4OPhaseHandler getConfigOptionalPhase() { + X4OPhaseHandler result = new AbstractX4OPhaseHandler() { + protected void setX4OPhase() { + phase = X4OPhase.configOptionalPhase; + } + public boolean isElementPhase() { + return false; + } + public void runElementPhase(Element element) throws X4OPhaseException { + } + public void runPhase(ElementContext elementContext) throws X4OPhaseException { + // Add the controller to EL + ValueExpression ee = getElementContext().getExpressionFactory().createValueExpression(getElementContext().getELContext(),"${vascController}", VascController.class); + ee.setValue(getElementContext().getELContext(), vascController); + } + }; + return result; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascDateFutureValidator.java b/src/main/java/com/idcanet/vasc/validators/VascDateFutureValidator.java index 69a2adb..dcb37b5 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascDateFutureValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascDateFutureValidator.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.validators; import java.lang.annotation.Annotation; +import java.util.Date; /** * Validates @@ -40,7 +41,12 @@ public class VascDateFutureValidator implements VascValidator { * @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object) */ public boolean isObjectValid(Object object) throws VascValidatorException { - return false; + if ((object instanceof Date)==false) { + return false; + } + Date dateCheck = (Date)object; + Date dateNow = new Date(); + return dateCheck.after(dateNow); } /** @@ -53,7 +59,6 @@ public class VascDateFutureValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { - return null; + public void initAnnotation(Annotation annotation) { } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascDatePastValidator.java b/src/main/java/com/idcanet/vasc/validators/VascDatePastValidator.java index ad46692..8a55159 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascDatePastValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascDatePastValidator.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.validators; import java.lang.annotation.Annotation; +import java.util.Date; /** * Validates @@ -40,7 +41,12 @@ public class VascDatePastValidator implements VascValidator { * @see com.idcanet.vasc.validators.VascValidator#isObjectValid(java.lang.Object) */ public boolean isObjectValid(Object object) throws VascValidatorException { - return false; + if ((object instanceof Date)==false) { + return false; + } + Date dateCheck = (Date)object; + Date dateNow = new Date(); + return dateCheck.after(dateNow); } /** @@ -53,7 +59,6 @@ public class VascDatePastValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { - return null; + public void initAnnotation(Annotation annotation) { } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascIntSizeValidator.java b/src/main/java/com/idcanet/vasc/validators/VascIntSizeValidator.java index c97f526..8d8e8e4 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascIntSizeValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascIntSizeValidator.java @@ -66,12 +66,11 @@ public class VascIntSizeValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { + public void initAnnotation(Annotation annotation) { VascIntSize a = VascIntSize.class.cast(annotation); VascIntSizeValidator v = new VascIntSizeValidator(); v.setMin(a.min()); v.setMax(a.max()); - return v; } /** diff --git a/src/main/java/com/idcanet/vasc/validators/VascLongSizeValidator.java b/src/main/java/com/idcanet/vasc/validators/VascLongSizeValidator.java index 76f417c..f162096 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascLongSizeValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascLongSizeValidator.java @@ -66,12 +66,11 @@ public class VascLongSizeValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { + public void initAnnotation(Annotation annotation) { VascLongSize a = VascLongSize.class.cast(annotation); VascLongSizeValidator v = new VascLongSizeValidator(); v.setMin(a.min()); v.setMax(a.max()); - return v; } /** diff --git a/src/main/java/com/idcanet/vasc/validators/VascObjectNotNullValidator.java b/src/main/java/com/idcanet/vasc/validators/VascObjectNotNullValidator.java index 60f923d..3450b17 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascObjectNotNullValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascObjectNotNullValidator.java @@ -53,7 +53,6 @@ public class VascObjectNotNullValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { - return new VascObjectNotNullValidator(); + public void initAnnotation(Annotation annotation) { } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascObjectNullValidator.java b/src/main/java/com/idcanet/vasc/validators/VascObjectNullValidator.java index 992a2da..56611f7 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascObjectNullValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascObjectNullValidator.java @@ -53,7 +53,6 @@ public class VascObjectNullValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { - return new VascObjectNullValidator(); + public void initAnnotation(Annotation annotation) { } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascStringEmailValidator.java b/src/main/java/com/idcanet/vasc/validators/VascStringEmailValidator.java index 4b438b7..f5534f7 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascStringEmailValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascStringEmailValidator.java @@ -27,7 +27,12 @@ package com.idcanet.vasc.validators; /** - * Validates + * Validates emails addresses. + * + * based on the following regex: + *
+ * EMAIL_REGEX = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
+ * 
* * @author Willem Cazander * @version 1.0 Sep 5, 2008 @@ -54,12 +59,5 @@ public class VascStringEmailValidator extends VascStringRegexValidator { * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.Class) */ public void initAnnotation(Class annotationType) { - //VascStringEmail a = VascStringEmail.class.cast(annotationType); - /* - if (a.regex().equals("null")) { - return; - } - setRegEx(a.regex()); - */ } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascStringLengthValidator.java b/src/main/java/com/idcanet/vasc/validators/VascStringLengthValidator.java index 967e5ba..afdc559 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascStringLengthValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascStringLengthValidator.java @@ -91,11 +91,10 @@ public class VascStringLengthValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { + public void initAnnotation(Annotation annotation) { VascStringLength a = VascStringLength.class.cast(annotation); VascStringLengthValidator v = new VascStringLengthValidator(); v.setMinLenght(a.min()); v.setMaxLenght(a.max()); - return v; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascStringRegexValidator.java b/src/main/java/com/idcanet/vasc/validators/VascStringRegexValidator.java index f051d6e..48ae209 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascStringRegexValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascStringRegexValidator.java @@ -31,7 +31,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Validates + * Validates with custum regex. * * @author Willem Cazander * @version 1.0 Sep 5, 2008 @@ -83,10 +83,9 @@ public class VascStringRegexValidator implements VascValidator { /** * @see com.idcanet.vasc.validators.VascValidator#initAnnotation(java.lang.annotation.Annotation) */ - public VascValidator initAnnotation(Annotation annotation) { + public void initAnnotation(Annotation annotation) { VascStringRegex a = VascStringRegex.class.cast(annotation); VascStringRegexValidator v = new VascStringRegexValidator(); - v.setRegEx(a.regex()); - return v; + v.setRegEx(a.regex()); } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascValidator.java b/src/main/java/com/idcanet/vasc/validators/VascValidator.java index 22e18f1..5820e0a 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascValidator.java @@ -45,5 +45,5 @@ public interface VascValidator { */ public Class getAnnotationType(); - public VascValidator initAnnotation(Annotation annotation); + public void initAnnotation(Annotation annotation); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/validators/VascValidatorClassParser.java b/src/main/java/com/idcanet/vasc/validators/VascValidatorClassParser.java index e3c82c2..88923bd 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascValidatorClassParser.java +++ b/src/main/java/com/idcanet/vasc/validators/VascValidatorClassParser.java @@ -66,8 +66,8 @@ public class VascValidatorClassParser { for (VascValidator v:validators) { for (Annotation a:method.getAnnotations()) { if (a.annotationType().equals(v.getAnnotationType())) { - VascValidator val = v.initAnnotation(a); - result.add(val); + v.initAnnotation(a); + result.add(v); } } } diff --git a/src/main/java/com/idcanet/vasc/validators/VascValidatorException.java b/src/main/java/com/idcanet/vasc/validators/VascValidatorException.java index f9e4fef..9c1040c 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascValidatorException.java +++ b/src/main/java/com/idcanet/vasc/validators/VascValidatorException.java @@ -28,12 +28,23 @@ package com.idcanet.vasc.validators; /** - * The VascValidator interface + * The VascValidatorException * * @author Willem Cazander * @version 1.0 Sep 5, 2008 */ public class VascValidatorException extends Exception { + private static final long serialVersionUID = 510901125063551186L; + + public VascValidatorException() { + } + public VascValidatorException(String message) { + super(message); + } + + public VascValidatorException(String message,Exception exception) { + super(message,exception); + } } \ No newline at end of file diff --git a/src/main/resources/META-INF/.faces-config.mex b/src/main/resources/META-INF/.faces-config.mex new file mode 100644 index 0000000..0928b8d --- /dev/null +++ b/src/main/resources/META-INF/.faces-config.mex @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/META-INF/faces-config.xml b/src/main/resources/META-INF/faces-config.xml new file mode 100644 index 0000000..536ab2d --- /dev/null +++ b/src/main/resources/META-INF/faces-config.xml @@ -0,0 +1,23 @@ + + + + com.idcanet.vasc.frontends.web.jsf.VascUIComponent + com.idcanet.vasc.frontends.web.jsf.VascUIComponent + + + + Controls the vasc actions + vascActionBean + com.idcanet.vasc.frontends.web.jsf.VascActionBean + request + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/fieldtype-lang.eld b/src/main/resources/META-INF/fieldtype-lang.eld index 0167ca3..3deb1b7 100644 --- a/src/main/resources/META-INF/fieldtype-lang.eld +++ b/src/main/resources/META-INF/fieldtype-lang.eld @@ -1,5 +1,5 @@ - + @@ -24,4 +24,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/resources/META-INF/fieldtypes.xml b/src/main/resources/META-INF/fieldtypes.xml index 16b6d8d..f1e16ab 100644 --- a/src/main/resources/META-INF/fieldtypes.xml +++ b/src/main/resources/META-INF/fieldtypes.xml @@ -1,5 +1,5 @@ - @@ -7,14 +7,14 @@ - + - - + + @@ -116,4 +116,4 @@ --> - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/resources/META-INF/vasc-lang.eld b/src/main/resources/META-INF/vasc-lang.eld index 9d7b1e8..8d8f763 100644 --- a/src/main/resources/META-INF/vasc-lang.eld +++ b/src/main/resources/META-INF/vasc-lang.eld @@ -1,5 +1,5 @@ - + @@ -8,31 +8,58 @@ - - + - + + + - + - + + + + + + + + + - + + + + + + + + + + + + - + + + + + + + + + + @@ -47,4 +74,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/resources/META-INF/vasc.tld b/src/main/resources/META-INF/vasc.tld new file mode 100644 index 0000000..7a7bfba --- /dev/null +++ b/src/main/resources/META-INF/vasc.tld @@ -0,0 +1,44 @@ + + + JSTL 1.1 core library + Vasc + 1.1 + vasc + http://vasc.idcanet.com/vasc.tld + + Renders the vasc entry JSF Frontend Renderer + vascEntry + com.idcanet.vasc.frontends.web.jsf.VascUIComponentTag + JSP + + vascController + true + true + + + + entryName + false + true + + + + vascFrontendData + true + true + + + + bundleName + false + false + + + + locale + false + false + + + + diff --git a/src/test/java/com/idcanet/vasc/SWTTableViewerTest.java b/src/test/java/com/idcanet/vasc/SWTTableViewerTest.java new file mode 100644 index 0000000..5e960db --- /dev/null +++ b/src/test/java/com/idcanet/vasc/SWTTableViewerTest.java @@ -0,0 +1,650 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.LogManager; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ColorCellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.window.ApplicationWindow; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Item; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.frontends.swt.SwtVascFrontend; + + +import junit.framework.TestCase; + +/** + * Tests a simple x4o xml language. + * + * @author Willem Cazander + * @version 1.0 Jul 24, 2006 + */ +public class SWTTableViewerTest extends TestCase { + + public void setUp() throws Exception { + // enable all logs + InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties"); + LogManager.getLogManager().readConfiguration( loggingProperties ); + loggingProperties.close(); + + // load xtes queries + } + + public static void main(String[] args) { + new PersonEditor().run(); + } + + public void tearDown() throws Exception { + } + /* + public void testTable() throws Exception { + + // get GUI + Display display = new Display(); + Shell shell = new Shell(display); + shell.setText("Vasc Test - Swt"); + + // define redering and render + SwtVascFrontend render = new SwtVascFrontend(shell); + + + VascEntry entry = TestTable.getVascTable(); + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + render.initEntry(entry); + render.renderView(); + + // view + shell.open(); + // Set up the event loop. + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + // If no more entries in event queue + display.sleep(); + } + } + display.dispose(); + } + */ +} + + +class PersonEditor extends ApplicationWindow { + // Table column names/properties + public static final String NAME = "Name"; + + public static final String MALE = "Male?"; + + public static final String AGE = "Age Range"; + + public static final String SHIRT_COLOR = "Shirt Color"; + + public static final String[] PROPS = { NAME, MALE, AGE, SHIRT_COLOR }; + + // The data model + private java.util.List people; + + /** + * Constructs a PersonEditor + */ + public PersonEditor() { + super(null); + people = new ArrayList(); + } + + /** + * Runs the application + */ + public void run() { + // Don't return from open() until window closes + setBlockOnOpen(true); + + // Open the main window + open(); + + // Dispose the display + Display.getCurrent().dispose(); + } + + /** + * Configures the shell + * + * @param shell + * the shell + */ + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Person Editor"); + shell.setSize(400, 400); + } + + /** + * Creates the main window's contents + * + * @param parent + * the main window + * @return Control + */ + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(1, false)); + + // Add a button to create the new person + Button newPerson = new Button(composite, SWT.PUSH); + newPerson.setText("Create New Person"); + + // Add the TableViewer + final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION); + tv.setContentProvider(new PersonContentProvider()); + tv.setLabelProvider(new PersonLabelProvider()); + tv.setInput(people); + + // Set up the table + Table table = tv.getTable(); + table.setLayoutData(new GridData(GridData.FILL_BOTH)); + + new TableColumn(table, SWT.CENTER).setText(NAME); + new TableColumn(table, SWT.CENTER).setText(MALE); + new TableColumn(table, SWT.CENTER).setText(AGE); + new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR); + + for (int i = 0, n = table.getColumnCount(); i < n; i++) { + table.getColumn(i).pack(); + } + + table.setHeaderVisible(true); + table.setLinesVisible(true); + + // Add a new person when the user clicks button + newPerson.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + Person p = new Person(); + p.setName("Name"); + p.setMale(true); + p.setAgeRange(Integer.valueOf("0")); + p.setShirtColor(new RGB(255, 0, 0)); + people.add(p); + tv.refresh(); + } + }); + + // Create the cell editors + CellEditor[] editors = new CellEditor[4]; + editors[0] = new TextCellEditor(table); + editors[1] = new CheckboxCellEditor(table); + editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES, + SWT.READ_ONLY); + editors[3] = new ColorCellEditor(table); + + // Set the editors, cell modifier, and column properties + tv.setColumnProperties(PROPS); + tv.setCellModifier(new PersonCellModifier(tv)); + tv.setCellEditors(editors); + + return composite; + } + + /** + * The application entry point + * + * @param args + * the command line arguments + */ + public static void main(String[] args) { + new PersonEditor().run(); + } + } + + /** + * This class provides the content for the person table + */ + + class PersonContentProvider implements IStructuredContentProvider { + /** + * Returns the Person objects + */ + public Object[] getElements(Object inputElement) { + return ((List) inputElement).toArray(); + } + + /** + * Disposes any created resources + */ + public void dispose() { + // Do nothing + } + + /** + * Called when the input changes + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // Ignore + } + } + + /** + * This class provides the content for the FoodList application + */ + + class FoodContentProvider implements IStructuredContentProvider { + /** + * Gets the food items for the list + * + * @param arg0 + * the data model + * @return Object[] + */ + public Object[] getElements(Object arg0) { + return ((GroceryList) arg0).getFoods().toArray(); + } + + /** + * Disposes any created resources + */ + public void dispose() { + // Do nothing + } + + /** + * Called when the input changes + * + * @param arg0 + * the viewer + * @param arg1 + * the old input + * @param arg2 + * the new input + */ + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + // Do nothing + } + } + + /** + * This class represents the cell modifier for the PersonEditor program + */ + + class PersonCellModifier implements ICellModifier { + private Viewer viewer; + + public PersonCellModifier(Viewer viewer) { + this.viewer = viewer; + } + + /** + * Returns whether the property can be modified + * + * @param element + * the element + * @param property + * the property + * @return boolean + */ + public boolean canModify(Object element, String property) { + // Allow editing of all values + return true; + } + + /** + * Returns the value for the property + * + * @param element + * the element + * @param property + * the property + * @return Object + */ + public Object getValue(Object element, String property) { + Person p = (Person) element; + if (PersonEditor.NAME.equals(property)) + return p.getName(); + else if (PersonEditor.MALE.equals(property)) + return Boolean.valueOf(p.isMale()); + else if (PersonEditor.AGE.equals(property)) + return p.getAgeRange(); + else if (PersonEditor.SHIRT_COLOR.equals(property)) + return p.getShirtColor(); + else + return null; + } + + /** + * Modifies the element + * + * @param element + * the element + * @param property + * the property + * @param value + * the value + */ + public void modify(Object element, String property, Object value) { + if (element instanceof Item) + element = ((Item) element).getData(); + + Person p = (Person) element; + if (PersonEditor.NAME.equals(property)) + p.setName((String) value); + else if (PersonEditor.MALE.equals(property)) + p.setMale(((Boolean) value).booleanValue()); + else if (PersonEditor.AGE.equals(property)) + p.setAgeRange((Integer) value); + else if (PersonEditor.SHIRT_COLOR.equals(property)) + p.setShirtColor((RGB) value); + + // Force the viewer to refresh + viewer.refresh(); + } + } + + /** + * This class represents a person + */ + + class Person { + private String name; + + private boolean male; + + private Integer ageRange; + + private RGB shirtColor; + + /** + * @return Returns the ageRange. + */ + public Integer getAgeRange() { + return ageRange; + } + + /** + * @param ageRange + * The ageRange to set. + */ + public void setAgeRange(Integer ageRange) { + this.ageRange = ageRange; + } + + /** + * @return Returns the male. + */ + public boolean isMale() { + return male; + } + + /** + * @param male + * The male to set. + */ + public void setMale(boolean male) { + this.male = male; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @param name + * The name to set. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return Returns the shirtColor. + */ + public RGB getShirtColor() { + return shirtColor; + } + + /** + * @param shirtColor + * The shirtColor to set. + */ + public void setShirtColor(RGB shirtColor) { + this.shirtColor = shirtColor; + } + } + + /** + * This class contains all the foods on the "grocery list" + */ + + class GroceryList { + // Holds the foods + private List foods; + + /** + * Constructs a grocery list + */ + public GroceryList() { + foods = new ArrayList(); + + // Add some foods + foods.add(new Food("Broccoli", true)); + foods.add(new Food("Bundt Cake", false)); + foods.add(new Food("Cabbage", true)); + foods.add(new Food("Candy Canes", false)); + foods.add(new Food("Eggs", true)); + foods.add(new Food("Potato Chips", false)); + foods.add(new Food("Milk", true)); + foods.add(new Food("Soda", false)); + foods.add(new Food("Chicken", true)); + foods.add(new Food("Cinnamon Rolls", false)); + } + + /** + * Returns the foods in this grocery list + * + * @return List + */ + public List getFoods() { + return Collections.unmodifiableList(foods); + } + } + + /** + * This class represents a type of food + */ + + class Food { + // The name of the food + private String name; + + // Is it healthy? + private boolean healthy; + + /** + * Food constructor + * + * @param name + * the name + * @param healthy + * whether or not it's healthy + */ + public Food(String name, boolean healthy) { + this.name = name; + this.healthy = healthy; + } + + /** + * Gets whether this is healthy + * + * @return boolean + */ + public boolean isHealthy() { + return healthy; + } + + /** + * Gets the name + * + * @return String + */ + public String getName() { + return name; + } + } + + /** + * This class provides the labels for the person table + */ + + class PersonLabelProvider implements ITableLabelProvider { + /** + * Returns the image + * + * @param element + * the element + * @param columnIndex + * the column index + * @return Image + */ + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + /** + * Returns the column text + * + * @param element + * the element + * @param columnIndex + * the column index + * @return String + */ + public String getColumnText(Object element, int columnIndex) { + Person person = (Person) element; + switch (columnIndex) { + case 0: + return person.getName(); + case 1: + return Boolean.toString(person.isMale()); + case 2: + return AgeRange.INSTANCES[person.getAgeRange().intValue()]; + case 3: + return person.getShirtColor().toString(); + } + return null; + } + + /** + * Adds a listener + * + * @param listener + * the listener + */ + public void addListener(ILabelProviderListener listener) { + // Ignore it + } + + /** + * Disposes any created resources + */ + public void dispose() { + // Nothing to dispose + } + + /** + * Returns whether altering this property on this element will affect the + * label + * + * @param element + * the element + * @param property + * the property + * @return boolean + */ + public boolean isLabelProperty(Object element, String property) { + return false; + } + + /** + * Removes a listener + * + * @param listener + * the listener + */ + public void removeListener(ILabelProviderListener listener) { + // Ignore + } + } + + + /** + * This class encapsulates age ranges + */ + + class AgeRange { + public static final String NONE = ""; + + public static final String BABY = "0 - 3"; + + public static final String TODDLER = "4 - 7"; + + public static final String CHILD = "8 - 12"; + + public static final String TEENAGER = "13 - 19"; + + public static final String ADULT = "20 - ?"; + + public static final String[] INSTANCES = { NONE, BABY, TODDLER, CHILD, + TEENAGER, ADULT }; + } \ No newline at end of file diff --git a/src/test/java/com/idcanet/vasc/SWTTest.java b/src/test/java/com/idcanet/vasc/SWTTest.java index 6732807..44149ec 100644 --- a/src/test/java/com/idcanet/vasc/SWTTest.java +++ b/src/test/java/com/idcanet/vasc/SWTTest.java @@ -29,6 +29,10 @@ package com.idcanet.vasc; import java.io.InputStream; import java.util.logging.LogManager; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.frontends.swt.SwtVascFrontend; @@ -53,18 +57,21 @@ public class SWTTest extends TestCase { public void tearDown() throws Exception { } - + /* public void testAll() throws Exception { // get GUI - /* Display display = new Display(); Shell shell = new Shell(display); shell.setText("Vasc Test - Swt"); // define redering and render SwtVascFrontend render = new SwtVascFrontend(shell); - render.initEntry(TestTable.getVascTable()); + + + VascEntry entry = TestTable.getVascTable(); + entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry); + render.initEntry(entry); render.renderView(); // view @@ -77,10 +84,8 @@ public class SWTTest extends TestCase { } } display.dispose(); - - */ } - + */ } \ No newline at end of file diff --git a/src/test/java/com/idcanet/vasc/SwingTest.java b/src/test/java/com/idcanet/vasc/SwingTest.java index 657a27f..7e68003 100644 --- a/src/test/java/com/idcanet/vasc/SwingTest.java +++ b/src/test/java/com/idcanet/vasc/SwingTest.java @@ -28,8 +28,6 @@ package com.idcanet.vasc; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.InputStream; -import java.util.logging.LogManager; import javax.swing.JFrame; import javax.swing.JMenu; @@ -52,14 +50,15 @@ public class SwingTest extends TestCase { public void setUp() throws Exception { // enable all logs - InputStream loggingProperties = this.getClass().getResourceAsStream("/META-INF/logging.properties"); - LogManager.getLogManager().readConfiguration( loggingProperties ); - loggingProperties.close(); + //InputStream loggingProperties = this.getClass().getResourceAsStream("META-INF/logging.properties"); + //LogManager.getLogManager().readConfiguration( loggingProperties ); + //loggingProperties.close(); } public void tearDown() throws Exception { } + /* public void testAll() throws Exception { JFrame.setDefaultLookAndFeelDecorated(false); VascEntry entry = TestTable.getVascTable(); @@ -69,11 +68,12 @@ public class SwingTest extends TestCase { Thread.sleep(1000); } } + */ public JFrame viewEntry(final VascEntry entry) throws Exception { // get GUI JFrame frame = new JFrame(); - frame.setTitle("Vasc Test - Swing - "+entry.getName()); + frame.setTitle("Vasc Test - Swing - "+entry.getHeaderName()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(null); diff --git a/src/test/java/com/idcanet/vasc/TestModelVascDataSource.java b/src/test/java/com/idcanet/vasc/TestModelVascDataSource.java index 98b9ee0..1674837 100644 --- a/src/test/java/com/idcanet/vasc/TestModelVascDataSource.java +++ b/src/test/java/com/idcanet/vasc/TestModelVascDataSource.java @@ -104,7 +104,7 @@ public class TestModelVascDataSource extends AbstractVascBackend implements Vasc // --- VascSelectItemModel interface - public List getVascSelectItems() { + public List getVascSelectItems(VascEntry entry) { List res = new ArrayList(4); for (Object o:testModels) { TestModel t = (TestModel)o; diff --git a/src/test/java/com/idcanet/vasc/TestTable.java b/src/test/java/com/idcanet/vasc/TestTable.java index 857e934..5acd332 100644 --- a/src/test/java/com/idcanet/vasc/TestTable.java +++ b/src/test/java/com/idcanet/vasc/TestTable.java @@ -26,23 +26,22 @@ package com.idcanet.vasc; +import java.io.File; +import java.io.FileOutputStream; import java.lang.reflect.Method; -import java.util.Date; import com.idcanet.vasc.core.VascController; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; -import com.idcanet.vasc.impl.DefaultVascBackedEntryFinalizer; import com.idcanet.vasc.impl.DefaultVascBackendController; import com.idcanet.vasc.impl.DefaultVascBackendControllerResolver; import com.idcanet.vasc.impl.DefaultVascEntryController; import com.idcanet.vasc.impl.DefaultVascEntryControllerResolver; -import com.idcanet.vasc.impl.DefaultVascFrontendEntryFinalizer; import com.idcanet.vasc.impl.DefaultVascController; -import com.idcanet.vasc.impl.DefaultVascEntry; -import com.idcanet.vasc.impl.DefaultVascEntryField; import com.idcanet.vasc.impl.DefaultVascFrontendData; import com.idcanet.vasc.impl.DefaultVascFrontendHelper; +import com.idcanet.vasc.impl.DefaultVascUserRoleController; +import com.idcanet.vasc.impl.DefaultVascUserRoleControllerResolver; import com.idcanet.vasc.impl.actions.AddRowAction; import com.idcanet.vasc.impl.actions.CSVExportGlobalAction; import com.idcanet.vasc.impl.actions.DeleteRowAction; @@ -87,11 +86,20 @@ public class TestTable { vascEntryFieldTypeControllerResolver.setVascEntryFieldTypeController(vascEntryFieldTypeController); c.setVascEntryFieldTypeControllerResolver(vascEntryFieldTypeControllerResolver); + + DefaultVascUserRoleControllerResolver vascUserRoleControllerResolver = new DefaultVascUserRoleControllerResolver(); + DefaultVascUserRoleController vascUserRoleController = new DefaultVascUserRoleController(2288L,"idca.nl","user","admin"); + vascUserRoleControllerResolver.setVascUserRoleController(vascUserRoleController); + c.setVascUserRoleControllerResolver(vascUserRoleControllerResolver); + return c; } static public void fill(VascEntry entry,VascController c) { + + + DefaultVascFrontendData vascFrontendData = new DefaultVascFrontendData(); vascFrontendData.setVascController(c); @@ -101,8 +109,16 @@ public class TestTable { DefaultVascFrontendHelper vascFrontendHelper = new DefaultVascFrontendHelper(); vascFrontendData.setVascFrontendHelper(vascFrontendHelper); - entry.setVascFrontendData(vascFrontendData); - + // hack + if (entry.getVascFrontendData()!=null) { + entry.setVascFrontendData(vascFrontendData); + return; + } else { + entry.setVascFrontendData(vascFrontendData); + } + + + entry.addRowAction(new AddRowAction()); entry.addRowAction(new EditRowAction()); entry.addRowAction(new DeleteRowAction()); @@ -117,61 +133,13 @@ public class TestTable { VascController c = getDefaultVascController(); VascParser parser = new VascParser(c); + File f = File.createTempFile("test-vasc", ".xml"); + parser.setDebugOutputStream(new FileOutputStream(f)); parser.parseResource("vasc/tables.xml"); VascEntry entry = parser.getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById("test1"); fill(entry,c); - - - // config table - - //VascEntry entry = new DefaultVascEntry(); - //entry.setId("test1"); - //entry.setBackendId("testBackend"); - - - - /* - //table.addUserOptions(userOption); - //table.addColumnActions(new GraphColumnAction()); - - VascEntryField field = new DefaultVascEntryField("name"); - field.setImage("/META-INF/images/silk/png/tick.png"); - entry.addVascEntryField(field); - - field = new DefaultVascEntryField("description"); - field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("EmailField")); - entry.addVascEntryField(field); - - field = new DefaultVascEntryField("active"); - field.setDefaultValue(true); - entry.addVascEntryField(field); - - field = new DefaultVascEntryField("date"); - field.setDefaultValue(new Date()); - entry.addVascEntryField(field); - - field = new DefaultVascEntryField("testModel"); - field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("ListField")); - field.getVascEntryFieldType().setDataObject(c.getVascBackendControllerResolver().getVascBackendController().getVascBackendById("testBackend")); - entry.addVascEntryField(field); - - - field = new DefaultVascEntryField("hexColor"); - field.setVascEntryFieldType(c.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("ColorField")); - field.setDefaultValue("#FF3355"); - entry.addVascEntryField(field); - - printEntry(entry); - DefaultVascBackedEntryFinalizer f = new DefaultVascBackedEntryFinalizer(); - entry = f.finalizeVascEntry(entry,c); - printEntry(entry); - - DefaultVascFrontendEntryFinalizer f2 = new DefaultVascFrontendEntryFinalizer(); - entry = f2.finalizeVascEntry(entry,c); - //printEntry(entry); - */ - + return entry; } @@ -188,7 +156,7 @@ public class TestTable { if (m.getParameterTypes().length>0) { continue; } - System.out.println("prop: "+m.getName()+" -> "+m.invoke(e, null)); + System.out.println("prop: "+m.getName()+" -> "+m.invoke(e)); } System.out.println(""); @@ -204,7 +172,7 @@ public class TestTable { if (m.getParameterTypes().length>0) { continue; } - System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef, null)); + System.out.println("prop: "+m.getName()+" -> "+m.invoke(vef)); } } } diff --git a/src/test/java/com/idcanet/vasc/models/TestModel.java b/src/test/java/com/idcanet/vasc/models/TestModel.java index 0671a52..c230b30 100644 --- a/src/test/java/com/idcanet/vasc/models/TestModel.java +++ b/src/test/java/com/idcanet/vasc/models/TestModel.java @@ -31,15 +31,12 @@ import java.util.Date; import org.hibernate.validator.NotNull; import org.hibernate.validator.Max; -import org.w3c.dom.Node; -import com.idcanet.vasc.annotations.VascColumnWidth; +import com.idcanet.vasc.annotations.VascEntry; +import com.idcanet.vasc.annotations.VascStyle; import com.idcanet.vasc.annotations.VascDefaultValue; -import com.idcanet.vasc.annotations.VascHelpId; -import com.idcanet.vasc.annotations.VascImage; -import com.idcanet.vasc.annotations.VascModelReference; -import com.idcanet.vasc.annotations.VascName; -import com.idcanet.vasc.annotations.VascDescription; +import com.idcanet.vasc.annotations.VascI18nModelReference; +import com.idcanet.vasc.annotations.VascI18n; import com.idcanet.vasc.validators.VascDateFuture; import com.idcanet.vasc.validators.VascObjectNotNull; import com.idcanet.vasc.validators.VascStringLength; @@ -51,7 +48,7 @@ import com.idcanet.vasc.validators.VascStringLength; * @author Willem Cazander * @version 1.0 Mar 28, 2007 */ -@VascDescription(key="En een tooltip op het model") +@VascEntry(headerName="En een tooltip op het model") public class TestModel { private String name = null; @@ -61,7 +58,7 @@ public class TestModel { private Date date = null; private TestModel testModel = null; private String hexColor = null; - private Node nonEditorField = null; + //private Node nonEditorField = null; /** * @return the date @@ -81,12 +78,12 @@ public class TestModel { /** * @return the description */ - @VascName(key="omscheiving") - @VascDescription(key="De omscheiving") - @VascHelpId(helpId="help.id") + @VascI18n( name="omscheiving", + description="De omscrijving", + image="/resources/images/gabelfresser.gif", + helpId="help.id") @VascDefaultValue(defaultValue="xxxxx") - @VascColumnWidth(width=200) - @VascImage(image="/resources/images/gabelfresser.gif") + @VascStyle(sizeList=200) @NotNull @Max(value=10) @VascObjectNotNull @@ -130,10 +127,11 @@ public class TestModel { this.price = price; } - @VascImage(image="/resources/images/gabelfresser.gif") - @VascModelReference + @NotNull @VascObjectNotNull + @VascI18nModelReference + @VascI18n(image="/resources/images/gabelfresser.gif") public TestModel getTestModel() { return testModel; } diff --git a/src/test/resources/vasc/tables.xml b/src/test/resources/vasc/tables.xml index fa785b0..46d1c9a 100644 --- a/src/test/resources/vasc/tables.xml +++ b/src/test/resources/vasc/tables.xml @@ -1,8 +1,39 @@ - + + + + + + + + + + + + + + + + + - + @@ -106,7 +137,7 @@ - + @@ -245,13 +275,14 @@ Master styleEdit="styleClass" choices="" - + choicesAsRadio="false" view="true" optional="false" create="true" edit="true" editReadOnly="false" + editBlank="false" list="true" rolesCreate="admin|manager" @@ -282,4 +313,4 @@ Master /> - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/resources/xtes/tests.xml b/src/test/resources/xtes/tests.xml index eb2fa33..d9ffd7c 100644 --- a/src/test/resources/xtes/tests.xml +++ b/src/test/resources/xtes/tests.xml @@ -1,5 +1,6 @@ - @@ -51,4 +52,4 @@ - \ No newline at end of file + \ No newline at end of file