2
0
Fork 0

[svn r382] hacked jsf frontend working

This commit is contained in:
willemc 2009-08-11 20:31:29 +02:00
parent 37fdf22282
commit 9a605f177a
123 changed files with 7035 additions and 2418 deletions

108
pom.xml
View file

@ -121,14 +121,14 @@
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86</artifactId>
<version>3.3.0-v3346</version>
<scope>provided</scope>
<scope>compile</scope>
<optional/>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>jface</artifactId>
<version>3.3.0-I20070606-0010</version>
<scope>provided</scope>
<scope>compile</scope>
<optional/>
</dependency>
@ -233,8 +233,108 @@
</profile>
</profiles>
-->
<!-- Eclipse OS-specific dependencies -->
<profiles>
<profile>
<id>linux-x86</id>
<activation>
<os>
<arch>i386</arch>
<family>unix</family>
<name>linux</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>linux-x86_64</id>
<activation>
<os>
<arch>amd64</arch>
<family>unix</family>
<name>linux</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86_64</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>solaris-sparc</id>
<activation>
<os>
<arch>sparc</arch>
<family>unix</family>
<name>SunOS</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.gtk.solaris</groupId>
<artifactId>sparc</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>macosx</id>
<activation>
<os>
<family>unix</family>
<name>mac os x</name>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.carbon</groupId>
<artifactId>macosx</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>win32</id>
<activation>
<os>
<arch>x86</arch>
<family>windows</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.win32.win32</groupId>
<artifactId>x86</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>win64</id>
<activation>
<os>
<arch>amd64</arch>
<family>windows</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.eclipse.swt.win32.win32</groupId>
<artifactId>x86_64</artifactId>
<version>[3.2.0,4.0.0)</version>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<plugins>

View file

@ -37,25 +37,6 @@ import java.lang.reflect.Method;
*/
public class VascAnnotationParser {
/** Determens if no when no annotation is found null will return or default key */
private Boolean noAnnotationNullReturn = null;
/**
* Creates an VascAnnotationParser
*/
public VascAnnotationParser() {
setNoAnnotationNullReturn(false);
}
/**
* Determens if no when no annotation is found null will return or default key
* default is false
* @param noAnnotationNullReturn
*/
public VascAnnotationParser(boolean noAnnotationNullReturn) {
setNoAnnotationNullReturn(noAnnotationNullReturn);
}
/**
* Gets the key of the VascToolTip key for the property of the class
* @param beanClass The class to search for the property
@ -137,6 +118,15 @@ public class VascAnnotationParser {
public Boolean getVascFieldOptional(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"optional");
}
public Boolean getVascFieldSortable(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"sortable");
}
public Boolean getVascFieldSumable(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"sumable");
}
public Boolean getVascFieldGraphable(Class<?> beanClass,String property) {
return (Boolean)getValue(beanClass,VascField.class,property,"graphable");
}
public String getVascFieldType(Class<?> beanClass,String property) {
@ -147,6 +137,13 @@ public class VascAnnotationParser {
}
public Class<?> getVascFieldTemplateClass(Class<?> beanClass,String property) {
return (Class<?>)getValue(beanClass,VascFieldTemplate.class,property,"templateClass");
}
public String getVascFieldTemplate(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascFieldTemplate.class,property,"template");
}
public String getVascRolesCreate(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascRoles.class,property,"rolesCreate");
}
@ -159,6 +156,15 @@ public class VascAnnotationParser {
public String getVascRolesList(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascRoles.class,property,"rolesList");
}
public VascChoices getVascChoices(Class<?> beanClass,String property) {
return (VascChoices)getValue(beanClass,VascChoices.class,property,null);
}
public VascEventListener getVascEventListener(Class<?> beanClass) {
return (VascEventListener)getValue(beanClass,VascEventListener.class,null,null);
}
/**
* TODO: change this, because we need differnce between key and value instance
@ -166,36 +172,67 @@ public class VascAnnotationParser {
* @param property
* @return
*/
public Object getVascDefaultValue(Class<?> beanClass,String property) {
return getValue(beanClass,VascDefaultValue.class,property,null);
public String getVascDefaultValue(Class<?> beanClass,String property) {
return (String)getValue(beanClass,VascDefaultValue.class,property,null);
}
public Object getVascDefaultValue(Class<?> beanClass) {
return getValue(beanClass,VascDefaultValue.class,null,null);
}
public String getVascDisplayName(Class<?> beanClass) {
//System.out.println("========== GetDisPlayName: "+beanClass);
for (Method method:beanClass.getMethods()) {
if(method.getName().startsWith("get")==false) { //a bit durty
if (method.getName().startsWith("get")==false) { //a bit durty
continue;
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
//System.out.println("Search template for: "+method.getName());
String tempProp = method.getName().substring(3);
if ("".equals(template.template())==false) {
tempProp = template.template();
}
for (Method method2:template.templateClass().getMethods()) {
if (method2.getName().equalsIgnoreCase("get"+tempProp)==false) { //a bit durty
continue;
}
Annotation anno = method2.getAnnotation(VascDisplayName.class);
//System.out.println("Template annot: "+anno+" prop: "+tempProp);
if (anno==null) {
break;
}
//System.out.println("Found template");
return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get
}
}
Annotation anno = method.getAnnotation(VascDisplayName.class);
if (anno==null) {
continue;
}
//System.out.println("Found normal");
return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get
}
return null;
//System.out.println("Defraulting to key");
return getVascPrimaryKey(beanClass); // fall back on primary key
}
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);
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
String tempProp = property;
if ("".equals(template.template())==false) {
tempProp = template.template();
}
String value = getVascDisplayName(template.templateClass(),tempProp);
if (value!=null) {
return value;
}
}
VascModelReference mt = method.getAnnotation(VascModelReference.class);
if (mt==null) {
String result = (String)getValue(beanClass,VascField.class,property,"displayName");
return result;
return null; // no display name
}
Class<?> typeClass = mt.type();
if (Object.class==mt.type()) {
@ -212,13 +249,20 @@ public class VascAnnotationParser {
if(method.getName().startsWith("get")==false) { //a bit durty
continue;
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
String value = getVascPrimaryKey(template.templateClass());
if (value!=null) {
return value;
}
}
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;
return null; // maybe fallback on getId() ?
}
@ -242,25 +286,24 @@ public class VascAnnotationParser {
if (field!=null) {
def = def+"."+field;
}
Annotation anno = beanClass.getAnnotation(annotationType);
if (anno==null) {
// no annotation == no default
if (annotationType.equals(VascDefaultValue.class)) {
return null;
}
// no annotion avaible
if (noAnnotationNullReturn) {
return null;
}
if (annotationType.equals(VascEventListener.class)) {
return null;
}
} else {
if (annotationType.equals(VascEventListener.class)) {
return anno;
}
result = doAnnotation(anno,def,field);
if(result!=null) {
return result;
}
if (noAnnotationNullReturn) {
return null;
}
}
return def;
}
@ -281,16 +324,50 @@ public class VascAnnotationParser {
continue;
}
//logger.finer("Found property: "+property);
VascI18nModelReference mt = method.getAnnotation(VascI18nModelReference.class);
if (mt!=null && annotationType.equals(VascI18n.class)) {
VascModelReference mt = method.getAnnotation(VascModelReference.class);
if (mt!=null & (annotationType.equals(VascI18n.class) | annotationType.equals(VascField.class) | annotationType.equals(VascStyle.class) )) {
Class typeClass = mt.type();
if (Object.class==mt.type()) {
typeClass = method.getReturnType();
//return returnType.getName()+"."+annotationType.toString();
}
// recursif function:
return getValue(typeClass,annotationType,propRest,field);
if ( annotationType.equals(VascStyle.class) ) {
String disName = getVascDisplayName(typeClass);
return getValue(typeClass,annotationType,disName,field);
}
if ( annotationType.equals(VascField.class) ) {
if ("backendName".equals(field)) {
//return property+"."+getValue(typeClass,annotationType,propRest,field);
}
} else {
// recursif function:
return getValue(typeClass,annotationType,propRest,field);
}
}
VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class);
if (template!=null) {
if (annotationType.equals(VascFieldTemplate.class)) {
if ("templateClass".equals(field)) {
return template.templateClass();
}
if ("template".equals(field)) {
return template.template();
}
return null;
}
String tempProp = property;
if ("".equals(template.template())==false) {
tempProp = template.template();
}
Object value = getValue(template.templateClass(),annotationType,tempProp,field);
if (value!=null) {
return value;
}
}
Annotation anno = method.getAnnotation(annotationType);
@ -302,9 +379,6 @@ public class VascAnnotationParser {
if(result!=null) {
return result;
}
if (noAnnotationNullReturn) {
return null;
}
break; // return default
}
@ -337,6 +411,9 @@ public class VascAnnotationParser {
if ("optional".equals(field)) {
return VascField.class.getMethod("optional").getDefaultValue();
}
if ("sortable".equals(field)) {
return VascField.class.getMethod("sortable").getDefaultValue();
}
// This are the default value then....
return null;
} catch (Exception e) {
@ -344,6 +421,9 @@ public class VascAnnotationParser {
return false;
}
}
if (annotationType.equals(VascFieldTemplate.class)) {
return null;
}
if (annotationType.equals(VascFieldType.class)) {
return null;
}
@ -353,6 +433,12 @@ public class VascAnnotationParser {
if (annotationType.equals(VascRoles.class)) {
return null;
}
if (annotationType.equals(VascChoices.class)) {
return null;
}
if (annotationType.equals(VascEventListener.class)) {
return null;
}
if (annotationType.equals(VascFieldOrder.class)) {
int indexOrder = 0;
for (Method method:beanClass.getMethods()) {
@ -401,12 +487,16 @@ public class VascAnnotationParser {
VascFieldOrder v = (VascFieldOrder)b;
return v.orderIndex();
}
if (a.equals(VascChoices.class)) {
VascChoices v = (VascChoices)b;
return v;
}
if (a.equals(VascDefaultValue.class)) {
VascDefaultValue v = (VascDefaultValue)b;
if ("null".equals(v.defaultValue())) {
return "";
if ("null".equals(v.value())) {
return null;
}
return v.defaultValue();
return v.value();
}
if (a.equals(VascStyle.class)) {
VascStyle c = (VascStyle)b;
@ -460,6 +550,15 @@ public class VascAnnotationParser {
if ("optional".equals(field)) {
return c.optional();
}
if ("sortable".equals(field)) {
return c.sortable();
}
if ("sumable".equals(field)) {
return c.sumable();
}
if ("graphable".equals(field)) {
return c.graphable();
}
return null;
}
if (a.equals(VascFieldType.class)) {
@ -505,19 +604,4 @@ public class VascAnnotationParser {
return null;
}
/**
* default is false
* @return Returns the noAnnotationNullReturn.
*/
public Boolean getNoAnnotationNullReturn() {
return noAnnotationNullReturn;
}
/**
* @param noAnnotationNullReturn The noAnnotationNullReturn to set.
*/
public void setNoAnnotationNullReturn(Boolean noAnnotationNullReturn) {
this.noAnnotationNullReturn = noAnnotationNullReturn;
}
}

View file

@ -46,7 +46,13 @@ public @interface VascChoices {
String[] choisesKeys() default {};
String[] choisesNames();
String[] choisesValues() default {};
Class<?> choisesType() default String.class;
boolean choisesAsRadio() default false;
String nullLabel() default "null";
String nullKeyValue() default "null";
}

View file

@ -0,0 +1,110 @@
/**
*
*/
package com.idcanet.vasc.annotations;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascSelectItem;
import com.idcanet.vasc.core.ui.VascSelectItemModel;
/**
* Selected the vasc choices
*
*
* @author Willem Cazander
* @version 1.0 Apr 23, 2009
*/
@SuppressWarnings("serial")
public class VascChoicesSelectItemModel implements VascSelectItemModel,Serializable {
private VascChoices vascChoices = null;
private String nullLabel = null;
private String nullKeyValue = null;
public VascChoicesSelectItemModel(VascChoices vascChoices) {
this.vascChoices=vascChoices;
}
/**
* @see com.idcanet.vasc.core.ui.VascSelectItemModel#getVascSelectItems(com.idcanet.vasc.core.VascEntry)
*/
public List<VascSelectItem> getVascSelectItems(com.idcanet.vasc.core.VascEntry entry) throws VascException {
List<VascSelectItem> result = new ArrayList<VascSelectItem>(10);
if ("null".equals(vascChoices.nullLabel())==false) {
nullLabel = vascChoices.nullLabel();
nullKeyValue = vascChoices.nullKeyValue();
}
if (nullLabel!=null) {
if (nullKeyValue==null) {
nullKeyValue = "null";
}
String nullLabelText = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(nullLabel);
VascSelectItem item = new VascSelectItem(nullLabelText,null,nullKeyValue);
result.add(item);
}
int index = 0;
boolean val = false;
String[] a = vascChoices.choisesKeys();
if (a.length==0) {
a=vascChoices.choisesValues();
val = true;
} else if (vascChoices.choisesKeys().length!=vascChoices.choisesValues().length) {
throw new IllegalStateException("Can't have unequal sizes of array of keys and values of vascChoices annotation.");
}
for (String key:a) {
VascSelectItem item = new VascSelectItem();
String name = null;
if (val) {
name = key;
} else {
name = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key);
}
item.setLabel(name);
Object value = vascChoices.choisesValues()[index];
if (vascChoices.choisesType().equals(String.class)==false) {
try {
value = vascChoices.choisesType().getConstructor(String.class).newInstance(key);
} catch (Exception e) {
}
}
item.setValue(value);
item.setKeyValue(key);
result.add(item);
index++;
}
return result;
}
/**
* @return the nullLabel
*/
public String getNullLabel() {
return nullLabel;
}
/**
* @param nullLabel the nullLabel to set
*/
public void setNullLabel(String nullLabel) {
this.nullLabel = nullLabel;
}
/**
* @return the nullKeyValue
*/
public String getNullKeyValue() {
return nullKeyValue;
}
/**
* @param nullKeyValue the nullKeyValue to set
*/
public void setNullKeyValue(String nullKeyValue) {
this.nullKeyValue = nullKeyValue;
}
}

View file

@ -48,5 +48,5 @@ public @interface VascDefaultValue {
* Note: special value for default, because else we can not set empty.
* @return
*/
String defaultValue() default "null";
String value() default "null";
}

View file

@ -0,0 +1,50 @@
/*
* 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;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
/**
* Event listener annotation
*
* @author Willem Cazander
* @version 1.0 Apr 23, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface VascEventListener {
String[] listeners();
VascEventType[] types();
}

View file

@ -59,4 +59,10 @@ public @interface VascField {
boolean view() default true;
boolean optional() default false;
boolean sortable() default true;
boolean sumable() default false;
boolean graphable() default false;
}

View file

@ -0,0 +1,54 @@
/*
* 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;
/**
* Adds template support for the vasc annotations.
*
* @author Willem Cazander
* @version 1.0 May 12, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascFieldTemplate {
/**
* The choices template for this field.
*/
String template() default "";
/**
* The template class to get the templated property
*/
Class<?> templateClass();
}

View file

@ -40,7 +40,7 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface VascI18nModelReference {
public @interface VascModelReference {
Class<?> type() default Object.class;
}

View file

@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
@ -70,13 +71,14 @@ public class JdbcVascBackend extends AbstractVascBackend {
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute() throws Exception {
public List<Object> execute(VascBackendState state) throws VascException {
JdbcConnectionProvider prov = getJdbcConnectionProvider();
Connection connection = prov.getJdbcConnection();
List<Object> result = new ArrayList<Object>(50);
List<Object> result = new ArrayList<Object>(50);
Connection connection = null;
try {
connection = prov.getJdbcConnection();
Statement s = connection.createStatement();
s.execute(getSqlList());
ResultSet rs = s.getResultSet();
@ -90,9 +92,14 @@ public class JdbcVascBackend extends AbstractVascBackend {
}
result.add(map);
}
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
connection.close();
try {
connection.close();
} catch (Exception e) {
}
}
}
return result;
@ -101,20 +108,20 @@ public class JdbcVascBackend extends AbstractVascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
return object;
}
/**
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
}
/**
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
}
/**
@ -132,6 +139,13 @@ public class JdbcVascBackend extends AbstractVascBackend {
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)
*/

View file

@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
@ -82,16 +83,17 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute() throws Exception {
public List<Object> execute(VascBackendState state) throws VascException {
// Copy parameters
for (String key:getDataParameterKeys()) {
Object value = getDataParameter(key);
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
query.setQueryParameter(key, value);
}
Connection c = getJdbcConnectionProvider().getJdbcConnection();
Connection c = null;
try {
c = getJdbcConnectionProvider().getJdbcConnection();;
PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query));
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
@ -114,9 +116,14 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
result.add(map);
}
return result;
} catch (Exception e) {
throw new VascException(e);
} finally {
if (c!=null) {
c.close();
try {
c.close();
} catch (Exception e) {
}
}
}
}
@ -124,20 +131,20 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
return object;
}
/**
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
}
/**
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
}
/**
@ -155,6 +162,13 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
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)
*/

View file

@ -29,6 +29,7 @@ package com.idcanet.vasc.backends.jpa;
import org.hibernate.Session;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascException;
/**
*
@ -43,36 +44,52 @@ abstract public class AbstractHibernateVascBackend extends AbstractVascBackend
*/
abstract Session getHibernateSession();
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
Session s = getHibernateSession();
try {
s.getTransaction().begin();
s.persist(object);
s.getTransaction().commit();
} finally {
if (s!=null) {
s.close();
if (s!=null && s.isOpen()) {
if (s.getTransaction().isActive()) {
s.getTransaction().rollback();
}
//s.close();
}
}
}
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
Session s = getHibernateSession();
try {
return s.merge(object);
s.getTransaction().begin();
Object result = s.merge(object);
s.getTransaction().commit();
return result;
} finally {
if (s!=null) {
s.close();
if (s!=null && s.isOpen()) {
if (s.getTransaction().isActive()) {
s.getTransaction().rollback();
}
//s.close();
}
}
}
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
Session s = getHibernateSession();
try {
s.getTransaction().begin();
Object newObject = s.merge(object);
s.delete(newObject);
s.getTransaction().commit();
} finally {
if (s!=null) {
s.close();
if (s!=null && s.isOpen()) {
if (s.getTransaction().isActive()) {
s.getTransaction().rollback();
}
//s.close();
}
}
}

View file

@ -29,6 +29,7 @@ package com.idcanet.vasc.backends.jpa;
import javax.persistence.EntityManager;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascException;
/**
*
@ -39,7 +40,7 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
abstract EntityManager getEntityManager();
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
EntityManager s = getEntityManager();
try {
s.getTransaction().begin();
@ -52,7 +53,7 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
}
}
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
EntityManager s = getEntityManager();
try {
s.getTransaction().begin();
@ -66,7 +67,7 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
}
}
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
EntityManager s = getEntityManager();
try {
s.getTransaction().begin();

View file

@ -0,0 +1,39 @@
/*
* 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 org.hibernate.Session;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2009
*/
public interface HibernateSessionProvider {
public Session getHibernateSession();
}

View file

@ -1,124 +0,0 @@
/*
* 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 org.hibernate.Query;
import org.hibernate.Session;
import com.idcanet.serv5.services.hibernate3.Hibernate3Factory;
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 com.idcanet.xtes.xpql.query.QueryParameterValue;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public class Serv5XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
private String session = null;
private com.idcanet.xtes.xpql.query.Query query = null;
public Serv5XpqlHibernateVascBackend() {
}
public Serv5XpqlHibernateVascBackend(String session,com.idcanet.xtes.xpql.query.Query query) {
setSession(session);
setQuery(query);
}
Session getHibernateSession() {
return Hibernate3Factory.getSession(getSession());
}
@SuppressWarnings("unchecked")
public List<Object> 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<QueryParameterValue> values = query.getOrderQueryParameterValues();
int i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;
}
List<Object> data = q.list();
return data;
} finally {
if (s!=null) {
s.close();
}
}
}
/**
* @return the session
*/
public String getSession() {
return session;
}
/**
* @param session the session to set
*/
public void setSession(String session) {
this.session = session;
}
/**
* @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;
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return null;
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return null;
}
}

View file

@ -0,0 +1,493 @@
/*
* 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 org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
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.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 XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
private HibernateSessionProvider hibernateSessionProvider = null;
private com.idcanet.xtes.xpql.query.Query query = null;
private com.idcanet.xtes.xpql.query.Query queryTotal = null;
private com.idcanet.xtes.xpql.query.Query queryMoveUp = null;
private com.idcanet.xtes.xpql.query.Query queryMoveUpDown = null;
private com.idcanet.xtes.xpql.query.Query queryMoveDown = null;
private com.idcanet.xtes.xpql.query.Query queryMoveDownUp = null;
private Class<?> resultClass = null;
public XpqlHibernateVascBackend() {
}
/**
* @see com.idcanet.vasc.backends.jpa.AbstractPersistenceVascBackend#getEntityManager()
*/
@Override
Session getHibernateSession() {
return hibernateSessionProvider.getHibernateSession();
}
@SuppressWarnings("unchecked")
public List<Object> execute(VascBackendState state) throws VascException {
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
query.setQueryParameter(key, value);
if (queryTotal!=null) {
queryTotal.setQueryParameter(key, value);
}
}
Session s = getHibernateSession();
try {
s.getTransaction().begin();
Query q = s.createQuery(query.toPreparedSQL(query));
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
int i = 0;
for (QueryParameterValue value:values) {
Object valueObject = value.getValue();
if (valueObject!=null) {
q.setParameter(i,valueObject);
} else {
q.setParameter(i,valueObject,Hibernate.INTEGER);
}
i++;
}
if (isPageable() & state.getPageSize()>0) {
q.setFirstResult(state.getPageIndex());
q.setMaxResults(state.getPageSize());
}
List<Object> data = q.list();
s.getTransaction().commit();
return data;
} finally {
if (s!=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#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.getParameter(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.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 hibernateSessionProvider
*/
public HibernateSessionProvider getHibernateSessionProvider() {
return hibernateSessionProvider;
}
/**
* @param hibernateSessionProvider the hibernateSessionProvider to set
*/
public void setHibernateSessionProvider(HibernateSessionProvider hibernateSessionProvider) {
this.hibernateSessionProvider = hibernateSessionProvider;
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
if (queryTotal==null) {
return false;
}
return true;
}
/**
* @see com.idcanet.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/
public long fetchTotalExecuteSize(VascBackendState state) {
Session s = getHibernateSession();
try {
s.getTransaction().begin();
Query q = s.createQuery(queryTotal.toPreparedSQL(queryTotal));
List<QueryParameterValue> values = queryTotal.getOrderQueryParameterValues();
int i = 0;
for (QueryParameterValue value:values) {
Object valueObject = value.getValue();
if (valueObject!=null) {
q.setParameter(i,valueObject);
} else {
q.setParameter(i,valueObject,Hibernate.INTEGER);
}
i++;
}
Long resultTotal = (Long)q.uniqueResult();
s.getTransaction().commit();
return resultTotal;
} finally {
if (s!=null) {
//em.close();
}
}
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#doRecordMoveDownById(java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
long result = 0l;
if (queryMoveDown!=null) {
Session s = getHibernateSession();
try {
s.getTransaction().begin();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveDown.setQueryParameter(key, value);
}
// set id
queryMoveDown.setQueryParameter("id", primaryId);
// execute update
Query q = s.createQuery(queryMoveDown.toPreparedSQL(queryMoveDown));
List<QueryParameterValue> values = queryMoveDown.getOrderQueryParameterValues();
int i = 0;
for (QueryParameterValue value:values) {
Object valueObject = value.getValue();
if (valueObject!=null) {
q.setParameter(i,valueObject);
} else {
q.setParameter(i,valueObject,Hibernate.INTEGER);
}
i++;
}
result+=q.executeUpdate();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveDownUp.setQueryParameter(key, value);
}
// set id
queryMoveDownUp.setQueryParameter("id", primaryId);
// execute update
q = s.createQuery(queryMoveDownUp.toPreparedSQL(queryMoveDownUp));
values = queryMoveDownUp.getOrderQueryParameterValues();
i = 0;
for (QueryParameterValue value:values) {
Object valueObject = value.getValue();
if (valueObject!=null) {
q.setParameter(i,valueObject);
} else {
q.setParameter(i,valueObject,Hibernate.INTEGER);
}
i++;
}
result+=q.executeUpdate();
s.getTransaction().commit();
} finally {
if (s!=null) {
//em.close();
}
}
}
return result;
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#doRecordMoveUpById(java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
long result = 0l;
if (queryMoveUp!=null) {
Session s = getHibernateSession();
try {
s.getTransaction().begin();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveUp.setQueryParameter(key, value);
}
// set id
queryMoveUp.setQueryParameter("id", primaryId);
// execute update
Query q = s.createQuery(queryMoveUp.toPreparedSQL(queryMoveUp));
List<QueryParameterValue> values = queryMoveUp.getOrderQueryParameterValues();
int i = 0;
for (QueryParameterValue value:values) {
Object valueObject = value.getValue();
if (valueObject!=null) {
q.setParameter(i,valueObject);
} else {
q.setParameter(i,valueObject,Hibernate.INTEGER);
}
i++;
}
result+=q.executeUpdate();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveUpDown.setQueryParameter(key, value);
}
// set id
queryMoveUpDown.setQueryParameter("id", primaryId);
// execute update
q = s.createQuery(queryMoveUpDown.toPreparedSQL(queryMoveUpDown));
values = queryMoveUpDown.getOrderQueryParameterValues();
i = 0;
for (QueryParameterValue value:values) {
Object valueObject = value.getValue();
if (valueObject!=null) {
q.setParameter(i,valueObject);
} else {
q.setParameter(i,valueObject,Hibernate.INTEGER);
}
i++;
}
result+=q.executeUpdate();
s.getTransaction().commit();
} finally {
if (s!=null) {
//em.close();
}
}
}
return result;
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {
return queryMoveUp!=null & queryMoveDown!=null;
}
/**
* @return the queryMoveUp
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveUp() {
return queryMoveUp;
}
/**
* @param queryMoveUp the queryMoveUp to set
*/
public void setQueryMoveUp(com.idcanet.xtes.xpql.query.Query queryMoveUp) {
this.queryMoveUp = queryMoveUp;
}
/**
* @return the queryMoveDown
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveDown() {
return queryMoveDown;
}
/**
* @param queryMoveDown the queryMoveDown to set
*/
public void setQueryMoveDown(com.idcanet.xtes.xpql.query.Query queryMoveDown) {
this.queryMoveDown = queryMoveDown;
}
/**
* @return the queryMoveUpDown
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveUpDown() {
return queryMoveUpDown;
}
/**
* @param queryMoveUpDown the queryMoveUpDown to set
*/
public void setQueryMoveUpDown(com.idcanet.xtes.xpql.query.Query queryMoveUpDown) {
this.queryMoveUpDown = queryMoveUpDown;
}
/**
* @return the queryMoveDownUp
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveDownUp() {
return queryMoveDownUp;
}
/**
* @param queryMoveDownUp the queryMoveDownUp to set
*/
public void setQueryMoveDownUp(com.idcanet.xtes.xpql.query.Query queryMoveDownUp) {
this.queryMoveDownUp = queryMoveDownUp;
}
}

View file

@ -31,6 +31,7 @@ import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
@ -47,13 +48,21 @@ import com.idcanet.xtes.xpql.query.QueryParameterValue;
* @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 com.idcanet.xtes.xpql.query.Query queryMoveUp = null;
private com.idcanet.xtes.xpql.query.Query queryMoveUpDown = null;
private com.idcanet.xtes.xpql.query.Query queryMoveDown = null;
private com.idcanet.xtes.xpql.query.Query queryMoveDownUp = null;
private Class<?> resultClass = null;
public XpqlPersistanceVascBackend() {
@ -70,51 +79,34 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
@SuppressWarnings("unchecked")
public List<Object> execute() throws Exception {
public List<Object> execute(VascBackendState state) throws VascException {
// Copy parameters
for (String key:getDataParameterKeys()) {
Object value = getDataParameter(key);
for (String key:state.getDataParameterKeys()) {
Object value = state.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<QueryParameterValue> 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<QueryParameterValue> values = query.getOrderQueryParameterValues();
int i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
Object valueObject = value.getValue();
q.setParameter(i,valueObject);
i++;
}
if (isPageable()) {
q.setFirstResult(getPageIndex());
q.setMaxResults(getPageSize());
if (isPageable() & state.getPageSize()>0) {
q.setFirstResult(state.getPageIndex());
q.setMaxResults(state.getPageSize());
}
em.getTransaction().begin();
List<Object> data = q.getResultList();
if (queryTotal==null) {
setPagesTotalRecords(data.size());
}
em.getTransaction().commit();
return data;
} finally {
if (em!=null) {
@ -143,6 +135,31 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
}
/**
* @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.getParameter(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)
*/
@ -237,14 +254,213 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
if (queryTotal==null) {
return false;
}
/*
if (query.getQueryParameterValue("offset")==null) {
return false;
}
if (query.getQueryParameterValue("limit")==null) {
return false;
}
*/
return true;
}
/**
* @see com.idcanet.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/
public long fetchTotalExecuteSize(VascBackendState state) {
EntityManager em = getEntityManager();
try {
Query q = em.createQuery(queryTotal.toPreparedSQL(queryTotal));
List<QueryParameterValue> values = queryTotal.getOrderQueryParameterValues();
int i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;
}
em.getTransaction().begin();
Long resultTotal = (Long)q.getSingleResult();
em.getTransaction().commit();
return resultTotal;
} finally {
if (em!=null) {
//em.close();
}
}
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#doRecordMoveDownById(VascBackendState state,java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
long result = 0l;
if (queryMoveDown!=null) {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveDown.setQueryParameter(key, value);
}
// set id
queryMoveDown.setQueryParameter("id", primaryId);
// execute update
Query q = em.createQuery(queryMoveDown.toPreparedSQL(queryMoveDown));
List<QueryParameterValue> values = queryMoveDown.getOrderQueryParameterValues();
int i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;
}
result+=q.executeUpdate();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveDownUp.setQueryParameter(key, value);
}
// set id
queryMoveDownUp.setQueryParameter("id", primaryId);
// execute update
q = em.createQuery(queryMoveDownUp.toPreparedSQL(queryMoveDownUp));
values = queryMoveDownUp.getOrderQueryParameterValues();
i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;
}
result+=q.executeUpdate();
em.getTransaction().commit();
} finally {
if (em!=null) {
//em.close();
}
}
}
return result;
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#doRecordMoveUpById(VascBackendState state,java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
long result = 0l;
if (queryMoveUp!=null) {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveUp.setQueryParameter(key, value);
}
// set id
queryMoveUp.setQueryParameter("id", primaryId);
// execute update
Query q = em.createQuery(queryMoveUp.toPreparedSQL(queryMoveUp));
List<QueryParameterValue> values = queryMoveUp.getOrderQueryParameterValues();
int i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;
}
result+=q.executeUpdate();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveUpDown.setQueryParameter(key, value);
}
// set id
queryMoveUpDown.setQueryParameter("id", primaryId);
// execute update
q = em.createQuery(queryMoveUpDown.toPreparedSQL(queryMoveUpDown));
values = queryMoveUpDown.getOrderQueryParameterValues();
i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;
}
result+=q.executeUpdate();
em.getTransaction().commit();
} finally {
if (em!=null) {
//em.close();
}
}
}
return result;
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {
return queryMoveUp!=null & queryMoveDown!=null;
}
/**
* @return the queryMoveUp
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveUp() {
return queryMoveUp;
}
/**
* @param queryMoveUp the queryMoveUp to set
*/
public void setQueryMoveUp(com.idcanet.xtes.xpql.query.Query queryMoveUp) {
this.queryMoveUp = queryMoveUp;
}
/**
* @return the queryMoveDown
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveDown() {
return queryMoveDown;
}
/**
* @param queryMoveDown the queryMoveDown to set
*/
public void setQueryMoveDown(com.idcanet.xtes.xpql.query.Query queryMoveDown) {
this.queryMoveDown = queryMoveDown;
}
/**
* @return the queryMoveUpDown
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveUpDown() {
return queryMoveUpDown;
}
/**
* @param queryMoveUpDown the queryMoveUpDown to set
*/
public void setQueryMoveUpDown(com.idcanet.xtes.xpql.query.Query queryMoveUpDown) {
this.queryMoveUpDown = queryMoveUpDown;
}
/**
* @return the queryMoveDownUp
*/
public com.idcanet.xtes.xpql.query.Query getQueryMoveDownUp() {
return queryMoveDownUp;
}
/**
* @param queryMoveDownUp the queryMoveDownUp to set
*/
public void setQueryMoveDownUp(com.idcanet.xtes.xpql.query.Query queryMoveDownUp) {
this.queryMoveDownUp = queryMoveDownUp;
}
}

View file

@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
@ -79,7 +80,7 @@ public class LdapVascBackend extends AbstractVascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
*/
public List<Object> execute() throws Exception {
public List<Object> execute(VascBackendState state) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
List<Object> result = new ArrayList<Object>(50);
@ -110,10 +111,21 @@ public class LdapVascBackend extends AbstractVascBackend {
while (i.hasNext()) {
LDAPAttribute attr = i.next();
//System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
map.put(attr.getName(), attr.getStringValueArray());
String[] s = attr.getStringValueArray();
if (s.length==1) {
map.put(attr.getName(), attr.getStringValue());
} else {
List<String> multiValue = new ArrayList<String>(s.length);
for (String ss:s) {
multiValue.add(ss);
}
map.put(attr.getName(), multiValue );
}
}
result.add(map);
}
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
connection.clone();
@ -125,7 +137,7 @@ public class LdapVascBackend extends AbstractVascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
@ -141,7 +153,7 @@ public class LdapVascBackend extends AbstractVascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
@ -149,6 +161,8 @@ public class LdapVascBackend extends AbstractVascBackend {
// entry.getAttributeSet().
connection.add(entry);
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
connection.clone();
@ -159,7 +173,7 @@ public class LdapVascBackend extends AbstractVascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
@ -198,16 +212,20 @@ public class LdapVascBackend extends AbstractVascBackend {
@SuppressWarnings("unchecked")
public Object getValue(VascEntryField field, Object record) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
String[] r = (String[])map.get(field.getBackendName());
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,...
}
if (r.length==1) {
return r[0];
}
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)
*/

View file

@ -33,8 +33,10 @@ import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
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.entry.VascEntryFieldValue;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
@ -51,18 +53,18 @@ public class MetaModelVascBackend extends AbstractVascBackend {
// interface
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
}
public List<Object> execute() throws Exception {
public List<Object> execute(VascBackendState state) throws VascException {
return null;
}
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
return null;
}
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {

View file

@ -26,11 +26,6 @@
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;
/**
*
@ -40,30 +35,7 @@ import java.util.Set;
abstract public class AbstractVascBackend implements VascBackend {
private String id = null;
protected Map<String,Object> parameters = null;
private int pageIndex = 0;
private int pageSize = 100;
private String sortField = null;
private String searchString = null;
private boolean ascending = true;
private long pagesTotalRecords = 0;
public AbstractVascBackend() {
parameters = new HashMap<String,Object>(10);
}
public void setDataParameter(String key,Object data) {
parameters.put(key,data);
}
public Object getDataParameter(String key) {
return parameters.get(key);
}
public Set<String> getDataParameterKeys() {
return parameters.keySet();
}
/**
* @see com.idcanet.vasc.core.VascBackend#getId()
*/
@ -80,7 +52,6 @@ abstract public class AbstractVascBackend implements VascBackend {
}
this.id=id;
}
/**
* @see com.idcanet.vasc.core.VascBackend#isPageable()
@ -90,74 +61,11 @@ abstract public class AbstractVascBackend implements VascBackend {
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPageIndex()
* @see com.idcanet.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/
public int getPageIndex() {
return pageIndex;
public long fetchTotalExecuteSize(VascBackendState state) {
return 0;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setPageIndex(int)
*/
public void setPageIndex(int pageIndex) {
if (pageIndex<1) {
pageIndex = 0;
}
if (pageIndex>(getPagesTotalRecords()/getPageSize())) {
pageIndex = new Long(getPagesTotalRecords()/getPageSize()).intValue();
}
this.pageIndex=pageIndex;
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPageSize()
*/
public int getPageSize() {
return pageSize;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setPageSize(int)
*/
public void setPageSize(int pageSize) {
this.pageSize=pageSize;
}
/**
* Returns the total amount of pages
* @return
*/
public List<VascBackendPageNumber> getVascBackendPageNumbers() {
int pages = new Long(getPagesTotalRecords()/getPageSize()).intValue();
List<VascBackendPageNumber> result = new ArrayList<VascBackendPageNumber>(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 long getPagesTotalRecords() {
return pagesTotalRecords;
}
protected void setPagesTotalRecords(long pagesTotalRecords) {
this.pagesTotalRecords=pagesTotalRecords;
}
/**
* @see com.idcanet.vasc.core.VascBackend#isSearchable()
@ -166,23 +74,6 @@ abstract public class AbstractVascBackend implements VascBackend {
return false;
}
/**
* @see com.idcanet.vasc.core.VascBackend#getSearchString()
*/
public String getSearchString() {
return searchString;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setSearchString(java.lang.String)
*/
public void setSearchString(String searchString) {
this.searchString=searchString;
}
/**
* @see com.idcanet.vasc.core.VascBackend#isSortable()
*/
@ -191,30 +82,23 @@ abstract public class AbstractVascBackend implements VascBackend {
}
/**
* @see com.idcanet.vasc.core.VascBackend#isSortAscending()
* @see com.idcanet.vasc.core.VascBackend#isRecordMoveable()
*/
public boolean isSortAscending() {
return ascending;
public boolean isRecordMoveable() {
return false;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setSortAscending(boolean)
* @see com.idcanet.vasc.core.VascBackend#doRecordMoveDownById(java.lang.Object)
*/
public void setSortAscending(boolean ascending) {
this.ascending=ascending;
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
return 0l;
}
/**
* @see com.idcanet.vasc.core.VascBackend#getSortField()
* @see com.idcanet.vasc.core.VascBackend#doRecordMoveUpById(java.lang.Object)
*/
public String getSortField() {
return sortField;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setSortField(java.lang.String)
*/
public void setSortField(String sortField) {
this.sortField=sortField;
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
return 0l;
}
}

View file

@ -27,7 +27,6 @@
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;
@ -49,10 +48,10 @@ abstract public class AbstractVascBackendProxy implements VascBackend {
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPagesTotalRecords()
* @see com.idcanet.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/
public long getPagesTotalRecords() {
return backend.getPagesTotalRecords();
public long fetchTotalExecuteSize(VascBackendState state) {
return backend.fetchTotalExecuteSize(state);
}
/**
@ -61,70 +60,21 @@ abstract public class AbstractVascBackendProxy implements VascBackend {
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()
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute() throws Exception {
return backend.execute();
public List<Object> execute(VascBackendState state) throws VascException {
return backend.execute(state);
}
/**
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws Exception {
public void delete(Object object) throws VascException {
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<String> getDataParameterKeys() {
return backend.getDataParameterKeys();
}
/**
* @see com.idcanet.vasc.core.VascBackend#getVascBackendPageNumbers()
*/
public List<VascBackendPageNumber> getVascBackendPageNumbers() {
return backend.getVascBackendPageNumbers();
}
/**
* @see com.idcanet.vasc.core.VascBackend#isPageable()
@ -143,14 +93,14 @@ abstract public class AbstractVascBackendProxy implements VascBackend {
/**
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws Exception {
public Object merge(Object object) throws VascException {
return backend.merge(object);
}
/**
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws Exception {
public void persist(Object object) throws VascException {
backend.persist(object);
}
@ -168,13 +118,6 @@ abstract public class AbstractVascBackendProxy implements VascBackend {
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()
*/
@ -190,44 +133,23 @@ abstract public class AbstractVascBackendProxy implements VascBackend {
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPageIndex()
* @see com.idcanet.vasc.core.VascBackend#doRecordMoveDownById(VascBackendState state,java.lang.Object)
*/
public int getPageIndex() {
return backend.getPageIndex();
}
/**
* @see com.idcanet.vasc.core.VascBackend#setPageIndex(int)
*/
public void setPageIndex(int index) {
backend.setPageIndex(index);
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
return backend.doRecordMoveDownById(state,primaryId);
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPageSize()
* @see com.idcanet.vasc.core.VascBackend#doRecordMoveUpById(VascBackendState state,java.lang.Object)
*/
public int getPageSize() {
return backend.getPageSize();
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
return backend.doRecordMoveUpById(state,primaryId);
}
/**
* @see com.idcanet.vasc.core.VascBackend#setPageSize(int)
* @see com.idcanet.vasc.core.VascBackend#isRecordMoveable()
*/
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);
public boolean isRecordMoveable() {
return backend.isRecordMoveable();
}
}

View file

@ -0,0 +1,134 @@
/*
* 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.HashMap;
import java.util.Map;
import java.util.Set;
/**
*
* @author Willem Cazander
* @version 1.0 May 26, 2009
*/
abstract public class AbstractVascBackendState implements VascBackendState {
private static final long serialVersionUID = 1L;
protected Map<String,Object> parameters = null;
private int pageIndex = 0;
private int pageSize = 0;
private String sortField = null;
private String searchString = null;
private boolean ascending = true;
//private long pagesTotalRecords = 0;
public AbstractVascBackendState() {
parameters = new HashMap<String,Object>(10);
}
public void setDataParameter(String key,Object data) {
parameters.put(key,data);
}
public Object getDataParameter(String key) {
return parameters.get(key);
}
public Set<String> getDataParameterKeys() {
return parameters.keySet();
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPageIndex()
*/
public int getPageIndex() {
return pageIndex;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setPageIndex(int)
*/
public void setPageIndex(int pageIndex) {
this.pageIndex=pageIndex;
}
/**
* @see com.idcanet.vasc.core.VascBackend#getPageSize()
*/
public int getPageSize() {
return pageSize;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setPageSize(int)
*/
public void setPageSize(int pageSize) {
this.pageSize=pageSize;
}
/**
* @see com.idcanet.vasc.core.VascBackend#getSearchString()
*/
public String getSearchString() {
return searchString;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setSearchString(java.lang.String)
*/
public void setSearchString(String searchString) {
this.searchString=searchString;
}
/**
* @see com.idcanet.vasc.core.VascBackend#isSortAscending()
*/
public boolean isSortAscending() {
return ascending;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setSortAscending(boolean)
*/
public void setSortAscending(boolean ascending) {
this.ascending=ascending;
}
/**
* @see com.idcanet.vasc.core.VascBackend#getSortField()
*/
public String getSortField() {
return sortField;
}
/**
* @see com.idcanet.vasc.core.VascBackend#setSortField(java.lang.String)
*/
public void setSortField(String sortField) {
this.sortField=sortField;
}
}

View file

@ -40,6 +40,11 @@ abstract public class AbstractVascFrontend implements VascFrontend {
return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params);
}
protected Object i18nImage(String key) {
return entry.getVascFrontendData().getVascEntryResourceImageResolver().getImageValue(entry,key);
}
public VascEntry getVascEntry() {
return entry;
}

View file

@ -27,7 +27,6 @@
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;
@ -41,18 +40,14 @@ public interface VascBackend {
public String getId();
public void setId(String id);
public List<Object> execute(VascBackendState state) throws VascException;
public void setDataParameter(String key,Object data);
public Object getDataParameter(String key);
public Set<String> getDataParameterKeys();
public void persist(Object object) throws VascException;
public List<Object> execute() throws Exception;
public Object merge(Object object) throws VascException;
public void persist(Object object) throws Exception;
public Object merge(Object object) throws Exception;
public void delete(Object object) throws Exception;
public void delete(Object object) throws VascException;
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field);
@ -64,46 +59,32 @@ public interface VascBackend {
* @return
*/
public boolean isSortable();
public String getSortField();
public void setSortField(String name);
public boolean isSortAscending();
public void setSortAscending(boolean ascending);
/**
* Defines if the backend supports pageing
* @return
*/
public boolean isPageable();
/**
* Returns the total amount of pages
* @return
*/
public List<VascBackendPageNumber> getVascBackendPageNumbers();
/**
* Returns the total amount of records.
* @return
*/
public long getPagesTotalRecords();
public long fetchTotalExecuteSize(VascBackendState state);
public void setPageSize(int size);
public int getPageSize();
public void setPageIndex(int index);
public int getPageIndex();
/**
* Defines if the backend supports pageing
* @return
*/
public boolean isSearchable();
public void setSearchString(String searchString);
public String getSearchString();
/**
* Defines if the backend supports moveing an record up or down.
* @return
*/
public boolean isRecordMoveable();
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException;
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException;
/*
public boolean hasSettings();

View file

@ -0,0 +1,54 @@
/*
* 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;
/**
* Can filter the data
*
* @author Willem Cazander
* @version 1.0 Apr 28, 2009
*/
public interface VascBackendFilter {
/**
* Inits the filter
*/
public void initFilter(VascEntry entry);
/**
* Only filters 1 object.
*/
public Object filterObject(Object object);
/**
* Force impl to have public clone methode
* @return
* @throws CloneNotSupportedException
*/
public VascBackendFilter clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,57 @@
/*
* 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;
import java.util.Set;
/**
* Holds all the data the backend needs to know to execute its work.
*
* @author Willem Cazander
* @version 1.0 May 26, 2009
*/
public interface VascBackendState extends Serializable {
public void setDataParameter(String key,Object data);
public Object getDataParameter(String key);
public Set<String> getDataParameterKeys();
public String getSortField();
public void setSortField(String name);
public boolean isSortAscending();
public void setSortAscending(boolean ascending);
public void setPageSize(int size);
public int getPageSize();
public void setPageIndex(int index);
public int getPageIndex();
public void setSearchString(String searchString);
public String getSearchString();
}

View file

@ -31,14 +31,11 @@ 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.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel;
/**
*
* TODO:
* private List<VascUserOption> userOptions = null;
* private List<VascListeners> listeners = null;
* private Map<String,VascFunction> vascFunctions = null;
* The main vasc entry
*
*
* @author Willem Cazander
@ -56,6 +53,16 @@ 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 helpId
*/
@ -76,35 +83,86 @@ public interface VascEntry extends Cloneable {
*/
public void setImage(String image);
/**
* @return the headerName
*/
public String getHeaderName();
/**
* @param headerName the headerName to set
* @return the listDescription
*/
public void setHeaderName(String headerName);
public String getListDescription();
/**
* @param listDescription the listDescription to set
*/
public void setListDescription(String listDescription);
/**
* @return the listImage
*/
public String getListImage();
/**
* @param listImage the listImage to set
*/
public void setListImage(String listImage);
/**
* @return the editDescription
*/
public String getEditDescription();
/**
* @param editDescription the editDescription to set
*/
public void setEditDescription(String editDescription);
/**
* @return the editImage
*/
public String getEditImage();
/**
* @param editImage the editImage to set
*/
public void setEditImage(String editImage);
/**
* @return the deleteDescription
*/
public String getDeleteDescription();
/**
* @param deleteDescription the deleteDescription to set
*/
public void setDeleteDescription(String deleteDescription);
/**
* @return the deleteImage
*/
public String getDeleteImage();
/**
* @param deleteImage the deleteImage to set
*/
public void setDeleteImage(String deleteImage);
/**
* @return the headerImage
* @return the createDescription
*/
public String getHeaderImage();
public String getCreateDescription();
/**
* @param headerImage the headerImage to set
* @param createDescription the createDescription to set
*/
public void setHeaderImage(String headerImage);
public void setCreateDescription(String createDescription);
/**
* @return the headerDescription
* @return the createImage
*/
public String getHeaderDescription();
public String getCreateImage();
/**
* @param headerDescription the headerDescription to set
* @param createImage the createImage to set
*/
public void setHeaderDescription(String headerDescription);
public void setCreateImage(String createImage);
/**
* @return the primaryKeyField
@ -191,6 +249,11 @@ public interface VascEntry extends Cloneable {
*/
public List<RowVascAction> getRowActions();
/**
* @return the RowVascAction
*/
public RowVascAction getRowActionById(String actionId);
/**
* @param rowAction the rowAction to add
*/
@ -206,6 +269,11 @@ public interface VascEntry extends Cloneable {
*/
public List<ColumnVascAction> getColumnActions();
/**
* @return the ColumnVascAction
*/
public ColumnVascAction getColumnActionById(String actionId);
/**
* @param columnAction the columnAction to add
*/
@ -221,6 +289,11 @@ public interface VascEntry extends Cloneable {
*/
public List<GlobalVascAction> getGlobalActions();
/**
* @return the GlobalVascAction
*/
public GlobalVascAction getGlobalActionById(String actionId);
/**
* @param globalAction the globalAction to add
*/
@ -236,6 +309,11 @@ public interface VascEntry extends Cloneable {
*/
public List<VascEntryFieldSet> getVascEntryFieldSets();
/**
* @return the VascEntryFieldSet
*/
public VascEntryFieldSet getVascEntryFieldSetById(String actionId);
/**
* @param vascEntryFieldSet the vascEntryFieldSet to add
*/
@ -251,6 +329,11 @@ public interface VascEntry extends Cloneable {
*/
public List<VascLinkEntry> getVascLinkEntries();
/**
* @return the VascLinkEntry
*/
public VascLinkEntry getVascLinkEntryById(String actionId);
/**
* @param vascLinkEntry the vascLinkEntry to add
*/
@ -294,6 +377,27 @@ public interface VascEntry extends Cloneable {
*/
public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel);
/**
* Added an VascEntryEventListener
* @param type
* @param listener
*/
public void addVascEntryEventListener(VascEntryEventListener.VascEventType type,VascEntryEventListener listener);
/**
* Returns the list of VascEntryEventListener for a speciec type.
* @param type
* @return
*/
public List<VascEntryEventListener> getVascEntryEventListeners(VascEntryEventListener.VascEventType type);
public void addListOption(VascEntryField listOption);
public List<VascEntryField> getListOptions();
public void addVascBackendFilter(VascBackendFilter filter);
public List<VascBackendFilter> getVascBackendFilters();
/**
* Force impl to have public clone methode
* @return

View file

@ -32,7 +32,7 @@ import com.idcanet.vasc.core.entry.VascEntryFieldValue;
import com.idcanet.vasc.validators.VascValidator;
/**
* Defines an VascTableColumn
* Defines an VascEntryField
*
*
*

View file

@ -44,9 +44,9 @@ public interface VascFrontend {
public void renderView() throws Exception;
public void renderEdit(Object rowBean) throws Exception;
public void renderEdit() throws Exception;
public void renderDelete(Object rowBean) throws Exception;
public void renderDelete() throws Exception;
public void renderExport(VascEntryExporter exporter) throws Exception;
}

View file

@ -28,6 +28,9 @@ package com.idcanet.vasc.core;
import java.util.List;
import com.idcanet.vasc.core.entry.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService;
import com.idcanet.vasc.core.entry.VascEntryResourceImageResolver;
import com.idcanet.vasc.core.entry.VascEntryResourceResolver;
import com.idcanet.vasc.core.ui.VascUIComponent;
@ -102,6 +105,7 @@ public interface VascFrontendData {
public void addFieldVascUIComponents(VascEntryField field,VascUIComponent uiComponent,Object editor);
public VascUIComponent getFieldVascUIComponent(VascEntryField field);
public Object getFieldRealRenderer(VascEntryField field);
public void clearFieldRenderObjects();
/**
* @return the vascBackend
@ -112,4 +116,57 @@ public interface VascFrontendData {
* @param vascBackend the vascBackend to set
*/
public void setVascBackend(VascBackend vascBackend);
/**
* @return the exceptionListener
*/
public VascEntryEventListener getExceptionListener();
/**
* @param exceptionListener the exceptionListener to set
*/
public void setExceptionListener(VascEntryEventListener exceptionListener);
/**
* @return the vascEntryResourceImageResolver
*/
public VascEntryResourceImageResolver getVascEntryResourceImageResolver();
/**
* @param vascEntryResourceImageResolver the vascEntryResourceImageResolver to set
*/
public void setVascEntryResourceImageResolver(VascEntryResourceImageResolver vascEntryResourceImageResolver);
public void addVascValidatorService(VascEntryFieldValidatorService validatorService);
public List<VascEntryFieldValidatorService> getVascValidatorServices();
/**
* @return the isEditCreate
*/
public boolean isEditCreate();
/**
* @param isEditCreate the isEditCreate to set
*/
public void setEditCreate(boolean isEditCreate);
/**
* @return the vascBackendState
*/
public VascBackendState getVascBackendState();
/**
* @param vascBackendState the vascBackendState to set
*/
public void setVascBackendState(VascBackendState vascBackendState);
/**
* @return the totalBackendRecords
*/
public Long getTotalBackendRecords();
/**
* @param totalBackendRecords the totalBackendRecords to set
*/
public void setTotalBackendRecords(Long totalBackendRecords);
}

View file

@ -26,9 +26,11 @@
package com.idcanet.vasc.core;
import java.util.List;
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;
/**
@ -46,27 +48,39 @@ public interface VascFrontendHelper {
public boolean renderGlobalVascAction(GlobalVascAction action);
public boolean renderRowVascAction(RowVascAction action);
public Integer getTotalColumnsWidth(VascEntry table);
public Integer getTotalColumnsWidth(VascEntry entry);
public void refreshData(VascEntry table) throws Exception;
/**
* Returns the total amount of pages
* @return
*/
public List<VascBackendPageNumber> getVascBackendPageNumbers(VascEntry entry);
public void refreshData(VascEntry entry);
public Object initEditObject(VascEntry table,Object object) throws Exception;
public Object createObject(VascEntry entry);
public void deleteObject(VascEntry entry);
public void initEditObjectColumn(VascEntryField field,Object object) throws Exception;
public void handleException(Exception e,VascEntry table);
public void addEventListener(VascEntryEventListener e);
public void removeEventListener(VascEntryEventListener e);
public void fireVascEvent(VascEntryEventListener.VascEventType type,Object data);
public Object mergeObject(VascEntry entry);
public boolean setUIComponentsBeanErrors(VascEntry table,Object bean);
public List<String> validateObjectField(VascEntryField field);
public void addExceptionListener(VascEntryEventListener listener);
public boolean validateAndSetErrorText(VascEntry entry);
public void removeExceptionListener(VascEntryEventListener listener);
public void headerOptionsCreatedFillData(VascEntry entry);
public Object mergeObject(VascEntry table,Object object);
public void editReadOnlyUIComponents(VascEntry entry);
public void handleException(VascEntry entry,Exception exception);
public void fireVascEvent(VascEntry entry,VascEventType type,Object data);
public void sortAction(VascEntry entry,VascEntryField field);
public void searchAction(VascEntry entry,String searchString);
public void pageAction(VascEntry entry,Integer page);
public void moveAction(VascEntry entry,Object object,boolean moveUp);
}

View file

@ -26,6 +26,8 @@
package com.idcanet.vasc.core;
import java.util.List;
/**
*
@ -40,11 +42,13 @@ public interface VascLinkEntry extends Cloneable {
public String getVascEntryId();
public void setVascEntryId(String vascEntryId);
public String getParameterName();
public void setParameterName(String parameterName);
public String getEntryParameterFieldId(String parameterName);
public void addEntryParameterFieldId(String parameterName,String valueFieldId);
public List<String> getEntryParameterFieldIdKeys();
public String getValueFieldId();
public void setValueFieldId(String valueFieldId);
public String getEntryCreateFieldValue(String valueFieldId);
public void addEntryCreateFieldValue(String valueFieldId,String selectedFieldId);
public List<String> getEntryCreateFieldValueKeys();
/**
* @return the viewAsDetail
@ -56,6 +60,16 @@ public interface VascLinkEntry extends Cloneable {
*/
public void setViewAsDetail(Boolean viewAsDetail);
/**
* @return the doActionId
*/
public String getDoActionId();
/**
* @param doActionId the doActionId to set
*/
public void setDoActionId(String doActionId);
/**
* Force impl to have public clone methode
* @return

View file

@ -37,10 +37,15 @@ abstract public class AbstractVascAction implements VascAction {
private String id = null;
private String name = null;
private String toolTip = null;
private String description = null;
private String image = null;
private String helpId = null;
public AbstractVascAction() {
setId(getActionId());
}
abstract protected String getActionId();
public VascAction clone() throws CloneNotSupportedException {
VascAction action;
@ -51,7 +56,7 @@ abstract public class AbstractVascAction implements VascAction {
}
action.setId(id);
action.setName(name);
action.setToolTip(toolTip);
action.setDescription(description);
action.setImage(image);
action.setHelpId(helpId);
return action;
@ -86,17 +91,17 @@ abstract public class AbstractVascAction implements VascAction {
}
/**
* @return the toolTip
* @return the description
*/
public String getToolTip() {
return toolTip;
public String getDescription() {
return description;
}
/**
* @param toolTip the toolTip to set
* @param description description toolTip to set
*/
public void setToolTip(String toolTip) {
this.toolTip = toolTip;
public void setDescription(String description) {
this.description = description;
}
/**

View file

@ -41,9 +41,9 @@ public interface VascAction extends Cloneable {
public void setName(String name);
public String getToolTip();
public String getDescription();
public void setToolTip(String toolTip);
public void setDescription(String description);
public String getImage();

View file

@ -26,16 +26,46 @@
package com.idcanet.vasc.core.entry;
import com.idcanet.vasc.core.VascEntry;
/**
*
* @author Willem Cazander
* @version 1.0 Aug 02, 2007
*/
public interface VascEntryEventListener {
public interface VascEntryEventListener extends Cloneable {
public enum VascEventType { DATA_UPDATE,OPTION_UPDATE,CLOSE_WINDOW,BEAN_MERGE,BEAN_INIT }
public enum VascEventType {
EXCEPTION,
public void vascEvent(VascEventType e,Object o);
DATA_CREATE,
DATA_READ,
DATA_SELECT,
DATA_PRE_UPDATE,
DATA_POST_UPDATE,
DATA_DELETE,
DATA_LIST_UPDATE,
DATA_SORT,
DATA_PAGE,
DATA_SEARCH,
OPTION_UPDATE,
}
/**
* Is executed when the type of event is fired.
* @param entry
* @param type
* @param data
*/
public void vascEvent(VascEntry entry,VascEventType type,Object data);
/**
* Force impl to have public clone methode
* @return
* @throws CloneNotSupportedException
*/
public VascEntryEventListener clone() throws CloneNotSupportedException;
}

View file

@ -30,6 +30,7 @@ import java.io.OutputStream;
import java.io.Serializable;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascException;
/**
@ -39,7 +40,7 @@ import com.idcanet.vasc.core.VascEntry;
*/
public interface VascEntryExporter extends Serializable {
public void doExport(OutputStream out,VascEntry vascEntry) throws Exception;
public void doExport(OutputStream out,VascEntry vascEntry) throws VascException;
public String getMineType();

View file

@ -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.entry;
import java.util.List;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
/**
* Executes validation on a field.
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public interface VascEntryFieldValidatorService {
public List<String> validateObjectField(VascEntryField field, Object selectedRecord,Object objectValue) throws VascException;
}

View file

@ -38,5 +38,7 @@ public interface VascEntryFieldValue {
public Object getValue(VascEntryField field,Object record) throws VascException;
public String getDisplayValue(VascEntryField field,Object record) throws VascException;
public void setValue(VascEntryField field,Object record,Object value) throws VascException;
}

View file

@ -0,0 +1,41 @@
/*
* 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.entry;
import com.idcanet.vasc.core.VascEntry;
/**
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public interface VascEntryResourceImageResolver {
public Object getImageValue(VascEntry entry,String key);
}

View file

@ -0,0 +1,67 @@
/*
* 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.ui;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
/**
*
* @author Willem Cazander
* @version 1.0 May 21, 2009
*/
public class VascOptionValueModelListener implements VascValueModelListener {
private VascEntryField vascEntryField = null;
public VascOptionValueModelListener() {
}
public VascOptionValueModelListener(VascEntryField vascEntryField) {
setVascEntryField(vascEntryField);
}
public void valueUpdate(VascValueModel model) throws VascException {
String key = vascEntryField.getBackendName();
Object value = model.getValue();
vascEntryField.getVascEntry().setEntryParameter(key, value);
}
/**
* @return the vascEntryField
*/
public VascEntryField getVascEntryField() {
return vascEntryField;
}
/**
* @param vascEntryField the vascEntryField to set
*/
public void setVascEntryField(VascEntryField vascEntryField) {
this.vascEntryField = vascEntryField;
}
}

View file

@ -38,5 +38,31 @@ import com.idcanet.vasc.core.VascException;
*/
public interface VascSelectItemModel {
/**
* Creates an SelectItem list.
* @param entry
* @return
* @throws VascException
*/
public List<VascSelectItem> getVascSelectItems(VascEntry entry) throws VascException;
/**
* @return the nullLabel
*/
public String getNullLabel();
/**
* @param nullLabel the nullLabel to set
*/
public void setNullLabel(String nullLabel);
/**
* @return the nullKeyValue
*/
public String getNullKeyValue();
/**
* @param nullKeyValue the nullKeyValue to set
*/
public void setNullKeyValue(String nullKeyValue);
}

View file

@ -28,6 +28,7 @@ package com.idcanet.vasc.core.ui;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
/**
*
@ -50,8 +51,14 @@ public interface VascUIComponent {
static public final String[] requiredUIComponents = {VASC_LABEL,VASC_TEXT,VASC_LIST,VASC_BUTTON};
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception;
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException;
public void setErrorText(String text);
public String getErrorText();
public void setDisabled(boolean disabled);
public boolean isDisabled();
public void setRendered(boolean rendered);
public boolean isRendered();
}

View file

@ -71,15 +71,14 @@ import com.idcanet.vasc.core.VascEntryField;
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.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryExporter;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
import com.idcanet.vasc.core.ui.VascColumnValueModelListener;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
import com.idcanet.vasc.frontends.swing.ui.SwingBoolean;
import com.idcanet.vasc.frontends.swing.ui.SwingButton;
import com.idcanet.vasc.frontends.swing.ui.SwingColorChooser;
import com.idcanet.vasc.frontends.swing.ui.SwingDate;
import com.idcanet.vasc.frontends.swing.ui.SwingLabel;
import com.idcanet.vasc.frontends.swing.ui.SwingList;
import com.idcanet.vasc.frontends.swing.ui.SwingText;
@ -140,15 +139,12 @@ public class SwingVascFrontend extends AbstractVascFrontend {
/**
* @see com.idcanet.vasc.core.VascViewRenderer#renderEdit(com.idcanet.vasc.core.VascEntry, java.lang.Object)
*/
public void renderEdit(Object rowBean) throws Exception {
public void renderEdit() throws Exception {
logger.fine("Rending Edit View");
rowBean = entry.getVascFrontendData().getVascFrontendHelper().initEditObject(entry, rowBean);
Object rowBean = entry.getVascFrontendData().getEntryDataObject();
String beanValue = rowBean.toString();
if (entry.getDisplayNameFieldId()!=null) {
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
Object vv = v.getVascEntryFieldValue().getValue(v, rowBean);
@ -167,10 +163,12 @@ public class SwingVascFrontend extends AbstractVascFrontend {
if(result==null) {
return;
}
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry, result);
entry.getVascFrontendData().setEntryDataObject(result);
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry);
}
public void renderDelete(Object rowBean) throws Exception {
public void renderDelete() throws Exception {
Object rowBean = entry.getVascFrontendData().getEntryDataObject();
String beanValue = rowBean.toString();
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
@ -190,10 +188,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
, null // Default button's label
);
if (response==JOptionPane.YES_OPTION) {
entry.getVascFrontendData().getVascBackend().delete(rowBean);
entry.getVascFrontendData().getEntryDataList().remove(rowBean);
entry.getVascFrontendData().setEntryDataObject(null);
//entry.getVascFrontendController().getVascFrontendHelper().fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, rowBean);
entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry);
}
}
@ -260,11 +255,9 @@ public class SwingVascFrontend extends AbstractVascFrontend {
body.setLayout(new SpringLayout());
int column = 0;
for (VascEntryField c:entry.getVascEntryFields()) {
entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean);
if (c.getEdit()==false) {
continue;
}
//if (c.isEditReadOnly()==true) {
@ -299,9 +292,9 @@ public class SwingVascFrontend extends AbstractVascFrontend {
saveButton.setToolTipText(i18n("vasc.dialog.save.tooltip"));
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if(entry.getVascFrontendData().getVascFrontendHelper().setUIComponentsBeanErrors(entry, bean)) {
return;
}
//if(entry.getVascFrontendData().getVascFrontendHelper().validateObject(entry, bean)) {
// return;
//}
result = bean;
setVisible(false);
}
@ -350,7 +343,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
try {
exporter.doExport(out, entry);
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e);
} finally {
if (out!=null) {
out.close();
@ -394,22 +387,22 @@ public class SwingVascFrontend extends AbstractVascFrontend {
header.setBackground(Color.WHITE);
header.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
if(entry.getHeaderImage()!=null) {
if(entry.getListImage()!=null) {
JLabel l = new JLabel();
// TODO: hack images working
//l.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(entry.getHeaderImage())).getScaledInstance(32, 32, Image.SCALE_SMOOTH)));
if (entry.getHeaderDescription()!=null) {
l.setToolTipText(i18n(entry.getHeaderDescription()));
if (entry.getListDescription()!=null) {
l.setToolTipText(i18n(entry.getListDescription()));
}
header.add(l,BorderLayout.WEST);
}
if(entry.getHeaderName()!=null) {
JLabel l = new JLabel(i18n(entry.getHeaderName()));
if(entry.getName()!=null) {
JLabel l = new JLabel(i18n(entry.getName()));
l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
l.setFont(new Font(null,Font.BOLD, 18));
if (entry.getHeaderDescription()!=null) {
l.setToolTipText(i18n(entry.getHeaderDescription()));
if (entry.getListDescription()!=null) {
l.setToolTipText(i18n(entry.getListDescription()));
}
header.add(l,BorderLayout.CENTER);
}
@ -419,7 +412,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
for (GlobalVascAction action:entry.getGlobalActions()) {
JButton but = new JButton();
but.setText(i18n(action.getName()));
but.setToolTipText(i18n(action.getToolTip()));
but.setToolTipText(i18n(action.getDescription()));
but.addActionListener(new GlobalActionListener(action));
but.setIcon(getImageIcon(action.getImage()));
top.add(but);
@ -444,15 +437,12 @@ public class SwingVascFrontend extends AbstractVascFrontend {
VascColumnModel model = new VascColumnModel();
//TODO: entry.getVascEntryController().addEventListener(model);
JTable table = new JTable();
//TODO: remove this extra model for sorting, AND fixup a real sorting stuff
TableSorter tableSorter = new TableSorter();
JTable table = new JTable();
// this regs the listeners for the sorting
tableSorter.setTableHeader(table.getTableHeader());
tableSorter.setTableModel(model);
//tableSorter.setTableHeader(table.getTableHeader());
//tableSorter.setTableModel(model);
table.setModel(tableSorter);
table.setModel(model);
table.getTableHeader().setReorderingAllowed(false);
// remove auto columns :(
@ -481,7 +471,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
table.addColumn(t);
counter++;
}
table.getSelectionModel().addListSelectionListener(new entrySectionListener(table,tableSorter));
table.getSelectionModel().addListSelectionListener(new EntrySectionListener(table));
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
@ -491,10 +481,10 @@ public class SwingVascFrontend extends AbstractVascFrontend {
return;
}
try {
// TODO: fix this
entry.getVascFrontendData().getVascFrontend().renderEdit(o);
// todo: fix
entry.getVascFrontendData().getVascFrontend().renderEdit();
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(ee, entry);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, ee);
}
}
}
@ -502,12 +492,10 @@ public class SwingVascFrontend extends AbstractVascFrontend {
JScrollPane scrollPane = new JScrollPane(table);
parent2.add(scrollPane);
}
class entrySectionListener implements ListSelectionListener {
class EntrySectionListener implements ListSelectionListener {
JTable table;
TableSorter tableSorter;
entrySectionListener(JTable table,TableSorter tableSorter) {
EntrySectionListener(JTable table) {
this.table = table;
this.tableSorter=tableSorter;
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
@ -516,7 +504,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
int rowIndex = table.getSelectedRow();
if (rowIndex!=-1) {
// temp; gets index by sorter
rowIndex = tableSorter.modelIndex(rowIndex);
//rowIndex = tableSorter.modelIndex(rowIndex);
Object data = entry.getVascFrontendData().getEntryDataList().get(rowIndex);
entry.getVascFrontendData().setEntryDataObject(data);
} else {
@ -558,7 +546,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
for(RowVascAction action:entry.getRowActions()) {
JButton but = new JButton();
but.setText(i18n(action.getName()));
but.setToolTipText(i18n(action.getToolTip()));
but.setToolTipText(i18n(action.getDescription()));
but.setIcon(getImageIcon(action.getImage()));
but.addActionListener(new RowActionListener(action));
panel.add(but);
@ -581,7 +569,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
try {
action.doRowAction(entry, entry.getVascFrontendData().getEntryDataObject());
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
@ -599,19 +587,21 @@ public class SwingVascFrontend extends AbstractVascFrontend {
try {
action.doGlobalAction(entry);
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
class VascColumnModel extends AbstractTableModel { //implements VascEventListener {
class VascColumnModel extends AbstractTableModel implements VascEntryEventListener {
private static final long serialVersionUID = 10L;
public void vascEvent(VascEventType e,Object o) {
if (e==VascEventType.DATA_UPDATE) {
fireTableDataChanged();
}
public void vascEvent(VascEntry entry,VascEventType e,Object o) {
fireTableDataChanged();
}
public VascEntryEventListener clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
/**
* @see javax.swing.entry.entryModel#getColumnCount()

View file

@ -1,492 +0,0 @@
/*
*
*
* THIS FILE IS FROM:
* http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting
*/
package com.idcanet.vasc.frontends.swing;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;
/**
* TableSorter is a decorator for TableModels; adding sorting
* functionality to a supplied TableModel. TableSorter does
* not store or copy the data in its TableModel; instead it maintains
* a map from the row indexes of the view to the row indexes of the
* model. As requests are made of the sorter (like getValueAt(row, col))
* they are passed to the underlying model after the row numbers
* have been translated via the internal mapping array. This way,
* the TableSorter appears to hold another copy of the table
* with the rows in a different order.
* <p/>
* TableSorter registers itself as a listener to the underlying model,
* just as the JTable itself would. Events recieved from the model
* are examined, sometimes manipulated (typically widened), and then
* passed on to the TableSorter's listeners (typically the JTable).
* If a change to the model has invalidated the order of TableSorter's
* rows, a note of this is made and the sorter will resort the
* rows the next time a value is requested.
* <p/>
* When the tableHeader property is set, either by using the
* setTableHeader() method or the two argument constructor, the
* table header may be used as a complete UI for TableSorter.
* The default renderer of the tableHeader is decorated with a renderer
* that indicates the sorting status of each column. In addition,
* a mouse listener is installed with the following behavior:
* <ul>
* <li>
* Mouse-click: Clears the sorting status of all other columns
* and advances the sorting status of that column through three
* values: {NOT_SORTED, ASCENDING, DESCENDING} (then back to
* NOT_SORTED again).
* <li>
* SHIFT-mouse-click: Clears the sorting status of all other columns
* and cycles the sorting status of the column through the same
* three values, in the opposite order: {NOT_SORTED, DESCENDING, ASCENDING}.
* <li>
* CONTROL-mouse-click and CONTROL-SHIFT-mouse-click: as above except
* that the changes to the column do not cancel the statuses of columns
* that are already sorting - giving a way to initiate a compound
* sort.
* </ul>
* <p/>
* This is a long overdue rewrite of a class of the same name that
* first appeared in the swing table demos in 1997.
*
* @author Philip Milne
* @author Brendon McLean
* @author Dan van Enckevort
* @author Parwinder Sekhon
* @version 2.0 02/27/04
*/
@SuppressWarnings("unchecked")
public class TableSorter extends AbstractTableModel {
private static final long serialVersionUID = 10L;
protected TableModel tableModel;
public static final int DESCENDING = -1;
public static final int NOT_SORTED = 0;
public static final int ASCENDING = 1;
private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);
public static final Comparator COMPARABLE_COMAPRATOR = new Comparator() {
public int compare(Object o1, Object o2) {
return ((Comparable) o1).compareTo(o2);
}
};
public static final Comparator LEXICAL_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
}
};
private Row[] viewToModel;
private int[] modelToView;
private JTableHeader tableHeader;
private MouseListener mouseListener;
private TableModelListener tableModelListener;
private Map columnComparators = new HashMap();
private List sortingColumns = new ArrayList();
public TableSorter() {
this.mouseListener = new MouseHandler();
this.tableModelListener = new TableModelHandler();
}
public TableSorter(TableModel tableModel) {
this();
setTableModel(tableModel);
}
public TableSorter(TableModel tableModel, JTableHeader tableHeader) {
this();
setTableHeader(tableHeader);
setTableModel(tableModel);
}
private void clearSortingState() {
viewToModel = null;
modelToView = null;
}
public TableModel getTableModel() {
return tableModel;
}
public void setTableModel(TableModel tableModel) {
if (this.tableModel != null) {
this.tableModel.removeTableModelListener(tableModelListener);
}
this.tableModel = tableModel;
if (this.tableModel != null) {
this.tableModel.addTableModelListener(tableModelListener);
}
clearSortingState();
fireTableStructureChanged();
}
public JTableHeader getTableHeader() {
return tableHeader;
}
public void setTableHeader(JTableHeader tableHeader) {
if (this.tableHeader != null) {
this.tableHeader.removeMouseListener(mouseListener);
TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
if (defaultRenderer instanceof SortableHeaderRenderer) {
this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
}
}
this.tableHeader = tableHeader;
if (this.tableHeader != null) {
this.tableHeader.addMouseListener(mouseListener);
this.tableHeader.setDefaultRenderer(
new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
}
}
public boolean isSorting() {
return sortingColumns.size() != 0;
}
private Directive getDirective(int column) {
for (int i = 0; i < sortingColumns.size(); i++) {
Directive directive = (Directive)sortingColumns.get(i);
if (directive.column == column) {
return directive;
}
}
return EMPTY_DIRECTIVE;
}
public int getSortingStatus(int column) {
return getDirective(column).direction;
}
private void sortingStatusChanged() {
clearSortingState();
fireTableDataChanged();
if (tableHeader != null) {
tableHeader.repaint();
}
}
public void setSortingStatus(int column, int status) {
Directive directive = getDirective(column);
if (directive != EMPTY_DIRECTIVE) {
sortingColumns.remove(directive);
}
if (status != NOT_SORTED) {
sortingColumns.add(new Directive(column, status));
}
sortingStatusChanged();
}
protected Icon getHeaderRendererIcon(int column, int size) {
Directive directive = getDirective(column);
if (directive == EMPTY_DIRECTIVE) {
return null;
}
return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
}
private void cancelSorting() {
sortingColumns.clear();
sortingStatusChanged();
}
public void setColumnComparator(Class type, Comparator comparator) {
if (comparator == null) {
columnComparators.remove(type);
} else {
columnComparators.put(type, comparator);
}
}
protected Comparator getComparator(int column) {
Class columnType = tableModel.getColumnClass(column);
Comparator comparator = (Comparator) columnComparators.get(columnType);
if (comparator != null) {
return comparator;
}
if (Comparable.class.isAssignableFrom(columnType)) {
return COMPARABLE_COMAPRATOR;
}
return LEXICAL_COMPARATOR;
}
private Row[] getViewToModel() {
if (viewToModel == null) {
int tableModelRowCount = tableModel.getRowCount();
viewToModel = new Row[tableModelRowCount];
for (int row = 0; row < tableModelRowCount; row++) {
viewToModel[row] = new Row(row);
}
if (isSorting()) {
Arrays.sort(viewToModel);
}
}
return viewToModel;
}
public int modelIndex(int viewIndex) {
return getViewToModel()[viewIndex].modelIndex;
}
private int[] getModelToView() {
if (modelToView == null) {
int n = getViewToModel().length;
modelToView = new int[n];
for (int i = 0; i < n; i++) {
modelToView[modelIndex(i)] = i;
}
}
return modelToView;
}
// TableModel interface methods
public int getRowCount() {
return (tableModel == null) ? 0 : tableModel.getRowCount();
}
public int getColumnCount() {
return (tableModel == null) ? 0 : tableModel.getColumnCount();
}
public String getColumnName(int column) {
return tableModel.getColumnName(column);
}
public Class getColumnClass(int column) {
return tableModel.getColumnClass(column);
}
public boolean isCellEditable(int row, int column) {
return tableModel.isCellEditable(modelIndex(row), column);
}
public Object getValueAt(int row, int column) {
return tableModel.getValueAt(modelIndex(row), column);
}
public void setValueAt(Object aValue, int row, int column) {
tableModel.setValueAt(aValue, modelIndex(row), column);
}
// Helper classes
private class Row implements Comparable {
private int modelIndex;
public Row(int index) {
this.modelIndex = index;
}
public int compareTo(Object o) {
int row1 = modelIndex;
int row2 = ((Row) o).modelIndex;
for (Iterator it = sortingColumns.iterator(); it.hasNext();) {
Directive directive = (Directive) it.next();
int column = directive.column;
Object o1 = tableModel.getValueAt(row1, column);
Object o2 = tableModel.getValueAt(row2, column);
int comparison = 0;
// Define null less than everything, except null.
if (o1 == null && o2 == null) {
comparison = 0;
} else if (o1 == null) {
comparison = -1;
} else if (o2 == null) {
comparison = 1;
} else {
comparison = getComparator(column).compare(o1, o2);
}
if (comparison != 0) {
return directive.direction == DESCENDING ? -comparison : comparison;
}
}
return 0;
}
}
private class TableModelHandler implements TableModelListener {
public void tableChanged(TableModelEvent e) {
// If we're not sorting by anything, just pass the event along.
if (!isSorting()) {
clearSortingState();
fireTableChanged(e);
return;
}
// If the table structure has changed, cancel the sorting; the
// sorting columns may have been either moved or deleted from
// the model.
if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
cancelSorting();
fireTableChanged(e);
return;
}
// We can map a cell event through to the view without widening
// when the following conditions apply:
//
// a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
// b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,
// c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,
// d) a reverse lookup will not trigger a sort (modelToView != null)
//
// Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.
//
// The last check, for (modelToView != null) is to see if modelToView
// is already allocated. If we don't do this check; sorting can become
// a performance bottleneck for applications where cells
// change rapidly in different parts of the table. If cells
// change alternately in the sorting column and then outside of
// it this class can end up re-sorting on alternate cell updates -
// which can be a performance problem for large tables. The last
// clause avoids this problem.
int column = e.getColumn();
if (e.getFirstRow() == e.getLastRow()
&& column != TableModelEvent.ALL_COLUMNS
&& getSortingStatus(column) == NOT_SORTED
&& modelToView != null) {
int viewIndex = getModelToView()[e.getFirstRow()];
fireTableChanged(new TableModelEvent(TableSorter.this,
viewIndex, viewIndex,
column, e.getType()));
return;
}
// Something has happened to the data that may have invalidated the row order.
clearSortingState();
fireTableDataChanged();
return;
}
}
private class MouseHandler extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getSource();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status = status + (e.isShiftDown() ? -1 : 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
}
}
}
private static class Arrow implements Icon {
private boolean descending;
private int size;
private int priority;
public Arrow(boolean descending, int size, int priority) {
this.descending = descending;
this.size = size;
this.priority = priority;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
Color color = c == null ? Color.GRAY : c.getBackground();
// In a compound sort, make each succesive triangle 20%
// smaller than the previous one.
int dx = (int)(size/2*Math.pow(0.8, priority));
int dy = descending ? dx : -dx;
// Align icon (roughly) with font baseline.
y = y + 5*size/6 + (descending ? -dy : 0);
int shift = descending ? 1 : -1;
g.translate(x, y);
// Right diagonal.
g.setColor(color.darker());
g.drawLine(dx / 2, dy, 0, 0);
g.drawLine(dx / 2, dy + shift, 0, shift);
// Left diagonal.
g.setColor(color.brighter());
g.drawLine(dx / 2, dy, dx, 0);
g.drawLine(dx / 2, dy + shift, dx, shift);
// Horizontal line.
if (descending) {
g.setColor(color.darker().darker());
} else {
g.setColor(color.brighter().brighter());
}
g.drawLine(dx, 0, 0, 0);
g.setColor(color);
g.translate(-x, -y);
}
public int getIconWidth() {
return size;
}
public int getIconHeight() {
return size;
}
}
private class SortableHeaderRenderer implements TableCellRenderer {
private TableCellRenderer tableCellRenderer;
public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {
this.tableCellRenderer = tableCellRenderer;
}
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
Component c = tableCellRenderer.getTableCellRendererComponent(table,
value, isSelected, hasFocus, row, column);
if (c instanceof JLabel) {
JLabel l = (JLabel) c;
l.setHorizontalTextPosition(JLabel.LEFT);
int modelColumn = table.convertColumnIndexToModel(column);
l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
}
return c;
}
}
private static class Directive {
private int column;
private int direction;
public Directive(int column, int direction) {
this.column = column;
this.direction = direction;
}
}
}

View file

@ -35,6 +35,7 @@ import javax.swing.JComponent;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -50,7 +51,7 @@ public class SwingBoolean implements VascUIComponent {
private JCheckBox checkBox = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
checkBox = new JCheckBox();
orgBackgroundColor = checkBox.getBackground();
checkBox.setSelected(new Boolean(model.getValue().toString()));
@ -83,14 +84,42 @@ public class SwingBoolean implements VascUIComponent {
checkBox.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !checkBox.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
checkBox.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return checkBox.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
checkBox.setVisible(rendered);
}
}
class SelectActionListener implements ActionListener {
private VascValueModel model;
private VascEntry table = null;
public SelectActionListener(VascValueModel model,VascEntry table) {
private VascEntry entry = null;
public SelectActionListener(VascValueModel model,VascEntry entry) {
this.model=model;
this.table=table;
this.entry=entry;
}
/**
@ -101,7 +130,7 @@ class SelectActionListener implements ActionListener {
try {
model.setValue(value);
} catch (Exception ee) {
table.getVascFrontendData().getVascFrontendHelper().handleException(ee, table);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}

View file

@ -33,6 +33,7 @@ import javax.swing.JComponent;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -47,7 +48,7 @@ public class SwingButton implements VascUIComponent {
private JButton vascButton = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
vascButton = new JButton("Color");
orgBackgroundColor = vascButton.getBackground();
((JComponent)gui).add(vascButton);
@ -79,4 +80,32 @@ public class SwingButton implements VascUIComponent {
vascButton.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !vascButton.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
vascButton.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return vascButton.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
vascButton.setVisible(rendered);
}
}

View file

@ -51,7 +51,7 @@ public class SwingColorChooser implements VascUIComponent {
private JButton colorButton = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
JButton colorButton = new JButton("Color");
orgBackgroundColor = colorButton.getBackground();
((JComponent)gui).add(colorButton);
@ -83,16 +83,44 @@ public class SwingColorChooser implements VascUIComponent {
colorButton.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !colorButton.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
colorButton.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return colorButton.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
colorButton.setVisible(rendered);
}
}
class SelectActionListener3 implements ActionListener {
private VascValueModel model;
private boolean hexEncoding = false;
private VascEntry table = null;
public SelectActionListener3(VascValueModel model,boolean hexEncoding,VascEntry table) {
private VascEntry entry = null;
public SelectActionListener3(VascValueModel model,boolean hexEncoding,VascEntry entry) {
this.model=model;
this.hexEncoding=hexEncoding;
this.table=table;
this.entry=entry;
}
/**
@ -114,7 +142,7 @@ class SelectActionListener3 implements ActionListener {
try {
model.setValue(newColor);
} catch (Exception ee) {
table.getVascFrontendData().getVascFrontendHelper().handleException(ee, table);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
} else {
String cur=null;
@ -133,7 +161,7 @@ class SelectActionListener3 implements ActionListener {
String newColorString = "#"+Integer.toHexString( newColor.getRGB() & 0x00ffffff );
model.setValue(newColorString);
} catch (Exception ee) {
table.getVascFrontendData().getVascFrontendHelper().handleException(ee, table);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}

View file

@ -29,12 +29,14 @@ package com.idcanet.vasc.frontends.swing.ui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.Date;
import javax.swing.JComponent;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
import com.michaelbaranov.microba.calendar.DatePicker;
@ -51,10 +53,14 @@ 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 {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
datePicker = new DatePicker();
orgBackgroundColor = datePicker.getBackground();
datePicker.setDate((Date)model.getValue());
try {
datePicker.setDate((Date)model.getValue());
} catch (PropertyVetoException e) {
throw new VascException(new VascException(e));
}
((JComponent)gui).add(datePicker);
datePicker.addActionListener(new SelectActionListener2(model,table));
return datePicker;
@ -84,14 +90,42 @@ public class SwingDate implements VascUIComponent {
datePicker.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !datePicker.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
datePicker.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return datePicker.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
datePicker.setVisible(rendered);
}
}
class SelectActionListener2 implements ActionListener {
private VascValueModel model;
private VascEntry table = null;
public SelectActionListener2(VascValueModel model,VascEntry table) {
private VascEntry entry = null;
public SelectActionListener2(VascValueModel model,VascEntry entry) {
this.model=model;
this.table=table;
this.entry=entry;
}
/**
@ -102,7 +136,7 @@ class SelectActionListener2 implements ActionListener {
try {
model.setValue(value);
} catch (Exception ee) {
table.getVascFrontendData().getVascFrontendHelper().handleException(ee, table);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}

View file

@ -33,6 +33,7 @@ import javax.swing.JLabel;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -47,7 +48,7 @@ public class SwingLabel implements VascUIComponent {
private JLabel label = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
label = new JLabel();
label.setHorizontalAlignment(JLabel.TRAILING);
orgBackgroundColor = label.getBackground();
@ -80,4 +81,32 @@ public class SwingLabel implements VascUIComponent {
label.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !label.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
label.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return label.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
label.setVisible(rendered);
}
}

View file

@ -39,6 +39,7 @@ import javax.swing.ListCellRenderer;
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.VascUIComponent;
@ -55,12 +56,12 @@ public class SwingList implements VascUIComponent {
private JComboBox comboBox = null;
private Color orgBackgroundColor = null;
public Object createComponent(final VascEntry table,VascEntryField entryField,final VascValueModel model,Object gui) throws Exception {
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
VascSelectItemModel items = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
if (items==null) {
comboBox = new JComboBox();
} else {
comboBox = new JComboBox(items.getVascSelectItems(table).toArray());
comboBox = new JComboBox(items.getVascSelectItems(entry).toArray());
}
orgBackgroundColor = comboBox.getBackground();
((JComponent)gui).add(comboBox);
@ -71,7 +72,7 @@ public class SwingList implements VascUIComponent {
try {
model.setValue(i.getValue());
} catch (Exception ee) {
table.getVascFrontendData().getVascFrontendHelper().handleException(ee, table);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
});
@ -119,6 +120,34 @@ public class SwingList implements VascUIComponent {
comboBox.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !comboBox.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
comboBox.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return comboBox.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
comboBox.setVisible(rendered);
}
}
class MyCellRenderer extends JLabel implements ListCellRenderer {

View file

@ -35,6 +35,7 @@ import javax.swing.event.DocumentListener;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -49,7 +50,7 @@ public class SwingText implements VascUIComponent {
private JTextField textField = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
textField = new JTextField();
orgBackgroundColor = textField.getBackground();
textField.setText(""+model.getValue());
@ -82,6 +83,34 @@ public class SwingText implements VascUIComponent {
textField.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !textField.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
textField.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return textField.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
textField.setVisible(rendered);
}
}
class TextListener implements DocumentListener {

View file

@ -36,6 +36,7 @@ import javax.swing.event.DocumentListener;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -50,7 +51,7 @@ public class SwingTextArea implements VascUIComponent {
private JTextArea textArea = null;
private Color orgBackgroundColor = null;
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createEtchedBorder());
textArea.setRows(8);
@ -91,6 +92,34 @@ public class SwingTextArea implements VascUIComponent {
textArea.setBackground(Color.RED);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !textArea.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
textArea.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return textArea.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
textArea.setVisible(rendered);
}
}
class TextAreaListener implements DocumentListener {

View file

@ -0,0 +1,227 @@
/*
* 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.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascColumnValueModelListener;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
/**
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public class SwtVascEditDialog extends Dialog {
private VascEntry entry = null;
private Shell shell = null;
public SwtVascEditDialog (VascEntry entry) {
super (Display.getCurrent().getActiveShell(), 0);
this.entry=entry;
}
protected String i18n(String key,Object...params) {
return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params);
}
protected Object i18nImage(String key) {
return entry.getVascFrontendData().getVascEntryResourceImageResolver().getImageValue(entry,key);
}
public void open() throws VascException {
shell = new Shell(getParent(), SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
shell.setText(i18n(entry.getName()));
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
shell.setLayout(layout);
Composite header = new Composite(shell, SWT.NONE);
GridLayout headerLayout = new GridLayout();
headerLayout.numColumns = 6;
header.setLayout(headerLayout);
header.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite body = new Composite(shell, SWT.NONE);
GridLayout bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
body.setLayout(bodyLayout);
body.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite footer = new Composite(shell, SWT.NONE);
GridLayout footerLayout = new GridLayout();
footerLayout.numColumns = 6;
footer.setLayout(footerLayout);
footer.setLayoutData(new GridData(SWT.NONE));
createHeader(header);
createBody(body);
createFooter(footer);
shell.pack();
shell.open();
Display display = shell.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public void createHeader(Composite header) {
String displayFieldId = entry.getDisplayNameFieldId();
VascEntryField dis = entry.getVascEntryFieldById(displayFieldId);
if (dis==null) {
throw new RuntimeException("Could not find: "+displayFieldId+" from: "+entry.getId());
}
String name = null;
try {
Object bean = entry.getVascFrontendData().getEntryDataObject();
name = dis.getVascEntryFieldValue().getDisplayValue(dis, bean);
} catch (VascException e) {
throw new RuntimeException("Could not display value from "+entry.getId(),e);
}
Color c = new Color(header.getDisplay(),255,255,255);
header.setBackground(c);
Label img = new Label(header, SWT.NONE);
if (entry.getVascFrontendData().isEditCreate()) {
img.setImage((Image)i18nImage(entry.getCreateImage()));
} else {
img.setImage((Image)i18nImage(entry.getEditImage()));
}
img.setBackground(c);
Font headerFont = new Font(header.getDisplay(), "verdana", 14, SWT.NONE);
Label l = new Label(header, SWT.CENTER);
if (entry.getVascFrontendData().isEditCreate()) {
l.setText(i18n(entry.getCreateDescription(),name));
} else {
l.setText(i18n(entry.getEditDescription(),name));
}
l.setFont(headerFont);
l.setBackground(c);
}
public void createBody(Composite body) throws VascException {
body.setLayout(new GridLayout(2, true));
body.setLayoutData(new GridData(GridData.FILL_BOTH));
Object bean = entry.getVascFrontendData().getEntryDataObject();
entry.getVascFrontendData().clearFieldRenderObjects(); // only needed for swt use
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) {
continue;
}
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
VascValueModel model = new VascValueModel();
model.setValue(i18n(c.getName()));
Control realLabel = (Control)label.createComponent(entry,c,model,body);
realLabel.setToolTipText(i18n(c.getDescription()));
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
model.addListener(new VascColumnValueModelListener(c,bean));
Control edit = (Control )editor.createComponent(entry,c,model,body);
if (edit.getLayoutData()==null) { // is for textarea which has custum layout data
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
edit.setLayoutData(gridData);
}
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,edit);
}
}
}
entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry);
}
public void createFooter(Composite body) {
Button saveButton = new Button(body, SWT.NONE);
saveButton.setImage((Image)i18nImage("vasc.action.saveAction.image"));
saveButton.setText(i18n("vasc.action.saveAction.name"));
saveButton.setToolTipText(i18n("vasc.action.saveAction.description"));
saveButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
try {
boolean error = entry.getVascFrontendData().getVascFrontendHelper().validateAndSetErrorText(entry);
if (error) {
return;
}
entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry);
shell.dispose();
} catch (Exception ee) {
ee.printStackTrace();
}
}
});
Button cancelButton = new Button(body, SWT.NONE);
cancelButton.setImage((Image)i18nImage("vasc.action.cancelAction.image"));
cancelButton.setText(i18n("vasc.action.cancelAction.name"));
cancelButton.setToolTipText(i18n("vasc.action.cancelAction.description"));
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
entry.getVascFrontendData().setEntryDataObject(null);
shell.dispose();
}
});
}
}

View file

@ -31,30 +31,35 @@ import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jface.resource.ImageDescriptor;
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.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
@ -62,20 +67,24 @@ import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import com.idcanet.fff.SwingImageHelper;
import com.idcanet.vasc.core.AbstractVascFrontend;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
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.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryExporter;
import com.idcanet.vasc.core.ui.VascColumnValueModelListener;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
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.core.ui.VascValueModelListener;
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.SwtList;
import com.idcanet.vasc.frontends.swt.ui.SwtText;
import com.idcanet.vasc.frontends.swt.ui.SwtTextArea;
@ -88,6 +97,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
private Logger logger = null;
private Composite parent = null;
private boolean renderGlobalActions = true;
public SwtVascFrontend(Composite parent) {
logger = Logger.getLogger(SwtVascFrontend.class.getName());
@ -104,6 +114,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
vfd.putVascUIComponent(VascUIComponent.VASC_LABEL,SwtLabel.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_TEXT, SwtText.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_BUTTON, SwtButton.class.getName());
vfd.putVascUIComponent(VascUIComponent.VASC_LIST, SwtList.class.getName());
// optional UI components
vfd.putVascUIComponent(VascUIComponent.VASC_BOOLEAN , SwtBoolean.class.getName());
@ -112,8 +123,24 @@ public class SwtVascFrontend extends AbstractVascFrontend {
//vfd.putVascUIComponent(VascUIComponent.VASC_COLOR, SwtColorChooser.class.getName());
}
private static final String[] FILTER_NAMES = {
/**
* @return the renderGlobalActions
*/
public boolean isRenderGlobalActions() {
return renderGlobalActions;
}
/**
* @param renderGlobalActions the renderGlobalActions to set
*/
public void setRenderGlobalActions(boolean renderGlobalActions) {
this.renderGlobalActions = renderGlobalActions;
}
private static final String[] FILTER_NAMES = {
"All Files (*.*)",
"Comma Separated Values Files (*.csv)",
"Microsoft Excel Spreadsheet Files (*.xls)",
@ -125,7 +152,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
dlg.setFilterNames(FILTER_NAMES);
dlg.setFilterExtensions(FILTER_EXTS);
dlg.setFileName(entry.getHeaderName()+".csv");
dlg.setFileName(entry.getName()+".csv");
String fileName = dlg.open();
logger.fine("FileName: "+fileName);
if (fileName == null) {
@ -144,225 +171,33 @@ public class SwtVascFrontend extends AbstractVascFrontend {
}
}
public void renderEdit(Object object) throws Exception {
public void renderEdit() throws Exception {
logger.fine("Rending Edit View");
object = entry.getVascFrontendData().getVascFrontendHelper().initEditObject(entry, object);
SwtVascEditDialog dialog = new SwtVascEditDialog(Display.getCurrent().getActiveShell(),object,"Vasc Edit","Edit");
Object result = dialog.open();
if(result==null) {
return;
SwtVascEditDialog dialog = new SwtVascEditDialog(entry);
dialog.open();
}
public void renderDelete() throws Exception {
boolean del = askDelete( Display.getCurrent().getActiveShell() );
if (del==false) {
return;
}
// yes
entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry);
}
private boolean askDelete(Shell shell) {
logger.finest("Asking for delete");
MessageBox askDelete = new MessageBox(shell,SWT.ICON_QUESTION|SWT.YES|SWT.NO);
askDelete.setText(i18n("crud.event.delete.confim.title"));
askDelete.setMessage(i18n("crud.event.delete.confim.question"));
int state = askDelete.open();
if (state == SWT.YES) {
return true;
}
/*
try {
result = entry.getVascDataSource().merge(object);
//table.getVascTableController().fireModelUpdateListeners(result);
} finally {
//TODO: or merge into table == faster
entry.getVascTableController().refreshData(entry);
}
*/
}
public ImageDescriptor getImageDescriptor(String path) {
try {
path = i18n(path);
logger.fine("Loading image: "+path);
ImageDescriptor result = ImageDescriptor.createFromFile(path.getClass(), path);
result = ImageDescriptor.createFromFile(SwingImageHelper.class, path);
if(result==null) {
// try load fff
//result = ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource(path));
}
if(result==null) {
throw new NullPointerException("Can't load resource: "+path);
}
return result;
} catch (Exception e) {
logger.warning("Could not load image from path: '"+path+"'");
try {
ImageDescriptor result = null; //ImageDescriptor.createFromURL(SwingImageHelper.class.getClass().getResource("/META-INF/images/silk/png/bomb.png"));
if(result==null) {
throw new NullPointerException("Can't load resource: "+path);
}
return result;
} catch (Exception e2) {
return ImageDescriptor.getMissingImageDescriptor(); // default swt missing image fall back
}
}
}
public void renderDelete(Object rowBean) throws Exception {
return false;
}
}
public class SwtVascEditDialog extends Dialog {
private Shell shell = null;
//private String headerText = null;
private String title = null;
private Object result = null;
private Object bean = null;
public SwtVascEditDialog (Shell parent,Object bean,String title,String headerText) {
super (parent, 0);
///this.headerText = headerText;
this.title = title;
this.bean = bean;
}
public Object open() {
shell = new Shell(getParent(), SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
shell.setText(title);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
shell.setLayout(layout);
Composite header = new Composite(shell, SWT.NONE);
GridLayout headerLayout = new GridLayout();
headerLayout.numColumns = 6;
header.setLayout(headerLayout);
header.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite body = new Composite(shell, SWT.NONE);
GridLayout bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
body.setLayout(bodyLayout);
body.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite footer = new Composite(shell, SWT.NONE);
GridLayout footerLayout = new GridLayout();
footerLayout.numColumns = 6;
footer.setLayout(footerLayout);
footer.setLayoutData(new GridData(SWT.NONE));
//createHeader(header);
try {
createBody(body);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//createFooter(footer);
// should be last
partCreated();
shell.pack();
shell.open();
Display display = shell.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
//image.dispose();
//closeDialog();
return result;
}
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()) {
entry.getVascFrontendData().getVascFrontendHelper().initEditObjectColumn(c, bean);
if (c.getEdit()==false) {
continue;
}
//if (c.isEditReadOnly()==true) {
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
VascValueModel model = new VascValueModel();
model.setValue(i18n(c.getName()));
label.createComponent(entry,c,model,body);
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
model.addListener(new VascColumnValueModelListener(c,bean));
Object g = editor.createComponent(entry,c,model,body);
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,g);
}
}
}
// create some spaceing , should replace by seperator
new Label(body, SWT.WRAP);
new Label(body, SWT.WRAP);
Button saveButton = new Button(body, SWT.NONE);
saveButton.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
saveButton.setText(i18n("vasc.dialog.save.name"));
saveButton.setToolTipText(i18n("vasc.dialog.save.tooltip"));
saveButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//if(hasRecordError()) {
// return;
//}
//result = bean;
shell.dispose();
}
});
Button cancelButton = new Button(body, SWT.NONE);
cancelButton.setImage(getImageDescriptor("vasc.dialog.cancel.image").createImage());
cancelButton.setText(i18n("vasc.dialog.cancel.name"));
cancelButton.setToolTipText(i18n("vasc.dialog.cancel.tooltip"));
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
result = null;
shell.dispose();
}
});
}
}
public Object defaultColumnEditor(VascEntryField column,Object bean,Object gui) throws Exception {
Composite body = (Composite)gui;
Text text = new Text(body,SWT.SINGLE);
text.addSelectionListener(new TextListener(column,bean));
text.setText(""+column.getVascEntryFieldValue().getValue(column, bean));
return text;
}
class TextListener extends SelectionAdapter {
private VascEntryField column = null;
private Object bean = null;
public TextListener(VascEntryField column,Object bean) {
this.column=column;
this.bean=bean;
}
/**
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent e) {
// SHIT it works :)
Object value = e.data;
logger.finer("Setting value: "+value);
try {
column.getVascEntryFieldValue().setValue(column, bean, value);
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
public void renderView() throws Exception {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
@ -390,85 +225,138 @@ public class SwtVascFrontend extends AbstractVascFrontend {
createHeader(header);
createBody(body);
createFooter(footer);
// should be last
partCreated();
}
public void createHeader(Composite header) {
logger.finest("Creating header");
Color c = header.getDisplay().getSystemColor(SWT.COLOR_WHITE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginTop = 0;
header.setLayout(layout);
header.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Composite headerBar = new Composite(header, SWT.NONE);
//GridLayout headerLayout = new GridLayout();
//headerLayout.numColumns = 1;
headerBar.setLayout(new FillLayout());
//headerBar.setLayoutData(new GridData(GridData.FILL_BOTH));
header.setBackground(c);
if (isRenderGlobalActions()) {
Composite headerBar = new Composite(header, SWT.NONE);
//GridLayout headerLayout = new GridLayout();
//headerLayout.numColumns = 1;
headerBar.setLayout(new FillLayout());
//headerBar.setLayoutData(new GridData(GridData.FILL_BOTH));
ToolBar toolBar = new ToolBar(headerBar, SWT.NONE);
for (GlobalVascAction action:entry.getGlobalActions()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderGlobalVascAction(action)==false) {
continue;
}
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
item.setText(i18n(action.getName()));
item.setToolTipText(i18n(action.getDescription()));
item.setImage((Image)i18nImage(action.getImage()));
item.addSelectionListener(new GlobalActionListener(action));
}
}
Composite headerName = new Composite(header, SWT.NONE);
GridLayout bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
bodyLayout.numColumns = 2;
headerName.setLayout(bodyLayout);
headerName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
//headerName.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite headerOptions = new Composite(header, SWT.NONE);
GridLayout footerLayout = new GridLayout();
footerLayout.numColumns = 1;
headerOptions.setLayout(footerLayout);
//headerOptions.setLayoutData(new GridData(SWT.NONE));
headerOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ToolBar toolBar = new ToolBar(headerBar, SWT.NONE);
for (GlobalVascAction action:entry.getGlobalActions()) {
ToolItem item = new ToolItem(toolBar, SWT.PUSH);
item.setText(i18n(action.getName()));
item.setToolTipText(i18n(action.getToolTip()));
if (action.getImage()!=null) {
item.setImage(getImageDescriptor(action.getImage()).createImage());
}
item.addSelectionListener(new GlobalActionListener(action));
}
Color c = new Color(header.getDisplay(),255,255,255);
headerName.setBackground(c);
if(entry.getHeaderName()!=null) {
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
Label l = new Label(headerName, SWT.CENTER);
l.setImage(getImageDescriptor(entry.getHeaderImage()).createImage());
l.setFont(headerFont);
l.setText(i18n(entry.getHeaderName()));
l.setBackground(c);
Label l = new Label(headerName, SWT.CENTER);
l.setImage((Image)i18nImage(entry.getListImage()));
l.setBackground(c);
Font headerFont = new Font(header.getDisplay(), "verdana", 16, SWT.BOLD);
l = new Label(headerName, SWT.CENTER);
l.setFont(headerFont);
l.setText(i18n(entry.getName()));
l.setBackground(c);
Composite headerText = new Composite(header, SWT.NONE);
bodyLayout = new GridLayout();
bodyLayout.numColumns = 1;
headerText.setLayout(bodyLayout);
headerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
headerText.setBackground(c);
l = new Label(headerText, SWT.CENTER);
l.setText(i18n(entry.getListDescription()));
l.setBackground(c);
Composite headerSplit = new Composite(header, SWT.NONE);
GridLayout headerSplitLayout = new GridLayout();
headerSplitLayout.numColumns = 2;
headerSplit.setLayout(headerSplitLayout);
headerSplit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Composite headerOptions = new Composite(headerSplit, SWT.NONE);
GridLayout headerOptionsLayout = new GridLayout();
headerOptionsLayout.numColumns = 2;
headerOptions.setLayout(headerOptionsLayout);
headerOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
try {
for (VascEntryField option:entry.getListOptions()) {
for (int i=0;i<option.getVascEntryFieldType().getUIComponentCount(option);i++) {
com.idcanet.vasc.core.ui.VascUIComponent label = option.getVascEntryFieldType().provideLabelUIComponent(i,option);
VascValueModel model = new VascValueModel();
model.setValue(i18n(option.getName()));
label.createComponent(entry,option,model,headerOptions);
com.idcanet.vasc.core.ui.VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option);
model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option));
model.addListener(new VascOptionValueModelListener(option));
model.setValue(null);
model.addListener(new VascValueModelListener() {
public void valueUpdate(VascValueModel model) throws VascException {
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);// mm
}
});
Object edit = editor.createComponent(entry,option,model,headerOptions);
// i==0 is for multi field editor support... which is stell very in progress
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(option, editor,edit);
}
}
}
// create options
//for(VascUserOption option:table.getUserOptions()) {
/*
if(option.getLabelText()!=null) {
Label l = new Label(header,SWT.WRAP);
l.setText(crudTable.i18n(cpo.getLabelText()));
l.setBackground(c);
}
// create ValueHolder
cpo.setValueHolder(new ValueHolder(null));
// create control
cpo.setTempObjectPropertyControl(cpo.getPropertyEditor().createPropertyEditor(header,cpo.getValueHolder()));
cpo.getValueHolder().addPropertyChangeListener(this);
*/
//}
}
class GlobalActionListener extends SelectionAdapter {
Composite headerRightOptions = new Composite(headerSplit, SWT.NONE | SWT.RIGHT | SWT.TOP );
GridLayout headerRightOptionsLayout = new GridLayout();
headerRightOptionsLayout.numColumns = 2;
headerRightOptions.setLayout(headerRightOptionsLayout);
headerRightOptions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label searchLabel = new Label(headerRightOptions, SWT.CENTER);
searchLabel.setText("Zoeken:");
final Text text = new Text(headerRightOptions, SWT.NONE | SWT.BORDER );
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String value = text.getText();
try {
entry.getVascFrontendData().getVascFrontendHelper().searchAction(entry, value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
});
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
} catch (Exception e) {
e.printStackTrace();
}
}
class GlobalActionListener extends SelectionAdapter {
private GlobalVascAction action = null;
public GlobalActionListener(GlobalVascAction action) {
@ -483,28 +371,26 @@ public class SwtVascFrontend extends AbstractVascFrontend {
try {
action.doGlobalAction(entry);
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
public void createBody(Composite body) {
logger.finer("Creating body");
// Create the table viewer to display the players
final TableViewer tableViewer = new TableViewer(body, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
// SWT.CHECK
final TableViewer tableViewer = new TableViewer(body, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
final Table table2 = tableViewer.getTable();
table2.setLayoutData(new GridData(GridData.FILL_BOTH));
table2.setHeaderVisible(true);
table2.setLinesVisible(true);
body.addControlListener(new ResizeTableControlListener(body,table2));
table2.addSelectionListener(new SelectionListener() {
/**
@ -542,36 +428,34 @@ public class SwtVascFrontend extends AbstractVascFrontend {
table2.setSortColumn(currentColumn);
dir = SWT.UP;
}
// sort the data based on column and direction
//String prop = (String)currentColumn.getData("PROP");
//List l = new ArrayList(10);
/*
* //columns[i].setData("PROP",table.getTableColumns().get(i)....);
*
for(int i=0;i<crudTable.getSelectionInList().getSize();i++) {
l.add(crudTable.getSelectionInList().getElementAt(i));
}
BeanPropertyComparator c = new BeanPropertyComparator();
c.setAscending(dir!=SWT.DOWN);
c.setProperty(prop);
Collections.sort(l,c);
crudTable.getSelectionInList().setList(l);
*/
table2.setSortDirection(dir);
VascEntryField field = (VascEntryField)currentColumn.getData();
entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field);
}
};
entry.addVascEntryEventListener(VascEventType.DATA_LIST_UPDATE, new VascEntryEventListener() {
public void vascEvent(VascEntry entry,VascEventType type,Object data) {
tableViewer.refresh();
table2.deselectAll();
}
public VascEntryEventListener clone() throws CloneNotSupportedException {
return this;
}
});
for(VascEntryField c:entry.getVascEntryFields()) {
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
continue;
}
TableColumn tc = new TableColumn(table2, SWT.LEFT);
tc.setText(c.getName());
tc.setToolTipText(c.getDescription());
if (c.getImage()!=null) {
tc.setImage(getImageDescriptor(c.getImage()).createImage());
}
tc.setText(i18n(c.getName()));
tc.setData(c);
tc.setToolTipText(i18n(c.getDescription()));
tc.setImage((Image)i18nImage(c.getImage()));
tc.addListener(SWT.Selection, sortListener);
tc.setMoveable(false);
tc.setMoveable(true);
tc.setResizable(true);
}
@ -579,14 +463,15 @@ public class SwtVascFrontend extends AbstractVascFrontend {
logger.finer("Total size: "+totalWidth);
TableColumn[] columns = table2.getColumns();
for (int i = 0; i < columns.length; i++) {
Integer cWidth = entry.getVascEntryFields().get(i).getSizeEdit();
if (cWidth==null) {
break;
VascEntryField c = (VascEntryField)columns[i].getData();
Integer cWidth = c.getSizeList();
if (cWidth!=null) {
//int w = (int)((double)totalSize/(double)totalSize)*cWidth;
columns[i].setWidth(cWidth);
//logger.finest("Setting column width: "+w+" total: "+totalSize+" c: "+cWidth+" of column: "+i);
} else {
columns[i].pack();
}
//int w = (int)((double)totalSize/(double)totalSize)*cWidth;
columns[i].setWidth(cWidth);
columns[i].pack();
//logger.finest("Setting column width: "+w+" total: "+totalSize+" c: "+cWidth+" of column: "+i);
}
logger.fine("Table with columns created: "+table2.getColumnCount());
@ -594,27 +479,64 @@ public class SwtVascFrontend extends AbstractVascFrontend {
tableViewer.refresh();
}
class ResizeTableControlListener implements ControlListener {
Composite comp = null;
Table table = null;
public ResizeTableControlListener(Composite comp,Table table) {
this.comp=comp;
this.table=table;
}
public void controlResized(ControlEvent e) {
Rectangle area = comp.getClientArea();
Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = area.width - 2*table.getBorderWidth();
if (preferredSize.y > area.height + table.getHeaderHeight()) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required
Point vBarSize = table.getVerticalBar().getSize();
width -= vBarSize.x;
}
Point oldSize = table.getSize();
if (oldSize.x > area.width) {
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
table.setSize(area.width, area.height);
} else {
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
table.setSize(area.width, area.height);
//column1.setWidth(width/3);
//column2.setWidth(width - column1.getWidth());
}
}
public void controlMoved(ControlEvent e) {
}
}
public void createFooter(Composite footer) {
logger.finest("Creating footer");
for(RowVascAction action:entry.getRowActions()) {
for( RowVascAction action:entry.getRowActions()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) {
continue;
}
Button actionButton = new Button(footer, SWT.NONE);
actionButton.setText(i18n(action.getName()));
actionButton.setToolTipText(i18n(action.getToolTip()));
if (action.getImage()!=null) {
actionButton.setImage(getImageDescriptor(action.getImage()).createImage());
}
actionButton.setToolTipText(i18n(action.getDescription()));
actionButton.setImage((Image)i18nImage(action.getImage()));
actionButton.addSelectionListener(new ActionListener(action));
}
}
class ActionListener extends SelectionAdapter {
private RowVascAction action = null;
public ActionListener(RowVascAction action) {
this.action=action;
}
/**
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@ -624,17 +546,11 @@ public class SwtVascFrontend extends AbstractVascFrontend {
try {
action.doRowAction(entry, entry.getVascFrontendData().getEntryDataObject());
} catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(e, entry);
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,e);
}
}
}
/**
* Is called when all createPartControl is done with creating Parts
*/
public void partCreated() {
}
class DefaultLabelProvider implements ITableLabelProvider {
@ -655,10 +571,27 @@ public class SwtVascFrontend extends AbstractVascFrontend {
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
public String getColumnText(Object bean, int columnNumber) {
VascEntryField vtc = entry.getVascEntryFields().get(columnNumber);
int col=0;
VascEntryField vtc = null;
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
continue;
}
if (col==columnNumber) {
vtc = c;
break;
}
col++;
}
if (vtc==null) {
// should not happen
vtc = entry.getVascEntryFields().get(columnNumber);
}
//if (vtc.getVascColumnRenderer()==null) {
try {
return ""+vtc.getVascEntryFieldValue().getValue(vtc,bean);
return vtc.getVascEntryFieldValue().getDisplayValue(vtc,bean);
} catch (Exception e) {
logger.log(Level.WARNING,"Error in get value: '"+vtc.getVascEntryFieldValue()+"' error: "+e.getMessage(),e);
return "Err";

View file

@ -35,6 +35,7 @@ import org.eclipse.swt.widgets.Composite;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -51,15 +52,26 @@ public class SwtBoolean implements VascUIComponent {
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
button = new Button((Composite)gui, SWT.CHECK);
orgBackgroundColor = button.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
//button.setImage(getImageDescriptor("vasc.dialog.save.image").createImage());
button.setText(model.getValue()+"");
button.setText("");
Object value = model.getValue();
if (value!=null) {
button.setSelection(new Boolean(model.getValue()+""));
}
//button.setToolTipText(i18n("vasc.dialog.save.tooltip"));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Boolean value = button.getSelection();
try {
System.out.println("setting value: "+value);
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
});
return button;
@ -89,4 +101,32 @@ public class SwtBoolean implements VascUIComponent {
button.setBackground(errorColor);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !button.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
button.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return button.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
button.setVisible(rendered);
}
}

View file

@ -35,6 +35,7 @@ import org.eclipse.swt.widgets.Composite;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -51,7 +52,7 @@ public class SwtButton implements VascUIComponent {
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
button = new Button((Composite)gui, SWT.NONE);
orgBackgroundColor = button.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
@ -89,4 +90,32 @@ public class SwtButton implements VascUIComponent {
button.setBackground(errorColor);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !button.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
button.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return button.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
button.setVisible(rendered);
}
}

View file

@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.Label;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -48,7 +49,7 @@ public class SwtLabel implements VascUIComponent {
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
label = new Label((Composite)gui, SWT.NONE);
orgBackgroundColor = label.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
@ -80,4 +81,32 @@ public class SwtLabel implements VascUIComponent {
label.setBackground(errorColor);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !label.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
label.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return label.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
label.setVisible(rendered);
}
}

View file

@ -0,0 +1,179 @@
/*
* 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.swt.ui;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
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.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
/**
*
*
* @author Willem Cazander
* @version 1.0 May 10, 2009
*/
public class SwtList implements VascUIComponent {
private Combo combo = null;
private Color orgBackgroundColor = null;
private Color errorColor = null;
private List<VascSelectItem> data = null;
public Object createComponent(final VascEntry entry,VascEntryField entryField,final VascValueModel model,Object gui) throws VascException {
combo = new Combo((Composite)gui,SWT.SINGLE | SWT.BORDER);
combo.setVisibleItemCount(8);
VascSelectItemModel items = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
if (items!=null) {
data = items.getVascSelectItems(entry);
}
fillCombo();
orgBackgroundColor = combo.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
VascSelectItem item = findItem(combo.getText());
if (item!=null) {
try {
model.setValue(item.getValue());
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
});
// sets default selected
for (VascSelectItem i:data) {
Object iValue = i.getValue();
Object mValue = model.getValue();
if (iValue==null && mValue==null) {
combo.setText(i.getLabel());
break;
}
if (iValue==null) {
continue;
}
if (iValue.equals(mValue)) {
combo.setText(i.getLabel());
break;
}
}
if (combo.getText()==null) {
combo.setText(data.get(0).getLabel()); // select top one.
}
return combo;
}
private void fillCombo() {
if (data==null | combo==null) {
return;
}
for (VascSelectItem i:data) {
if (i.isDisabled()) {
continue;
}
combo.add(i.getLabel());
}
}
private VascSelectItem findItem(String text) {
for (VascSelectItem i:data) {
if (i.getLabel().equals(text)) {
return i;
}
}
return null;
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
*/
public String getErrorText() {
if (combo==null) {
return null;
}
return combo.getToolTipText();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
if (combo==null) {
return;
}
combo.setToolTipText(text);
if (text==null) {
combo.setBackground(orgBackgroundColor);
} else {
combo.setBackground(errorColor);
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !combo.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
combo.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return combo.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
combo.setVisible(rendered);
}
}

View file

@ -26,22 +26,21 @@
package com.idcanet.vasc.frontends.swt.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
/**
*
* Renders the swt text field.
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
@ -52,18 +51,38 @@ public class SwtText implements VascUIComponent {
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
text = new Text((Composite)gui, SWT.NONE);
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
text = new Text((Composite)gui, SWT.NONE | SWT.BORDER);
orgBackgroundColor = text.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
text.setText(model.getValue()+"");
text.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
}
});
Object value = model.getValue();
if (value!=null) {
text.setText(value.toString());
}
text.addModifyListener(new TextListener(model,entry));
return text;
}
class TextListener implements ModifyListener {
private VascValueModel model = null;
private VascEntry entry = null;
public TextListener(VascValueModel model,VascEntry entry) {
this.model=model;
this.entry=entry;
}
public void modifyText(ModifyEvent e) {
Object value = text.getText();
try {
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
*/
@ -77,17 +96,43 @@ public class SwtText implements VascUIComponent {
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
public void setErrorText(String textString) {
if (text==null) {
return;
}
/*
text.setToolTipText(text);
if (text==null) {
text.setToolTipText(textString);
if (textString==null) {
text.setBackground(orgBackgroundColor);
} else {
text.setBackground(errorColor);
}
*/
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !text.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
text.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return text.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
text.setVisible(rendered);
}
}

View file

@ -27,18 +27,21 @@
package com.idcanet.vasc.frontends.swt.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.ui.VascValueModel;
/**
*
*
@ -51,18 +54,59 @@ public class SwtTextArea implements VascUIComponent {
private Color orgBackgroundColor = null;
private Color errorColor = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
text = new Text((Composite)gui, SWT.MULTI);
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
text = new Text((Composite)gui, SWT.MULTI | SWT.BORDER);
orgBackgroundColor = text.getBackground();
errorColor = new Color(((Composite)gui).getDisplay(),255,0,0);
text.setText(model.getValue()+"");
text.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
}
});
int cols = 25;
int rows = 3;
String colsString = entryField.getVascEntryFieldType().getProperty("editor.columns");
if (colsString!=null && "".equals(colsString)==false) {
cols = new Integer(colsString);
}
String rowsString = entryField.getVascEntryFieldType().getProperty("editor.rows");
if (rowsString!=null && "".equals(rowsString)==false) {
rows = new Integer(rowsString);
}
GC gc = new GC(text);
FontMetrics fm = gc.getFontMetrics ();
gc.dispose ();
int width = cols * fm.getAverageCharWidth();
int height = rows * fm.getHeight();
GridData data = new GridData();
data.widthHint = width;
data.heightHint = height;
text.setLayoutData(data);
Object value = model.getValue();
if (value!=null) {
text.setText(value.toString());
}
text.addModifyListener(new TextListener(model,entry));
return text;
}
class TextListener implements ModifyListener {
private VascValueModel model = null;
private VascEntry entry = null;
public TextListener(VascValueModel model,VascEntry entry) {
this.model=model;
this.entry=entry;
}
public void modifyText(ModifyEvent e) {
Object value = text.getText();
try {
model.setValue(value);
} catch (Exception ee) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry,ee);
}
}
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
*/
@ -76,17 +120,43 @@ public class SwtTextArea implements VascUIComponent {
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
*/
public void setErrorText(String text) {
public void setErrorText(String textString) {
if (text==null) {
return;
}
/*
text.setToolTipText(text);
if (text==null) {
text.setToolTipText(textString);
if (textString==null) {
text.setBackground(orgBackgroundColor);
} else {
text.setBackground(errorColor);
}
*/
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public boolean isDisabled() {
return !text.isEnabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setDisabled(boolean disabled) {
text.setEnabled(!disabled);
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
return text.isVisible();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
text.setVisible(rendered);
}
}

View file

@ -3,6 +3,7 @@
*/
package com.idcanet.vasc.frontends.web.jsf;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@ -10,11 +11,11 @@ import java.util.Map;
* @author willemc
*
*/
public class VascActionBean {
public class VascActionBean implements Serializable {
private String searchString = null;
private Map<String,Object> values = new HashMap<String,Object>(10);
private VascDataBackendBean selected = null;
/**
* @return the searchString
@ -36,4 +37,18 @@ public class VascActionBean {
public Map<String, Object> getValues() {
return values;
}
/**
* @return the selected
*/
public VascDataBackendBean getSelected() {
return selected;
}
/**
* @param selected the selected to set
*/
public void setSelected(VascDataBackendBean selected) {
this.selected = selected;
}
}

View file

@ -0,0 +1,513 @@
/*
* 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.Serializable;
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;
/**
*
*
* @author Willem Cazander
* @version 1.0 May 03, 2009
*/
public class VascDataBackendBean implements Serializable {
private static final long serialVersionUID = 3881688974089760074L;
private VascEntry entry = null;
private Object record = null;
private boolean realValue = false;
public VascDataBackendBean(VascEntry entry,Object record) {
this.entry=entry;
this.record=record;
}
public boolean isRealValue() {
return realValue;
}
public void setRealValue(boolean realValue) {
this.realValue=realValue;
}
static public VascEntryField getFieldIdByIndex(VascEntry entry,int index) {
if (index>entry.getVascEntryFields().size()) {
throw new IllegalArgumentException("Index is bigger then total field size: "+index);
}
return entry.getVascEntryFields().get(index);
}
static public int getIndexId(VascEntryField field) {
int i =0;
for (VascEntryField f:field.getVascEntry().getVascEntryFields()) {
if (f.getId().equals(field.getId())) {
return i;
}
i++;
}
throw new IllegalArgumentException("Could not find field.");
}
private Object getValue(int index) {
try {
VascEntryField field = getFieldIdByIndex(entry,index);
VascEntryFieldValue value = field.getVascEntryFieldValue();
if (isRealValue()) {
return value.getValue(field, record);
}
return value.getDisplayValue(field, record);
} catch (VascException e) {
return "Error: "+e.getMessage();
}
}
private void setValue(int index,Object valueObject) {
try {
VascEntryField field = getFieldIdByIndex(entry,index);
VascEntryFieldValue value = field.getVascEntryFieldValue();
value.setValue(field, record,valueObject);
} catch (VascException e) {
throw new RuntimeException("Could not set value on record.",e);
}
}
public Object getRecord() {
return record;
}
// GET/SET bean methods for using in EL
public Object getField0() {
return getValue(0);
}
public void setField0(Object o) {
setValue(0,o);
}
public Object getField1() {
return getValue(1);
}
public void setField1(Object o) {
setValue(1,o);
}
public Object getField2() {
return getValue(2);
}
public void setField2(Object o) {
setValue(2,o);
}
public Object getField3() {
return getValue(3);
}
public void setField3(Object o) {
setValue(3,o);
}
public Object getField4() {
return getValue(4);
}
public void setField4(Object o) {
setValue(4,o);
}
public Object getField5() {
return getValue(5);
}
public void setField5(Object o) {
setValue(5,o);
}
public Object getField6() {
return getValue(6);
}
public void setField6(Object o) {
setValue(6,o);
}
public Object getField7() {
return getValue(7);
}
public void setField7(Object o) {
setValue(7,o);
}
public Object getField8() {
return getValue(8);
}
public void setField8(Object o) {
setValue(8,o);
}
public Object getField9() {
return getValue(9);
}
public void setField9(Object o) {
setValue(9,o);
}
public Object getField10() {
return getValue(10);
}
public void setField10(Object o) {
setValue(10,o);
}
public Object getField11() {
return getValue(11);
}
public void setField11(Object o) {
setValue(11,o);
}
public Object getField12() {
return getValue(12);
}
public void setField12(Object o) {
setValue(12,o);
}
public Object getField13() {
return getValue(13);
}
public void setField13(Object o) {
setValue(13,o);
}
public Object getField14() {
return getValue(14);
}
public void setField14(Object o) {
setValue(14,o);
}
public Object getField15() {
return getValue(15);
}
public void setField15(Object o) {
setValue(15,o);
}
public Object getField16() {
return getValue(16);
}
public void setField16(Object o) {
setValue(16,o);
}
public Object getField17() {
return getValue(17);
}
public void setField17(Object o) {
setValue(17,o);
}
public Object getField18() {
return getValue(18);
}
public void setField18(Object o) {
setValue(18,o);
}
public Object getField19() {
return getValue(19);
}
public void setField19(Object o) {
setValue(19,o);
}
public Object getField20() {
return getValue(20);
}
public void setField20(Object o) {
setValue(20,o);
}
public Object getField21() {
return getValue(21);
}
public void setField21(Object o) {
setValue(21,o);
}
public Object getField22() {
return getValue(22);
}
public void setField22(Object o) {
setValue(22,o);
}
public Object getField23() {
return getValue(23);
}
public void setField23(Object o) {
setValue(23,o);
}
public Object getField24() {
return getValue(24);
}
public void setField24(Object o) {
setValue(24,o);
}
public Object getField25() {
return getValue(25);
}
public void setField25(Object o) {
setValue(25,o);
}
public Object getField26() {
return getValue(26);
}
public void setField26(Object o) {
setValue(26,o);
}
public Object getField27() {
return getValue(27);
}
public void setField27(Object o) {
setValue(27,o);
}
public Object getField28() {
return getValue(28);
}
public void setField28(Object o) {
setValue(28,o);
}
public Object getField29() {
return getValue(29);
}
public void setField29(Object o) {
setValue(29,o);
}
public Object getField30() {
return getValue(30);
}
public void setField30(Object o) {
setValue(30,o);
}
public Object getField31() {
return getValue(31);
}
public void setField31(Object o) {
setValue(31,o);
}
public Object getField32() {
return getValue(32);
}
public void setField32(Object o) {
setValue(32,o);
}
public Object getField33() {
return getValue(33);
}
public void setField33(Object o) {
setValue(33,o);
}
public Object getField34() {
return getValue(34);
}
public void setField34(Object o) {
setValue(34,o);
}
public Object getField35() {
return getValue(35);
}
public void setField35(Object o) {
setValue(35,o);
}
public Object getField36() {
return getValue(36);
}
public void setField36(Object o) {
setValue(36,o);
}
public Object getField37() {
return getValue(37);
}
public void setField37(Object o) {
setValue(37,o);
}
public Object getField38() {
return getValue(38);
}
public void setField38(Object o) {
setValue(38,o);
}
public Object getField39() {
return getValue(39);
}
public void setField39(Object o) {
setValue(39,o);
}
public Object getField40() {
return getValue(40);
}
public void setField40(Object o) {
setValue(40,o);
}
public Object getField41() {
return getValue(41);
}
public void setField41(Object o) {
setValue(41,o);
}
public Object getField42() {
return getValue(42);
}
public void setField42(Object o) {
setValue(42,o);
}
public Object getField43() {
return getValue(43);
}
public void setField43(Object o) {
setValue(43,o);
}
public Object getField44() {
return getValue(44);
}
public void setField44(Object o) {
setValue(44,o);
}
public Object getField45() {
return getValue(45);
}
public void setField45(Object o) {
setValue(45,o);
}
public Object getField46() {
return getValue(46);
}
public void setField46(Object o) {
setValue(46,o);
}
public Object getField47() {
return getValue(47);
}
public void setField47(Object o) {
setValue(47,o);
}
public Object getField48() {
return getValue(48);
}
public void setField48(Object o) {
setValue(48,o);
}
public Object getField49() {
return getValue(49);
}
public void setField49(Object o) {
setValue(49,o);
}
}

View file

@ -31,6 +31,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FactoryFinder;
import javax.faces.application.ViewExpiredException;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
@ -65,8 +66,6 @@ public class VascRequestFacesFilter implements Filter {
public void destroy() {
}
/**
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
@ -125,19 +124,19 @@ public class VascRequestFacesFilter implements Filter {
}
//log
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO,"entityName="+entityName+" actionName="+actionName+" actionRecordId="+actionRecordId);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,"entityName="+entityName+" actionName="+actionName+" actionRecordId="+actionRecordId);
}
// add to response
request.setAttribute("requestScopeVascEntityName", entityName);
request.setAttribute("requestScopeVascActionName", actionName);
request.setAttribute("requestScopeVascRecordId" , actionRecordId);
request.setAttribute("requestScopeVascPath" , request.getRequestURI());
// 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);
@ -145,14 +144,18 @@ public class VascRequestFacesFilter implements Filter {
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);
try {
request.getRequestDispatcher(templateFile).include(request, response);
} catch (ViewExpiredException e) {
// lets try again
response.sendRedirect(request.getRequestURL().toString());
}
// done
}
private abstract static class ProtectedFacesContext extends FacesContext {
protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) {
FacesContext.setCurrentInstance(facesContext);

View file

@ -0,0 +1,123 @@
/*
* 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.Locale;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
/**
* Fixes the action url
*
* @author Willem Cazander
* @version 1.0 May 05, 2009
*/
public class VascViewHandler extends ViewHandler {
private ViewHandler parentViewHandler = null;
public VascViewHandler(ViewHandler viewHandler) {
super();
this.parentViewHandler = viewHandler;
}
/**
* @see javax.faces.application.ViewHandler#getActionURL(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public String getActionURL(FacesContext context, String name) {
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
if (request.getAttribute("requestScopeVascPath")==null) {
return parentViewHandler.getActionURL(context, name);
}
String path = (String)request.getAttribute("requestScopeVascPath");
return path;
}
/**
* @see javax.faces.application.ViewHandler#calculateLocale(javax.faces.context.FacesContext)
*/
@Override
public Locale calculateLocale(FacesContext context) {
return parentViewHandler.calculateLocale(context);
}
/**
* @see javax.faces.application.ViewHandler#calculateRenderKitId(javax.faces.context.FacesContext)
*/
@Override
public String calculateRenderKitId(FacesContext context) {
return parentViewHandler.calculateRenderKitId(context);
}
/**
* @see javax.faces.application.ViewHandler#createView(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public UIViewRoot createView(FacesContext context, String name) {
return parentViewHandler.createView(context, name);
}
/**
* @see javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public String getResourceURL(FacesContext context, String resource) {
return parentViewHandler.getResourceURL(context, resource);
}
/**
* @see javax.faces.application.ViewHandler#renderView(javax.faces.context.FacesContext, javax.faces.component.UIViewRoot)
*/
@Override
public void renderView(FacesContext context, UIViewRoot viewRoot) throws IOException, FacesException {
parentViewHandler.renderView(context, viewRoot);
}
/**
* @see javax.faces.application.ViewHandler#restoreView(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
public UIViewRoot restoreView(FacesContext context, String name) {
return parentViewHandler.restoreView(context, name);
}
/**
* @see javax.faces.application.ViewHandler#writeState(javax.faces.context.FacesContext)
*/
@Override
public void writeState(FacesContext context) throws IOException {
parentViewHandler.writeState(context);
}
}

View file

@ -0,0 +1,74 @@
/*
* 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.component.UIComponent;
import javax.faces.context.FacesContext;
import com.idcanet.vasc.core.ui.VascUIComponent;
/**
*
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2009
*/
abstract public class AbstractJSFBaseComponent implements VascUIComponent {
protected String componentId = null;
/**
* @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) {
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered()
*/
public boolean isRendered() {
UIComponent component = (UIComponent)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isRendered();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setRendered(boolean)
*/
public void setRendered(boolean rendered) {
// todo: disabled until templates fixes
//UIComponent component = (UIComponent)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
//component.setRendered(rendered);
}
}

View file

@ -34,7 +34,7 @@ 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.VascException;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -44,32 +44,33 @@ 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 {
public class JSFBoolean extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
component = (HtmlSelectBooleanCheckbox)application.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)application.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
if (entryField.getEditReadOnly()) {
component.setDisabled(true);
}
componentId = component.getId();
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public String getErrorText() {
return "";
public boolean isDisabled() {
HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setErrorText(String text) {
public void setDisabled(boolean disabled) {
HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}

View file

@ -34,7 +34,7 @@ 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.VascException;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -44,30 +44,30 @@ import com.idcanet.vasc.core.ui.VascValueModel;
* @author Willem Cazander
* @version 1.0 Mar 25, 2009
*/
public class JSFLabel implements VascUIComponent {
public class JSFLabel extends AbstractJSFBaseComponent {
private HtmlOutputText component = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
component = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
HtmlOutputText component = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
component.setValue(""+model.getValue());
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public String getErrorText() {
return "";
public boolean isDisabled() {
return false;
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setErrorText(String text) {
public void setDisabled(boolean disabled) {
}
}

View file

@ -28,10 +28,11 @@ package com.idcanet.vasc.frontends.web.jsf.ui;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.el.ValueExpression;
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;
@ -40,13 +41,12 @@ 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.VascException;
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;
@ -56,112 +56,147 @@ import com.idcanet.vasc.core.ui.VascValueModel;
* @author Willem Cazander
* @version 1.0 Mar 28, 2009
*/
public class JSFList implements VascUIComponent {
public class JSFList extends AbstractJSFBaseComponent {
private HtmlSelectOneMenu component = null;
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry entry,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
component = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
HtmlSelectOneMenu component = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
if (entryField.getEditReadOnly()) {
component.setDisabled(true);
}
componentId = component.getId();
String id = component.getId();
ValueExpression itemsTestVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItems_"+id+"']}", TestModel.class);
VascSelectItemModel itemModel = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
List<VascSelectItem> items = itemModel.getVascSelectItems(entry);
ValueExpression itemsDisVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItemDis_"+id+"']}", Boolean.class);
itemsDisVE.setValue(FacesContext.getCurrentInstance().getELContext(), false);
String id = entry.getId()+"_"+entryField.getId();
((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).setAttribute(id, items);
component.setConverter(new VascConverter(id));
TestModel t = new TestModel();
t.entryField=entryField;
itemsTestVE.setValue(FacesContext.getCurrentInstance().getELContext(), t);
component.setConverter(new VascConverter(t));
List<SelectItem> value = new ArrayList<SelectItem>(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);
ValueExpression itemsVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItems_"+id+"']}", List.class);
item.setValueExpression("value", itemsVE);
component.getChildren().add(item);
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public String getErrorText() {
return "";
public boolean isDisabled() {
HtmlSelectOneMenu component = (HtmlSelectOneMenu)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
public void setErrorText(String text) {
if (text==null) {
return;
public void setDisabled(boolean disabled) {
HtmlSelectOneMenu component = (HtmlSelectOneMenu)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}
class TestModel extends ArrayList<SelectItem> implements Serializable {
private static final long serialVersionUID = -5266070864271715383L;
public VascEntryField entryField;
private List<VascSelectItem> items;
@Override
public int size() {
if (super.isEmpty()) {
getItems();
}
FacesMessage message = new FacesMessage(text);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(component.getId(),message);
return super.size();
}
@Override
public Iterator<SelectItem> iterator() {
if (super.isEmpty()) {
getItems();
}
return super.iterator();
}
@Override
public boolean isEmpty() {
if (super.isEmpty()) {
getItems();
}
return super.isEmpty();
}
public List<SelectItem> getItems() {
List<SelectItem> value = new ArrayList<SelectItem>(50);
VascSelectItemModel itemModel = (VascSelectItemModel)entryField.getVascEntryFieldType().getDataObject();
try {
items = itemModel.getVascSelectItems(entryField.getVascEntry());
} catch (VascException e) {
e.printStackTrace();
return value;
}
for (VascSelectItem v:items) {
SelectItem si = new SelectItem();
si.setLabel(v.getLabel());
si.setValue(v.getValue());
si.setDisabled(v.isDisabled());
this.add(si);
}
return value;
}
public List<VascSelectItem> getVascItems() {
return items;
}
}
class VascConverter implements Converter,Serializable {
private static final long serialVersionUID = 6198813637409531713L;
private String id = null;
private TestModel testModel = null;
public VascConverter(String id) {
this.id=id;
public VascConverter(TestModel testModel) {
this.testModel=testModel;
}
/**
* 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<VascSelectItem> items = (List<VascSelectItem>)((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getAttribute(id);
for (VascSelectItem v:items) {
//System.out.println("Check: "+value+" key: "+v.getKeyValue());
for (VascSelectItem v:testModel.getVascItems()) {
if (value.equals(v.getKeyValue())) {
//System.out.println("FOUND VALUE");
return v.getValue();
}
}
throw new ConverterException("Could not convert value: "+value);
throw new ConverterException("Could not convert value as object: "+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<VascSelectItem> items = (List<VascSelectItem>)((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getAttribute(id);
for (VascSelectItem v:items) {
//System.out.println("Check: "+value+" key: "+v.getKeyValue());
for (VascSelectItem v:testModel.getVascItems()) {
if (value.equals(v.getValue())) {
//System.out.println("FOUND");
return v.getKeyValue();
}
}
throw new ConverterException("Could not convert value: "+value);
throw new ConverterException("Could not convert value as string: "+value);
}
}

View file

@ -26,16 +26,19 @@
package com.idcanet.vasc.frontends.web.jsf.ui;
import java.io.Serializable;
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 javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -45,42 +48,67 @@ 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 {
public class JSFText extends AbstractJSFBaseComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
component = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
HtmlInputText component = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
componentId = component.getId();
component.setConverter(new VascNullConverter());
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()
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public String getErrorText() {
return "";
public boolean isDisabled() {
HtmlInputText component = (HtmlInputText)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
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);
public void setDisabled(boolean disabled) {
HtmlInputText component = (HtmlInputText)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}
class VascNullConverter implements Converter,Serializable {
private static final long serialVersionUID = 61988136374095313L;
/**
* 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 ""; }
if ((value=value.trim()).length() == 0) { return ""; }
return 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 ""; }
return ""+value;
}
}

View file

@ -27,7 +27,6 @@
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;
@ -35,7 +34,7 @@ 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.VascException;
import com.idcanet.vasc.core.ui.VascValueModel;
@ -45,18 +44,15 @@ import com.idcanet.vasc.core.ui.VascValueModel;
* @author Willem Cazander
* @version 1.0 Mar 25, 2009
*/
public class JSFTextArea implements VascUIComponent {
public class JSFTextArea extends AbstractJSFBaseComponent {
private HtmlInputTextarea component = null;
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws Exception {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
component = (HtmlInputTextarea)application.createComponent(HtmlInputTextarea.COMPONENT_TYPE);
HtmlInputTextarea component = (HtmlInputTextarea)application.createComponent(HtmlInputTextarea.COMPONENT_TYPE);
component.setId(viewRoot.createUniqueId());
if (entryField.getEditReadOnly()) {
component.setDisabled(true);
}
componentId = component.getId();
String cols = entryField.getVascEntryFieldType().getProperty("editor.columns");
if (cols!=null && "".equals(cols)==false) {
component.setCols(new Integer(cols));
@ -68,23 +64,21 @@ public class JSFTextArea implements VascUIComponent {
((UIComponent)gui).getChildren().add(component);
return component;
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#getErrorText()
* @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled()
*/
public String getErrorText() {
return "";
public boolean isDisabled() {
HtmlInputTextarea component = (HtmlInputTextarea)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
return component.isDisabled();
}
/**
* @see com.idcanet.vasc.core.ui.VascUIComponent#setErrorText(java.lang.String)
* @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean)
*/
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);
public void setDisabled(boolean disabled) {
HtmlInputTextarea component = (HtmlInputTextarea)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId);
component.setDisabled(disabled);
}
}

View file

@ -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.actions.VascAction;
/**
* Checks for minimal needed stuff
@ -55,43 +56,40 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
public VascEntry finalizeVascEntry(VascEntry entry,VascController vascController) throws VascException {
// First Check if we all have ids
if (entry.getId()==null) {
String id = entry.getId();
if (id==null) {
throw new IllegalArgumentException("The VascEntry need an id.");
}
if (entry.getBackendId()==null) {
throw new IllegalArgumentException("The VascEntry need an backendId.");
throw new IllegalArgumentException("The VascEntry need an backendId in entryId: "+id);
}
if (entry.getVascEntryFields().size()==0) {
throw new IllegalArgumentException("We need at least one VascEntryField.");
throw new IllegalArgumentException("We need at least one VascEntryField in entryId: "+id);
}
for (VascEntryField vef:entry.getVascEntryFields()) {
if (vef.getId()==null) {
throw new IllegalArgumentException("All VascEntryField need an id");
throw new IllegalArgumentException("All VascEntryField need an id in entryId: "+id);
}
}
for (VascEntryField vef:entry.getListOptions()) {
if (vef.getId()==null) {
throw new IllegalArgumentException("All listOption VascEntryField to have an id in entryId: "+id);
}
}
// Check if backendId is valid
VascBackend back = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() );
if (back==null) {
throw new IllegalArgumentException("The VascEntry backendId is not found in backends: '"+entry.getBackendId()+"'");
throw new IllegalArgumentException("The VascEntry backendId is not found in backends: '"+entry.getBackendId()+"' in entryId: "+id);
}
// Fill up all not field i18n keys
String id = entry.getId();
// header
if (entry.getHeaderName()==null) {
entry.setHeaderName("vasc.entry."+id+".headerName");
}
if (entry.getHeaderDescription()==null) {
entry.setHeaderDescription("vasc.entry."+id+".headerDescription");
}
if (entry.getHeaderImage()==null) {
entry.setHeaderImage("vasc.entry."+id+".headerImage");
}
// Fill up all not field i18n keys
// entry fields
if (entry.getName()==null) {
entry.setName("vasc.entry."+id+".name");
}
if (entry.getImage()==null) {
entry.setImage("vasc.entry."+id+".image");
}
@ -99,19 +97,44 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
entry.setHelpId("vasc.entry."+id+".helpId");
}
if (entry.getListDescription()==null) {
entry.setListDescription("vasc.entry."+id+".listDescription");
}
if (entry.getListImage()==null) {
entry.setListImage("vasc.entry."+id+".listImage");
}
if (entry.getEditDescription()==null) {
entry.setEditDescription("vasc.entry."+id+".editDescription");
}
if (entry.getEditImage()==null) {
entry.setEditImage("vasc.entry."+id+".editImage");
}
if (entry.getDeleteDescription()==null) {
entry.setDeleteDescription("vasc.entry."+id+".deleteDescription");
}
if (entry.getDeleteImage()==null) {
entry.setDeleteImage("vasc.entry."+id+".deleteImage");
}
if (entry.getCreateDescription()==null) {
entry.setCreateDescription("vasc.entry."+id+".createDescription");
}
if (entry.getCreateImage()==null) {
entry.setCreateImage("vasc.entry."+id+".createImage");
}
// optional field sets
for (VascEntryFieldSet s:entry.getVascEntryFieldSets()) {
// check id
String sid = s.getId();
if (sid==null) {
throw new IllegalArgumentException("All VascEntryFieldSet need an id");
throw new IllegalArgumentException("All VascEntryFieldSet need an id in entryId: "+id);
}
// check if refenced ids are avalible
for (String fid:s.getVascEntryFieldIds()) {
if (entry.getVascEntryFieldById(fid)==null) {
throw new IllegalArgumentException("VascEntryFieldSet "+sid+" has non excisting field id: "+fid);
throw new IllegalArgumentException("VascEntryFieldSet "+sid+" has non excisting field id: "+fid+" in entryId: "+id);
}
}
@ -188,6 +211,19 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
//if (vef.getDefaultValue()==null) {
// vef.setDefaultValue("vasc.entry."+id+"."+vid+".defaultValue");
//}
if (vef.getView()==null) {
vef.setView(true);
}
if (vef.getList()==null) {
vef.setList(true);
}
if (vef.getEdit()==null) {
vef.setEdit(true);
}
if (vef.getEditReadOnly()==null) {
vef.setEditReadOnly(true);
}
if (vef.getVascEntryFieldValue()==null) {
VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() );
@ -233,6 +269,10 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
}
index++;
}
if (index==entry.getVascEntryFields().size()) {
// no primarry key found selecting the first field.
index=0;
}
VascEntryField idField = entry.getVascEntryFields().remove(index);
entry.getVascEntryFields().add(0, idField);
@ -242,12 +282,124 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
// check id
String vid = vle.getId();
if (vid==null) {
throw new IllegalArgumentException("All VascLinkEntry need an id");
throw new IllegalArgumentException("All VascLinkEntry need an id in entryId: "+id);
}
}
for (VascEntryField vef:entry.getListOptions()) {
String vid = vef.getId();
// set manual stuff
if (vef.getBackendName()==null) {
vef.setBackendName(vid);
}
if (vef.getVascEntry()==null) {
vef.setVascEntry(entry);
}
if (vef.getOrderIndex()==null) {
vef.setOrderIndex(orderIndex);
}
orderIndex = orderIndex+100;
// fill up properties
if (vef.getName()==null) {
vef.setName("vasc.entry."+id+"."+vid+".name");
}
if (vef.getDescription()==null) {
vef.setDescription("vasc.entry."+id+"."+vid+".description");
}
if (vef.getImage()==null) {
vef.setImage("vasc.entry."+id+"."+vid+".image");
}
if (vef.getHelpId()==null) {
vef.setHelpId("vasc.entry."+id+"."+vid+".helpId");
}
if (vef.getStyleEdit()==null) {
vef.setStyleEdit("vasc.entry."+id+"."+vid+".styleEdit");
}
if (vef.getStyleList()==null) {
vef.setStyleList("vasc.entry."+id+"."+vid+".styleEdit");
}
//if (vef.getDefaultValue()==null) {
// vef.setDefaultValue("vasc.entry."+id+"."+vid+".defaultValue");
//}
if (vef.getView()==null) {
vef.setView(true);
}
if (vef.getList()==null) {
vef.setList(true);
}
if (vef.getEdit()==null) {
vef.setEdit(true);
}
if (vef.getEditReadOnly()==null) {
vef.setEditReadOnly(true);
}
if (vef.getVascEntryFieldValue()==null) {
//VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() );
//vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef));
}
}
// ..
for (VascAction action:entry.getGlobalActions()) {
String aid = action.getId();
if (aid==null) {
throw new IllegalArgumentException("Action has no id: "+action+" in entryId: "+id);
}
if (action.getName()==null) {
action.setName("vasc.action."+aid+".name");
}
if (action.getDescription()==null) {
action.setDescription("vasc.action."+aid+".description");
}
if (action.getImage()==null) {
action.setImage("vasc.action."+aid+".image");
}
if (action.getHelpId()==null) {
action.setHelpId("vasc.action."+aid+".helpId");
}
}
for (VascAction action:entry.getRowActions()) {
String aid = action.getId();
if (aid==null) {
throw new IllegalArgumentException("Action has no id: "+action+" in entryId: "+id);
}
if (action.getName()==null) {
action.setName("vasc.action."+aid+".name");
}
if (action.getDescription()==null) {
action.setDescription("vasc.action."+aid+".description");
}
if (action.getImage()==null) {
action.setImage("vasc.action."+aid+".image");
}
if (action.getHelpId()==null) {
action.setHelpId("vasc.action."+aid+".helpId");
}
}
for (VascAction action:entry.getColumnActions()) {
String aid = action.getId();
if (aid==null) {
throw new IllegalArgumentException("Action has no id: "+action+" in entryId: "+id);
}
if (action.getName()==null) {
action.setName("vasc.action."+aid+".name");
}
if (action.getDescription()==null) {
action.setDescription("vasc.action."+aid+".description");
}
if (action.getImage()==null) {
action.setImage("vasc.action."+aid+".image");
}
if (action.getHelpId()==null) {
action.setHelpId("vasc.action."+aid+".helpId");
}
}
return entry;
@ -255,4 +407,4 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
}
}

View file

@ -0,0 +1,39 @@
/*
* 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 com.idcanet.vasc.core.AbstractVascBackendState;
/**
*
*
* @author Willem Cazander
* @version 1.0 May 26, 2009
*/
public class DefaultVascBackendState extends AbstractVascBackendState {
private static final long serialVersionUID = 1L;
}

View file

@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.VascBackendFilter;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascEntryFieldSet;
@ -40,6 +41,7 @@ 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.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel;
/**
@ -51,14 +53,19 @@ import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel;
public class DefaultVascEntry implements VascEntry {
private String id = null;
private String name = null;
private String helpId = null;
private String image = null;
private String headerName = null;
private String headerImage = null;
private String headerDescription = null;
private String listDescription = null;
private String listImage = null;
private String editDescription = null;
private String editImage = null;
private String deleteDescription = null;
private String deleteImage = null;
private String createDescription = null;
private String createImage = null;
private String primaryKeyFieldId = null;
private String displayNameFieldId = null;
@ -78,6 +85,9 @@ public class DefaultVascEntry implements VascEntry {
private List<VascLinkEntry> vascLinkEntries = null;
private Map<String,Object> entryParameters = null;
private VascEntryFieldEventChannel vascEntryFieldEventChannel = null;
private Map<VascEntryEventListener.VascEventType,List<VascEntryEventListener>> eventListeners = null;
private List<VascEntryField> listOptions = null;
private List<VascBackendFilter> backendFilters = null;
private String backendId = null;
private VascFrontendData vascFrontendData = null;
@ -86,7 +96,7 @@ public class DefaultVascEntry implements VascEntry {
* Te constructor
*/
public DefaultVascEntry() {
vascFields = new ArrayList<VascEntryField>(10);
vascFields = new ArrayList<VascEntryField>(20);
rowActions = new ArrayList<RowVascAction>(10);
columnActions = new ArrayList<ColumnVascAction>(10);
@ -94,7 +104,11 @@ public class DefaultVascEntry implements VascEntry {
vascEntryFieldSets = new ArrayList<VascEntryFieldSet>(10);
vascLinkEntries = new ArrayList<VascLinkEntry>(10);
entryParameters = new HashMap<String,Object>();
entryParameters = new HashMap<String,Object>(10);
eventListeners = new HashMap<VascEntryEventListener.VascEventType,List<VascEntryEventListener>>(3);
listOptions = new ArrayList<VascEntryField>(5);
backendFilters = new ArrayList<VascBackendFilter>(3);
}
/**
@ -105,11 +119,17 @@ public class DefaultVascEntry implements VascEntry {
DefaultVascEntry result = new DefaultVascEntry();
result.id=id;
result.name=name;
result.helpId=helpId;
result.image=image;
result.headerName=headerName;
result.headerDescription=headerDescription;
result.headerImage=headerImage;
result.listDescription=listDescription;
result.listImage=listImage;
result.editDescription=editDescription;
result.editImage=editImage;
result.deleteDescription=deleteDescription;
result.deleteImage=deleteImage;
result.createDescription=createDescription;
result.createImage=createImage;
result.primaryKeyFieldId=primaryKeyFieldId;
result.displayNameFieldId=displayNameFieldId;
result.vascDisplayOnly=vascDisplayOnly;
@ -141,6 +161,23 @@ public class DefaultVascEntry implements VascEntry {
for (VascLinkEntry l:vascLinkEntries) {
result.vascLinkEntries.add(l.clone());
}
for (VascEntryEventListener.VascEventType type:eventListeners.keySet()) {
List<VascEntryEventListener> lists = eventListeners.get(type);
for (VascEntryEventListener e:lists) {
VascEntryEventListener listener = e.clone();
result.addVascEntryEventListener(type, listener);
}
}
for (VascEntryField listOption:listOptions) {
VascEntryField ff = listOption.clone();
ff.setVascEntry(result);
result.listOptions.add(ff);
}
for (VascBackendFilter f:backendFilters) {
VascBackendFilter ff = f.clone();
result.backendFilters.add(ff);
}
// no cloning of the values here ?
for (String key:entryParameters.keySet()) {
@ -167,6 +204,20 @@ 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 helpId
*/
@ -194,49 +245,119 @@ public class DefaultVascEntry implements VascEntry {
public void setImage(String image) {
this.image = image;
}
/**
* @return the headerName
* @return the listDescription
*/
public String getHeaderName() {
return headerName;
public String getListDescription() {
return listDescription;
}
/**
* @param headerName the headerName to set
* @param listDescription the listDescription to set
*/
public void setHeaderName(String headerName) {
this.headerName = headerName;
public void setListDescription(String listDescription) {
this.listDescription = listDescription;
}
/**
* @return the headerImage
* @return the listImage
*/
public String getHeaderImage() {
return headerImage;
public String getListImage() {
return listImage;
}
/**
* @param headerImage the headerImage to set
* @param listImage the listImage to set
*/
public void setHeaderImage(String headerImage) {
this.headerImage = headerImage;
public void setListImage(String listImage) {
this.listImage = listImage;
}
/**
* @return the headerDescription
* @return the editDescription
*/
public String getHeaderDescription() {
return headerDescription;
public String getEditDescription() {
return editDescription;
}
/**
* @param headerDescription the headerDescription to set
* @param editDescription the editDescription to set
*/
public void setHeaderDescription(String headerDescription) {
this.headerDescription = headerDescription;
public void setEditDescription(String editDescription) {
this.editDescription = editDescription;
}
/**
* @return the editImage
*/
public String getEditImage() {
return editImage;
}
/**
* @param editImage the editImage to set
*/
public void setEditImage(String editImage) {
this.editImage = editImage;
}
/**
* @return the deleteDescription
*/
public String getDeleteDescription() {
return deleteDescription;
}
/**
* @param deleteDescription the deleteDescription to set
*/
public void setDeleteDescription(String deleteDescription) {
this.deleteDescription = deleteDescription;
}
/**
* @return the deleteImage
*/
public String getDeleteImage() {
return deleteImage;
}
/**
* @param deleteImage the deleteImage to set
*/
public void setDeleteImage(String deleteImage) {
this.deleteImage = deleteImage;
}
/**
* @return the createDescription
*/
public String getCreateDescription() {
return createDescription;
}
/**
* @param createDescription the createDescription to set
*/
public void setCreateDescription(String createDescription) {
this.createDescription = createDescription;
}
/**
* @return the createImage
*/
public String getCreateImage() {
return createImage;
}
/**
* @param createImage the createImage to set
*/
public void setCreateImage(String createImage) {
this.createImage = createImage;
}
/**
* @return the primaryKeyFieldId
*/
@ -361,6 +482,18 @@ public class DefaultVascEntry implements VascEntry {
return rowActions;
}
/**
* @return the RowVascAction
*/
public RowVascAction getRowActionById(String actionId) {
for (RowVascAction a:rowActions) {
if (a.getId().equals(actionId)) {
return a;
}
}
return null;
}
/**
* @param rowAction the rowAction to add
*/
@ -382,6 +515,18 @@ public class DefaultVascEntry implements VascEntry {
return columnActions;
}
/**
* @return the ColumnVascAction
*/
public ColumnVascAction getColumnActionById(String actionId) {
for (ColumnVascAction a:columnActions) {
if (a.getId().equals(actionId)) {
return a;
}
}
return null;
}
/**
* @param columnAction the columnActions to add
*/
@ -403,6 +548,18 @@ public class DefaultVascEntry implements VascEntry {
return globalActions;
}
/**
* @return the GlobalVascAction
*/
public GlobalVascAction getGlobalActionById(String actionId) {
for (GlobalVascAction a:globalActions) {
if (a.getId().equals(actionId)) {
return a;
}
}
return null;
}
/**
* @param globalAction the globalAction to add
*/
@ -424,6 +581,18 @@ public class DefaultVascEntry implements VascEntry {
return vascEntryFieldSets;
}
/**
* @return the VascEntryFieldSet
*/
public VascEntryFieldSet getVascEntryFieldSetById(String fieldSetId) {
for (VascEntryFieldSet a:vascEntryFieldSets) {
if (a.getId().equals(fieldSetId)) {
return a;
}
}
return null;
}
/**
* @param vascEntryFieldSet the vascEntryFieldSet to add
*/
@ -445,6 +614,18 @@ public class DefaultVascEntry implements VascEntry {
return vascLinkEntries;
}
/**
* @return the VascLinkEntry
*/
public VascLinkEntry getVascLinkEntryById(String linkId) {
for (VascLinkEntry a:vascLinkEntries) {
if (a.getId().equals(linkId)) {
return a;
}
}
return null;
}
/**
* @param vascLinkEntry the vascLinkEntry to set
*/
@ -535,4 +716,51 @@ public class DefaultVascEntry implements VascEntry {
public void setVascEntryFieldEventChannel(VascEntryFieldEventChannel vascEntryFieldEventChannel) {
this.vascEntryFieldEventChannel = vascEntryFieldEventChannel;
}
/**
* Added an VascEntryEventListener
* @param type
* @param listener
*/
public void addVascEntryEventListener(VascEntryEventListener.VascEventType type,VascEntryEventListener listener) {
List<VascEntryEventListener> result = eventListeners.get(type);
if (result==null) {
result = new ArrayList<VascEntryEventListener>(3);
eventListeners.put(type,result);
}
result.add(listener);
}
/**
* Returns the list of VascEntryEventListener for a speciec type.
* @param type
* @return
*/
public List<VascEntryEventListener> getVascEntryEventListeners(VascEntryEventListener.VascEventType type) {
List<VascEntryEventListener> result = eventListeners.get(type);
if (result!=null) {
return result;
}
return new ArrayList<VascEntryEventListener>(0);
}
public void addListOption(VascEntryField listOption) {
if (listOption==null) {
throw new NullPointerException("can not add null listOption.");
}
listOptions.add(listOption);
}
public List<VascEntryField> getListOptions() {
return listOptions;
}
public void addVascBackendFilter(VascBackendFilter filter) {
backendFilters.add(filter);
}
public List<VascBackendFilter> getVascBackendFilters() {
return backendFilters;
}
}

View file

@ -62,6 +62,9 @@ public class DefaultVascEntryController implements VascEntryControllerLocal {
*/
public VascEntry getVascEntryById(String id) {
VascEntry entry = entries.get(id);
if (entry==null) {
throw new NullPointerException("Could not find vasc entry with id: "+id);
}
try {
return entry.clone();
} catch (CloneNotSupportedException e) {

View file

@ -139,7 +139,9 @@ public class DefaultVascEntryField implements VascEntryField {
result.vascEntryFieldValue=vascEntryFieldValue;
result.vascValidators.addAll(vascValidators);
for (VascValidator val:vascValidators) {
result.vascValidators.add(val.clone());
}
return result;
}

View file

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.VascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascController;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascEntryFinalizer;
@ -39,6 +40,9 @@ import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.VascFrontend;
import com.idcanet.vasc.core.VascFrontendData;
import com.idcanet.vasc.core.VascFrontendHelper;
import com.idcanet.vasc.core.entry.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService;
import com.idcanet.vasc.core.entry.VascEntryResourceImageResolver;
import com.idcanet.vasc.core.entry.VascEntryResourceResolver;
import com.idcanet.vasc.core.ui.VascUIComponent;
@ -54,14 +58,20 @@ public class DefaultVascFrontendData implements VascFrontendData {
private Object entryDataObject = null;
private VascFrontend vascFrontend = null;
private VascBackend vascBackend = null;
private VascBackendState vascBackendState = null;
private VascEntryFinalizer vascEntryFinalizer = null;
private VascFrontendHelper vascFrontendHelper = null;
private VascEntryResourceResolver vascEntryResourceResolver = null;
private VascEntryResourceImageResolver vascEntryResourceImageResolver = null;
private Map<String,String> uiComponents = null;
private VascController vascController = null;
private VascEntryEventListener exceptionListener = null;
private boolean isEditCreate = false;
private Long totalBackendRecords = null;
private Map<VascEntryField,VascUIComponent> fieldComps = null;
private Map<VascEntryField,Object> fieldEditors = null;
private List<VascEntryFieldValidatorService> validatorServices = null;
public DefaultVascFrontendData() {
entryDataList = new ArrayList<Object>(0);
@ -69,6 +79,7 @@ public class DefaultVascFrontendData implements VascFrontendData {
fieldComps = new HashMap<VascEntryField,VascUIComponent>(8);
fieldEditors = new HashMap<VascEntryField,Object>(8);
validatorServices = new ArrayList<VascEntryFieldValidatorService>(4);
}
/**
@ -214,6 +225,11 @@ public class DefaultVascFrontendData implements VascFrontendData {
fieldEditors.put(field, editor);
}
public void clearFieldRenderObjects() {
fieldComps.clear();
fieldEditors.clear();
}
/**
* @see com.idcanet.vasc.core.VascFrontendData#getFieldRealRenderer(com.idcanet.vasc.core.VascEntryField)
*/
@ -241,4 +257,88 @@ public class DefaultVascFrontendData implements VascFrontendData {
public void setVascBackend(VascBackend vascBackend) {
this.vascBackend = vascBackend;
}
/**
* @return the exceptionListener
*/
public VascEntryEventListener getExceptionListener() {
return exceptionListener;
}
/**
* @param exceptionListener the exceptionListener to set
*/
public void setExceptionListener(VascEntryEventListener exceptionListener) {
this.exceptionListener = exceptionListener;
}
/**
* @return the vascEntryResourceImageResolver
*/
public VascEntryResourceImageResolver getVascEntryResourceImageResolver() {
return vascEntryResourceImageResolver;
}
/**
* @param vascEntryResourceImageResolver the vascEntryResourceImageResolver to set
*/
public void setVascEntryResourceImageResolver(VascEntryResourceImageResolver vascEntryResourceImageResolver) {
this.vascEntryResourceImageResolver = vascEntryResourceImageResolver;
}
/**
* @see com.idcanet.vasc.core.VascFrontendData#addVascValidatorService(com.idcanet.vasc.core.entry.VascEntryFieldValidatorService)
*/
public void addVascValidatorService(VascEntryFieldValidatorService validatorService) {
validatorServices.add(validatorService);
}
/**
* @see com.idcanet.vasc.core.VascFrontendData#getVascValidatorServices()
*/
public List<VascEntryFieldValidatorService> getVascValidatorServices() {
return validatorServices;
}
/**
* @return the isEditCreate
*/
public boolean isEditCreate() {
return isEditCreate;
}
/**
* @param isEditCreate the isEditCreate to set
*/
public void setEditCreate(boolean isEditCreate) {
this.isEditCreate = isEditCreate;
}
/**
* @return the vascBackendState
*/
public VascBackendState getVascBackendState() {
return vascBackendState;
}
/**
* @param vascBackendState the vascBackendState to set
*/
public void setVascBackendState(VascBackendState vascBackendState) {
this.vascBackendState = vascBackendState;
}
/**
* @return the totalBackendRecords
*/
public Long getTotalBackendRecords() {
return totalBackendRecords;
}
/**
* @param totalBackendRecords the totalBackendRecords to set
*/
public void setTotalBackendRecords(Long totalBackendRecords) {
this.totalBackendRecords = totalBackendRecords;
}
}

View file

@ -26,20 +26,24 @@
package com.idcanet.vasc.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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.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.VascEntryFieldValidatorService;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
import com.idcanet.vasc.core.ui.VascUIComponent;
import com.idcanet.vasc.validators.VascValidator;
/**
*
@ -48,16 +52,8 @@ import com.idcanet.vasc.validators.VascValidator;
*/
public class DefaultVascFrontendHelper implements VascFrontendHelper {
private Logger logger = null;
//private List<VascEventListener> eventListeners = null;
//private List<VascExceptionListener> exceptionListeners = null;
private Logger logger = Logger.getLogger(DefaultVascFrontendHelper.class.getName());
public DefaultVascFrontendHelper() {
logger = Logger.getLogger(DefaultVascFrontendHelper.class.getName());
//eventListeners = new ArrayList<VascEventListener>(2);
//exceptionListeners = new ArrayList<VascExceptionListener>(2);
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#renderView(com.idcanet.vasc.core.VascEntryField)
*/
@ -92,6 +88,11 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper {
if (renderView(field)==false) {
return false;
}
if (field.getVascEntry().getVascFrontendData().isEditCreate()) {
if (renderCreate(field)==false) {
return false;
}
}
VascUserRoleController u = field.getVascEntry().getVascFrontendData().getVascController().getVascUserRoleControllerResolver().getVascUserRoleController();
if (field.getRolesEdit()!=null && u.hasRole(field.getRolesEdit())) {
return true;
@ -150,24 +151,14 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper {
return true;
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#addEventListener(com.idcanet.vasc.core.entry.VascEntryEventListener)
*/
public void addEventListener(VascEntryEventListener e) {
// TODO Auto-generated method stub
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#addExceptionListener(com.idcanet.vasc.core.entry.VascEntryEventListener)
*/
public void addExceptionListener(VascEntryEventListener listener) {
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#fireVascEvent(com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType, java.lang.Object)
*/
public void fireVascEvent(VascEventType type, Object data) {
public void fireVascEvent(VascEntry entry,VascEventType type, Object data) {
List<VascEntryEventListener> list = entry.getVascEntryEventListeners(type);
for (VascEntryEventListener l:list) {
l.vascEvent(entry, type, data);
}
}
/**
@ -177,7 +168,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper {
int result = 0;
for(VascEntryField c:entry.getVascEntryFields()) {
if(c.getSizeList()==null) {
Logger.getLogger(VascEntry.class.getName()).finer("Column no size: "+c.getName());
logger.finer("Column no size: "+c.getName());
} else {
result+=c.getSizeList();
}
@ -186,193 +177,310 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper {
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#handleException(java.lang.Exception, com.idcanet.vasc.core.VascEntry)
* Returns the total amount of pages
* @return
*/
public void handleException(Exception e, VascEntry table) {
e.printStackTrace();
/*
if (exceptionListeners.isEmpty()) {
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,e.getMessage(),e);
return;
public List<VascBackendPageNumber> getVascBackendPageNumbers(VascEntry entry) {
List<VascBackendPageNumber> result = new ArrayList<VascBackendPageNumber>(30);
VascBackendState state = entry.getVascFrontendData().getVascBackendState();
if (state.getPageSize()==0) {
return result; // paging disabled
}
for(VascExceptionListener ee:exceptionListeners) {
try {
ee.handleException(e, table);
} catch (Exception eee) {
Logger.getLogger(DefaultVascTableController.class.getName()).log(Level.WARNING,"Error in ExceptionListener: "+eee.getMessage(),eee);
Long total = entry.getVascFrontendData().getTotalBackendRecords();
if (total==null) {
return result; // no pages
}
int pages = new Long(total/state.getPageSize()).intValue();
int counter = 0;
for (int i=0;i<=pages;i++) {
VascBackendPageNumber pn = new VascBackendPageNumber(i);
if (state.getPageIndex()==i) {
pn.setSelected(true);
}
result.add(pn);
counter++;
if (counter>45) {
break;
}
}
*/
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#initEditObject(com.idcanet.vasc.core.VascEntry, java.lang.Object)
*/
public Object initEditObject(VascEntry entry, Object object) throws Exception {
if (object!=null) {
return object;
}
object = entry.getVascFrontendData().getVascBackend().provideVascEntryRecordCreator(entry).newRecord(entry);
//fireVascEvent(VascEventListener.VascEventType.BEAN_INIT, object);
return object;
return result;
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#handleException(com.idcanet.vasc.core.VascEntry,java.lang.Exception)
*/
public void handleException(VascEntry entry,Exception exception) {
VascEntryEventListener listener = entry.getVascFrontendData().getExceptionListener();
if (listener==null) {
logger.log(Level.WARNING,exception.getMessage(),exception);
}
try {
listener.vascEvent(entry,VascEventType.EXCEPTION , exception);
} catch (Exception eee) {
logger.log(Level.WARNING,"Error in ExceptionListener: "+eee.getMessage(),eee);
}
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#initEditObjectColumn(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
* @see com.idcanet.vasc.core.VascFrontendHelper#initEditObject(com.idcanet.vasc.core.VascEntry)
*/
public void initEditObjectColumn(VascEntryField field, Object bean) throws Exception {
Object value = field.getVascEntryFieldValue().getValue(field, bean);
if(value==null & field.getDefaultValue()!=null) {
try {
logger.finer("Setting default value for: "+field.getName()+" def: "+field.getDefaultValue());
field.getVascEntryFieldValue().setValue(field, bean, field.getDefaultValue());
} catch (Exception e) {
logger.log(Level.WARNING,"Error in setting default value: '"+field.getDefaultValue()+"' error: "+e.getMessage(),e);
}
}
public Object createObject(VascEntry entry) {
try {
Object object = entry.getVascFrontendData().getVascBackend().provideVascEntryRecordCreator(entry).newRecord(entry);
for (VascEntryField field:entry.getVascEntryFields()) {
Object value = field.getVascEntryFieldValue().getValue(field, object);
if (value==null & field.getDefaultValue()!=null) {
logger.finer("Setting default value for: "+field.getName()+" def: "+field.getDefaultValue());
field.getVascEntryFieldValue().setValue(field, object, field.getDefaultValue());
}
}
fireVascEvent(entry,VascEventType.DATA_CREATE, object);
return object;
} catch (Exception e) {
handleException(entry,e);
return null; /// ?? ,,
}
}
protected int removeObjectFromDataList(VascEntry entry,Object object) {
int indexOld = entry.getVascFrontendData().getEntryDataList().indexOf(object);
if (entry.getVascFrontendData().getEntryDataList().remove(object)) {
return indexOld; // java worked well for use
}
// remove only work on (jpa)beans with an overrided equals method.
// we lets do the search ourselfs here because we should know the primary key value
try {
VascEntryField field = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId());
Object idObject = field.getVascEntryFieldValue().getValue(field, object);
// is only null when creating objects
if (idObject!=null) {
int index = 0;
for (Object o:entry.getVascFrontendData().getEntryDataList()) {
field = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId());
Object id = field.getVascEntryFieldValue().getValue(field, o);
if (idObject.equals(id)) {
break;
}
index++;
}
if (index<entry.getVascFrontendData().getEntryDataList().size()) {
entry.getVascFrontendData().getEntryDataList().remove(index);
return index;
}
}
} catch (VascException e) {
handleException(entry,e);
}
return 0; // make better (0=top of list)
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#mergeObject(com.idcanet.vasc.core.VascEntry, java.lang.Object)
* @see com.idcanet.vasc.core.VascFrontendHelper#mergeObject(com.idcanet.vasc.core.VascEntry)
*/
public Object mergeObject(VascEntry entry, Object object) {
public Object mergeObject(VascEntry entry) {
Object object = entry.getVascFrontendData().getEntryDataObject();
Object result = null;
try {
object = entry.getVascFrontendData().getVascBackend().merge(object);
//fireVascEvent(VascEventListener.VascEventType.BEAN_MERGE,object);
// todo: make faster
// add to table at position old old object
// then remove old object
// send refresh
refreshData(entry);
fireVascEvent(entry,VascEventType.DATA_PRE_UPDATE,object);
int index = removeObjectFromDataList(entry,object);
result = entry.getVascFrontendData().getVascBackend().merge(object);
entry.getVascFrontendData().getEntryDataList().add(index, result);
entry.getVascFrontendData().setEntryDataObject(null);
fireVascEvent(entry,VascEventType.DATA_POST_UPDATE,result);
fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE, object);
} catch (Exception e) {
handleException(e, entry);
handleException(entry,e);
}
return result;
}
/**
* Deletes the selected row object from the list and fires event.
* @param entry
* @param object
*/
public void deleteObject(VascEntry entry) {
Object object = entry.getVascFrontendData().getEntryDataObject();
try {
entry.getVascFrontendData().getVascBackend().delete(object);
} catch (Exception e) {
handleException(entry,e);
}
removeObjectFromDataList(entry,object);
entry.getVascFrontendData().setEntryDataObject(null);
fireVascEvent(entry,VascEventType.DATA_DELETE, object);
fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE, object);
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#refreshData(com.idcanet.vasc.core.VascEntry)
*/
public void refreshData(VascEntry entry) throws Exception {
public void refreshData(VascEntry entry) {
entry.getVascFrontendData().setEntryDataObject(null);
entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascBackend().execute());
//fireVascEvent(VascEventListener.VascEventType.DATA_UPDATE, null);
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#removeEventListener(com.idcanet.vasc.core.entry.VascEntryEventListener)
*/
public void removeEventListener(VascEntryEventListener e) {
// TODO Auto-generated method stub
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#removeExceptionListener(com.idcanet.vasc.core.entry.VascEntryEventListener)
*/
public void removeExceptionListener(VascEntryEventListener listener) {
// TODO Auto-generated method stub
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#setUIComponentsBeanErrors(com.idcanet.vasc.core.VascEntry, java.lang.Object)
*/
public boolean setUIComponentsBeanErrors(VascEntry entry, Object bean) {
boolean error = false;
if (bean==null) {
logger.finest("No bean to check.");
return true; // nothing to check
}
//ClassValidator val = new ClassValidator(bean.getClass());
//InvalidValue[] ival = val.getInvalidValues(bean);
//logger.fine("Got invaliled value: "+ival.length);
for (VascEntryField col:entry.getVascEntryFields()) {
try {
Object object = col.getVascEntryFieldValue().getValue(col, bean);
VascUIComponent comp = entry.getVascFrontendData().getFieldVascUIComponent(col);
for (VascValidator val:col.getVascEntryFieldType().getVascValidators()) {
if (val.isObjectValid(object)==false) {
comp.setErrorText("error");
error = true;
} else {
comp.setErrorText(null);
}
}
for (VascValidator val:col.getVascValidators()) {
if (val.isObjectValid(object)==false) {
comp.setErrorText("error");
error = true;
} else {
comp.setErrorText(null);
}
}
} catch (Exception e) {
e.printStackTrace();
}
/*
if(col.getVascUIComponent()==null) {
continue; // we only DISPLAY user input errors !!
}
if (col instanceof VascAnnotationTableColumn) {
VascAnnotationTableColumn column = (VascAnnotationTableColumn)col;
try {
for (String key:entry.getEntryParameterKeys()) {
Object value = entry.getEntryParameter(key);
entry.getVascFrontendData().getVascBackendState().setDataParameter(key, value);
}
entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascBackend().execute(entry.getVascFrontendData().getVascBackendState()));
InvalidValue iv = findInvalidValueByProperty(ival,column.getBeanProperty());
if(iv==null) {
column.getVascUIComponent().setErrorText(null);
continue; // no error on this property
}
error = true;
column.getVascUIComponent().setErrorText(iv.getMessage());
Long total = entry.getVascFrontendData().getTotalBackendRecords();
if (total==null) {
// fetch on first time.
total = entry.getVascFrontendData().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascBackendState());
entry.getVascFrontendData().setTotalBackendRecords(total);
}
*/
} catch (Exception e) {
handleException(entry, e);
}
fireVascEvent(entry,VascEventType.DATA_READ, null);
fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE, null);
}
public void headerOptionsCreatedFillData(VascEntry entry) {
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
}
/**
* @see com.idcanet.vasc.core.VascFrontendHelper#validateObjectField(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
public List<String> validateObjectField(VascEntryField field) {
if (field==null) {
throw new NullPointerException("Can't validate null field.");
}
VascEntry entry = field.getVascEntry();
if (entry.getVascFrontendData().getEntryDataObject()==null) {
throw new NullPointerException("Can't validate null entry object.");
}
List<String> error = new ArrayList<String>(3);
try {
Object objectSelected = entry.getVascFrontendData().getEntryDataObject();
Object objectValue = field.getVascEntryFieldValue().getValue(field, objectSelected);
for (VascEntryFieldValidatorService s:entry.getVascFrontendData().getVascValidatorServices()) {
error.addAll(s.validateObjectField(field, objectSelected, objectValue));
}
} catch (VascException e) {
handleException(entry, e);
}
logger.finest("Checked for errors: "+error);
return error;
}
/*
private InvalidValue findInvalidValueByProperty(InvalidValue[] ival,String property) {
for(InvalidValue iv:ival) {
if(iv.getPropertyName().equals(property)) {
return iv;
}
}
return null;
}
*/
/*
public void addEventListener(VascEventListener e) {
eventListeners.add(e);
}
public void removeEventListener(VascEventListener e) {
eventListeners.remove(e);
/**
*
*/
public boolean validateAndSetErrorText(VascEntry entry) {
boolean hadError = false;
for (VascEntryField field:entry.getVascEntryFields()) {
VascUIComponent comp = entry.getVascFrontendData().getFieldVascUIComponent(field);
List<String> error = validateObjectField(field);
logger.info("Check field: "+field.getId()+" comp: "+comp+" Errors: "+error.size());
if (error.isEmpty()) {
if (comp!=null) {
comp.setErrorText(null);
}
continue;
}
if (comp==null) {
logger.warning("Field: "+field.getId()+" gives errors but no UI component to display.");
continue;
}
hadError=true;
StringBuffer buf = new StringBuffer(100);
for (String s:error) {
buf.append(s);
buf.append('\n');
}
comp.setErrorText(buf.toString());
}
return hadError;
}
public void fireVascEvent(VascEventListener.VascEventType type,Object data) {
for(VascEventListener e:eventListeners) {
e.vascEvent(type, data);
public void editReadOnlyUIComponents(VascEntry entry) {
// reset edit read only
for (VascEntryField f:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getFieldVascUIComponent(f)==null) {
continue;
}
// TODO: move back to rendered when jsf fixes
if (entry.getVascFrontendData().getVascFrontendHelper().renderCreate(f) == false &
entry.getVascFrontendData().isEditCreate()) {
//entry.getVascFrontendData().getFieldVascUIComponent(f).setRendered(false);
entry.getVascFrontendData().getFieldVascUIComponent(f).setDisabled(true);
} else {
//entry.getVascFrontendData().getFieldVascUIComponent(f).setRendered(true);
entry.getVascFrontendData().getFieldVascUIComponent(f).setDisabled(false);
}
// only when editing set edit readonlys
if (entry.getVascFrontendData().getVascFrontendHelper().renderEditReadOnly(f) &
entry.getVascFrontendData().isEditCreate()==false) {
entry.getVascFrontendData().getFieldVascUIComponent(f).setDisabled(true);
} else {
if (entry.getVascFrontendData().isEditCreate()==false) { // todo: remove when jsf fixes
entry.getVascFrontendData().getFieldVascUIComponent(f).setDisabled(false);
}
}
}
}
public void addExceptionListener(VascExceptionListener listener) {
exceptionListeners.add(listener);
public void sortAction(VascEntry entry,VascEntryField field) {
String curSort = entry.getVascFrontendData().getVascBackendState().getSortField();
if (field.getBackendName().equals(curSort)) {
entry.getVascFrontendData().getVascBackendState().setSortAscending(!entry.getVascFrontendData().getVascBackendState().isSortAscending());
}
String sortID = field.getBackendName();
entry.getVascFrontendData().getVascBackendState().setSortField(sortID);
entry.getVascFrontendData().getVascBackendState().setPageIndex(0);
fireVascEvent(entry,VascEntryEventListener.VascEventType.DATA_SORT, field);
refreshData(entry);
}
public void removeExceptionListener(VascExceptionListener listener) {
exceptionListeners.remove(listener);
public void searchAction(VascEntry entry,String searchString) {
entry.getVascFrontendData().getVascBackendState().setSearchString(searchString);
entry.getVascFrontendData().getVascBackendState().setSortField(null);
entry.getVascFrontendData().getVascBackendState().setPageIndex(0);
fireVascEvent(entry,VascEntryEventListener.VascEventType.DATA_SEARCH, searchString);
refreshData(entry);
}
public void pageAction(VascEntry entry,Integer pageIndex) {
if (pageIndex<1) {
pageIndex = 0;
}
Long total = entry.getVascFrontendData().getTotalBackendRecords(); // note: total is only null when pageAction is done before first refresh, which should never happen anyway.
if (total!=null && pageIndex>(total/entry.getVascFrontendData().getVascBackendState().getPageSize())) {
pageIndex = new Long(total/entry.getVascFrontendData().getVascBackendState().getPageSize()).intValue();
}
entry.getVascFrontendData().getVascBackendState().setPageIndex(pageIndex);
fireVascEvent(entry,VascEntryEventListener.VascEventType.DATA_PAGE, pageIndex);
// lets load data;
refreshData(entry);
}
public void moveAction(VascEntry entry,Object record,boolean moveUp) {
if (entry.getVascFrontendData().getVascBackend().isRecordMoveable()) {
try {
VascEntryField p = entry.getVascEntryFieldById(entry.getPrimaryKeyFieldId());
Object primaryId = p.getVascEntryFieldValue().getValue(p, record);
if (moveUp) {
entry.getVascFrontendData().getVascBackend().doRecordMoveUpById(entry.getVascFrontendData().getVascBackendState(),primaryId);
} else {
entry.getVascFrontendData().getVascBackend().doRecordMoveDownById(entry.getVascFrontendData().getVascBackendState(),primaryId);
}
} catch (Exception e) {
handleException(entry, e);
}
// lets load data;
refreshData(entry);
}
}
*/
}

View file

@ -26,6 +26,11 @@
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.VascLinkEntry;
@ -37,11 +42,12 @@ import com.idcanet.vasc.core.VascLinkEntry;
*/
public class DefaultVascLinkEntry implements VascLinkEntry {
private String id;
private String id = null;
private String vascEntryId = null;
private String parameterName = null;
private String valueFieldId = null;
private Map<String,String> entryParameterFieldIds = new HashMap<String,String>(3);
private Map<String,String> entryCreateFieldValues = new HashMap<String,String>(3);
private Boolean viewAsDetail = null;
private String doActionId = null;
/**
* @return the id
@ -57,34 +63,27 @@ public class DefaultVascLinkEntry implements VascLinkEntry {
this.id = id;
}
/**
* @return the parameterName
*/
public String getParameterName() {
return parameterName;
public String getEntryParameterFieldId(String parameterName) {
return entryParameterFieldIds.get(parameterName);
}
/**
* @param parameterName the parameterName to set
*/
public void setParameterName(String parameterName) {
this.parameterName = parameterName;
public void addEntryParameterFieldId(String parameterName,String valueFieldId) {
entryParameterFieldIds.put(parameterName, valueFieldId);
}
/**
* @return the valueFieldId
*/
public String getValueFieldId() {
return valueFieldId;
public List<String> getEntryParameterFieldIdKeys() {
return new ArrayList<String>(entryParameterFieldIds.keySet());
}
/**
* @param valueFieldId the valueFieldId to set
*/
public void setValueFieldId(String valueFieldId) {
this.valueFieldId = valueFieldId;
public String getEntryCreateFieldValue(String valueFieldId) {
return entryCreateFieldValues.get(valueFieldId);
}
public void addEntryCreateFieldValue(String valueFieldId,String selectedFieldId) {
entryCreateFieldValues.put(valueFieldId, selectedFieldId);
}
public List<String> getEntryCreateFieldValueKeys() {
return new ArrayList<String>(entryCreateFieldValues.keySet());
}
/**
* @return the vascEntryId
*/
@ -113,16 +112,31 @@ public class DefaultVascLinkEntry implements VascLinkEntry {
this.viewAsDetail = viewAsDetail;
}
/**
* @return the doActionId
*/
public String getDoActionId() {
return doActionId;
}
/**
* @param doActionId the doActionId to set
*/
public void setDoActionId(String doActionId) {
this.doActionId = doActionId;
}
/**
* @see java.lang.Object#clone()
*/
@Override
public VascLinkEntry clone() throws CloneNotSupportedException {
DefaultVascLinkEntry result = new DefaultVascLinkEntry();
result.doActionId=doActionId;
result.viewAsDetail=viewAsDetail;
result.vascEntryId=vascEntryId;
result.parameterName=parameterName;
result.valueFieldId=valueFieldId;
result.entryParameterFieldIds=entryParameterFieldIds;
result.entryCreateFieldValues=entryCreateFieldValues;
result.id=id;
return result;
}

View file

@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import com.idcanet.vasc.core.VascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
@ -38,7 +39,7 @@ import com.idcanet.vasc.core.ui.VascSelectItemModel;
/**
* The DefaultVascLinkEntry
* The DefaultVascSelectItemModel
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
@ -48,6 +49,9 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel {
private String entryId = null;
private String keyFieldId = null;
private String displayFieldId = null;
private String nullLabel = null;
private String nullKeyValue = null;
private Boolean returnKeyValue = null;
/**
* @see com.idcanet.vasc.core.ui.VascSelectItemModel#getVascSelectItems(com.idcanet.vasc.core.VascEntry)
@ -55,7 +59,15 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel {
public List<VascSelectItem> getVascSelectItems(VascEntry entry) throws VascException {
List<VascSelectItem> result = new ArrayList<VascSelectItem>(100);
VascEntry ve = entry.getVascFrontendData().getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById(entryId);
if (keyFieldId==null) {
keyFieldId = ve.getPrimaryKeyFieldId();
}
VascEntryField key = ve.getVascEntryFieldById(keyFieldId);
if (displayFieldId==null) {
displayFieldId = ve.getDisplayNameFieldId();
}
VascEntryField dis = ve.getVascEntryFieldById(displayFieldId);
if (key==null) {
throw new VascException("Could not find: "+keyFieldId+" from: "+ve.getId());
@ -66,16 +78,34 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel {
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());
if (nullLabel!=null) {
if (nullKeyValue==null) {
nullKeyValue = "null";
}
String nameId = ""+dis.getVascEntryFieldValue().getValue(dis, o);
VascSelectItem item = new VascSelectItem(nameId,o,keyId);
nullLabel = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(nullLabel);
VascSelectItem item = new VascSelectItem(nullLabel,null,nullKeyValue);
result.add(item);
}
// set para
VascBackendState state = new DefaultVascBackendState();
for (String key2:ve.getEntryParameterKeys()) {
Object value = ve.getEntryParameter(key2);
state.setDataParameter(key2, value);
}
// execute
for (Object o:back.execute(state)) {
Object keyId = key.getVascEntryFieldValue().getValue(key, o);
String nameId = dis.getVascEntryFieldValue().getDisplayValue(dis, o);
if (returnKeyValue!=null && true==returnKeyValue) {
VascSelectItem item = new VascSelectItem(nameId,keyId,""+keyId);
result.add(item);
} else {
VascSelectItem item = new VascSelectItem(nameId,o,""+keyId);
result.add(item);
}
}
} catch (Exception e) {
throw new VascException(e);
}
@ -123,4 +153,46 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel {
public void setDisplayFieldId(String displayFieldId) {
this.displayFieldId = displayFieldId;
}
/**
* @return the nullLabel
*/
public String getNullLabel() {
return nullLabel;
}
/**
* @param nullLabel the nullLabel to set
*/
public void setNullLabel(String nullLabel) {
this.nullLabel = nullLabel;
}
/**
* @return the nullKeyValue
*/
public String getNullKeyValue() {
return nullKeyValue;
}
/**
* @param nullKeyValue the nullKeyValue to set
*/
public void setNullKeyValue(String nullKeyValue) {
this.nullKeyValue = nullKeyValue;
}
/**
* @return the returnKeyValue
*/
public Boolean getReturnKeyValue() {
return returnKeyValue;
}
/**
* @param returnKeyValue the returnKeyValue to set
*/
public void setReturnKeyValue(Boolean returnKeyValue) {
this.returnKeyValue = returnKeyValue;
}
}

View file

@ -0,0 +1,80 @@
/*
* 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.VascBackendFilter;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascException;
/**
* Simple filter support
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascBackendProxyFilter extends AbstractVascBackendProxy {
private long records = 0;
private VascBackendFilter filter = null;
public VascBackendProxyFilter(VascBackend backend,VascEntry entry,VascBackendFilter filter) {
super(backend);
this.filter=filter;
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
@Override
public List<Object> execute(VascBackendState state) throws VascException {
List<Object> result = backend.execute(state);
if (filter==null) {
return result;
}
List<Object> search = new ArrayList<Object>(result.size()/2);
for (Object o:result) {
Object r = filter.filterObject(o);
if (r!=null) {
search.add(r);
}
}
records = search.size();
return search;
}
@Override
public long fetchTotalExecuteSize(VascBackendState state) {
return records;
}
}

View file

@ -31,7 +31,9 @@ import java.util.List;
import com.idcanet.vasc.core.AbstractVascBackendProxy;
import com.idcanet.vasc.core.VascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascException;
/**
@ -57,14 +59,19 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy {
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
@Override
public List<Object> execute() throws Exception {
List<Object> allData = backend.execute();
List<Object> paged = new ArrayList<Object>(getPageSize());
int off = getPageIndex()*getPageSize();
int offMax = off+getPageSize();
public List<Object> execute(VascBackendState state) throws VascException {
List<Object> allData = backend.execute(state);
int pageSize = state.getPageSize();
if (pageSize==0) {
records = allData.size();
return allData;
}
List<Object> paged = new ArrayList<Object>(state.getPageSize());
int off = state.getPageIndex()*pageSize;
int offMax = off+state.getPageSize();
for (int i=off;i<offMax;i++) {
if (i>=allData.size()) {
break;
@ -77,7 +84,7 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy {
}
@Override
public long getPagesTotalRecords() {
public long fetchTotalExecuteSize(VascBackendState state) {
return records;
}
}

View file

@ -35,8 +35,9 @@ 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.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascException;
/**
@ -62,16 +63,20 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy {
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
@Override
public List<Object> execute() throws Exception {
List<Object> result = backend.execute();
if (getSearchString()==null) {
records = backend.getPagesTotalRecords();
public List<Object> execute(VascBackendState state) throws VascException {
List<Object> result = backend.execute(state);
if (state.getSearchString()==null) {
if (backend.isPageable()) {
records = backend.fetchTotalExecuteSize(state);
} else {
records = result.size();
}
return result;
}
String searchString = getSearchString().toLowerCase();
String searchString = state.getSearchString().toLowerCase();
List<Object> search = new ArrayList<Object>(result.size()/4);
for (Object o:result) {
for (Method method:o.getClass().getMethods()) {
@ -93,7 +98,12 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy {
if (method.getReturnType().isAssignableFrom(Map.class)) {
continue;
}
Object res = method.invoke(o,null);
Object res;
try {
res = method.invoke(o,null);
} catch (Exception e) {
throw new VascException(e);
}
if (res==null) {
continue;
}
@ -109,17 +119,7 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy {
}
@Override
public long getPagesTotalRecords() {
public long fetchTotalExecuteSize(VascBackendState state) {
return records;
}
@Override
public List<VascBackendPageNumber> getVascBackendPageNumbers() {
if (getSearchString()==null) {
return backend.getVascBackendPageNumbers();
}
// limit the pages to the number of search results.
List<VascBackendPageNumber> r = backend.getVascBackendPageNumbers();
int pages = new Long(getPagesTotalRecords()/getPageSize()).intValue();
return r.subList(0, pages);
}
}

View file

@ -32,6 +32,7 @@ import java.util.List;
import com.idcanet.vasc.core.AbstractVascBackendProxy;
import com.idcanet.vasc.core.VascBackend;
import com.idcanet.vasc.core.VascBackendState;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
@ -56,23 +57,52 @@ public class VascBackendProxySort extends AbstractVascBackendProxy {
// sort stuff
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
*/
@SuppressWarnings("unchecked")
@Override
public List<Object> execute() throws Exception {
List<Object> result = backend.execute();
if (getSortField()==null) {
public List<Object> execute(final VascBackendState state) throws VascException {
List<Object> result = backend.execute(state);
if (state.getSortField()==null) {
return result;
}
final VascEntryField field = entry.getVascEntryFieldById(getSortField());
final VascEntryField field = entry.getVascEntryFieldById(state.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()) {
Comparable c1 = null;
Comparable c2 = null;
if (field.getDisplayName()!=null) {
c1 = (Comparable)fieldValue.getDisplayValue(field, o1);
c2 = (Comparable)fieldValue.getDisplayValue(field, o2);
} else {
c1 = (Comparable)fieldValue.getValue(field, o1);
c2 = (Comparable)fieldValue.getValue(field, o2);
}
if (c1==null & c2==null) {
return 0;
}
if (c1==null) {
if (state.isSortAscending()) {
return 1;
} else {
return -1;
}
}
if (c2==null) {
if (state.isSortAscending()) {
return -1;
} else {
return 1;
}
}
if (c1 instanceof String & c2 instanceof String) {
c1 = ((String)c1).toLowerCase();
c2 = ((String)c2).toLowerCase();
}
if (state.isSortAscending()) {
return c1.compareTo(c2);
} else {
return c2.compareTo(c1);

View file

@ -37,15 +37,18 @@ 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");
static public final String ACTION_ID = "addRowAction";
protected String getActionId() {
return ACTION_ID;
}
public void doRowAction(VascEntry enty,Object rowObject) throws Exception {
enty.getVascFrontendData().getVascFrontend().renderEdit(null);
public void doRowAction(VascEntry entry,Object rowObject) throws Exception {
entry.getVascFrontendData().setEditCreate(true);
Object object = entry.getVascFrontendData().getVascFrontendHelper().createObject(entry);
entry.getVascFrontendData().setEntryDataObject(object);
entry.getVascFrontendData().getVascFrontend().renderEdit();
}
/**

View file

@ -32,6 +32,7 @@ import java.io.PrintWriter;
import com.idcanet.vasc.core.entry.VascEntryExporter;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.actions.AbstractVascAction;
import com.idcanet.vasc.core.actions.GlobalVascAction;
@ -41,28 +42,28 @@ import com.idcanet.vasc.core.actions.GlobalVascAction;
* @version 1.0 Mar 30, 2007
*/
public class CSVExportGlobalAction extends AbstractVascAction implements GlobalVascAction,VascEntryExporter {
private static final long serialVersionUID = -3951608685719832654L;
static public final String ACTION_ID = "csvExportAction";
public CSVExportGlobalAction() {
setId("CSVExportGlobalAction");
setName("vasc.action.csv.name");
setToolTip("vasc.action.csv.tooltip");
setImage("vasc.action.csv.image");
protected String getActionId() {
return ACTION_ID;
}
public void doGlobalAction(VascEntry entry) throws Exception {
entry.getVascFrontendData().getVascFrontend().renderExport(this);
}
public void doExport(OutputStream out,VascEntry entry) throws Exception {
public void doExport(OutputStream out,VascEntry entry) throws VascException {
PrintWriter p = new PrintWriter(out);
p.write("# csv\n");
for (VascEntryField c:entry.getVascEntryFields()) {
p.write(c.getName()+"\t");
p.write(c.getId()+"\t");
}
p.write("\n");
for (Object o:entry.getVascFrontendData().getEntryDataList()) {
for (VascEntryField c:entry.getVascEntryFields()) {
p.write(c.getVascEntryFieldValue().getValue(c, o)+"\t");
p.write(c.getVascEntryFieldValue().getDisplayValue(c, o)+"\t");
}
p.write("\n");
p.flush();

View file

@ -36,19 +36,19 @@ import com.idcanet.vasc.core.actions.RowVascAction;
* @version 1.0 Mar 30, 2007
*/
public class DeleteRowAction extends AbstractVascAction implements RowVascAction {
static public final String ACTION_ID = "deleteRowAction";
public DeleteRowAction() {
setId("deleteRowAction");
setName("vasc.action.del.name");
setToolTip("vasc.action.del.tooltip");
setImage("vasc.action.del.image");
protected String getActionId() {
return ACTION_ID;
}
public void doRowAction(VascEntry entry,Object rowObject) throws Exception {
if (rowObject==null) {
return;
return; // nothing selected
}
entry.getVascFrontendData().getVascFrontend().renderDelete(rowObject);
entry.getVascFrontendData().setEntryDataObject(rowObject);
entry.getVascFrontendData().getVascFrontend().renderDelete();
}
/**

View file

@ -29,6 +29,7 @@ package com.idcanet.vasc.impl.actions;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.actions.AbstractVascAction;
import com.idcanet.vasc.core.actions.RowVascAction;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
/**
*
@ -37,19 +38,21 @@ 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");
static public final String ACTION_ID = "editRowAction";
protected String getActionId() {
return ACTION_ID;
}
public void doRowAction(VascEntry entry,Object rowObject) throws Exception {
if (rowObject==null) {
return;
return; // nothing selected
}
entry.getVascFrontendData().getVascFrontend().renderEdit(rowObject);
entry.getVascFrontendData().setEditCreate(false);
entry.getVascFrontendData().getVascFrontendHelper().fireVascEvent(entry, VascEventType.DATA_SELECT, rowObject);
entry.getVascFrontendData().setEntryDataObject(rowObject);
entry.getVascFrontendData().getVascFrontend().renderEdit();
}

View file

@ -37,11 +37,10 @@ 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");
static public final String ACTION_ID = "refreshDataAction";
protected String getActionId() {
return ACTION_ID;
}

View file

@ -31,6 +31,7 @@ import java.io.PrintWriter;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.actions.AbstractVascAction;
import com.idcanet.vasc.core.actions.GlobalVascAction;
import com.idcanet.vasc.core.entry.VascEntryExporter;
@ -42,27 +43,29 @@ 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");
private static final long serialVersionUID = 3719424578585760828L;
static public final String ACTION_ID = "xmlExportAction";
protected String getActionId() {
return ACTION_ID;
}
public void doGlobalAction(VascEntry entry) throws Exception {
entry.getVascFrontendData().getVascFrontend().renderExport(this);
}
public void doExport(OutputStream out,VascEntry entry) throws Exception {
public void doExport(OutputStream out,VascEntry entry) throws VascException {
PrintWriter p = new PrintWriter(out);
p.write("<xml version=\"1.0\"/>\n");
p.write("<?xml version=\"1.0\"?>\n");
p.write("<data>\n");
for (Object o:entry.getVascFrontendData().getEntryDataList()) {
p.write("\t<row>\n");
for (VascEntryField c:entry.getVascEntryFields()) {
p.write("<column name=\""+c.getName()+"\"><![CDATA[");
p.write(""+c.getVascEntryFieldValue().getValue(c, o));
p.write("\t\t<column name=\""+c.getId()+"\"><![CDATA[");
p.write(""+c.getVascEntryFieldValue().getDisplayValue(c, o));
p.write("]]></column>\n");
}
p.write("\t</row>\n");
p.flush();
}
p.write("</data>\n");

View file

@ -67,6 +67,13 @@ public class BeanPropertyVascEntryFieldValue implements VascEntryFieldValue {
}
}
/**
* @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.column.VascColumnValue#setValue(com.idcanet.vasc.core.column.VascTableColumn, java.lang.Object, java.lang.Object)
*/

View file

@ -54,29 +54,24 @@ public class DefaultVascEntryResourceResolver implements VascEntryResourceResolv
this(ResourceBundle.getBundle(baseName, locale));
}
public String getKeyMapping(String key) {
if (resourceBundle==null) {
return key;
} else {
return resourceBundle.getString(key);
}
}
public String getTextValue(String text,Object...params) {
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;
}
if (text==null) {
throw new NullPointerException("Can't get null text key value.");
}
String textValue = null;
try {
textValue = resourceBundle.getString(text);
} catch (MissingResourceException mre) {
return text;
}
if (params.length>0) {
textValue = MessageFormat.format(textValue, params);
}
return textValue;
}
/**
@ -90,6 +85,9 @@ public class DefaultVascEntryResourceResolver implements VascEntryResourceResolv
* @param resourceBundle the resourceBundle to set
*/
public void setResourceBundle(ResourceBundle resourceBundle) {
if (resourceBundle==null) {
throw new NullPointerException("may not set resourceBundle to null.");
}
this.resourceBundle = resourceBundle;
}
}

View file

@ -0,0 +1,185 @@
/*
* 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.entry;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.hibernate.validator.MessageInterpolator;
import org.hibernate.validator.Validator;
import com.idcanet.vasc.core.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService;
/**
* Executes the hibernate field validators
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public class HibernateValidatorService implements VascEntryFieldValidatorService {
private Logger logger = Logger.getLogger(HibernateValidatorService.class.getName());
@SuppressWarnings("unchecked")
public List<String> validateObjectField(VascEntryField field, Object selectedRecord,Object objectValue) throws VascException {
List<String> error = new ArrayList<String>(3);
try {
ClassValidator val = new ClassValidator(selectedRecord.getClass(),new VascHibernateMessage(field.getVascEntry()));
InvalidValue[] ival = val.getInvalidValues(selectedRecord);
logger.fine("Hiber Validating: "+ival.length);
String prop = field.getBackendName();
InvalidValue iv = findInvalidValueByProperty(ival,prop);
if(iv!=null) {
error.add(iv.getMessage());
}
} catch (Exception e) {
throw new VascException(e);
}
return error;
}
private InvalidValue findInvalidValueByProperty(InvalidValue[] ival,String property) {
for(InvalidValue iv:ival) {
if(iv.getPropertyName().equals(property)) {
return iv;
}
}
return null;
}
class VascHibernateMessage implements MessageInterpolator, Serializable {
private static final long serialVersionUID = -8241727232507976072L;
//private static final Logger log = Logger.getLogger(VascHibernateMessage.class.getName());
private Map<String, Object> annotationParameters = new HashMap<String, Object>();
private String annotationMessage;
private String interpolateMessage;
private VascEntry vascEntry;
public VascHibernateMessage(VascEntry vascEntry) {
this.vascEntry=vascEntry;
}
public void initialize(Annotation annotation, MessageInterpolator defaultInterpolator) {
Class<?> clazz = annotation.getClass();
for ( Method method : clazz.getMethods() ) {
try {
//FIXME remove non serilalization elements on writeObject?
if ( method.getReturnType() != void.class
&& method.getParameterTypes().length == 0
&& ! Modifier.isStatic( method.getModifiers() ) ) {
//cannot use an exclude list because the parameter name could match a method name
annotationParameters.put( method.getName(), method.invoke( annotation ) );
}
}
catch (IllegalAccessException e) {
//really should not happen, but we degrade nicely
//log.warning( "Unable to access {}", StringHelper.qualify( clazz.toString(), method.getName() ) );
}
catch (InvocationTargetException e) {
//really should not happen, but we degrade nicely
//log.warn( "Unable to access {}", StringHelper.qualify( clazz.toString(), method.getName() ) );
}
}
annotationMessage = (String) annotationParameters.get( "message" );
if (annotationMessage == null) {
throw new IllegalArgumentException( "Annotation " + clazz + " does not have an (accessible) message attribute");
}
//do not resolve the property eagerly to allow validator.apply to work wo interpolator
}
public String interpolate(String message, Validator validator, MessageInterpolator defaultInterpolator) {
if ( annotationMessage!=null && annotationMessage.equals( message ) ) {
//short cut
if (interpolateMessage == null) {
interpolateMessage = replace( annotationMessage );
}
return interpolateMessage;
}
else {
//TODO keep them in a weak hash map, but this might not even be useful
return replace( message );
}
}
public String getAnnotationMessage() {
return annotationMessage;
}
private String replace(String message) {
StringTokenizer tokens = new StringTokenizer( message, "#{}", true );
StringBuilder buf = new StringBuilder( 30 );
boolean escaped = false;
boolean el = false;
while ( tokens.hasMoreTokens() ) {
String token = tokens.nextToken();
if ( !escaped && "#".equals( token ) ) {
el = true;
}
if ( !el && "{".equals( token ) ) {
escaped = true;
}
else if ( escaped && "}".equals( token ) ) {
escaped = false;
}
else if ( !escaped ) {
if ( "{".equals( token ) ) el = false;
buf.append( token );
}
else {
Object variable = annotationParameters.get( token );
if ( variable != null ) {
buf.append( variable );
}
else {
String string = null;
string = vascEntry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(token);
if ( string != null ) buf.append( replace( string ) );
}
}
}
return buf.toString();
}
}
}

View file

@ -0,0 +1,98 @@
/*
* 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.entry;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService;
import com.idcanet.vasc.validators.VascObjectNotNullValidator;
import com.idcanet.vasc.validators.VascStringLengthValidator;
import com.idcanet.vasc.validators.VascValidator;
import com.idcanet.vasc.validators.VascValidatorMessages;
/**
* Scans for JPA annotations and wrap some items aroud in a vasc validator.
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public class PersistanceValidatorService implements VascEntryFieldValidatorService {
private Logger logger = Logger.getLogger(PersistanceValidatorService.class.getName());
public List<String> validateObjectField(VascEntryField field, Object selectedRecord,Object objectValue) throws VascException {
List<String> error = new ArrayList<String>(3);
try {
List<VascValidator> vals = new ArrayList<VascValidator>(2);
String property = field.getBackendName();
for (Method method:selectedRecord.getClass().getMethods()) {
if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty
continue;
}
Column col = method.getAnnotation(Column.class);
if (col!=null) {
if (col.nullable()==false) {
Id idAnno = method.getAnnotation(Id.class);
GeneratedValue genAnno = method.getAnnotation(GeneratedValue.class);
if (idAnno!=null || genAnno!=null) {
continue; // don't add validator in JPA ID.
}
VascObjectNotNullValidator val = new VascObjectNotNullValidator();
vals.add(val);
}
// weird default 255 value
if (col.length()!=255) {
VascStringLengthValidator val = new VascStringLengthValidator();
val.setMaxLenght(col.length());
val.setNullable(col.nullable());
vals.add(val);
}
}
}
VascValidatorMessages m = new VascValidatorMessages();
for (VascValidator val:vals) {
logger.finer("Validating: "+val);
if (val.isObjectValid(objectValue)==false) {
error.add(m.getErrorMessage(field.getVascEntry(), val));
}
}
} catch (Exception e) {
throw new VascException(e);
}
return error;
}
}

View file

@ -0,0 +1,70 @@
/*
* 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.entry;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValidatorService;
import com.idcanet.vasc.validators.VascValidator;
import com.idcanet.vasc.validators.VascValidatorMessages;
/**
* Executes the normal vasc validators for fields.
*
* @author Willem Cazander
* @version 1.0 May 13, 2009
*/
public class VascValidatorsValidatorService implements VascEntryFieldValidatorService {
private Logger logger = Logger.getLogger(VascValidatorsValidatorService.class.getName());
public List<String> validateObjectField(VascEntryField field, Object selectedRecord,Object objectValue) throws VascException {
List<String> error = new ArrayList<String>(3);
try {
VascValidatorMessages m = new VascValidatorMessages();
for (VascValidator val:field.getVascEntryFieldType().getVascValidators()) {
logger.finer("Validating: "+val);
if (val.isObjectValid(objectValue)==false) {
error.add(m.getErrorMessage(field.getVascEntry(), val));
}
}
for (VascValidator val:field.getVascValidators()) {
logger.finer("Validating: "+val);
if (val.isObjectValid(objectValue)==false) {
error.add(m.getErrorMessage(field.getVascEntry(), val));
}
}
} catch (Exception e) {
throw new VascException(e);
}
return error;
}
}

View file

@ -46,7 +46,7 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType {
Object value = entryField.getVascEntryFieldValue().getValue(entryField, record);
if (value instanceof List) {
return ((List)value).get(index);
return ((List<?>)value).get(index);
}
if (value instanceof String[]) {
if (index >= ((String[])value).length ) {
@ -65,7 +65,7 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType {
Object value = entryField.getVascEntryFieldValue().getValue(entryField, record);
if (value instanceof List) {
((List)value).set(index, newValue);
((List<Object>)value).set(index, newValue);
return;
}
if (value instanceof String[]) {
@ -98,7 +98,7 @@ public class MultiTextVascEntryFieldType extends DefaultVascEntryFieldType {
Object value = entryField.getVascEntryFieldValue().getValue(entryField, record);
if (value instanceof List) {
return ((List)value).size()+1;
return ((List<?>)value).size()+1;
}
if (value instanceof String[]) {
return ((String[])value).length+1;

View file

@ -29,17 +29,24 @@ package com.idcanet.vasc.impl.x4o;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Method;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
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.annotations.VascChoices;
import com.idcanet.vasc.annotations.VascChoicesSelectItemModel;
import com.idcanet.vasc.annotations.VascEventListener;
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.core.entry.VascEntryEventListener;
import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType;
import com.idcanet.vasc.impl.DefaultVascEntryField;
import com.idcanet.vasc.validators.VascValidator;
import com.idcanet.vasc.validators.VascValidatorClassParser;
@ -62,61 +69,67 @@ public class AnnotationParserElement extends AbstractElement {
*/
@Override
public void doElementRun() throws ElementException {
try {
String className = getAttributes().get("className");
String addFields = getAttributes().get("addFields");
Object parentObject = getParent().getElementObject();
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();
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;
fillEntry(entry,modelClass,parser);
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);
}
}
private void fillEntry(VascEntry entry,Class<?> modelClass,VascAnnotationParser parser) {
private void fillEntry(VascEntry entry,Class<?> modelClass,VascAnnotationParser parser) throws ElementException {
if (entry.getId()==null) {
}
if (entry.getHeaderName()==null) {
}
if (entry.getHeaderDescription()==null) {
}
if (entry.getHeaderImage()==null) {
}
VascEventListener vc = parser.getVascEventListener (modelClass);
if (vc!=null) {
if (vc.listeners().length!=vc.types().length) {
throw new IllegalArgumentException("Total listeners and types are not equals on: "+modelClass);
}
int i = 0;
for (VascEventType type:vc.types()) {
String listenerClass = vc.listeners()[i];
VascEntryEventListener listener;
try {
listener = (VascEntryEventListener)X4OParser.loadClass(listenerClass).newInstance();
entry.addVascEntryEventListener(type, listener);
} catch (Exception e) {
throw new ElementException("Could not create listener: "+listenerClass+" for entryId: "+entry.getId(),e);
}
i++;
}
}
}
@ -126,7 +139,7 @@ public class AnnotationParserElement extends AbstractElement {
if (value!=null && "".equals(value)==false) {
field.setBackendName(value);
}
if (field.getDisplayName()==null) {
field.setDisplayName( parser.getVascDisplayName (modelClass, field.getId()));
@ -167,7 +180,55 @@ public class AnnotationParserElement extends AbstractElement {
if (field.getOptional()==null) {
field.setOptional( parser.getVascFieldOptional (modelClass, field.getId()));
}
if (field.getSortable()==null) {
field.setSortable( parser.getVascFieldSortable (modelClass, field.getId()));
}
if (field.getSumable()==null) {
field.setSumable( parser.getVascFieldSumable (modelClass, field.getId()));
if (field.getSumable()==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();
if (retType.isAssignableFrom(Number.class)) {
field.setSumable(true);
}
}
}
if (field.getSumable()==null) {
field.setSumable(false);
}
}
if (field.getGraphable()==null) {
field.setGraphable( parser.getVascFieldGraphable (modelClass, field.getId()));
if (field.getGraphable()==null) {
field.setGraphable(field.getSumable());
}
}
if (field.getRolesCreate()==null) {
field.setRolesCreate( parser.getVascRolesCreate (modelClass, field.getId()));
@ -197,12 +258,34 @@ public class AnnotationParserElement extends AbstractElement {
}
VascValidatorClassParser validatorParser = new VascValidatorClassParser();
Class<?> temp = parser.getVascFieldTemplateClass (modelClass, field.getId());
String tempProp = parser.getVascFieldTemplate (modelClass, field.getId());
if (temp!=null) {
if (tempProp==null) {
tempProp=field.getId();
}
if (tempProp.isEmpty()) {
tempProp=field.getId();
}
List<VascValidator> val = validatorParser.getValidatorsByPropertyName(temp, tempProp);
for (VascValidator v:val) {
field.addVascValidator(v);
}
}
List<VascValidator> val = validatorParser.getValidatorsByPropertyName(modelClass, field.getId());
for (VascValidator v:val) {
field.addVascValidator(v);
field.addVascValidator(v); // todo: merg with already added list of template so we can override.
}
VascController vascController = VascParser.getVascController(this.getElementContext());
VascChoices vc = parser.getVascChoices (modelClass, field.getId());
if (vc!=null) {
VascEntryFieldType type = vascController.getVascEntryFieldTypeControllerResolver().getVascEntryFieldTypeController().getVascEntryFieldTypeById("ListField");
type.setDataObject(new VascChoicesSelectItemModel(vc));
field.setVascEntryFieldType(type);
}
if (field.getVascEntryFieldType()==null) {
String fieldType = parser.getVascFieldType (modelClass, field.getId());
if (fieldType!=null) {
@ -278,6 +361,59 @@ public class AnnotationParserElement extends AbstractElement {
}
}
}
if (field.getDefaultValue()==null) {
String defValue = parser.getVascDefaultValue (modelClass, field.getId());
if (defValue!=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();
try {
//System.out.println("creating real def value of: "+defValue+" for: "+retType.getName());
Object defObject = null;
if (Date.class.equals(retType)) {
defObject = new Date();
} else if (Calendar.class.equals(retType)) {
defObject = Calendar.getInstance();
} else {
defObject = retType.getConstructor(String.class).newInstance(defValue);
}
//System.out.println("real object: "+defObject);
field.setDefaultValue(defObject);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
private void addFields(VascEntry entry,Class<?> modelClass) {
@ -304,9 +440,6 @@ public class AnnotationParserElement extends AbstractElement {
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);

View file

@ -28,8 +28,8 @@ 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.vasc.core.VascEntry;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
@ -53,10 +53,9 @@ public class SetParameterElement extends AbstractElement {
String name = getAttributes().get("name");
String value = getAttributes().get("value");
String type = getAttributes().get("type");
VascBackend back = (VascBackend)getParent().getElementObject();
VascEntry entry = (VascEntry)getParent().getElementObject();
VascController cont = VascParser.getVascController(getElementContext());
logger.info("Setting parameter name: "+name+" value: "+value+" type: "+type);
logger.fine("Setting parameter name: "+name+" value: "+value+" type: "+type);
if ("setUserParameter".equals(getElementClass().getTag())) {
if (value==null) {
@ -65,29 +64,29 @@ public class SetParameterElement extends AbstractElement {
if ("id".equals(value)) {
if ("int".equals(type)) {
Long userId = cont.getVascUserRoleControllerResolver().getVascUserRoleController().getUserId();
back.setDataParameter(name, userId.intValue());
entry.setEntryParameter(name, userId.intValue());
} else {
Long userId = cont.getVascUserRoleControllerResolver().getVascUserRoleController().getUserId();
back.setDataParameter(name, userId);
entry.setEntryParameter(name, userId);
}
} else {
String userName = cont.getVascUserRoleControllerResolver().getVascUserRoleController().getUserName();
back.setDataParameter(name, userName);
entry.setEntryParameter(name, userName);
}
return;
}
if (type==null) {
back.setDataParameter(name, value);
entry.setEntryParameter(name, value);
return;
}
if ("long".equalsIgnoreCase(type)) {
back.setDataParameter(name, new Long(value));
entry.setEntryParameter(name, new Long(value));
return;
}
if ("int".equalsIgnoreCase(type)) {
back.setDataParameter(name, new Integer(value));
entry.setEntryParameter(name, new Integer(value));
return;
}

View file

@ -0,0 +1,78 @@
/*
* 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.VascEntry;
import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.x4o.element.AbstractElementBindingHandler;
import com.idcanet.x4o.element.Element;
import com.idcanet.x4o.element.ElementBindingException;
/**
* Binds fields
*
*
* @author Willem Cazander
* @version 1.0 Apr 02, 2009
*/
public class VascEntryFieldBindingHandler 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 VascEntry) { p=true; }
if (child instanceof VascEntryField) { 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 childObject = element.getElementObject();
Object parentObject = element.getParent().getElementObject();
if (parentObject instanceof VascEntry) {
VascEntry parent = (VascEntry)parentObject;
if (childObject instanceof VascEntryField) {
VascEntryField child = (VascEntryField) childObject;
if (element.getElementClass().getTag().equals("listOption")) {
parent.addListOption(child);
} else {
parent.addVascEntryField(child);
}
}
}
}
}

View file

@ -0,0 +1,59 @@
/*
* 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 com.idcanet.vasc.core.VascLinkEntry;
import com.idcanet.x4o.element.AbstractElement;
import com.idcanet.x4o.element.ElementException;
/**
* Adds the link is paramets
*
* @author Willem Cazander
* @version 1.0 Jun 09, 2009
*/
public class VascLinkEntryParameterElement extends AbstractElement {
/**
* @see com.idcanet.x4o.element.AbstractElement#doElementRun()
*/
@Override
public void doElementRun() throws ElementException {
String valueFieldId = getAttributes().get("valueFieldId");
String parameterName = getAttributes().get("name");
String selectedFieldId = getAttributes().get("selectedFieldId");
VascLinkEntry link = (VascLinkEntry)getParent().getElementObject();
if (parameterName!=null) {
// normal parameter
link.addEntryParameterFieldId(parameterName, valueFieldId);
} else {
link.addEntryCreateFieldValue(valueFieldId,selectedFieldId);
}
}
}

Some files were not shown because too many files have changed in this diff Show more