diff --git a/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java b/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java index 49177b5..f803012 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascBundleKeyGenerator.java @@ -48,10 +48,12 @@ public class VascBundleKeyGenerator { private boolean generateDescription = true; private boolean generateImage = true; private boolean generateHelpId = true; + private List dubId = null; public VascBundleKeyGenerator() { models = new ArrayList>(30); keys = new HashMap(300); + dubId = new ArrayList(30); } public void addModelClass(Class model) { @@ -66,6 +68,7 @@ public class VascBundleKeyGenerator { public void generateMissingKeys(StringBuffer buffer,ResourceBundle bundle) { if (keys.isEmpty()==false) { keys.clear(); + dubId.clear(); } for (Class modelClass:models) { generatorI18nKeys(modelClass); @@ -86,6 +89,7 @@ public class VascBundleKeyGenerator { public void generateRemoveKeys(StringBuffer buffer,ResourceBundle bundle,String excludeRegex) { if (keys.isEmpty()==false) { keys.clear(); + dubId.clear(); } for (Class modelClass:models) { generatorI18nKeys(modelClass); @@ -107,6 +111,7 @@ public class VascBundleKeyGenerator { public void generateKeys(StringBuffer buffer) { if (keys.isEmpty()==false) { keys.clear(); + dubId.clear(); } for (Class modelClass:models) { generatorI18nKeys(modelClass); @@ -138,7 +143,12 @@ public class VascBundleKeyGenerator { if (isGenerateHelpId()) { appendKey(vap.getVascI18nHelpId(bean),prop1); } - + + String idKey = vap.getVascPrimaryKey(bean); + String nameKey = vap.getVascDisplayName(bean); + if (idKey!=null && idKey.equals(nameKey)) { + dubId.add("idKey and nameKey is the same: "+bean.getName()); + } for (Method method:bean.getMethods()) { if (method.getName().startsWith("get")==false) { //a bit durty @@ -228,4 +238,8 @@ public class VascBundleKeyGenerator { public void setGenerateHelpId(boolean generateHelpId) { this.generateHelpId = generateHelpId; } + + public List getDubIdNameKeys() { + return dubId; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/BeanVascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/backends/BeanVascEntryFieldValue.java new file mode 100644 index 0000000..c3d94e7 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/BeanVascEntryFieldValue.java @@ -0,0 +1,109 @@ +/* + * Copyright 2004-2010 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; + +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.x4o.impl.DefaultElementObjectPropertyValue; + +/** + * + * @author Willem Cazander + * @version 1.0 Dec 05, 2009 + */ +public class BeanVascEntryFieldValue implements VascEntryFieldValue { + + private static final long serialVersionUID = 1L; + private DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue(); + + /** + * @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 { + if (field==null) { + throw new NullPointerException("Can't get value of null field."); + } + if (field.getBackendName()==null) { + throw new NullPointerException("Can't get value of null backendName field."); + } + if (record==null) { + throw new NullPointerException("Can't get value of null object."); + } + try { + Object o = bean.getProperty(record,field.getBackendName()); + return o; + } catch (Exception e) { + throw new VascException(e); + } + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + public String getDisplayValue(VascEntryField field, Object record) throws VascException { + Object value = getValue(field,record); + if (value==null) { + return ""; + } + if (field.getDisplayName()==null) { + if (value instanceof String) { + return (String)value; + } + return ""+value; + } + try { + Object result = bean.getProperty(value, field.getDisplayName()); + if (result instanceof String) { + return (String)result; + } + return ""+result; + } 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 { + if (field==null) { + throw new NullPointerException("Can't set value of null field."); + } + if (field.getBackendName()==null) { + throw new NullPointerException("Can't set value of null backendName field."); + } + if (record==null) { + throw new NullPointerException("Can't set value of null object."); + } + try { + bean.setProperty(record, field.getBackendName(), value); + } catch (Exception e) { + throw new VascException(e); + } + } +} diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java b/src/main/java/com/idcanet/vasc/backends/BeanVascEntryRecordCreator.java similarity index 78% rename from src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java rename to src/main/java/com/idcanet/vasc/backends/BeanVascEntryRecordCreator.java index f77e039..9352ee2 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java +++ b/src/main/java/com/idcanet/vasc/backends/BeanVascEntryRecordCreator.java @@ -1,7 +1,7 @@ /** * */ -package com.idcanet.vasc.backends.jpa; +package com.idcanet.vasc.backends; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; @@ -16,6 +16,9 @@ public class BeanVascEntryRecordCreator implements VascEntryRecordCreator { private Class resultClass = null; public BeanVascEntryRecordCreator(Class resultClass) { + if (resultClass==null) { + throw new NullPointerException("Can't provide creator service with null class object."); + } this.resultClass=resultClass; } diff --git a/src/main/java/com/idcanet/vasc/backends/MapVascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/backends/MapVascEntryFieldValue.java new file mode 100644 index 0000000..417897d --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/MapVascEntryFieldValue.java @@ -0,0 +1,49 @@ +/** + * + */ +package com.idcanet.vasc.backends; + +import java.util.Map; + +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; + +/** + * @author willemc + * + */ +public class MapVascEntryFieldValue implements VascEntryFieldValue { + + private static final long serialVersionUID = 1L; + + /** + * @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 r = map.get(field.getBackendName()); + if (r==null) { + return ""; // create new value, ldap does not return data for field that an user does not have, but other do,... + } + return r; + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + public String getDisplayValue(VascEntryField field, Object record) throws VascException { + return ""+getValue(field,record); // not supported (this)ldap is already fully string based. + } + + /** + * @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); + } + +} diff --git a/src/main/java/com/idcanet/vasc/backends/MapVascEntryRecordCreator.java b/src/main/java/com/idcanet/vasc/backends/MapVascEntryRecordCreator.java new file mode 100644 index 0000000..d6d95fb --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/MapVascEntryRecordCreator.java @@ -0,0 +1,27 @@ +/** + * + */ +package com.idcanet.vasc.backends; + +import java.util.HashMap; +import java.util.Map; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.entry.VascEntryRecordCreator; + +/** + * @author willemc + * + */ +public class MapVascEntryRecordCreator implements VascEntryRecordCreator { + + private static final long serialVersionUID = 1L; + + public Class getObjectClass() { + return Map.class; + } + + public Object newRecord(VascEntry entry) throws Exception { + return new HashMap(10); + } +} 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 18f5a10..4f6b824 100644 --- a/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdbcVascBackend.java @@ -34,6 +34,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.idcanet.vasc.backends.MapVascEntryFieldValue; +import com.idcanet.vasc.backends.MapVascEntryRecordCreator; import com.idcanet.vasc.core.AbstractVascBackend; import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; @@ -128,50 +130,14 @@ public class JdbcVascBackend extends AbstractVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - 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#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public String getDisplayValue(VascEntryField field, Object record) throws VascException { - return ""+getValue(field,record); // not supported - } - - /** - * @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; + return new MapVascEntryFieldValue(); } /** * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new VascEntryRecordCreator() { - - public Class getObjectClass() { - return Map.class; - } - - public Object newRecord(VascEntry entry) throws Exception { - return new HashMap(10); - } - }; + return new MapVascEntryRecordCreator(); } /** diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java b/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java index 0679f86..74788c6 100644 --- a/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java +++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java @@ -42,7 +42,7 @@ import javax.sql.DataSource; public class JdniDataSourceJdbcConnectionProvider implements JdbcConnectionProvider { /** The context in which database data sources are found. */ - private String dataSourceContext = "java:comp/env/jdbc/"; + private String dataSourceContext = "java:/"; private String dataSourceName = null; diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java deleted file mode 100644 index d63313c..0000000 --- a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - */ -package com.idcanet.vasc.backends.jpa; - -import com.idcanet.vasc.core.VascEntryField; -import com.idcanet.vasc.core.VascException; -import com.idcanet.vasc.core.entry.VascEntryFieldValue; -import com.idcanet.x4o.impl.DefaultElementObjectPropertyValue; - -/** - * @author willemc - * - */ -public class BeanVascEntryFieldValue implements VascEntryFieldValue { - - private static final long serialVersionUID = 1L; - private DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue(); - - /** - * @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.getProperty(record,field.getBackendName()); - return o; - } catch (Exception e) { - throw new VascException(e); - } - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public String getDisplayValue(VascEntryField field, Object record) throws VascException { - Object value = getValue(field,record); - if (value==null) { - return ""; - } - if (field.getDisplayName()==null) { - if (value instanceof String) { - return (String)value; - } - return ""+value; - } - try { - Object result = bean.getProperty(value, field.getDisplayName()); - if (result instanceof String) { - return (String)result; - } - return ""+result; - } 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.setProperty(record, field.getBackendName(), value); - } catch (Exception e) { - throw new VascException(e); - } - } -} diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java index ca6739f..f241dac 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java @@ -32,6 +32,8 @@ import org.hibernate.Hibernate; import org.hibernate.Query; import org.hibernate.Session; +import com.idcanet.vasc.backends.BeanVascEntryFieldValue; +import com.idcanet.vasc.backends.BeanVascEntryRecordCreator; import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; @@ -102,7 +104,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { } i++; } - if (isPageable() & state.getPageSize()>0) { + if (isPageable()) { q.setFirstResult(state.getPageIndex()); q.setMaxResults(state.getPageSize()); } diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java index d182834..94497c8 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java @@ -31,6 +31,8 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; +import com.idcanet.vasc.backends.BeanVascEntryFieldValue; +import com.idcanet.vasc.backends.BeanVascEntryRecordCreator; import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; @@ -101,7 +103,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend //System.out.println("Set para index: "+i+" value: "+valueObject+" valueClass: "+valueObject.getClass()+" valueType: "+value.getValueType()); i++; } - if (isPageable() & state.getPageSize()>0) { + if (isPageable()) { q.setFirstResult(state.getPageIndex()); q.setMaxResults(state.getPageSize()); } @@ -421,4 +423,15 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend public void setQueryMoveDownUp(com.idcanet.xtes.xpql.query.Query queryMoveDownUp) { this.queryMoveDownUp = queryMoveDownUp; } + + /** + * @see com.idcanet.vasc.core.VascBackend#isSearchable() + */ + public boolean isSearchable() { + if (query.getQueryParameterValue("text_search")==null) { + return false; + } + //return true; + return false; + } } \ 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 c69ecee..12eee3d 100644 --- a/src/main/java/com/idcanet/vasc/backends/ldap/LdapVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/ldap/LdapVascBackend.java @@ -32,6 +32,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import com.idcanet.vasc.backends.MapVascEntryFieldValue; +import com.idcanet.vasc.backends.MapVascEntryRecordCreator; import com.idcanet.vasc.core.AbstractVascBackend; import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; @@ -43,6 +45,7 @@ import com.novell.ldap.LDAPAttribute; import com.novell.ldap.LDAPAttributeSet; import com.novell.ldap.LDAPConnection; import com.novell.ldap.LDAPEntry; +import com.novell.ldap.LDAPModification; import com.novell.ldap.LDAPSearchConstraints; import com.novell.ldap.LDAPSearchResults; @@ -90,6 +93,8 @@ public class LdapVascBackend extends AbstractVascBackend { LDAPSearchConstraints cons = new LDAPSearchConstraints(); cons.setBatchSize( 0 ); cons.setTimeLimit( 10000 ) ; + cons.setReferralFollowing(true); + connection.setConstraints(cons); int searchScope = LDAPConnection.SCOPE_ONE; String searchBase = baseDN; @@ -141,8 +146,72 @@ public class LdapVascBackend extends AbstractVascBackend { LdapConnectionProvider prov = getLdapConnectionProvider(); LDAPConnection connection = prov.getLdapConnection(); try { - + Map map = (Map)object; + String keyValue = (String)map.get(keyAttribute); + LDAPSearchConstraints cons = new LDAPSearchConstraints(); + cons.setBatchSize( 0 ); + cons.setTimeLimit( 10000 ) ; + cons.setReferralFollowing(true); + connection.setConstraints(cons); + + int searchScope = LDAPConnection.SCOPE_ONE; + String searchBase = baseDN; + String filter = "(&("+keyAttribute+"="+keyValue+"))"; + System.out.println("ldap filter: "+filter); + LDAPSearchResults searchResults = connection.search( + searchBase, // object to read + searchScope, // scope - read single object + filter, // search filter + null, // return all attributes + false); // return attrs and values + + if (searchResults.hasMore()==false) { + // no result to mod + return object; + } + LDAPEntry entry = searchResults.next(); + List mods = new ArrayList(20); + for (String key:map.keySet()) { + Object value = map.get(key); + LDAPAttribute attr = entry.getAttribute(key); + + String[] s = attr.getStringValueArray(); + if (s.length==1) { + String v = (String)value; + if (attr.getStringValue().equals(v)==false) { + LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(key,v)); + mods.add(mod); + } + map.put(attr.getName(), attr.getStringValue()); + } else { + List multiValue = new ArrayList(s.length); + for (String ss:s) { + multiValue.add(ss); + } + List v = null; + if (value instanceof String) { + v = new ArrayList(1); + v.add((String)value); + } else { + v = (List)value; + } + if (v.equals(multiValue)==false) { + LDAPAttribute a = new LDAPAttribute(key); + for (String vv:v) { + a.addValue(vv); + } + LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,a); + mods.add(mod); + } + } + } + + LDAPModification[] m = new LDAPModification[mods.size()]; + mods.toArray(m); + connection.modify(entry.getDN(), m); return object; + } catch (Exception e) { + throw new VascException(e); } finally { if (connection!=null) { connection.clone(); @@ -177,7 +246,26 @@ public class LdapVascBackend extends AbstractVascBackend { LdapConnectionProvider prov = getLdapConnectionProvider(); LDAPConnection connection = prov.getLdapConnection(); try { - + Map map = (Map)object; + String keyValue = (String)map.get(keyAttribute); + int searchScope = LDAPConnection.SCOPE_ONE; + String searchBase = baseDN; + String filter = "(&("+ldapFilter+")("+keyAttribute+"="+keyValue+"))"; + LDAPSearchResults searchResults = connection.search( + searchBase, // object to read + searchScope, // scope - read single object + filter, // search filter + null, // return all attributes + false); // return attrs and values + + if (searchResults.hasMore()==false) { + // no result to mod + return; + } + LDAPEntry entry = searchResults.next(); + connection.delete(entry.getDN()); + } catch (Exception e) { + throw new VascException(e); } finally { if (connection!=null) { connection.clone(); @@ -189,53 +277,14 @@ public class LdapVascBackend extends AbstractVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new VascEntryRecordCreator() { - - public Class getObjectClass() { - return Map.class; - } - - public Object newRecord(VascEntry entry) throws Exception { - return new HashMap(10); - } - }; + return new MapVascEntryRecordCreator(); } /** * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - 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 r = map.get(field.getBackendName()); - if (r==null) { - return ""; // create new value, ldap does not return data for field that an user does not have, but other do,... - } - return r; - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public String getDisplayValue(VascEntryField field, Object record) throws VascException { - return ""+getValue(field,record); // not supported (this)ldap is already fully string based. - } - - /** - * @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; + return new MapVascEntryFieldValue(); } /** diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java b/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java index 290ffe2..f745a75 100644 --- a/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascBackend.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core; +import java.util.Map; + /** * @@ -101,4 +103,32 @@ abstract public class AbstractVascBackend implements VascBackend { public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException { return 0l; } + + /** + * @see com.idcanet.vasc.core.VascBackend#executePageSummary() + */ + public Map executePageSummary() { + return null; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#executeTotalSummary() + */ + public Map executeTotalSummary() { + return null; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isPageSummary() + */ + public boolean isPageSummary() { + return false; + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isTotalSummary() + */ + public boolean isTotalSummary() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java b/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java index 5383a2c..78894d7 100644 --- a/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascBackendProxy.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.core; import java.util.List; +import java.util.Map; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; @@ -152,4 +153,32 @@ abstract public class AbstractVascBackendProxy implements VascBackend { public boolean isRecordMoveable() { return backend.isRecordMoveable(); } + + /** + * @see com.idcanet.vasc.core.VascBackend#executePageSummary() + */ + public Map executePageSummary() { + return backend.executePageSummary(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#executeTotalSummary() + */ + public Map executeTotalSummary() { + return backend.executeTotalSummary(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isPageSummary() + */ + public boolean isPageSummary() { + return backend.isPageSummary(); + } + + /** + * @see com.idcanet.vasc.core.VascBackend#isTotalSummary() + */ + public boolean isTotalSummary() { + return backend.isTotalSummary(); + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascBackend.java b/src/main/java/com/idcanet/vasc/core/VascBackend.java index 28746a3..925bf2a 100644 --- a/src/main/java/com/idcanet/vasc/core/VascBackend.java +++ b/src/main/java/com/idcanet/vasc/core/VascBackend.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.core; import java.util.List; +import java.util.Map; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; @@ -49,9 +50,21 @@ public interface VascBackend { public void delete(Object object) throws VascException; - + + /** + * Creates a new Field acces obj the the given field entry. + * note: Do not use inline class here because it needs to be seriabable and the backend is not seriabbzle. + * @param field + * @return + */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field); + /** + * Creates a new RecordCreater obj the the given entry. + * note: Do not use inline class here because it needs to be seriabable and the backend is not seriabbzle. + * @param vascEntry + * @return + */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry); /** @@ -86,6 +99,13 @@ public interface VascBackend { public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException; public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException; + + public boolean isPageSummary(); + public Map executePageSummary(); + + public boolean isTotalSummary(); + public Map executeTotalSummary(); + /* public boolean hasSettings(); public Map getSettings(); diff --git a/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java b/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java index 2d7efaa..dbed6d7 100644 --- a/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/core/VascFrontendHelper.java @@ -50,6 +50,8 @@ public interface VascFrontendHelper { public Integer getTotalColumnsWidth(VascEntry entry); + public List getVascLinkEntryByType(VascEntry entry,VascLinkEntryType type); + /** * Returns the total amount of pages * @return diff --git a/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java b/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java index 556c314..53f0441 100644 --- a/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java +++ b/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java @@ -52,14 +52,14 @@ public interface VascLinkEntry extends Cloneable,Serializable { public List getEntryCreateFieldValueKeys(); /** - * @return the viewAsDetail + * @return the vascLinkEntryType */ - public Boolean getViewAsDetail(); + public VascLinkEntryType getVascLinkEntryType(); /** - * @param viewAsDetail the viewAsDetail to set + * @param vascLinkEntryType the vascLinkEntryType to set */ - public void setViewAsDetail(Boolean viewAsDetail); + public void setVascLinkEntryType(VascLinkEntryType vascLinkEntryType); /** * @return the doActionId @@ -71,6 +71,16 @@ public interface VascLinkEntry extends Cloneable,Serializable { */ public void setDoActionId(String doActionId); + /** + * @return the name + */ + public String getName(); + + /** + * @param name the name to set + */ + public void setName(String name); + /** * Force impl to have public clone methode * @return diff --git a/src/main/java/com/idcanet/vasc/core/VascLinkEntryType.java b/src/main/java/com/idcanet/vasc/core/VascLinkEntryType.java new file mode 100644 index 0000000..79db136 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/core/VascLinkEntryType.java @@ -0,0 +1,44 @@ +/* + * 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.io.Serializable; + +/** + * The type of a VascLinkEntry + * + * @author Willem Cazander + * @version 1.0 Mrt 16, 2010 + */ +public enum VascLinkEntryType implements Serializable { + + EDIT_INLINE, + EDIT_TAB, + LIST; + + public static VascLinkEntryType DEFAULT_TYPE = VascLinkEntryType.EDIT_TAB; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java index 3bc8879..d841442 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -56,11 +56,16 @@ import com.idcanet.vasc.core.VascBackendPageNumber; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascEntryState; +import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.VascLinkEntryType; 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.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.vasc.impl.actions.AddRowAction; +import com.idcanet.vasc.impl.actions.DeleteRowAction; +import com.idcanet.vasc.impl.actions.EditRowAction; /** * @@ -132,6 +137,43 @@ public class JSFVascEntrySupportBean implements Serializable { return r; } + public String getParentSelectedDisplayName() { + if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + return ""; // no parent + } + + VascEntry parent = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + Object row = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataObject(); + if (row==null) { + return "no-selection"; + } + VascEntryField v = parent.getVascEntryFieldById(parent.getDisplayNameFieldId()); + VascEntryFieldValue ve = v.getVascEntryFieldValue(); + String result = "no-data"; + try { + result = ve.getDisplayValue(v, row); + } catch (VascException e) { + e.printStackTrace(); + } + return result; + } + + public String getSelectedDisplayName() { + Object row = entry.getVascFrontendData().getVascEntryState().getEntryDataObject(); + if (row==null) { + return "no-selection"; + } + VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId()); + VascEntryFieldValue ve = v.getVascEntryFieldValue(); + String result = "no-data"; + try { + result = ve.getDisplayValue(v, row); + } catch (VascException e) { + e.printStackTrace(); + } + return result; + } + public int getTotalColumnCount() { int t = 0; t += getTotalFieldColumnCount(); @@ -165,14 +207,27 @@ public class JSFVascEntrySupportBean implements Serializable { } public int getTotalLinkColumnCount() { - JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(FacesContext.getCurrentInstance().getViewRoot(),entry.getId()); - String disableLinkColumns = (String)comp.getAttributes().get(JSFVascUIComponent.DISABLE_LINK_COLUMNS); - if (disableLinkColumns!=null && disableLinkColumns.equals("true")) { - return 0; // not added too table. - } - return entry.getVascLinkEntries().size(); + return getVascLinkEntriesList().size(); } + public List getVascLinkEntriesList() { + return entry.getVascFrontendData().getVascFrontendHelper().getVascLinkEntryByType(entry,VascLinkEntryType.LIST); + } + public List getVascLinkEntriesEditTab() { + return entry.getVascFrontendData().getVascFrontendHelper().getVascLinkEntryByType(entry,VascLinkEntryType.EDIT_TAB); + } + public List getVascLinkEntriesEditInline() { + return entry.getVascFrontendData().getVascFrontendHelper().getVascLinkEntryByType(entry,VascLinkEntryType.EDIT_INLINE); + } + public List getVascLinkEntriesEditTabParentState() { + if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + List result = new ArrayList(0); + return result; + } + return entry.getVascFrontendData().getVascFrontendHelper().getVascLinkEntryByType(entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(),VascLinkEntryType.EDIT_TAB); + } + + public long getPageTotalRecordCount() { long result = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); return result; @@ -338,6 +393,51 @@ public class JSFVascEntrySupportBean implements Serializable { throw new IllegalArgumentException("Component is of link of button type: "+comp); } + public List getParentCustomRowActions() { + List result = new ArrayList(5); + VascEntry entry = getVascEntry(); + if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + return result; + } + VascEntry parent = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + for (RowVascAction action:parent.getRowActions()) { + String actionId = action.getId(); + if (AddRowAction.ACTION_ID.equals(actionId)) { + continue; + } + if (DeleteRowAction.ACTION_ID.equals(actionId)) { + continue; + } + if (EditRowAction.ACTION_ID.equals(actionId)) { + continue; + } + result.add(action); + } + return result; + } + + public void parentCustomRowaction(ActionEvent event) { + String actionIdString = getComponentType(event.getComponent()); + logger.fine("parentCustomRowaction: "+actionIdString); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + return; + } + VascEntry parent = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + + RowVascAction action = parent.getRowActionById(actionIdString); + Object parentSelected = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataObject(); + logger.fine("parentCustomRowaction do on: "+action+" parentSelection: "+parentSelected); + try { + action.doRowAction(parent,parentSelected); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + logger.fine("parentCustomRowaction DONE"); + } + + public boolean getHasMultiRowActions() { int size = getVascEntry().getVascFrontendData().getVascFrontendHelper().getMultiRowActions(getVascEntry()).size(); if (size==0) { @@ -466,10 +566,19 @@ public class JSFVascEntrySupportBean implements Serializable { return getVascEntry().getVascFrontendData().getVascEntryState().getParent()!=null; } + public boolean getRenderBackEditAction() { + if (getVascEntry().getVascFrontendData().getVascEntryState().getParent()!=null) { + if (getVascEntry().getVascFrontendData().getVascEntryState().getParent().getVascEntry().getRowActionById("editRowAction")==null) { + return false; // parent is not editable + } + return true; + } + return false; + } + public void backAction(ActionEvent event) { logger.fine("backAction"); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); - VascEntry entry = getVascEntry(); comp.initGoto(entry.getVascFrontendData().getVascEntryState().getParent()); try { entry.getVascFrontendData().getVascFrontend().renderView(); @@ -482,21 +591,18 @@ public class JSFVascEntrySupportBean implements Serializable { logger.fine("backEditAction"); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = getVascEntry(); - comp.initGoto(entry.getVascFrontendData().getVascEntryState().getParent()); // select record to edit Object rowObject = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataObject(); - int index = entry.getVascFrontendData().getVascEntryState().getParent().getEntryDataList().indexOf(rowObject); - tableDataModel.setRowIndex(index); - - try { - entry.getVascFrontendData().getVascEntryState().setEditCreate(false); - entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascEventType.DATA_SELECT, rowObject); - entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); - entry.getVascFrontendData().getVascFrontend().renderEdit(); - } catch (Exception e) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); - } + //String idField = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry().getPrimaryKeyFieldId(); + // VascEntryField field = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry().getVascEntryFieldById(idField); +// try { + // Object id = field.getVascEntryFieldValue().getValue(field, rowObject); + comp.initGoto(entry.getVascFrontendData().getVascEntryState().getParent(),rowObject); + // } catch (VascException e1) { + // TODO Auto-generated catch block + // e1.printStackTrace(); + //} } @@ -627,6 +733,7 @@ public class JSFVascEntrySupportBean implements Serializable { VascDataBackendBean selected = comp.getSupportBean().getSelectedTableRecord(); logger.finer("Set selected: "+selected); VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().getVascEntryState().setEntryDataObject(selected.getRecord()); VascLinkEntry l = entry.getVascLinkEntryById(linkId); comp.initGoto(l); try { @@ -695,6 +802,7 @@ public class JSFVascEntrySupportBean implements Serializable { logger.fine("cancelAction"); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); + this.getSelected().setRealValue(false); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); try { entry.getVascFrontendData().getVascFrontend().renderView(); @@ -745,7 +853,7 @@ public class JSFVascEntrySupportBean implements Serializable { } public void processDirectDownloadChange(ValueChangeEvent event){ - + // first do normal global selection of action aka: globalAction(event); copyed: JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); @@ -782,8 +890,9 @@ public class JSFVascEntrySupportBean implements Serializable { } selectedExporterAction = "null"; // reset selection to top one. + FacesContext fc = FacesContext.getCurrentInstance(); try { - FacesContext fc = FacesContext.getCurrentInstance(); + HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse(); String filename = "export-list."+ex.getType(); response.setHeader("Content-disposition", "attachment; filename=" + filename); @@ -793,10 +902,10 @@ public class JSFVascEntrySupportBean implements Serializable { ex.doExport(out, entry); out.close(); - - fc.responseComplete(); } catch (Exception e) { entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } finally { + fc.responseComplete(); } } @@ -858,6 +967,7 @@ public class JSFVascEntrySupportBean implements Serializable { * @param selected the selected to set */ public void setSelected(VascDataBackendBean selected) { + logger.info("Set selected records: "+selected+" on: "+this); this.selected = selected; } @@ -979,8 +1089,19 @@ public class JSFVascEntrySupportBean implements Serializable { public void setSelectedMultiRowAction(String selectedMultiRowAction) { this.selectedMultiRowAction = selectedMultiRowAction; } - - + + /** + * @return the selectAllValue + */ + public Boolean getSelectAllValue() { + return false; + } + + /** + * @param selectAllValue the selectAllValue to set + */ + public void setSelectAllValue(Boolean selectAllValue) { + } } class JSFVascSupportI18nMapController implements Map { private VascEntry entry = null; diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java index 3d7869a..1522e11 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java @@ -93,10 +93,8 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser logger.finer("renderEdit"); UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); - comp.setRenderFacetState("editView"); - + comp.setRenderFacetState("editView"); entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry); - //String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); VascDataBackendBean selBean = null; if (entry.getVascFrontendData().getVascEntryState().isEditCreate()) { @@ -130,9 +128,9 @@ public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Ser JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); comp.setRenderFacetState("listView"); - if (comp.getSupportBean().getSelected()!=null) { - comp.getSupportBean().getSelected().setRealValue(false); - comp.getSupportBean().setSelected(null); - } + //if (comp.getSupportBean().getSelected()!=null) { + // comp.getSupportBean().getSelected().setRealValue(false); + // comp.getSupportBean().setSelected(null); + //} } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java index a557b17..2ce4751 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java @@ -27,7 +27,9 @@ package com.idcanet.vasc.frontends.web.jsf; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.logging.Logger; import javax.el.ValueExpression; @@ -45,6 +47,7 @@ import com.idcanet.vasc.core.VascFrontendData; import com.idcanet.vasc.core.VascLinkEntry; import com.idcanet.vasc.core.entry.VascEntryEventListener; import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFListModel; import com.idcanet.vasc.impl.DefaultVascFactory; /** @@ -74,6 +77,7 @@ public class JSFVascUIComponent extends UIComponentBase { private VascLinkEntry link = null; private VascEntryState linkState = null; private VascEntryState state = null; + private Object stateEditId = null; private Logger logger = null; private Boolean initClear = null; @@ -187,6 +191,12 @@ public class JSFVascUIComponent extends UIComponentBase { this.state=state; } + protected void initGoto(VascEntryState state,Object stateEditId) { + logger.fine("init goto "+state); + this.state=state; + this.stateEditId=stateEditId; + } + public Boolean getInitClear() { return initClear; } @@ -194,9 +204,14 @@ public class JSFVascUIComponent extends UIComponentBase { @Override public void encodeBegin(FacesContext context) throws IOException { logger.fine("Comp encodeBegin link: "+link); + // no need to add multiple + if (renderer==null) { + logger.finer("Adding phase listener: JSFVascValidatePhaseListener"); + context.getViewRoot().addPhaseListener(new JSFVascValidatePhaseListener()); + } boolean init = false; if (renderer==null | link!=null | state!=null) { - renderFacetState = "listView"; + renderFacetState = "listView"; VascEntry entry = createClonedVascEntry(); renderer = new JSFVascFrontendRenderer(); try { @@ -209,13 +224,36 @@ public class JSFVascUIComponent extends UIComponentBase { supportBean.setSearchString(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getSearchString()); init = true; + } + + if (stateEditId!=null) { + Object rowObject = stateEditId; - // no need to add multiple - if (renderer==null) { - logger.info("Adding phase listener: JSFVascValidatePhaseListener"); - context.getViewRoot().addPhaseListener(new JSFVascValidatePhaseListener()); + // setup for renderEdit() of frontend + List list = new ArrayList(1); + list.add(new VascDataBackendBean(supportBean.getVascEntry(),rowObject,0)); + supportBean.getTableDataModel().setWrappedData(list); + supportBean.getTableDataModel().setRowIndex(0); + + // edit action copyed + try { + VascEntry entry = supportBean.getVascEntry(); + entry.getVascFrontendData().getVascEntryState().setEditCreate(false); + entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascEventType.DATA_SELECT, rowObject); + entry.getVascFrontendData().getVascEntryState().setEntryDataObject(rowObject); + entry.getVascFrontendData().getVascFrontend().renderEdit(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // refresh all drop down lists.. + for (String key:supportBean.getEditSelectItemModels().keySet()) { + Object o = supportBean.getEditSelectItemModels().get(key); + if (o instanceof JSFListModel) { + JSFListModel t = (JSFListModel)o; + t.requestRefresh(); } - } // set the support bean @@ -277,6 +315,9 @@ public class JSFVascUIComponent extends UIComponentBase { if (link!=null) { entryName = link.getVascEntryId(); } + if (state!=null) { + entryName = state.getVascEntry().getId(); + } VascEntry entry = vascController.getVascEntryController().getVascEntryById(entryName); if (entry==null) { @@ -289,6 +330,11 @@ public class JSFVascUIComponent extends UIComponentBase { frontendData.getVascEntryState().setVascBackend(backend); frontendData.getVascEntryState().setVascEntry(entry); + if (state!=null) { + // copy prevois parent + frontendData.getVascEntryState().setParent(state.getParent()); + } + if (link!=null) { // save state if (linkState==null) { @@ -303,6 +349,14 @@ public class JSFVascUIComponent extends UIComponentBase { for (String parameterName:link.getEntryParameterFieldIdKeys()) { String fieldId = link.getEntryParameterFieldId(parameterName); VascEntryField v = getVascEntry().getVascEntryFieldById(fieldId); + if (v==null) { + logger.warning("Could nog get VascEntryField for fieldID: "+fieldId); + continue; + } + if (v.getVascEntryFieldValue()==null) { + logger.warning("Could not get VascEntryFieldValue for fieldID: "+fieldId); + continue; + } Object selectedValue = v.getVascEntryFieldValue().getValue(v, selected); // set data parameter on new vasc entry diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java index 14c5e04..a5bc241 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java @@ -61,8 +61,10 @@ import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.VascLinkEntryType; import com.idcanet.vasc.core.actions.RowVascAction; import com.idcanet.vasc.core.ui.VascOptionValueModelListener; +import com.idcanet.vasc.core.ui.VascUIComponent; import com.idcanet.vasc.core.ui.VascValueModel; import com.idcanet.vasc.impl.actions.AddRowAction; @@ -95,6 +97,10 @@ public class JSFVascUIComponentRenderer extends Renderer { // check if injection is needed if (comp.getInitClear()!=null) { injectAll(facesContext,comp,comp.getInitClear()); + + // hack for edit back action to set field disabled + VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry); } // render the current facet of the vasc component @@ -119,8 +125,8 @@ public class JSFVascUIComponentRenderer extends Renderer { String injectTableColumnsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_TABLE_COLUMNS_ID); UIComponent injectEditFieldsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("editView"),injectEditFieldsId); - UIComponent injectTableOptionsComponent = JSFVascUIComponent.findComponentById(comp.getCurrentView(),injectTableOptionsId); - UIComponent injectTableColumnsComponent = JSFVascUIComponent.findComponentById(comp.getCurrentView(),injectTableColumnsId); + UIComponent injectTableOptionsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableOptionsId); + UIComponent injectTableColumnsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("listView"),injectTableColumnsId); if (injectEditFieldsComponent==null) { throw new NullPointerException("Could not find injectEditFieldsId: "+injectEditFieldsId); } @@ -166,15 +172,15 @@ public class JSFVascUIComponentRenderer extends Renderer { if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) { continue; } - + //System.out.println("Multi edit size: "+c.getVascEntryFieldType().getUIComponentCount(c)+" of: "+c.getVascEntryFieldType()); for (int i=0;i errors = entry.getVascFrontendData().getVascFrontendHelper().validateObjectField(field); - System.out.println("Validate: "+component+" errors: "+errors.size()+" value: "+object); + logger.fine("Validate: "+component+" errors: "+errors.size()+" value: "+object); if (errors.isEmpty()) { return; // no errors } - StringBuffer buf = new StringBuffer(200); + buf = new StringBuffer(200); for (String err:errors) { buf.append(err); buf.append('\n'); } + } catch (Exception e) { + e.printStackTrace(); + return; + } + FacesMessage message = new FacesMessage(buf.toString()); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); @@ -263,18 +280,20 @@ public class JSFVascUIComponentRenderer extends Renderer { for (VascEntryField option:entry.getListOptions()) { for (int i=0;i kids = component.getFacetsAndChildren(); + while (kids.hasNext()) { + UIComponent child = kids.next(); validateUIInput(child,context); } } 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 index a26d26b..21f1834 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java @@ -151,7 +151,7 @@ public class VascRequestFacesFilter implements Filter { facesContext.setViewRoot(viewRoot); } try { - request.getRequestDispatcher(templateFile).include(request, response); + request.getRequestDispatcher(templateFile).forward(request, response); } catch (ViewExpiredException e) { // lets try again response.sendRedirect(request.getRequestURL().toString()); 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 index 3d3484e..0f6eb3f 100644 --- 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 @@ -27,7 +27,6 @@ package com.idcanet.vasc.frontends.web.jsf.ui; import java.io.Serializable; -import java.util.ArrayList; import java.util.List; import javax.el.ValueExpression; @@ -39,13 +38,11 @@ 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 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; import com.idcanet.vasc.core.ui.VascValueModel; import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent; @@ -67,42 +64,17 @@ public class JSFList extends AbstractJSFBaseComponent { componentId = component.getId(); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent((UIComponent)gui); - String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); - - String id = component.getId(); - ValueExpression itemsTestVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+id+"']}", TestModel.class); - - - List items; - List value = new ArrayList(50); - VascSelectItemModel itemModel = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject(); - try { - items = itemModel.getVascSelectItems(entryField.getVascEntry()); - } catch (VascException e) { - throw new VascException(e); - } - for (VascSelectItem v:items) { - SelectItem si = new SelectItem(); - si.setLabel(v.getLabel()); - si.setValue(v.getValue()); - si.setDisabled(v.isDisabled()); - value.add(si); - } - - TestModel t = new TestModel(items); - t.addAll(value); - t.entryField=entryField; + String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + ValueExpression itemsTestVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+componentId+"']}", JSFListModel.class); + + JSFListModel t = new JSFListModel(entryField); itemsTestVE.setValue(FacesContext.getCurrentInstance().getELContext(), t); component.setConverter(new VascConverter(t)); - - UISelectItems item = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE); - item.setId(viewRoot.createUniqueId()); - ValueExpression itemsVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+id+"']}", List.class); - item.setValueExpression("value", itemsVE); - component.getChildren().add(item); - ((UIComponent)gui).getChildren().add(component); + + setValueTestModel(component); + return component; } @@ -121,27 +93,30 @@ public class JSFList extends AbstractJSFBaseComponent { HtmlSelectOneMenu component = (HtmlSelectOneMenu)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); component.setDisabled(disabled); } -} -class TestModel extends ArrayList implements Serializable { - private static final long serialVersionUID = -5266070864271715383L; - public VascEntryField entryField; - private List items; - - public TestModel(List items) { - this.items=items; - } - - public List getVascItems() { - return items; + private void setValueTestModel(HtmlSelectOneMenu component) { + Application application = FacesContext.getCurrentInstance().getApplication(); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + + UISelectItems item = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE); + item.setId(viewRoot.createUniqueId()); + + JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,null); + String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + String id = component.getId(); + ValueExpression itemsVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+id+"']}", List.class); + item.setValueExpression("value", itemsVE); + + component.getChildren().clear(); + component.getChildren().add(item); } } class VascConverter implements Converter,Serializable { private static final long serialVersionUID = 6198813637409531713L; - private TestModel testModel = null; + private JSFListModel testModel = null; - public VascConverter(TestModel testModel) { + public VascConverter(JSFListModel testModel) { this.testModel=testModel; } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFListModel.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFListModel.java new file mode 100644 index 0000000..4bd33df --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFListModel.java @@ -0,0 +1,180 @@ +/* + * 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.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import javax.faces.model.SelectItem; + +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; + + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 28, 2009 + */ +public class JSFListModel implements Serializable,List { + + private static final long serialVersionUID = -5266070864271715383L; + private VascEntryField entryField; + private List items = null; + private List selectItems = null; + private boolean refresh = true; + + public JSFListModel() { + items = new ArrayList(40); + selectItems = new ArrayList(40); + } + + public JSFListModel(VascEntryField entryField) { + this(); + this.entryField=entryField; + } + + public List getVascItems() { + refresh(); + return items; + } + + public List getSelectItems() { + refresh(); + return selectItems; + } + + public void requestRefresh() { + refresh = true; + } + + private void refresh() { + if (refresh==false) { + return; + } + refresh=false; + items.clear(); + selectItems.clear(); + + VascSelectItemModel itemModel = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject(); + try { + items = itemModel.getVascSelectItems(entryField.getVascEntry()); + } catch (VascException e) { + throw new RuntimeException(e); + } + for (VascSelectItem v:items) { + selectItems.add(convert(v)); + } + } + + private SelectItem convert(VascSelectItem v) { + SelectItem si = new SelectItem(); + si.setLabel(v.getLabel()); + si.setValue(v.getValue()); + si.setDisabled(v.isDisabled()); + return si; + } + + // === LIST interface + + public void add(int arg0, SelectItem arg1) { + getSelectItems().add(arg0,arg1); + } + public boolean add(SelectItem arg0) { + return getSelectItems().add(arg0); + } + public boolean addAll(Collection arg0) { + return getSelectItems().addAll(arg0); + } + public boolean addAll(int arg0, Collection arg1) { + return getSelectItems().addAll(arg0,arg1); + } + public void clear() { + getSelectItems().clear(); + } + public boolean contains(Object arg0) { + return getSelectItems().contains(arg0); + } + public boolean containsAll(Collection arg0) { + return getSelectItems().containsAll(arg0); + } + public SelectItem get(int index) { + return getSelectItems().get(index); + } + public int indexOf(Object arg0) { + return getSelectItems().indexOf(arg0); + } + public boolean isEmpty() { + return getSelectItems().isEmpty(); + } + public Iterator iterator() { + return getSelectItems().iterator(); + } + public int lastIndexOf(Object arg0) { + return getSelectItems().lastIndexOf(arg0); + } + public ListIterator listIterator() { + return getSelectItems().listIterator(); + } + public ListIterator listIterator(int arg0) { + return getSelectItems().listIterator(arg0); + } + public SelectItem remove(int arg0) { + return getSelectItems().remove(arg0); + } + public boolean remove(Object arg0) { + return getSelectItems().remove(arg0); + } + public boolean removeAll(Collection arg0) { + return getSelectItems().removeAll(arg0); + } + public boolean retainAll(Collection arg0) { + return getSelectItems().retainAll(arg0); + } + public SelectItem set(int arg0, SelectItem arg1) { + return getSelectItems().set(arg0, arg1); + } + public int size() { + return getSelectItems().size(); + } + public List subList(int arg0, int arg1) { + return getSelectItems().subList(arg0, arg1); + } + public Object[] toArray() { + return getSelectItems().toArray(); + } + public T[] toArray(T[] a) { + return getSelectItems().toArray(a); + } +} diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java index ac9dd9e..0f816ec 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java @@ -38,6 +38,7 @@ import com.idcanet.vasc.core.VascEntryFieldType; import com.idcanet.vasc.core.VascEntryFinalizer; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.VascLinkEntryType; import com.idcanet.vasc.core.actions.VascAction; /** @@ -225,11 +226,14 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { if (vef.getList()==null) { vef.setList(true); } + if (vef.getCreate()==null) { + vef.setCreate(true); + } if (vef.getEdit()==null) { vef.setEdit(true); } if (vef.getEditReadOnly()==null) { - vef.setEditReadOnly(true); + vef.setEditReadOnly(false); } if (vef.getVascEntryFieldValue()==null) { @@ -293,6 +297,16 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { if (vid==null) { throw new IllegalArgumentException("All VascLinkEntry need an id in entryId: "+id); } + if (vle.getVascEntryId()==null) { + throw new IllegalArgumentException("All VascLinkEntry need an vascEntryId: "+id); + } + + if (vle.getVascLinkEntryType()==null) { + vle.setVascLinkEntryType(VascLinkEntryType.DEFAULT_TYPE); + } + if (vle.getName()==null) { + vle.setName("vasc.entry."+vle.getVascEntryId()+".name"); + } } for (VascEntryField vef:entry.getListOptions()) { @@ -339,11 +353,14 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { if (vef.getList()==null) { vef.setList(true); } + if (vef.getCreate()==null) { + vef.setCreate(true); + } if (vef.getEdit()==null) { vef.setEdit(true); } if (vef.getEditReadOnly()==null) { - vef.setEditReadOnly(true); + vef.setEditReadOnly(false); } if (vef.getVascEntryFieldValue()==null) { diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java index e8bc941..68570ef 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007 IDCA. All rights reserved. + * Copyright 2004-2010 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: @@ -32,12 +32,15 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import com.idcanet.vasc.core.VascBackendFilter; import com.idcanet.vasc.core.VascBackendPageNumber; import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.VascFrontendHelper; +import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.VascLinkEntryType; import com.idcanet.vasc.core.VascUserRoleController; import com.idcanet.vasc.core.actions.GlobalVascAction; import com.idcanet.vasc.core.actions.RowVascAction; @@ -177,6 +180,20 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { return result; } + public List getVascLinkEntryByType(VascEntry entry,VascLinkEntryType type) { + List result = new ArrayList(10); + for (VascLinkEntry link:entry.getVascLinkEntries()) { + if (type==null) { + result.add(link); + continue; + } + if (type.equals(link.getVascLinkEntryType())) { + result.add(link); + } + } + return result; + } + /** * Returns the total amount of pages * @return @@ -220,20 +237,26 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { public Object createObject(VascEntry entry) { try { Object object = entry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryRecordCreator(entry.clone()).newRecord(entry); + if (object==null) { + throw new IllegalStateException("Can't work with null object for backend storage."); + } for (VascEntryField field:entry.getVascEntryFields()) { + if (field.getDefaultValue()==null) { + continue; // no default value to set. + } Object value = field.getVascEntryFieldValue().getValue(field, object); - if (value==null & field.getDefaultValue()!=null) { - - Object defaultValue = field.getDefaultValue(); - if (defaultValue instanceof String) { - String def = (String)defaultValue; - if (def.equals("now()")) { // TODO: add default string parsers - defaultValue = new Date(); - } - } - logger.finer("Setting default value for: "+field.getName()+" def: "+defaultValue); - field.getVascEntryFieldValue().setValue(field, object, defaultValue); + if (value!=null) { + continue; // value is already set by backend creator. } + Object defaultValue = field.getDefaultValue(); + if (defaultValue instanceof String) { + String def = (String)defaultValue; + if (def.equals("now()")) { // TODO: add default string parsers + defaultValue = new Date(); + } + } + logger.finer("Setting default value for: "+field.getName()+" def: "+defaultValue); + field.getVascEntryFieldValue().setValue(field, object, defaultValue); } fireVascEvent(entry,VascEventType.DATA_CREATE, object); return object; @@ -286,7 +309,16 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { try { fireVascEvent(entry,VascEventType.DATA_PRE_UPDATE,object); int index = removeObjectFromDataList(entry,object); + + // merge object on backend result = entry.getVascFrontendData().getVascEntryState().getVascBackend().merge(object); + + // put object thrue the filters + for (VascBackendFilter filter:entry.getVascBackendFilters()) { + result = filter.filterObject(result); + } + + // put object back in list entry.getVascFrontendData().getVascEntryState().getEntryDataList().add(index, result); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); fireVascEvent(entry,VascEventType.DATA_POST_UPDATE,result); @@ -353,6 +385,17 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { throw new NullPointerException("Can't validate null entry object."); } List error = new ArrayList(3); + + // skip non-create and non-edit fields + if (entry.getVascFrontendData().getVascFrontendHelper().renderCreate(field) == false & + entry.getVascFrontendData().getVascEntryState().isEditCreate()) { + return error; + } + if (entry.getVascFrontendData().getVascFrontendHelper().renderEditReadOnly(field) & + entry.getVascFrontendData().getVascEntryState().isEditCreate()==false) { + return error; + } + try { Object objectSelected = entry.getVascFrontendData().getVascEntryState().getEntryDataObject(); Object objectValue = field.getVascEntryFieldValue().getValue(field, objectSelected); diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java index 7960196..d1eaa02 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascLinkEntry.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.VascLinkEntryType; /** @@ -47,9 +48,10 @@ public class DefaultVascLinkEntry implements VascLinkEntry { private String vascEntryId = null; private Map entryParameterFieldIds = new HashMap(3); private Map entryCreateFieldValues = new HashMap(3); - private Boolean viewAsDetail = null; + private VascLinkEntryType vascLinkEntryType = null; private String doActionId = null; - + private String name = null; + /** * @return the id */ @@ -100,17 +102,17 @@ public class DefaultVascLinkEntry implements VascLinkEntry { } /** - * @return the viewAsDetail + * @return the vascLinkEntryType */ - public Boolean getViewAsDetail() { - return viewAsDetail; + public VascLinkEntryType getVascLinkEntryType() { + return vascLinkEntryType; } /** - * @param viewAsDetail the viewAsDetail to set + * @param vascLinkEntryType the vascLinkEntryType to set */ - public void setViewAsDetail(Boolean viewAsDetail) { - this.viewAsDetail = viewAsDetail; + public void setVascLinkEntryType(VascLinkEntryType vascLinkEntryType) { + this.vascLinkEntryType = vascLinkEntryType; } /** @@ -127,6 +129,20 @@ public class DefaultVascLinkEntry implements VascLinkEntry { this.doActionId = doActionId; } + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** * @see java.lang.Object#clone() */ @@ -134,11 +150,12 @@ public class DefaultVascLinkEntry implements VascLinkEntry { public VascLinkEntry clone() throws CloneNotSupportedException { DefaultVascLinkEntry result = new DefaultVascLinkEntry(); result.doActionId=doActionId; - result.viewAsDetail=viewAsDetail; + result.vascLinkEntryType=vascLinkEntryType; result.vascEntryId=vascEntryId; result.entryParameterFieldIds=entryParameterFieldIds; result.entryCreateFieldValues=entryCreateFieldValues; result.id=id; + result.name=name; 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 index 82abecf..a780ddd 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java @@ -27,7 +27,9 @@ package com.idcanet.vasc.impl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.idcanet.vasc.core.VascBackend; import com.idcanet.vasc.core.VascBackendState; @@ -54,6 +56,8 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { private String nullLabel = null; private String nullKeyValue = null; private Boolean returnKeyValue = null; + private Map entryParameterFieldIds = new HashMap(3); + private Boolean useParentFields = null; /** * @see com.idcanet.vasc.core.ui.VascSelectItemModel#getVascSelectItems(com.idcanet.vasc.core.VascEntry) @@ -95,9 +99,41 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { VascBackendState state = new DefaultVascBackendState(); for (String key2:ve.getEntryParameterKeys()) { Object value = ve.getEntryParameter(key2); + //System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName()); state.setDataParameter(key2, value); } - + for (String paraName:entryParameterFieldIds.keySet()) { + + VascEntry fieldEntry = entry; + if (useParentFields!=null && useParentFields==true) { + if (entry.getVascFrontendData().getVascEntryState().getParent()==null) { + throw new IllegalStateException("Requested to use parent state field values but no parent state found."); + } + fieldEntry = entry.getVascFrontendData().getVascEntryState().getParent().getVascEntry(); + } + + String paraValueId = entryParameterFieldIds.get(paraName); + VascEntryField fieldOrg = fieldEntry.getVascEntryFieldById(paraValueId); + if (fieldOrg==null) { + //System.out.println("could not find field: "+paraValueId); + continue; + } + VascEntryField field = fieldOrg.clone(); + field.getVascValidators().clear(); + VascEntryFieldValue v = fieldEntry.getVascFrontendData().getVascEntryState().getVascBackend().provideVascEntryFieldValue(field); + + Object record = fieldEntry.getVascFrontendData().getVascEntryState().getEntryDataObject(); + if (record==null) { + //System.out.println("could not get selected records from state."); + continue; + } + Object value = v.getValue(fieldOrg, record); + + //System.out.println("Set entry paras name: "+paraName+" value: "+value+" class: "+value.getClass().getName()); + state.setDataParameter(paraName, value); + } + + // TODO: FIX >>>>>>>>>>>>>>>>>> if (key.getVascEntryFieldValue()==null) { // TODO: fix this for better remote support @@ -218,4 +254,28 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { public void setReturnKeyValue(Boolean returnKeyValue) { this.returnKeyValue = returnKeyValue; } + + public String getEntryParameterFieldId(String parameterName) { + return entryParameterFieldIds.get(parameterName); + } + public void addEntryParameterFieldId(String parameterName,String valueFieldId) { + entryParameterFieldIds.put(parameterName, valueFieldId); + } + public List getEntryParameterFieldIdKeys() { + return new ArrayList(entryParameterFieldIds.keySet()); + } + + /** + * @return the useParentFields + */ + public Boolean getUseParentFields() { + return useParentFields; + } + + /** + * @param useParentFields the useParentFields to set + */ + public void setUseParentFields(Boolean useParentFields) { + this.useParentFields = useParentFields; + } } \ 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 72c769e..fa49e9f 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java @@ -65,7 +65,7 @@ public class CSVExportGlobalAction extends AbstractVascAction implements GlobalV int oldIndex = entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageIndex(); Long total = entry.getVascFrontendData().getVascEntryState().getTotalBackendRecords(); int pages = total.intValue()/entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize(); - for (int page=0;page - - + + - + + + diff --git a/src/test/java/com/idcanet/vasc/SwingTest.java b/src/test/java/com/idcanet/vasc/SwingTest.java index 299855c..68c01bd 100644 --- a/src/test/java/com/idcanet/vasc/SwingTest.java +++ b/src/test/java/com/idcanet/vasc/SwingTest.java @@ -62,17 +62,21 @@ public class SwingTest extends TestCase { assertEquals(true, true); } - /* - public void testAll() throws Exception { + public static void main(String[] argu){ JFrame.setDefaultLookAndFeelDecorated(false); + try { VascEntry entry = TestTable.getVascTable(); - JFrame frame = viewEntry(entry); + + SwingTest s = new SwingTest(); + JFrame frame = s.viewEntry(entry); while (frame.isVisible()) { - Thread.sleep(1000); + Thread.sleep(100000); } + } catch (Exception e) { + e.printStackTrace(); + } } - */ public JFrame viewEntry(final VascEntry entry) throws Exception { // get GUI