diff --git a/pom.xml b/pom.xml index 078efb6..26bdfda 100644 --- a/pom.xml +++ b/pom.xml @@ -321,6 +321,13 @@ http://repository.ops4j.org/maven2/ false + + eobjects-metamodel + eobjects.org + default + http://repo.eobjects.org + true + diff --git a/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java index 2b5d926..9ad53ec 100644 --- a/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java +++ b/vasc-backend/vasc-backend-ldap/src/main/java/net/forwardfire/vasc/backend/ldap/LdapConnectionProviderImpl.java @@ -56,7 +56,11 @@ public class LdapConnectionProviderImpl implements LdapConnectionProvider { } return lc; } catch (Exception e) { - throw new RuntimeException(e); + if (bindUser!=null && bindPass!=null) { + throw new RuntimeException("Connect as: "+bindUser+" pass: "+bindPass+" message: "+e.getMessage(),e); + } else { + throw new RuntimeException(e); + } } } diff --git a/vasc-backend/vasc-backend-metamodel/pom.xml b/vasc-backend/vasc-backend-metamodel/pom.xml index 009c8fb..ed0e903 100644 --- a/vasc-backend/vasc-backend-metamodel/pom.xml +++ b/vasc-backend/vasc-backend-metamodel/pom.xml @@ -17,8 +17,8 @@ org.eobjects.metamodel - MetaModel-core - 2.1 + MetaModel-full + 3.0-SNAPSHOT \ No newline at end of file diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextCsv.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextCsv.java new file mode 100644 index 0000000..030abe9 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextCsv.java @@ -0,0 +1,91 @@ +package net.forwardfire.vasc.backend.metamodel; + +import java.io.File; +import java.net.URL; + +import org.eobjects.metamodel.DataContext; +import org.eobjects.metamodel.csv.CsvConfiguration; +import org.eobjects.metamodel.csv.CsvDataContext; + +public class MetaModelDataContextCsv implements MetaModelDataContextProvider { + + private String file = null; + private String resource = null; + private String url = null; + private CsvConfiguration csvConfiguration = null; + + public DataContext getDataContext() { + if (csvConfiguration==null) { + csvConfiguration = new CsvConfiguration(); + } + CsvDataContext dataContext; + if (file != null) { + dataContext = new CsvDataContext(new File(file),csvConfiguration); + } else if (url != null) { + try { + dataContext = new CsvDataContext(new URL(url),csvConfiguration); + } catch (Exception e) { + throw new IllegalStateException("Could not parse url: "+e.getMessage(),e); + } + } else { + throw new IllegalStateException("No file or url defined."); + } + return dataContext; + } + + /** + * @return the file + */ + public String getFile() { + return file; + } + + /** + * @param file the file to set + */ + public void setFile(String file) { + this.file = file; + } + + /** + * @return the resource + */ + public String getResource() { + return resource; + } + + /** + * @param resource the resource to set + */ + public void setResource(String resource) { + this.resource = resource; + } + + /** + * @return the url + */ + public String getUrl() { + return url; + } + + /** + * @param url the url to set + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return the csvConfiguration + */ + public CsvConfiguration getCsvConfiguration() { + return csvConfiguration; + } + + /** + * @param csvConfiguration the csvConfiguration to set + */ + public void setCsvConfiguration(CsvConfiguration csvConfiguration) { + this.csvConfiguration = csvConfiguration; + } +} diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java new file mode 100644 index 0000000..b58e7f3 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextMongodb.java @@ -0,0 +1,141 @@ +package net.forwardfire.vasc.backend.metamodel; + +import java.net.UnknownHostException; + +import org.eobjects.metamodel.DataContext; +import org.eobjects.metamodel.mongodb.MongoDbDataContext; + +import com.mongodb.DB; +import com.mongodb.Mongo; +import com.mongodb.MongoOptions; +import com.mongodb.ServerAddress; + +public class MetaModelDataContextMongodb implements MetaModelDataContextProvider { + + private String hostname = "localhost"; + private int port = 27017; + private String database = null; + private String username = null; + private String password = null; + private boolean readonly = false; + + protected static Mongo mongo = null; + protected static DB db = null; + + public DataContext getDataContext() { + MongoDbDataContext dataContext = new MongoDbDataContext(getMongodbConnection()); + return dataContext; + } + + public DB getMongodbConnection() { + if (db!=null) { + return db; + } + synchronized (this) { + ServerAddress server; + try { + server = new ServerAddress(hostname,port); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + MongoOptions options = new MongoOptions(); + mongo = new Mongo(server,options); + db = mongo.getDB(database); + if (username!=null && password!=null) { + boolean auth = db.authenticate(username, password.toCharArray()); + if (auth==false) { + throw new RuntimeException("Could not auth to db: "+database+" with username: "+username); + } + } + if (readonly) { + db.setReadOnly(true); + } + //logger.info("Connection to: "+db.getName()); + } + return db; + } + + /** + * @return the hostname + */ + public String getHostname() { + return hostname; + } + + /** + * @param hostname the hostname to set + */ + public void setHostname(String hostname) { + this.hostname = hostname; + } + + /** + * @return the port + */ + public int getPort() { + return port; + } + + /** + * @param port the port to set + */ + public void setPort(int port) { + this.port = port; + } + + /** + * @return the database + */ + public String getDatabase() { + return database; + } + + /** + * @param database the database to set + */ + public void setDatabase(String database) { + this.database = database; + } + + /** + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * @param username the username to set + */ + public void setUsername(String username) { + this.username = username; + } + + /** + * @return the password + */ + public String getPassword() { + return password; + } + + /** + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * @return the readonly + */ + public boolean isReadonly() { + return readonly; + } + + /** + * @param readonly the readonly to set + */ + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } +} diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextProvider.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextProvider.java new file mode 100644 index 0000000..6b22836 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelDataContextProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + +package net.forwardfire.vasc.backend.metamodel; + +import org.eobjects.metamodel.DataContext; + +/** + * Provides an metamodel datacontext object to the metamodel backend. + * + * @author Willem Cazander + * @version 1.0 Apr 25, 2012 + */ +public interface MetaModelDataContextProvider { + + /** + * Returns a DB connection. + * @return An DB connection to mongodb + */ + public DataContext getDataContext(); +} diff --git a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java index ce73785..c683df7 100644 --- a/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java +++ b/vasc-backend/vasc-backend-metamodel/src/main/java/net/forwardfire/vasc/backend/metamodel/MetaModelVascBackend.java @@ -23,17 +23,21 @@ package net.forwardfire.vasc.backend.metamodel; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eobjects.metamodel.DataContext; +import org.eobjects.metamodel.UpdateCallback; +import org.eobjects.metamodel.UpdateScript; +import org.eobjects.metamodel.UpdateableDataContext; import org.eobjects.metamodel.data.DataSet; import org.eobjects.metamodel.data.Row; import org.eobjects.metamodel.query.Query; import org.eobjects.metamodel.query.SelectItem; import org.eobjects.metamodel.schema.Schema; import org.eobjects.metamodel.schema.Table; +import org.eobjects.metamodel.update.RowUpdationBuilder; import net.forwardfire.vasc.backend.AbstractVascBackend; import net.forwardfire.vasc.backend.VascBackendState; @@ -53,13 +57,23 @@ import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; */ public class MetaModelVascBackend extends AbstractVascBackend { - private DataContext dataContext = null; + private MetaModelDataContextProvider dataContextProvider = null; + private UpdateableDataContext dataContext = null; private String table = null; + private String tableId = null; + + private UpdateableDataContext getUpdateableDataContext() { + if (dataContext!=null) { + return dataContext; + } + dataContext = (UpdateableDataContext)dataContextProvider.getDataContext(); + return dataContext; + } public List execute(VascBackendState state) throws VascException { + UpdateableDataContext dataContext = getUpdateableDataContext(); Schema schema = dataContext.getDefaultSchema(); Table t = schema.getTableByName(table); - //dataContext.query().from("").select("").where(""). Query q = dataContext.query().from(t).select(t.getColumns()).toQuery(); DataSet ds = dataContext.executeQuery(q); List result = new ArrayList(50); @@ -78,13 +92,52 @@ public class MetaModelVascBackend extends AbstractVascBackend { } public void persist(Object object) throws VascException { + UpdateableDataContext dataContext = getUpdateableDataContext(); + dataContext.executeUpdate(new UpdateScript() { + public void run(UpdateCallback backendImpl) { + Table table = backendImpl.createTable(null, "some_entries").withColumn("foo").withColumn("bar") + .withColumn("baz").withColumn("list").execute(); + + backendImpl.insertInto(table).value("foo", 1).value("bar", "hello").execute(); + backendImpl.insertInto(table).value("foo", 2).value("bar", "world").execute(); + backendImpl.insertInto(table).value("foo", 3).value("bar", "hi").execute(); + + Map nestedObj = new HashMap(); + nestedObj.put("foo", "bar"); + nestedObj.put("123", 456); + + backendImpl.insertInto(table).value("foo", 4).value("bar", "there").value("baz", nestedObj) + .value("list", Arrays.asList(1, 2, 3)).execute(); + } + }); } + @SuppressWarnings("unchecked") public Object merge(Object object) throws VascException { + final Map map = (Map)object; + UpdateableDataContext dataContext = getUpdateableDataContext(); + dataContext.executeUpdate(new UpdateScript() { + public void run(UpdateCallback backendImpl) { + RowUpdationBuilder query = backendImpl.update(table).where(tableId).equals(""+map.get(tableId)); + for (String key:map.keySet()) { + Object value = map.get(key); + query.value(key, value); + } + query.execute(); + } + }); return object; } + @SuppressWarnings("unchecked") public void delete(Object object) throws VascException { + final Map map = (Map)object; + UpdateableDataContext dataContext = getUpdateableDataContext(); + dataContext.executeUpdate(new UpdateScript() { + public void run(UpdateCallback backendImpl) { + backendImpl.deleteFrom(table).where(tableId).in(""+map.get(tableId)).execute(); + } + }); } public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { @@ -94,4 +147,46 @@ public class MetaModelVascBackend extends AbstractVascBackend { public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { return new MapVascEntryRecordCreator(); } + + /** + * @return the dataContextProvider + */ + public MetaModelDataContextProvider getDataContextProvider() { + return dataContextProvider; + } + + /** + * @param dataContextProvider the dataContextProvider to set + */ + public void setDataContextProvider(MetaModelDataContextProvider dataContextProvider) { + this.dataContextProvider = dataContextProvider; + } + + /** + * @return the table + */ + public String getTable() { + return table; + } + + /** + * @param table the table to set + */ + public void setTable(String table) { + this.table = table; + } + + /** + * @return the tableId + */ + public String getTableId() { + return tableId; + } + + /** + * @param tableId the tableId to set + */ + public void setTableId(String tableId) { + this.tableId = tableId; + } } diff --git a/vasc-backend/vasc-backend-metamodel/src/main/resources/META-INF/vasc/vasc-backend-metamodel.eld b/vasc-backend/vasc-backend-metamodel/src/main/resources/META-INF/vasc/vasc-backend-metamodel.eld new file mode 100644 index 0000000..648e9d8 --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/src/main/resources/META-INF/vasc/vasc-backend-metamodel.eld @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/vasc-backend/vasc-backend-metamodel/src/main/resources/META-INF/vasc/vasc-namespaces.xml b/vasc-backend/vasc-backend-metamodel/src/main/resources/META-INF/vasc/vasc-namespaces.xml new file mode 100644 index 0000000..bf948ca --- /dev/null +++ b/vasc-backend/vasc-backend-metamodel/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -0,0 +1,8 @@ + + + + + Vasc namespace for the metamodel backend + + vasc-backend-metamodel.eld + \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java index 9f7dc74..80b41d5 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/AbstractVascBackend.java @@ -53,6 +53,13 @@ abstract public class AbstractVascBackend implements VascBackend { this.id=id; } + /** + * @see net.forwardfire.vasc.backend.VascBackend#isReadOnly() + */ + public boolean isReadOnly() { + return false; + } + /** * @see net.forwardfire.vasc.backend.VascBackend#isPageable() */ diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java index b423bf6..d0d6474 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackend.java @@ -44,6 +44,8 @@ public interface VascBackend { public List execute(VascBackendState state) throws VascException; + public boolean isReadOnly(); + public void persist(Object object) throws VascException; public Object merge(Object object) throws VascException; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java index 2c694b8..bcaa1d7 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VascBackendController.java @@ -22,6 +22,8 @@ package net.forwardfire.vasc.backend; +import java.util.List; + /** * @@ -31,4 +33,6 @@ package net.forwardfire.vasc.backend; public interface VascBackendController { public VascBackend getVascBackendById(String id); + + public List getVascBackendIds(); } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/VirtualVascBackend.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VirtualVascBackend.java new file mode 100644 index 0000000..0734f5f --- /dev/null +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/VirtualVascBackend.java @@ -0,0 +1,170 @@ +package net.forwardfire.vasc.backend; + +import java.util.ArrayList; +import java.util.List; + +import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue; +import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator; +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascEntryFieldSet; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.VascLinkEntry; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; +import net.forwardfire.vasc.core.entry.VascEntryRecordCreator; +import net.forwardfire.vasc.impl.DefaultVascEntry; +import net.forwardfire.vasc.impl.DefaultVascEntryField; +import net.forwardfire.vasc.impl.DefaultVascEntryFieldSet; +import net.forwardfire.vasc.impl.DefaultVascLinkEntry; + +public class VirtualVascBackend extends AbstractVascBackend { + + private VascController vascController = null; + private String vascType = "entry"; + private String entryId = null; + + public List execute(VascBackendState state) throws VascException { + List result = new ArrayList(100); + entryId = (String)state.getDataParameter("entry_id"); + if ("entry".equals(vascType)) { + for (String id:vascController.getVascEntryController().getVascEntryIds()) { + result.add(vascController.getVascEntryController().getVascEntryById(id)); + } + } else if ("field".equals(vascType)) { + if (entryId!=null) { + VascEntry ve = vascController.getVascEntryController().getVascEntryById(entryId); + result.addAll(ve.getVascEntryFields()); + } + } else if ("fieldset".equals(vascType)) { + if (entryId!=null) { + VascEntry ve = vascController.getVascEntryController().getVascEntryById(entryId); + result.addAll(ve.getVascEntryFieldSets()); + } + } else if ("linkentries".equals(vascType)) { + if (entryId!=null) { + VascEntry ve = vascController.getVascEntryController().getVascEntryById(entryId); + result.addAll(ve.getVascLinkEntries()); + } + } else if ("listoptions".equals(vascType)) { + if (entryId!=null) { + VascEntry ve = vascController.getVascEntryController().getVascEntryById(entryId); + result.addAll(ve.getListOptions()); + } + } + + return result; + } + + public void persist(Object object) throws VascException { + edit(object,false,true); + } + + public Object merge(Object object) throws VascException { + return edit(object,true,true); + } + + public void delete(Object object) throws VascException { + edit(object,true,false); + } + + public Object edit(Object object,boolean removeReal,boolean addEdit) throws VascException { + + if (object instanceof VascEntry) { + entryId = ((VascEntry)object).getId(); + } + VascEntry veReal = ((VascEntryControllerLocal)vascController.getVascEntryController()).getMasterVascEntryById(entryId); + + if ("entry".equals(vascType)) { + + } else if ("field".equals(vascType)) { + VascEntryField vef = (VascEntryField)object; + if (removeReal) { + VascEntryField vefReal = veReal.getVascEntryFieldById(vef.getId()); + veReal.removeVascEntryField(vefReal); + } + if (addEdit) { + veReal.addVascEntryField(vef); + } + } else if ("fieldset".equals(vascType)) { + VascEntryFieldSet vefs = (VascEntryFieldSet)object; + if (removeReal) { + VascEntryFieldSet vefsReal = veReal.getVascEntryFieldSetById(vefs.getId()); + veReal.removeVascEntryFieldSet(vefsReal); + } + if (addEdit) { + veReal.addVascEntryFieldSet(vefs); + } + } else if ("linkentries".equals(vascType)) { + VascLinkEntry vefs = (VascLinkEntry)object; + if (removeReal) { + VascLinkEntry vefsReal = veReal.getVascLinkEntryById(vefs.getId()); + veReal.removeVascLinkEntry(vefsReal); + } + if (addEdit) { + veReal.addVascLinkEntry(vefs); + } + } else if ("listoptions".equals(vascType)) { + VascEntryField vef = (VascEntryField)object; + if (removeReal) { + VascEntryField vefReal = veReal.getListOptionById(vef.getId()); + veReal.removeListOption(vefReal); + } + if (addEdit) { + veReal.addListOption(vef); + } + } + return object; + } + + + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new BeanVascEntryFieldValue(); + } + + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + if ("entry".equals(vascType)) { + return new BeanVascEntryRecordCreator(DefaultVascEntry.class); + } else if ("field".equals(vascType)) { + return new BeanVascEntryRecordCreator(DefaultVascEntryField.class); + } else if ("fieldset".equals(vascType)) { + return new BeanVascEntryRecordCreator(DefaultVascEntryFieldSet.class); + } else if ("linkentries".equals(vascType)) { + return new BeanVascEntryRecordCreator(DefaultVascLinkEntry.class); + } else if ("listoptions".equals(vascType)) { + return new BeanVascEntryRecordCreator(DefaultVascEntryField.class); + } + return null; + } + + /** + * @return the vascController + */ + public VascController getVascController() { + return vascController; + } + + /** + * @param vascController the vascController to set + */ + public void setVascController(VascController vascController) { + this.vascController = vascController; + } + + /** + * @return the vascType + */ + public String getVascType() { + return vascType; + } + + /** + * @param vascType the vascType to set + */ + public void setVascType(String vascType) { + this.vascType = vascType; + } + + +} diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java index b451159..6a08a3a 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/AbstractVascBackendProxy.java @@ -51,6 +51,13 @@ abstract public class AbstractVascBackendProxy implements VascBackend { this.backend=backend; } + /** + * @see net.forwardfire.vasc.backend.VascBackend#isReadOnly() + */ + public boolean isReadOnly() { + return backend.isReadOnly(); + } + /** * @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state) */ diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java index 308efb8..bcdab67 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySearch.java @@ -22,12 +22,8 @@ package net.forwardfire.vasc.backend.proxy; -import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Set; import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.backend.VascBackendState; @@ -36,8 +32,6 @@ import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.entry.VascEntryFieldValue; - - /** * Simple text search * @@ -82,6 +76,9 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy { for (VascEntryField field:entry.getVascEntryFields()) { VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field); Object value = fieldValue.getValue(field, record); + if (value==null) { + continue; // can't search null values. + } String r = value.toString().toLowerCase(); if (r.contains(searchString)) { search.add(record); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java index fdfe839..99913d6 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/backend/proxy/VascBackendProxySort.java @@ -33,9 +33,6 @@ import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.entry.VascEntryFieldValue; - - - /** * Add an sortware sort an a backend * @@ -66,14 +63,15 @@ public class VascBackendProxySort extends AbstractVascBackendProxy { try { final VascEntryField field = entry.getVascEntryFieldById(state.getSortField()); final VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field.clone()); - Collections.sort(result, new Comparator() { + Collections.sort(result, new Comparator() { + @SuppressWarnings("rawtypes") public int compare(Object o1, Object o2) { try { Comparable c1 = null; Comparable c2 = null; if (field.getDisplayName()!=null) { - c1 = (Comparable)fieldValue.getDisplayValue(field, o1); - c2 = (Comparable)fieldValue.getDisplayValue(field, o2); + c1 = fieldValue.getDisplayValue(field, o1); + c2 = fieldValue.getDisplayValue(field, o2); } else { c1 = (Comparable)fieldValue.getValue(field, o1); c2 = (Comparable)fieldValue.getValue(field, o2); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java index 8f6e3e5..bb1d1d6 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/AbstractVascEntryFieldType.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.x4o.xml.conv.ObjectConverter; + import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.validators.VascValidator; @@ -45,6 +47,7 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { protected Class autoDetectClass = null; protected List vascValidators = null; protected Map properties = null; + protected ObjectConverter objectConverter = null; protected Object dataObject = null; protected String uiComponentId = null; @@ -215,4 +218,18 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType { VascValueModel model = new VascValueModel(); return model; } + + /** + * @return the objectConverter + */ + public ObjectConverter getObjectConverter() { + return objectConverter; + } + + /** + * @param objectConverter the objectConverter to set + */ + public void setObjectConverter(ObjectConverter objectConverter) { + this.objectConverter = objectConverter; + } } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java index c44774f..277165f 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntry.java @@ -403,7 +403,9 @@ public interface VascEntry extends Cloneable,Serializable { public void addListOption(VascEntryField listOption); + public void removeListOption(VascEntryField listOption); public List getListOptions(); + public VascEntryField getListOptionById(String listOptionId); public void addVascBackendFilter(VascBackendFilter filter); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryField.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryField.java index 379f9c0..860a76d 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryField.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryField.java @@ -377,7 +377,7 @@ public interface VascEntryField extends Cloneable,Serializable { public void setGraphable(Boolean graphable); /** - * Force impl to have public clone methode + * Force impl to have public clone method * @return * @throws CloneNotSupportedException */ diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldType.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldType.java index 1e79452..7319d03 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldType.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldType.java @@ -25,6 +25,8 @@ package net.forwardfire.vasc.core; import java.io.Serializable; import java.util.List; +import org.x4o.xml.conv.ObjectConverter; + import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.validators.VascValidator; @@ -67,6 +69,17 @@ public interface VascEntryFieldType extends Serializable { public VascUIComponent provideEditorUIComponent(int index,VascEntryField entryField) throws VascException; public VascValueModel provideEditorVascValueModel(int index,VascEntryField entryField) throws VascException; + + /** + * @return the objectConverter + */ + public ObjectConverter getObjectConverter(); + + /** + * @param objectConverter the objectConverter to set + */ + public void setObjectConverter(ObjectConverter objectConverter); + /** * Force impl to have public clone methode * @return diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldTypeController.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldTypeController.java index 1164864..5735321 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldTypeController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/VascEntryFieldTypeController.java @@ -35,4 +35,6 @@ public interface VascEntryFieldTypeController { public VascEntryFieldType getVascEntryFieldTypeById(String id); public List getVascEntryFieldTypeIds(); + + public VascEntryFieldType getVascEntryFieldTypeByClass(Class clazz); } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/core/ui/VascOptionValueModelListener.java b/vasc-core/src/main/java/net/forwardfire/vasc/core/ui/VascOptionValueModelListener.java index 450013b..d762a08 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/core/ui/VascOptionValueModelListener.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/core/ui/VascOptionValueModelListener.java @@ -26,6 +26,7 @@ import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; /** + * VascOptionValueModelListener to handle editors which sets entry parameter values. * * @author Willem Cazander * @version 1.0 May 21, 2009 diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java index c2aa8af..49c970e 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackedEntryFinalizer.java @@ -24,21 +24,21 @@ package net.forwardfire.vasc.impl; import java.util.Collections; import java.util.Comparator; +import java.util.Locale; + +import org.x4o.xml.conv.ObjectConverterException; import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryFieldSet; -import net.forwardfire.vasc.core.VascEntryFieldType; import net.forwardfire.vasc.core.VascEntryFinalizer; import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascLinkEntry; import net.forwardfire.vasc.core.VascLinkEntryType; import net.forwardfire.vasc.core.actions.VascAction; - - /** * Checks for minimal needed stuff * and fills up the rest. @@ -79,7 +79,7 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { // Check if backendId is valid VascBackend back = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() ); if (back==null) { - throw new IllegalArgumentException("The VascEntry backendId is not found in backends: '"+entry.getBackendId()+"' in entryId: "+id); + throw new IllegalArgumentException("The VascEntry backend is not found in backends: '"+entry.getBackendId()+"' in entryId: "+id); } @@ -234,22 +234,17 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { vef.setEditReadOnly(false); } + /* moved to fillVascEntryFrontend if (vef.getVascEntryFieldValue()==null) { VascBackend back2 = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() ); vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef)); } + */ if (vef.getVascEntryFieldType()==null) { Object defValue = vef.getDefaultValue(); if (defValue != null) { - for (String typeId: vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeIds()) { - VascEntryFieldType type = vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById(typeId); - Class autoClass = type.getAutoDetectClass(); - if (autoClass!=null && autoClass.isAssignableFrom(defValue.getClass())) { - vef.setVascEntryFieldType(type); - break; - } - } + vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeByClass(defValue.getClass())); } if (vef.getVascEntryFieldType()==null) { vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextField")); @@ -257,6 +252,19 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { //vef.setStyleList("vasc.entry."+id+"."+vid+".styleEdit"); } + + if (vef.getDefaultValue()!=null && vef.getDefaultValue() instanceof String) { + if (vef.getVascEntryFieldType().getObjectConverter() != null) { + Object value; + try { + value = vef.getVascEntryFieldType().getObjectConverter().convertTo(vef.getDefaultValue(), Locale.getDefault()); + } catch (ObjectConverterException e) { + throw new VascException(e); + } + vef.setDefaultValue(value); + } + } + //for (VascValidator vv:vef.getVascValidators()) { //} } @@ -363,6 +371,18 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { //VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() ); //vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef)); } + + if (vef.getDefaultValue()!=null && vef.getDefaultValue() instanceof String) { + if (vef.getVascEntryFieldType()!=null && vef.getVascEntryFieldType().getObjectConverter() != null) { + Object value; + try { + value = vef.getVascEntryFieldType().getObjectConverter().convertTo(vef.getDefaultValue(), Locale.getDefault()); + } catch (ObjectConverterException e) { + throw new VascException(e); + } + vef.setDefaultValue(value); + } + } } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java index 363b185..cf52099 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascBackendController.java @@ -22,7 +22,10 @@ package net.forwardfire.vasc.impl; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import net.forwardfire.vasc.backend.VascBackend; @@ -62,5 +65,14 @@ public class DefaultVascBackendController implements VascBackendControllerLocal } backends.put(backend.getId(), backend); } + + public List getVascBackendIds() { + List result = new ArrayList(50); + for (String id:backends.keySet()) { + result.add(id); + } + Collections.sort(result); // lets do abc for consistance behauvior. + return result; + } } \ No newline at end of file diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java index 906de1d..544e7ca 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascEntry.java @@ -824,6 +824,19 @@ public class DefaultVascEntry implements VascEntry { return listOptions; } + public VascEntryField getListOptionById(String listOptionId) { + for (VascEntryField vef:listOptions) { + if (vef.getId().equals(listOptionId)) { + return vef; + } + } + return null; + } + + public void removeListOption(VascEntryField listOption) { + listOptions.remove(listOption); + } + public void addVascBackendFilter(VascBackendFilter filter) { backendFilters.add(filter); diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java index 6531a59..2d3c93f 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFactory.java @@ -37,7 +37,9 @@ import net.forwardfire.vasc.backend.proxy.VascBackendProxyTimerLogger; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryControllerLocal; +import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.impl.actions.AddRowAction; import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction; @@ -139,20 +141,26 @@ public class DefaultVascFactory { static public void fillVascControllerLocalEntries(VascEntryControllerLocal c,VascController con) throws VascException { for (String id:c.getVascEntryIds()) { VascEntry entry = c.getMasterVascEntryById(id); - if (entry.isVascDisplayOnly()==false) { - if (entry.isVascAdminCreate()) { - entry.addRowAction(new AddRowAction()); + + // hackje for calling multiple times on same entries. + if (entry.getGlobalActionById(XMLExportGlobalAction.ACTION_ID)==null) { + + if (entry.isVascDisplayOnly()==false) { + if (entry.isVascAdminCreate()) { + entry.addRowAction(new AddRowAction()); + } + if (entry.isVascAdminEdit()) { + entry.addRowAction(new EditRowAction()); + } + if (entry.isVascAdminDelete()) { + entry.addRowAction(new DeleteRowAction()); + } } - if (entry.isVascAdminEdit()) { - entry.addRowAction(new EditRowAction()); - } - if (entry.isVascAdminDelete()) { - entry.addRowAction(new DeleteRowAction()); - } - } - entry.addGlobalAction(new XMLExportGlobalAction()); - entry.addGlobalAction(new CSVExportGlobalAction()); - entry.addGlobalAction(new RefreshDataGlobalAction()); + entry.addGlobalAction(new XMLExportGlobalAction()); + entry.addGlobalAction(new CSVExportGlobalAction()); + entry.addGlobalAction(new RefreshDataGlobalAction()); + } + /* DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver(resourceBundle); @@ -208,6 +216,14 @@ public class DefaultVascFactory { VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); frontendData.getVascEntryState().setVascBackend(backend); frontendData.getVascEntryState().setVascEntry(entry); + + for (VascEntryField field:entry.getVascEntryFields()) { + if (field.getVascEntryFieldValue()==null) { + VascEntryFieldValue v = backend.provideVascEntryFieldValue(field); + field.setVascEntryFieldValue(v); + } + } + frontendData.setVascFrontendPager(new DefaultVascFrontendPager(entry)); frontendData.setVascFrontendActions(new DefaultVascFrontendActions(entry)); } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java index 5bd566a..0a23317 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendActions.java @@ -26,6 +26,7 @@ import java.util.Date; import java.util.logging.Logger; import net.forwardfire.vasc.backend.VascBackendFilter; +import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; @@ -170,21 +171,33 @@ public class DefaultVascFrontendActions implements VascFrontendActions { public void refreshData() { entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_READ, null); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); + VascBackendState backendState = entry.getVascFrontendData().getVascEntryState().getVascBackendState(); try { // check and correct max page size - if (entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()>entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()) { - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()); + if (backendState.getPageSize() > backendState.getPageSizeMax()) { + backendState.setPageSize(backendState.getPageSizeMax()); } - + // Sets parameters to backend state for (String key:entry.getEntryParameterKeys()) { Object value = entry.getEntryParameter(key); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(key, value); - } - entry.getVascFrontendData().getVascEntryState().setEntryDataList(entry.getVascFrontendData().getVascEntryState().getVascBackend().execute(entry.getVascFrontendData().getVascEntryState().getVascBackendState())); + backendState.setDataParameter(key, value); + } - // also update total every time - Long total = entry.getVascFrontendData().getVascEntryState().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState()); + // Execute to get data. + entry.getVascFrontendData().getVascEntryState().setEntryDataList(entry.getVascFrontendData().getVascEntryState().getVascBackend().execute(backendState)); + + // Update total every time first + Long total = entry.getVascFrontendData().getVascEntryState().getVascBackend().fetchTotalExecuteSize(backendState); entry.getVascFrontendData().getVascEntryState().setTotalBackendRecords(total); + + // check if we need to change the current page + int pages = new Long(total/backendState.getPageSize()).intValue(); + if (backendState.getPageIndex() > pages) { + backendState.setPageIndex(pages); + entry.getVascFrontendData().getVascEntryState().setEntryDataList(entry.getVascFrontendData().getVascEntryState().getVascBackend().execute(backendState)); + } + + } catch (Exception e) { entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java index f6ad502..90865d6 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendHelper.java @@ -26,8 +26,6 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; -import net.forwardfire.vasc.backend.VascBackendPageNumber; -import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascException; @@ -42,8 +40,6 @@ import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener.VascFronte import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.frontend.VascFrontendHelper; - - /** * * @author Willem Cazander diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java index 8188fcb..f2a6cf5 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/DefaultVascFrontendPager.java @@ -148,7 +148,7 @@ public class DefaultVascFrontendPager implements VascFrontendPager { if (total==null) { return result; // no pages } - int pages = new Long(total/state.getPageSize()).intValue(); + int pages = new Long(total/state.getPageSize()).intValue(); for (int i=0;i<=pages;i++) { VascBackendPageNumber pn = new VascBackendPageNumber(i); if (state.getPageIndex()==i) { diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldType.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldType.java index db310f4..ceec625 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldType.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldType.java @@ -40,6 +40,9 @@ public class DefaultVascEntryFieldType extends AbstractVascEntryFieldType { public VascEntryFieldType clone() throws CloneNotSupportedException { DefaultVascEntryFieldType clone = new DefaultVascEntryFieldType(); clone.id=id; + if (objectConverter!=null) { + clone.objectConverter=objectConverter.clone(); + } clone.autoDetectClass=autoDetectClass; clone.uiComponentId=uiComponentId; clone.inputMask=inputMask; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldTypeController.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldTypeController.java index 01a7c03..0be723e 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldTypeController.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/DefaultVascEntryFieldTypeController.java @@ -100,4 +100,16 @@ public class DefaultVascEntryFieldTypeController implements VascEntryFieldTypeCo Collections.sort(result); // lets do abc for consistance behauvior. return result; } + + + public VascEntryFieldType getVascEntryFieldTypeByClass(Class clazz) { + for (String typeId: vascEntryFieldTypes.keySet()) { + VascEntryFieldType type = getVascEntryFieldTypeById(typeId); + Class autoClass = type.getAutoDetectClass(); + if (autoClass!=null && autoClass.isAssignableFrom(clazz)) { + return type; + } + } + return null; + } } diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/FieldTypeParser.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/FieldTypeParser.java index 425e72a..ab95158 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/FieldTypeParser.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/type/FieldTypeParser.java @@ -33,6 +33,8 @@ import net.forwardfire.vasc.core.VascEntryFieldType; import org.xml.sax.SAXException; +import org.x4o.xml.conv.DefaultObjectConverterProvider; +import org.x4o.xml.conv.ObjectConverter; import org.x4o.xml.core.X4OParser; import org.x4o.xml.element.Element; @@ -63,8 +65,13 @@ public class FieldTypeParser extends X4OParser { public List getTypes() { List result = new ArrayList(4); + DefaultObjectConverterProvider convProvider = new DefaultObjectConverterProvider(true); for (Element e:getElementContext().getRootElement().getChilderen()) { VascEntryFieldType a = (VascEntryFieldType)e.getElementObject(); + if (a.getObjectConverter()==null && a.getAutoDetectClass()!=null) { + ObjectConverter conv = convProvider.getObjectConverterForClass(a.getAutoDetectClass()); + a.setObjectConverter(conv); // move to x4o or finalizer + } result.add(a); } return result; diff --git a/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java b/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java index 38deb48..b44207b 100644 --- a/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java +++ b/vasc-core/src/main/java/net/forwardfire/vasc/impl/ui/VascSelectItemModelStringEnum.java @@ -43,6 +43,7 @@ public class VascSelectItemModelStringEnum implements VascSelectItemModel { private static final long serialVersionUID = 1L; private Object data = null; + private Class enumClass = null; private String nullLabel = null; private String nullKeyValue = null; private Boolean returnKeyValue = null; @@ -54,6 +55,12 @@ public class VascSelectItemModelStringEnum implements VascSelectItemModel { public List getVascSelectItems(VascEntry currentEntry) throws VascException { List result = new ArrayList(100); + if (enumClass!=null) { + for (Object o:enumClass.getEnumConstants()) { + String value = o.toString(); + result.add(new VascSelectItem(value,value,value)); + } + } if (data==null) { return result; } @@ -143,4 +150,18 @@ public class VascSelectItemModelStringEnum implements VascSelectItemModel { public void setUseParentFields(Boolean useParentFields) { this.useParentFields = useParentFields; } + + /** + * @return the enumClass + */ + public Class getEnumClass() { + return enumClass; + } + + /** + * @param enumClass the enumClass to set + */ + public void setEnumClass(Class enumClass) { + this.enumClass = enumClass; + } } \ No newline at end of file diff --git a/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld b/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld index e80ab3d..e81878b 100644 --- a/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld +++ b/vasc-core/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld @@ -16,7 +16,7 @@ - + @@ -28,4 +28,27 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld b/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld index 24cbc75..d83c6b3 100644 --- a/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld +++ b/vasc-core/src/main/resources/META-INF/vasc/vasc-lang.eld @@ -3,7 +3,7 @@ - + @@ -32,7 +32,11 @@ - + + + + + @@ -71,4 +75,8 @@ + + + + \ No newline at end of file diff --git a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project index 2f745b9..52ee197 100644 --- a/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project +++ b/vasc-demo/vasc-demo-petstore-j2ee5/vasc-demo-petstore-j2ee5-ejb/.project @@ -21,12 +21,12 @@ - org.eclipse.m2e.core.maven2Builder + org.eclipse.wst.validation.validationbuilder - org.eclipse.wst.validation.validationbuilder + org.eclipse.m2e.core.maven2Builder diff --git a/vasc-demo/vasc-demo-swing/pom.xml b/vasc-demo/vasc-demo-swing/pom.xml index 09b0969..bb32c4a 100644 --- a/vasc-demo/vasc-demo-swing/pom.xml +++ b/vasc-demo/vasc-demo-swing/pom.xml @@ -7,7 +7,6 @@ .. vasc-demo-swing - net.forwardfire.vasc.demo vasc-demo-swing vasc-demo-swing @@ -31,6 +30,11 @@ vasc-backend-mongodb ${project.version} + + net.forwardfire.vasc + vasc-backend-metamodel + ${project.version} + net.forwardfire.vasc vasc-backend-jdbc @@ -41,5 +45,15 @@ juel ${juel.version} + + postgresql + postgresql + 9.1-901.jdbc4 + + + mysql + mysql-connector-java + 5.1.19 + \ No newline at end of file diff --git a/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/JMainFrame.java b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/JMainFrame.java new file mode 100644 index 0000000..1b0761b --- /dev/null +++ b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/JMainFrame.java @@ -0,0 +1,640 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + +package net.forwardfire.vasc.demo.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; +import javax.swing.event.TreeModelListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; + +import org.eobjects.metamodel.DataContext; +import org.eobjects.metamodel.schema.Column; +import org.eobjects.metamodel.schema.Table; + +import net.forwardfire.vasc.backend.VascBackendControllerLocal; +import net.forwardfire.vasc.backend.VascBackendFilter; +import net.forwardfire.vasc.backend.metamodel.MetaModelDataContextCsv; +import net.forwardfire.vasc.backend.metamodel.MetaModelDataContextMongodb; +import net.forwardfire.vasc.backend.metamodel.MetaModelDataContextProvider; +import net.forwardfire.vasc.backend.metamodel.MetaModelVascBackend; +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryController; +import net.forwardfire.vasc.core.VascEntryControllerLocal; +import net.forwardfire.vasc.core.VascEntryField; +import net.forwardfire.vasc.core.VascEntryFieldSet; +import net.forwardfire.vasc.core.VascLinkEntry; +import net.forwardfire.vasc.frontends.swing.SwingPanelIntegration; +import net.forwardfire.vasc.frontends.swing.SwingPanelTabbed; +import net.forwardfire.vasc.impl.DefaultVascEntry; +import net.forwardfire.vasc.impl.DefaultVascEntryField; +import net.forwardfire.vasc.impl.DefaultVascFactory; +import net.forwardfire.vasc.validators.VascValidator; + +public class JMainFrame extends JFrame { + + VascManager vascManager = null; + SwingPanelIntegration spi = null; + JTabbedPane tabPane = null; + JTree vascTree = null; + JMenu fileMenu = new JMenu("File"); + JMenu connMenu = new JMenu("Connection"); + JMenu vascMenu = new JMenu("Entries"); + + public JMainFrame(VascManager vascManager ) { + this.vascManager=vascManager; + setTitle("Vasc Swing Demo"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + + setLayout(new BorderLayout()); + add(createTreePane(), BorderLayout.LINE_START); + add(createContentPane(), BorderLayout.LINE_END); + add(createLogPane(), BorderLayout.PAGE_END); + + createMenuItems(); + JMenuBar menubar = new JMenuBar(); + menubar.add(fileMenu); + menubar.add(connMenu); + menubar.add(vascMenu); + + // view + setJMenuBar(menubar); + setMinimumSize(new Dimension(1111,888)); + pack(); + //setVisible(true); + + //spi.createNewVascView(ve); + } + + class VascTreeModel extends DefaultTreeModel { + public VascTreeModel(TreeNode root) { + super(root); + } + + private static final long serialVersionUID = -7436681803506994277L; + + @Override + public void addTreeModelListener(TreeModelListener l) { + super.addTreeModelListener(l); + } + } + + private JPanel createTreePane() { + + DefaultMutableTreeNode root = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.NONE,null)); + + vascTree = new JTree(new VascTreeModel(root)); + vascTree.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + if (e.getClickCount() == 2 && vascTree.getSelectionModel().isSelectionEmpty()==false) { + try { + DefaultMutableTreeNode node = (DefaultMutableTreeNode)vascTree.getSelectionModel().getSelectionPath().getLastPathComponent(); + if (node.getUserObject() instanceof String) { + return; + } + VascTreeNode vascNode = (VascTreeNode)node.getUserObject(); + if (vascNode != null) { + if (vascNode.type == VascTreeNodeType.ENTRY) { + VascEntry ee = vascManager.getVascController().getVascEntryController().getVascEntryById(vascNode.id).clone(); + DefaultVascFactory.fillVascEntryFrontend(ee, vascManager.getVascController(), DefaultVascFactory.getDefaultVascFrontendData(null)); + spi.createNewVascView(ee); + } else if (vascNode.type == VascTreeNodeType.ENTRY_FIELD) { + VascEntryField vef = vascManager.getVascController().getVascEntryController().getVascEntryById(vascNode.entryId).getVascEntryFieldById(vascNode.id); + JDialogVascEntryField d = new JDialogVascEntryField(JMainFrame.this,vef); + d.setVisible(true); + } + } + } catch (Exception ee) { + ee.printStackTrace(); + } + } + } + }); + + JPanel treePanel = new JPanel(); + treePanel.setBorder(BorderFactory.createLineBorder(Color.PINK)); + treePanel.add(vascTree); + return treePanel; + } + + private JPanel createContentPane() { + JPanel contentPane = new JPanel(); + tabPane = new JTabbedPane(); + spi = new SwingPanelTabbed(tabPane); + contentPane.add(tabPane); + return contentPane; + } + + private JPanel createLogPane() { + JPanel logPanel = new JPanel(); + logPanel.add(new JLabel("log")); + return logPanel; + } + + class VascTreeNode { + public VascTreeNode() {} + public VascTreeNode(VascTreeNodeType type,String id) { this.type=type;this.id=id; } + public VascTreeNode(VascTreeNodeType type,String id,String entryId) { this.type=type;this.id=id;this.entryId=entryId; } + VascTreeNodeType type; + String id; + String entryId; + @Override + public String toString() { + return id; + } + + } + enum VascTreeNodeType { + NONE, + BACKEND, + ENTRY, + ENTRY_FIELD, + ENTRY_FIELD_SET + } + + private void rebuildTree() { + + DefaultMutableTreeNode root = (DefaultMutableTreeNode)vascTree.getModel().getRoot(); + root.removeAllChildren(); + + DefaultMutableTreeNode backends = new DefaultMutableTreeNode("VascBackends"); + for (String id:vascManager.getVascController().getVascBackendController().getVascBackendIds()) { + DefaultMutableTreeNode backendNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.BACKEND,id)); + backends.add(backendNode); + } + root.add(backends); + + DefaultMutableTreeNode entries = new DefaultMutableTreeNode("VascEntries"); + for (String id:vascManager.getVascController().getVascEntryController().getVascEntryIds()) { + VascEntry ve = vascManager.getVascController().getVascEntryController().getVascEntryById(id); + DefaultMutableTreeNode entryNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY,id)); + entries.add(entryNode); + + DefaultMutableTreeNode fields = new DefaultMutableTreeNode("Fields"); + for (VascEntryField vef:ve.getVascEntryFields()) { + DefaultMutableTreeNode vefNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD,vef.getId(),id)); + fields.add(vefNode); + + /* + DefaultMutableTreeNode validators = new DefaultMutableTreeNode("Validators"); + for (VascValidator vv:vef.getVascValidators()) { + DefaultMutableTreeNode vNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD,vv.getClass().getSimpleName())); + validators.add(vNode); + } + vefNode.add(validators); + */ + } + entryNode.add(fields); + + DefaultMutableTreeNode fieldSets = new DefaultMutableTreeNode("FieldSets"); + for (VascEntryFieldSet vefs:ve.getVascEntryFieldSets()) { + DefaultMutableTreeNode vefsNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD_SET,vefs.getId(),id)); + fieldSets.add(vefsNode); + } + entryNode.add(fieldSets); + + DefaultMutableTreeNode links = new DefaultMutableTreeNode("Links"); + for (VascLinkEntry vle:ve.getVascLinkEntries()) { + DefaultMutableTreeNode vefsNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD_SET,vle.getId())); + links.add(vefsNode); + } + entryNode.add(links); + + DefaultMutableTreeNode filters = new DefaultMutableTreeNode("Backend Filters"); + for (VascBackendFilter vbf:ve.getVascBackendFilters()) { + DefaultMutableTreeNode vefsNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD_SET,vbf.getClass().getSimpleName())); + filters.add(vefsNode); + } + entryNode.add(links); + + DefaultMutableTreeNode param = new DefaultMutableTreeNode("Backend Parameters"); + for (String key:ve.getEntryParameterKeys()) { + DefaultMutableTreeNode vefsNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD_SET,key)); + param.add(vefsNode); + } + entryNode.add(param); + + + DefaultMutableTreeNode options = new DefaultMutableTreeNode("List Options"); + for (VascEntryField vef:ve.getListOptions()) { + DefaultMutableTreeNode vefsNode = new DefaultMutableTreeNode(new VascTreeNode(VascTreeNodeType.ENTRY_FIELD_SET,vef.getId())); + options.add(vefsNode); + } + entryNode.add(options); + } + root.add(entries); + + SwingUtilities.updateComponentTreeUI(vascTree); + } + + private void createMenuItems() { + JMenuItem openXmlItem = new JMenuItem("Open Xml"); + openXmlItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + final JFileChooser fc = new JFileChooser(); + //fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnVal = fc.showOpenDialog((JMenuItem)e.getSource()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + vascManager.openFile(file); + rebuildTree(); + } + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + }); + fileMenu.add(openXmlItem); + JMenuItem closeXmlItem = new JMenuItem("Close"); + fileMenu.add(closeXmlItem); + fileMenu.addSeparator(); + JMenuItem exitItem = new JMenuItem("Exit"); + fileMenu.add(exitItem); + + JMenuItem connectVascItem = new JMenuItem("Add Vasc"); + connectVascItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + } + }); + connMenu.add(connectVascItem); + + JMenuItem connectMongoItem = new JMenuItem("Connect Mongo"); + connectMongoItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + }); + connMenu.add(connectMongoItem); + + JMenuItem connectPgItem = new JMenuItem("Add Postgres"); + connMenu.add(connectPgItem); + JMenuItem connectMysqlItem = new JMenuItem("Add Mysql"); + connMenu.add(connectMysqlItem); + JMenuItem connectLdapItem = new JMenuItem("Add Ldap"); + connMenu.add(connectLdapItem); + connMenu.addSeparator(); + JMenuItem connectMetaCsvItem = new JMenuItem("Add meta csv"); + connectMetaCsvItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JDialogMetaCsv d = new JDialogMetaCsv(JMainFrame.this); + d.setVisible(true); + } + }); + connMenu.add(connectMetaCsvItem); + JMenuItem connectMetaXmlItem = new JMenuItem("Add meta xml"); + connMenu.add(connectMetaXmlItem); + JMenuItem connectMetaMongoItem = new JMenuItem("Add meta mongo"); + connectMetaMongoItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JDialogMetaMongodb d = new JDialogMetaMongodb(JMainFrame.this); + d.setVisible(true); + } + }); + connMenu.add(connectMetaMongoItem); + JMenuItem connectMetaJdbcItem = new JMenuItem("Add meta jdbc"); + connMenu.add(connectMetaJdbcItem); + + /* + for (final String id:ve.getVascFrontendData().getVascController().getVascEntryController().getVascEntryIds()) { + JMenuItem item = new JMenuItem(id); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + VascEntry ee = ve.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id).clone(); + DefaultVascFactory.fillVascEntryFrontend(ee, ve.getVascFrontendData().getVascController(), DefaultVascFactory.getDefaultVascFrontendData(null)); + spi.createNewVascView(ee); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + }); + vascMenu.add(item); + } + */ + + JMenuItem item = new JMenuItem("Close tab."); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (tabPane.getSelectedIndex()>=0) { + tabPane.removeTabAt(tabPane.getSelectedIndex()); // todo release vasc frontend + } + } + + }); + vascMenu.add(item); + } + + public class JDialogMetaCsv extends JDialog implements ActionListener { + + private static final long serialVersionUID = -8638394652416472734L; + + public JDialogMetaCsv(Frame aFrame) { + setTitle("Add csv file"); + setMinimumSize(new Dimension(640,480)); + setPreferredSize(new Dimension(999,666)); + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + clearAndHide(); + } + }); + JPanel mainPanel = new JPanel(); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + mainPanel.setLayout(new BorderLayout()); + //mainPanel.add(createPanelTop(),BorderLayout.NORTH); + mainPanel.add(createPanelCenter(),BorderLayout.CENTER); + //mainPanel.add(createPanelBottom(),BorderLayout.SOUTH); + getContentPane().add(mainPanel); + pack(); + setLocationRelativeTo(aFrame); + } + + public void clearAndHide() { + setVisible(false); + } + + public JPanel createPanelCenter() { + JPanel result = new JPanel(); + //result.setLayout(new SpringLayout()); + + result.add(new JLabel("File")); + JButton fileButton = new JButton("Open"); + fileButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final JFileChooser fc = new JFileChooser(); + int returnVal = fc.showOpenDialog((JButton)e.getSource()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + MetaModelDataContextCsv ds = new MetaModelDataContextCsv(); + ds.setFile(file.getAbsolutePath()); + createMetaEntry(ds,file.getName(),null); + } + } + }); + result.add(fileButton); + + return result; + } + + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + + } + } + + public class JDialogMetaMongodb extends JDialog implements ActionListener { + + private static final long serialVersionUID = -8638394652416472734L; + private JTextField hostname = null; + private JTextField database = null; + + public JDialogMetaMongodb(Frame aFrame) { + setTitle("Add mongodb"); + setMinimumSize(new Dimension(800,600)); + setPreferredSize(new Dimension(999,666)); + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + clearAndHide(); + } + }); + JPanel mainPanel = new JPanel(); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + mainPanel.setLayout(new BorderLayout()); + //mainPanel.add(createPanelTop(),BorderLayout.NORTH); + mainPanel.add(createPanelCenter(),BorderLayout.CENTER); + //mainPanel.add(createPanelBottom(),BorderLayout.SOUTH); + getContentPane().add(mainPanel); + pack(); + setLocationRelativeTo(aFrame); + } + + public void clearAndHide() { + setVisible(false); + } + + public JPanel createPanelCenter() { + JPanel result = new JPanel(); + //result.setLayout(new SpringLayout()); + + result.add(new JLabel("Hostname")); + hostname = new JTextField("localhost"); + result.add(hostname); + + result.add(new JLabel("Database")); + database = new JTextField("lefiona"); + result.add(database); + + JButton fileButton = new JButton("Connect"); + fileButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + MetaModelDataContextMongodb ds = new MetaModelDataContextMongodb(); + ds.setHostname(hostname.getText()); + ds.setDatabase(database.getText()); + DataContext metaDs = ds.getDataContext(); + for (String table:metaDs.getDefaultSchema().getTableNames()) { + createMetaEntry(ds,table,table); + } + } + }); + result.add(fileButton); + + return result; + } + + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + + } + } + + + public class JDialogVascEntryField extends JDialog implements ActionListener { + + private static final long serialVersionUID = -8638394652416472734L; + private JButton okButton = null; + private JButton cancelButton = null; + private JTextField idField = null; + private JTextField backendNameField = null; + private JComboBox fieldTypeBox = null; + private VascEntryField field = null; + + public JDialogVascEntryField(Frame aFrame,VascEntryField field) { + this.field = field; + setTitle("Vasc Entry Field"); + setMinimumSize(new Dimension(800,600)); + setPreferredSize(new Dimension(999,666)); + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + clearAndHide(); + } + }); + JPanel mainPanel = new JPanel(); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); + mainPanel.setLayout(new BorderLayout()); + //mainPanel.add(createPanelTop(),BorderLayout.NORTH); + mainPanel.add(createPanelCenter(),BorderLayout.CENTER); + mainPanel.add(createPanelBottom(),BorderLayout.SOUTH); + getContentPane().add(mainPanel); + pack(); + setLocationRelativeTo(aFrame); + } + + public void clearAndHide() { + setVisible(false); + } + + public JPanel createPanelCenter() { + JPanel result = new JPanel(); + //result.setLayout(new SpringLayout()); + + result.add(new JLabel("id")); + idField = new JTextField(field.getId()); + result.add(idField); + + result.add(new JLabel("backendName")); + backendNameField = new JTextField(field.getBackendName()); + result.add(backendNameField); + + result.add(new JLabel("type")); + fieldTypeBox = new JComboBox(vascManager.getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeIds().toArray()); + fieldTypeBox.setSelectedItem(field.getVascEntryFieldType().getId()); + result.add(fieldTypeBox); + + return result; + } + + private JPanel createPanelBottom() { + JPanel result = new JPanel(); + okButton = new JButton("ok"); + okButton.addActionListener(this); + cancelButton = new JButton("cancel"); + cancelButton.addActionListener(this); + result.add(okButton); + result.add(cancelButton); + return result; + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource()==cancelButton) { + clearAndHide(); + return; + } + if (e.getSource()==okButton) { + + VascEntryField vef = ((VascEntryControllerLocal)vascManager.getVascController().getVascEntryController()).getMasterVascEntryById(field.getVascEntry().getId()).getVascEntryFieldById(field.getId()); + vef.setVascEntryFieldType(vascManager.getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById((String)fieldTypeBox.getSelectedItem())); + + clearAndHide(); + return; + } + } + } + + private void createMetaEntry(MetaModelDataContextProvider ds,String id,String tableName) { + DataContext metaDs = ds.getDataContext(); + Table metaTable = null; + if (tableName==null) { + metaTable = metaDs.getDefaultSchema().getTable(0); + } else { + metaTable = metaDs.getDefaultSchema().getTableByName(tableName); + } + Column[] keys = metaTable.getPrimaryKeys(); + Column[] cols = metaTable.getColumns(); + if (cols.length==0) { + return; // vasc needs at least one column + } + + MetaModelVascBackend backend = new MetaModelVascBackend(); + backend.setId(id+"_backend"); + backend.setDataContextProvider(ds); + backend.setTable(metaTable.getName()); + if (keys.length>0) { + backend.setTableId(keys[0].getName()); + } else { + backend.setTableId(cols[0].getName()); + //TODO backend.setRequestReadOnly(true); + } + + VascEntry ve = new DefaultVascEntry(); + ve.setId(id); + ve.setBackendId(id+"_backend"); + for (Column c:cols) { + VascEntryField vef = new DefaultVascEntryField(c.getName()); + vef.setVascEntryFieldType(vascManager.getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeByClass(c.getType().getJavaEquivalentClass())); + ve.addVascEntryField(vef); + } + + try { + ((VascBackendControllerLocal)vascManager.getVascController().getVascBackendController()).addVascBackend(backend); + ((VascEntryControllerLocal)vascManager.getVascController().getVascEntryController()).addVascEntry(ve, vascManager.getVascController()); + + // mm TODO rm this fill which adds the global actions ... and show updated tree in editor + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vascManager.getVascController().getVascEntryController(), vascManager.getVascController()); + rebuildTree(); + } catch (Exception ee) { + ee.printStackTrace(); + } + } +} diff --git a/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java index 621c0f1..b92ec82 100644 --- a/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java +++ b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/SwingStartup.java @@ -22,115 +22,38 @@ package net.forwardfire.vasc.demo.swing; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.FileOutputStream; import java.lang.reflect.Method; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; -import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascEntryField; -import net.forwardfire.vasc.frontends.swing.SwingVascFrontend; -import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.impl.x4o.VascParser; public class SwingStartup { + private JMainFrame mainFrame = null; + private VascManager vascManager = null; + public static void main(String[] argu){ - JFrame.setDefaultLookAndFeelDecorated(false); try { - VascEntry entry = getVascTable(); - - SwingStartup s = new SwingStartup(); - JFrame frame = s.viewEntry(entry); - - while (frame.isVisible()) { - Thread.sleep(100000); - } + SwingStartup s = new SwingStartup(); + s.init(); + s.open(); } catch (Exception e) { e.printStackTrace(); } } - public JFrame viewEntry(final VascEntry entry) throws Exception { - // get GUI - JFrame frame = new JFrame(); - frame.setTitle("Vasc Test - Swing - "+entry.getName()); - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - frame.setLocationRelativeTo(null); - - JMenuBar menubar = new JMenuBar(); - JMenu vascMenu = new JMenu("Vasc Entries"); - - for (final String id:entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryIds()) { - JMenuItem item = new JMenuItem(id); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id); - fill(ee,entry.getVascFrontendData().getVascController()); - viewEntry(ee); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - - }); - vascMenu.add(item); - } - menubar.add(vascMenu); - frame.setJMenuBar(menubar); - - // define redering - JPanel panel = new JPanel(); - SwingVascFrontend render = new SwingVascFrontend(panel); - frame.add(panel); + public void init() throws Exception { + vascManager = new VascManager(); + vascManager.start(); - // render - render.initEntry(entry); - render.renderView(); - - // get data - entry.getVascFrontendData().getVascFrontendActions().refreshData(); - - // view - frame.pack(); - frame.setVisible(true); - - return frame; + mainFrame = new JMainFrame(vascManager); } - - - - static public void fill(VascEntry entry,VascController vascController) { - DefaultVascFactory.fillVascEntryFrontend(entry, vascController, DefaultVascFactory.getDefaultVascFrontendData(null)); - entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(0); - } - - static public VascEntry getVascTable() throws Exception { - - VascController c = DefaultVascFactory.getDefaultVascController(2288L,"forwarddire.net","user","admin"); - - VascParser parser = new VascParser(c); - File f = File.createTempFile("test-vasc", ".xml"); - parser.setDebugOutputStream(new FileOutputStream(f)); - parser.parseResource("net/forwardfire/vasc/demo/swing/example/tables.xml"); - - DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) c.getVascEntryController(), c); - - VascEntry entry = parser.getVascController().getVascEntryController().getVascEntryById("users"); - fill(entry,c); - return entry; + + public void open() throws Exception { + mainFrame.setVisible(true); } + static void printEntry(VascEntry e) throws Exception { diff --git a/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/VascManager.java b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/VascManager.java new file mode 100644 index 0000000..cd4cddf --- /dev/null +++ b/vasc-demo/vasc-demo-swing/src/main/java/net/forwardfire/vasc/demo/swing/VascManager.java @@ -0,0 +1,62 @@ +package net.forwardfire.vasc.demo.swing; + +import java.io.File; +import java.io.FileOutputStream; + +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntryControllerLocal; +import net.forwardfire.vasc.core.VascException; +import net.forwardfire.vasc.impl.DefaultVascFactory; +import net.forwardfire.vasc.impl.x4o.VascParser; + +public class VascManager { + + VascController vascController = null; + + public VascManager() { + + } + + public void start() { + try { + vascController = DefaultVascFactory.getDefaultVascController(2288L,"forwardfire.net","user","admin"); + initEditor(); + } catch (VascException e) { + throw new RuntimeException(e); + } + } + + public void stop() { + } + + private void initEditor() { + try { + VascParser parser = new VascParser(vascController); + parser.addGlobalELBean("vascController", vascController); + parser.parseResource("net/forwardfire/vasc/demo/swing/example/vasc-edit.xml"); + + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vascController.getVascEntryController(), vascController); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public void openFile(File file) { + try { + VascParser parser = new VascParser(vascController); + File f = File.createTempFile("test-vasc", ".xml"); + parser.setDebugOutputStream(new FileOutputStream(f)); + parser.parseFile(file.getAbsolutePath()); + + DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vascController.getVascEntryController(), vascController); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public VascController getVascController() { + return vascController; + } +} diff --git a/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml b/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml index 3abcb5c..08665d3 100644 --- a/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml +++ b/vasc-demo/vasc-demo-swing/src/main/resources/net/forwardfire/vasc/demo/swing/example/tables.xml @@ -1,5 +1,6 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -79,13 +128,13 @@ - + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java index 4e048b2..e70216e 100644 --- a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPagerPanel.java @@ -49,12 +49,7 @@ public class SwingPagerPanel extends JPanel implements VascEntryFrontendEventLis public SwingPagerPanel(VascEntry vascEntry) { this.vascEntry=vascEntry; - //result = this; result = new JPanel(); - // result.setBackground(Color.green); - //result.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); - - add(result); vascEntry.getVascFrontendData().addVascEntryFrontendEventListener(this); } diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelFrame.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelFrame.java new file mode 100644 index 0000000..eb7d826 --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelFrame.java @@ -0,0 +1,137 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + +package net.forwardfire.vasc.frontends.swing; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; + +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; +import net.forwardfire.vasc.impl.DefaultVascFactory; + +/** + * SwingPanelFrame to render into frames. + * + * + * + * @author Willem Cazander + * @version 1.0 Feb 6, 2012 + */ +public class SwingPanelFrame implements SwingPanelIntegration { + + Map panels = new HashMap(5); + boolean addVascMenu = true; + + public SwingPanelFrame() { + this(true); + } + public SwingPanelFrame(boolean addVascMenu) { + this.addVascMenu=addVascMenu; + } + + public void createNewVascView(VascEntry entry) throws Exception { + // define redering + JPanel panel = initVascView(); + SwingVascFrontend render = new SwingVascFrontend(panel,this); + + // render + render.initEntry(entry); + render.renderView(); + + entry.getVascFrontendData().addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() { + private static final long serialVersionUID = -6801954395965101748L; + public void vascEvent(VascEntry entry, Object data) { + if (data instanceof Exception) { + Exception e = (Exception)data; + e.printStackTrace(); + } + } + public VascFrontendEventType[] getEventTypes() { + return new VascFrontendEventType[] {VascFrontendEventType.EXCEPTION}; + } + }); + + // get data + entry.getVascFrontendData().getVascFrontendActions().refreshData(); + openVascView(panel, entry); + } + + public JPanel initVascView() { + return new JPanel(); + } + + public void openVascView(JPanel pane,final VascEntry entry) { + JFrame frame = new JFrame(); + frame.setTitle("Vasc Edit - Swing - "+entry.getName()); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.setLocationRelativeTo(null); + + JMenuBar menubar = new JMenuBar(); + JMenu vascMenu = new JMenu("Vasc Entries"); + + if (addVascMenu) { + for (final String id:entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryIds()) { + JMenuItem item = new JMenuItem(id); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id).clone(); + //TestModelEntry.fill(ee,entry.getVascFrontendData().getVascController()); + DefaultVascFactory.fillVascEntryFrontend(ee, entry.getVascFrontendData().getVascController(), DefaultVascFactory.getDefaultVascFrontendData(null)); + createNewVascView(ee); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + }); + vascMenu.add(item); + } + menubar.add(vascMenu); + frame.setJMenuBar(menubar); + } + + frame.add(pane); + + // view + frame.pack(); + frame.setVisible(true); + + panels.put(pane,frame); + } + + public void closeVascView(JPanel pane,VascEntry entry) { + JFrame frame = panels.get(pane); + if (frame!=null) { + frame.setVisible(false); + } + } +} diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelIntegration.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelIntegration.java new file mode 100644 index 0000000..6826961 --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelIntegration.java @@ -0,0 +1,19 @@ +package net.forwardfire.vasc.frontends.swing; + +import javax.swing.JPanel; + +import net.forwardfire.vasc.core.VascEntry; + +/** + * SwingPanelIntegration provides the JPanels to vasc to integrate into application panel handing. + * + * @author Willem Cazander + * @version 1.0 Feb 6, 2012 + */ +public interface SwingPanelIntegration { + + public void createNewVascView(VascEntry entry) throws Exception; + public JPanel initVascView(); + public void openVascView(JPanel pane,VascEntry entry); + public void closeVascView(JPanel pane,VascEntry entry); +} diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelTabbed.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelTabbed.java new file mode 100644 index 0000000..d055d9d --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingPanelTabbed.java @@ -0,0 +1,92 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + +package net.forwardfire.vasc.frontends.swing; + +import javax.swing.JPanel; +import javax.swing.JTabbedPane; + +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; + +/** + * SwingPanelTabbed to render into tabs. + * + * + * + * @author Willem Cazander + * @version 1.0 Feb 6, 2012 + */ +public class SwingPanelTabbed implements SwingPanelIntegration { + + JTabbedPane tabbedPane = null; + + public SwingPanelTabbed(JTabbedPane tabbedPane) { + this.tabbedPane=tabbedPane; + } + + public void createNewVascView(VascEntry entry) throws Exception { + // define redering + JPanel panel = initVascView(); + SwingVascFrontend render = new SwingVascFrontend(panel,this); + + // render + render.initEntry(entry); + render.renderView(); + + entry.getVascFrontendData().addVascEntryFrontendEventListener(new VascEntryFrontendEventListener() { + private static final long serialVersionUID = -6801954395965101748L; + public void vascEvent(VascEntry entry, Object data) { + if (data instanceof Exception) { + Exception e = (Exception)data; + e.printStackTrace(); + } + } + public VascFrontendEventType[] getEventTypes() { + return new VascFrontendEventType[] {VascFrontendEventType.EXCEPTION}; + } + }); + + // get data + entry.getVascFrontendData().getVascFrontendActions().refreshData(); + openVascView(panel, entry); + } + + public JPanel initVascView() { + return new JPanel(); + } + + public void openVascView(JPanel pane,final VascEntry entry) { + tabbedPane.addTab(entry.getName(), pane); + tabbedPane.setSelectedIndex(tabbedPane.getTabCount()-1); + } + + public void closeVascView(JPanel pane,VascEntry entry) { + for (int i=0;i rowActions = null; + private SwingPanelIntegration panels = null; - public SwingVascFrontend(JComponent parent) { + public SwingVascFrontend(JComponent parent,SwingPanelIntegration panels) { logger = Logger.getLogger(SwingVascFrontend.class.getName()); this.parent=parent; + this.panels=panels; + rowActions = new HashMap(5); } /** @@ -159,14 +166,10 @@ public class SwingVascFrontend extends AbstractVascFrontend { beanValue=beanValue.substring(0, 30); } } - SwingVascEditDialog dialog = new SwingVascEditDialog(this,parent,entry,rowBean,beanValue); - Object result = dialog.openDialog(); - logger.finest("OPEN closed : "+result); - if(result==null) { - return; - } - entry.getVascFrontendData().getVascEntryState().setEntryDataObject(result); - entry.getVascFrontendData().getVascFrontendActions().mergeObject(); + JPanel editPanel = panels.initVascView(); + SwingVascEditDialog dialog = new SwingVascEditDialog(this,editPanel,entry,rowBean,beanValue,panels); + + panels.openVascView(editPanel,entry); } public void renderDelete() throws Exception { @@ -309,8 +312,8 @@ public class SwingVascFrontend extends AbstractVascFrontend { VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c); model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c)); + model.addListener(new VascOptionValueModelListener(c)); model.setValue(c.getDefaultValue()); - //model.addListener(new VascColumnValueModelListener(c,bean)); Object g = editor.createComponent(entry,c,model,body); column++; @@ -320,6 +323,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { body.add(new JLabel()); // fill :( } } + entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry); // add search column++; @@ -327,10 +331,17 @@ public class SwingVascFrontend extends AbstractVascFrontend { body.add(searchLabel); final JTextField searchField = new JTextField(); body.add(searchField); + searchField.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + String searchText = searchField.getText(); + entry.getVascFrontendData().getVascFrontendActions().searchAction(searchText); + } + }); JButton searchButton = new JButton("Search"); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - entry.getVascFrontendData().getVascFrontendActions().searchAction(searchField.getText()); + String searchText = searchField.getText(); + entry.getVascFrontendData().getVascFrontendActions().searchAction(searchText); } }); body.add(searchButton); @@ -396,7 +407,7 @@ public class SwingVascFrontend extends AbstractVascFrontend { counter++; } table.getSelectionModel().addListSelectionListener(new EntrySectionListener(table)); - table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { @@ -428,40 +439,16 @@ public class SwingVascFrontend extends AbstractVascFrontend { public void mouseClicked(MouseEvent e) { TableColumnModel colModel = table.getColumnModel(); int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); - //int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex(); -/* - if (modelIndex < 0) - return; - if (sortCol == modelIndex) - isSortAsc = !isSortAsc; - else - sortCol = modelIndex; - - for (int i = 0; i < columnsCount; i++) { - TableColumn column = colModel.getColumn(i); - column.setHeaderValue(getColumnName(column.getModelIndex())); - } - table.getTableHeader().repaint(); - */ - TableColumn tc = colModel.getColumn(columnModelIndex); VascEntryField field = (VascEntryField)tc.getHeaderValue(); - //VascEntry entry = comp.getVascEntry(); - //VascEntryField field = entry.getVascEntryFieldById(fieldIdString); - - entry.getVascFrontendData().getVascFrontendActions().sortAction(field); - - sortOrder = entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending(); - sortField = field.getId(); - - try { - entry.getVascFrontendData().getVascFrontend().renderView(); - } catch (Exception ee) { - entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, ee); - } - - //Collections.sort(vector,new MyComparator(isSortAsc)); - //table.tableChanged(new TableModelEvent(MyTableModel.this)); + entry.getVascFrontendData().getVascFrontendActions().sortAction(field); + sortOrder = entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending(); + sortField = field.getId(); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception ee) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, ee); + } table.repaint(); } } @@ -474,7 +461,33 @@ public class SwingVascFrontend extends AbstractVascFrontend { if (e.getValueIsAdjusting()) { return; } + + if (table.getSelectedRowCount()==0) { + for (RowVascAction action:rowActions.keySet()) { + JButton but = rowActions.get(action); + if (action.getId().contains("add")==false) { + but.setEnabled(false); + } + } + } else if (table.getSelectedRowCount()==1) { + for (JButton but:rowActions.values()) { + but.setEnabled(true); + } + } else { + for (RowVascAction action:rowActions.keySet()) { + JButton but = rowActions.get(action); + if (action.isMultiRowAction()) { + but.setEnabled(true); + } else { + if (action.getId().contains("add")==false) { + but.setEnabled(false); + } + } + } + } + int rowIndex = table.getSelectedRow(); + if (rowIndex!=-1) { // temp; gets index by sorter //rowIndex = tableSorter.modelIndex(rowIndex); @@ -529,6 +542,10 @@ public class SwingVascFrontend extends AbstractVascFrontend { but.setToolTipText(i18n(action.getDescription())); but.setIcon(getImageIcon(action.getImage())); but.addActionListener(new RowActionListener(action)); + if (action.getId().contains("add")==false) { + but.setEnabled(false); + } + rowActions.put(action, but); panel.add(but); } bottomPanel.add(panel,BorderLayout.SOUTH); diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascTableModel.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascTableModel.java index 4b801e5..39a0d08 100644 --- a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascTableModel.java +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/SwingVascTableModel.java @@ -104,7 +104,7 @@ public class SwingVascTableModel extends AbstractTableModel implements VascEntry } public VascFrontendEventType[] getEventTypes() { - VascFrontendEventType[] result = {VascFrontendEventType.POST_UPDATE,VascFrontendEventType.POST_READ}; + VascFrontendEventType[] result = {VascFrontendEventType.POST_UPDATE,VascFrontendEventType.POST_READ,VascFrontendEventType.POST_DELETE}; return result; } } diff --git a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/ui/SwingBoolean.java b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/ui/SwingBoolean.java index 67ef0f3..9d266ba 100644 --- a/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/ui/SwingBoolean.java +++ b/vasc-frontend/vasc-frontend-swing/src/main/java/net/forwardfire/vasc/frontends/swing/ui/SwingBoolean.java @@ -52,7 +52,9 @@ public class SwingBoolean implements VascUIComponent { 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())); + if (model.getValue()!=null) { + checkBox.setSelected(new Boolean(model.getValue().toString())); + } ((JComponent)gui).add(checkBox); checkBox.addActionListener(new SelectActionListener(model,table)); return checkBox; diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java index 0f79fec..e19d60b 100644 --- a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java +++ b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTest.java @@ -22,53 +22,30 @@ package net.forwardfire.vasc; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryControllerLocal; -import net.forwardfire.vasc.frontends.swing.SwingVascFrontend; +import net.forwardfire.vasc.frontends.swing.SwingPanelFrame; +import net.forwardfire.vasc.frontends.swing.SwingPanelIntegration; import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.test.frontend.data.TestModelEntry; - - +import net.forwardfire.vasc.test.frontend.data.TestModelData; import junit.framework.TestCase; /** - * Tests a simple x4o xml language. + * SwingTestTabbed shows interfaces in frames. * * @author Willem Cazander * @version 1.0 Jul 24, 2006 */ public class SwingTest extends TestCase { - private TestModelEntry entry = null; - - public void setUp() throws Exception { - // enable all logs - //InputStream loggingProperties = this.getClass().getResourceAsStream("META-INF/logging.properties"); - //LogManager.getLogManager().readConfiguration( loggingProperties ); - //loggingProperties.close(); - } - - public void tearDown() throws Exception { - } - public void testNull() throws Exception { assertEquals(true, true); //main(new String[] {}); } - public static void main(String[] argu){ - JFrame.setDefaultLookAndFeelDecorated(false); + public static void main(String[] argu){ SwingTest s = new SwingTest(); try { s.open(); @@ -78,69 +55,13 @@ public class SwingTest extends TestCase { } public void open() throws Exception { + SwingPanelIntegration spi = new SwingPanelFrame(); + TestModelData testData = new TestModelData(); + VascController vc = testData.getTestVascController(); + testData.createVascEntries(vc,(VascEntryControllerLocal)vc.getVascEntryController()); - entry = new TestModelEntry(); - VascController vc = entry.getTestVascController(); - - VascEntry ve = entry.createVascEntry(vc); - - ((VascEntryControllerLocal)vc.getVascEntryController()).addVascEntry(ve,vc); - DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vc.getVascEntryController(), vc); - + VascEntry ve = testData.getTestEntry(vc); DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); - - JFrame frame = viewEntry(ve); - - while (frame.isVisible()) { - Thread.sleep(1000); - } - } - - public JFrame viewEntry(final VascEntry entry) throws Exception { - // get GUI - JFrame frame = new JFrame(); - frame.setTitle("Vasc Test - Swing - "+entry.getName()); - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - frame.setLocationRelativeTo(null); - - JMenuBar menubar = new JMenuBar(); - JMenu vascMenu = new JMenu("Vasc Entries"); - - for (final String id:entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryIds()) { - JMenuItem item = new JMenuItem(id); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - VascEntry ee = entry.getVascFrontendData().getVascController().getVascEntryController().getVascEntryById(id); - //TestModelEntry.fill(ee,entry.getVascFrontendData().getVascController()); - viewEntry(ee); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - - }); - vascMenu.add(item); - } - menubar.add(vascMenu); - frame.setJMenuBar(menubar); - - // define redering - JPanel panel = new JPanel(); - SwingVascFrontend render = new SwingVascFrontend(panel); - frame.add(panel); - - // render - render.initEntry(entry); - render.renderView(); - - // get data - entry.getVascFrontendData().getVascFrontendActions().refreshData(); - - // view - frame.pack(); - frame.setVisible(true); - - return frame; + spi.createNewVascView(ve); } } \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTestTabbed.java b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTestTabbed.java new file mode 100644 index 0000000..926b75a --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/SwingTestTabbed.java @@ -0,0 +1,121 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + +package net.forwardfire.vasc; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JTabbedPane; + +import net.forwardfire.vasc.core.VascController; +import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; +import net.forwardfire.vasc.frontends.swing.SwingPanelIntegration; +import net.forwardfire.vasc.frontends.swing.SwingPanelTabbed; +import net.forwardfire.vasc.impl.DefaultVascFactory; +import net.forwardfire.vasc.test.frontend.data.TestModelData; + +import junit.framework.TestCase; + +/** + * SwingTestTabbed shows interfaces in tabs. + * + * @author Willem Cazander + * @version 1.0 Feb 06, 2012 + */ +public class SwingTestTabbed extends TestCase { + + public void testNull() throws Exception { + assertEquals(true, true); + //main(new String[] {}); + } + + public static void main(String[] argu){ + SwingTestTabbed s = new SwingTestTabbed(); + try { + s.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void open() throws Exception { + TestModelData testData = new TestModelData(); + final VascController vc = testData.getTestVascController(); + testData.createVascEntries(vc,(VascEntryControllerLocal)vc.getVascEntryController()); + + JFrame frame = new JFrame(); + frame.setTitle("Vasc Tabbed Test"); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.setLocationRelativeTo(null); + + final JTabbedPane pane = new JTabbedPane(); + final SwingPanelIntegration spi = new SwingPanelTabbed(pane); + frame.add(pane); + + JMenuBar menubar = new JMenuBar(); + JMenu vascMenu = new JMenu("Entries"); + for (final String id:vc.getVascEntryController().getVascEntryIds()) { + JMenuItem item = new JMenuItem(id); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + VascEntry ee = vc.getVascEntryController().getVascEntryById(id).clone(); + DefaultVascFactory.fillVascEntryFrontend(ee, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); + spi.createNewVascView(ee); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + }); + vascMenu.add(item); + } + JMenuItem item = new JMenuItem("Close tab."); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (pane.getSelectedIndex()>=0) { + pane.removeTabAt(pane.getSelectedIndex()); // todo release vasc frontend + } + } + + }); + vascMenu.add(item); + menubar.add(vascMenu); + frame.setJMenuBar(menubar); + + // view + frame.setMinimumSize(new Dimension(800,600)); + frame.pack(); + frame.setVisible(true); + + VascEntry ve = testData.getTestEntry(vc); + DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); + spi.createNewVascView(ve); + } +} \ No newline at end of file diff --git a/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/Test.java b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/Test.java new file mode 100644 index 0000000..b403262 --- /dev/null +++ b/vasc-frontend/vasc-frontend-swing/src/test/java/net/forwardfire/vasc/Test.java @@ -0,0 +1,74 @@ +package net.forwardfire.vasc; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; + +public class Test implements ActionListener { + + JFrame frame; + JTabbedPane tabPane; + JButton addTab; + ImageIcon close; + Dimension size; + int tabCounter = 0; + + public static void main(String[] args) { + Test jtab = new Test(); + } + + public Test() { + frame = new JFrame(); + tabPane = new JTabbedPane(); + addTab = new JButton("Add Tab"); + addTab.addActionListener(this); + close = new ImageIcon("/home/willemc/door_out.png"); + size = new Dimension(close.getIconWidth()+1,close.getIconHeight()+1); + frame.add(tabPane,BorderLayout.CENTER); + frame.add(addTab, BorderLayout.NORTH); + frame.setSize(300, 300); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + + public void actionPerformed(ActionEvent e) { + JLabel label = null; + final JPanel panel = new JPanel(); + JPanel tab = new JPanel(); + tab.setOpaque(false); + try{ + String str = JOptionPane.showInputDialog(null, "Enter Tab Name : ", "JavaJazzUp", 1); + + if (str.length() == 0){ + JOptionPane.showMessageDialog(null,"Please Enter the Tab Name : ", "JavaJazzUp",1); + } else if (str != null){ + label = new JLabel(str); + panel.add(new JLabel("test"+str)); + } else { + JOptionPane.showMessageDialog(null,"You pressed cancel button.", "JavaJazzUp",1); + } + JButton tabClose = new JButton(close); + tabClose.setPreferredSize(size); + tabClose.addActionListener(new ActionListener() { + public void + actionPerformed(ActionEvent e) { + int tNum = tabPane.indexOfComponent(panel); + tabPane.removeTabAt(tNum); + } + }); + tab.add(label, BorderLayout.WEST); + tab.add(tabClose, BorderLayout.EAST); + tabPane.addTab(null, panel); + tabPane.setTabComponentAt(tabPane.getTabCount()-1, tab); + } catch(Exception ex){} + } +} diff --git a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java index 0ead43a..44917c5 100644 --- a/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java +++ b/vasc-frontend/vasc-frontend-swt/src/main/java/net/forwardfire/vasc/frontends/swt/SwtVascFrontend.java @@ -329,7 +329,7 @@ public class SwtVascFrontend extends AbstractVascFrontend { net.forwardfire.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.setValue(option.getDefaultValue()); model.addListener(new VascValueModelListener() { public void valueUpdate(VascValueModel model) throws VascException { entry.getVascFrontendData().getVascFrontendActions().refreshData();// mm diff --git a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java b/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java index 2bf9d72..3ecbb7b 100644 --- a/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java +++ b/vasc-frontend/vasc-frontend-swt/src/test/java/net/forwardfire/vasc/SWTTest.java @@ -28,7 +28,7 @@ import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.frontends.swt.SwtVascFrontend; import net.forwardfire.vasc.impl.DefaultVascFactory; -import net.forwardfire.vasc.test.frontend.data.TestModelEntry; +import net.forwardfire.vasc.test.frontend.data.TestModelData; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -45,7 +45,7 @@ import junit.framework.TestCase; */ public class SWTTest extends TestCase { - private TestModelEntry entry = null; + private TestModelData testData = null; public void setUp() throws Exception { } @@ -70,13 +70,12 @@ public class SWTTest extends TestCase { // define redering and render SwtVascFrontend render = new SwtVascFrontend(shell); - entry = new TestModelEntry(); - VascController vc = entry.getTestVascController(); - VascEntry ve = entry.createVascEntry(vc); - ((VascEntryControllerLocal)vc.getVascEntryController()).addVascEntry(ve,vc); - DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vc.getVascEntryController(), vc); - DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); - + testData = new TestModelData(); + VascController vc = testData.getTestVascController(); + testData.createVascEntries(vc,(VascEntryControllerLocal)vc.getVascEntryController()); + + VascEntry ve = testData.getTestEntry(vc); + DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); ve.getVascFrontendData().getVascFrontendActions().refreshData(); render.initEntry(ve); render.renderView(); diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java index 17c05ae..2c47336 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerBase.java @@ -1,9 +1,30 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + package net.forwardfire.vasc.frontends.web.jsf; import java.util.List; import java.util.Map; -import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; @@ -11,6 +32,12 @@ import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.impl.DefaultVascFactory; +/** + * AbstractJSFVascFacesControllerBase for making jsf frontend. + * + * @author Willem Cazander + * @version 1.0 Dec 21, 2011 + */ public abstract class AbstractJSFVascFacesControllerBase { abstract VascFrontendData getNewVascFrontendData(); diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java index 3e45dbb..61638b4 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/AbstractJSFVascFacesControllerEJB.java @@ -325,6 +325,10 @@ abstract public class AbstractJSFVascFacesControllerEJB extends AbstractJSFVascF Object result = vascManager.invokeBackendMethod(backendId, "isTotalSummary", args); return (Boolean)result; } + + public boolean isReadOnly() { + return false; + } } /** diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java index afb4bc0..f696aa3 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntryEventListener.java @@ -29,15 +29,14 @@ import javax.el.ValueExpression; import javax.faces.context.FacesContext; import net.forwardfire.vasc.core.VascEntry; -import net.forwardfire.vasc.core.VascEntryField; -import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener; - /** - * @author willemc - * + * JSFVascEntryEventListener fills data in support bean. + * + * @author Willem Cazander + * @version 1.0 Sep 11, 2009 */ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener { @@ -59,6 +58,7 @@ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener public void vascEvent(VascEntry entry,Object dataNotUsed) { + /* moved to fillVascEntryFrontend try { for (VascEntryField field:entry.getVascEntryFields()) { if (field.getVascEntryFieldValue()==null) { @@ -73,6 +73,7 @@ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener } catch (Exception e) { throw new RuntimeException(e); } + */ List data = entry.getVascFrontendData().getVascEntryState().getEntryDataList(); List result = new ArrayList(data.size()); int index = 0; diff --git a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java index 0d8f3a1..8ac541d 100644 --- a/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java +++ b/vasc-frontend/vasc-frontend-web-jsf/src/main/java/net/forwardfire/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -64,7 +64,7 @@ import net.forwardfire.vasc.impl.actions.EditRowAction; /** - * + * JSFVascEntrySupportBean add EL support for renderer. * * @author Willem Cazander * @version 1.0 Sep 10, 2009 @@ -1012,7 +1012,7 @@ class JSFVascSupportI18nMapController implements Map { return null; } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public void putAll(Map m) { } diff --git a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelData.java similarity index 75% rename from vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java rename to vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelData.java index e610e5c..fdc5589 100644 --- a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelEntry.java +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelData.java @@ -27,6 +27,7 @@ import java.lang.reflect.Method; import net.forwardfire.vasc.backend.VascBackendControllerLocal; import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascEntry; +import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.impl.DefaultVascEntry; import net.forwardfire.vasc.impl.DefaultVascEntryField; @@ -37,24 +38,32 @@ import net.forwardfire.vasc.impl.DefaultVascFactory; * @author Willem Cazander * @version 1.0 Aug 2, 2007 */ -public class TestModelEntry { +public class TestModelData { public VascController getTestVascController() throws Exception { VascController c = DefaultVascFactory.getDefaultVascController(1234L,"Nice UserName","user","role_admin"); // for test - TestModelVascDataSource backend = new TestModelVascDataSource(); - backend.generatorData(10876); - backend.setId("testBackend"); - ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend); + TestModelVascDataSource backends = new TestModelVascDataSource(); + backends.generatorData(10876); + + backends.orderModel.setId("orderModelBackend"); + ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backends.orderModel); + backends.orderLineModel.setId("orderLineModelBackend"); + ((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backends.orderLineModel); + return c; } - public VascEntry createVascEntry(VascController vc) throws Exception { + public VascEntry getTestEntry(VascController vc) { + return vc.getVascEntryController().getVascEntryById("orderModel"); + } + + public void createVascEntries(VascController vc,VascEntryControllerLocal vecl) throws Exception { VascEntry ve = new DefaultVascEntry(); - ve.setId("testEntry"); - ve.setBackendId("testBackend"); + ve.setId("orderModel"); + ve.setBackendId("orderModelBackend"); VascEntryField field = new DefaultVascEntryField(); field.setId("name"); @@ -89,9 +98,34 @@ public class TestModelEntry { field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField")); field.setBackendName("active"); field.setDefaultValue("true"); // obj does also work ! we are first need to fix string defaults. + ve.addListOption(field); - return ve; + vecl.addVascEntry(ve,vc); + + + ve = new DefaultVascEntry(); + ve.setId("orderLineModel"); + ve.setBackendId("orderLineModelBackend"); + + field = new DefaultVascEntryField(); + field.setId("name"); + ve.addVascEntryField(field); + + field = new DefaultVascEntryField(); + field.setId("price"); + field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("FloatField")); + ve.addVascEntryField(field); + + field = new DefaultVascEntryField(); + field.setId("date"); + field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("DateField")); + ve.addVascEntryField(field); + + vecl.addVascEntry(ve,vc); + + + DefaultVascFactory.fillVascControllerLocalEntries(vecl, vc); } static void printEntry(VascEntry e) throws Exception { diff --git a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModel.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelOrder.java similarity index 91% rename from vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModel.java rename to vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelOrder.java index cad107f..516feb8 100644 --- a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModel.java +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelOrder.java @@ -42,16 +42,31 @@ import net.forwardfire.vasc.validators.VascStringLength; * @version 1.0 Mar 28, 2007 */ @VascEntry(headerName="En een tooltip op het model") -public class TestModel { +public class TestModelOrder { + private Integer id = null; private String name = null; private String description = null; private Float price = null; private Boolean active = null; private Date date = null; - private TestModel testModel = null; + private TestModelOrder testModel = null; private String hexColor = null; //private Node nonEditorField = null; + + /** + * @return the id + */ + public Integer getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Integer id) { + this.id = id; + } /** * @return the date @@ -60,7 +75,7 @@ public class TestModel { public Date getDate() { return date; } - + /** * @param date the date to set */ @@ -125,11 +140,11 @@ public class TestModel { @VascObjectNotNull @VascModelReference @VascI18n(image="/resources/images/gabelfresser.gif") - public TestModel getTestModel() { + public TestModelOrder getTestModel() { return testModel; } - public void setTestModel(TestModel testModel) { + public void setTestModel(TestModelOrder testModel) { this.testModel = testModel; } diff --git a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelOrderLine.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelOrderLine.java new file mode 100644 index 0000000..4e0ca2a --- /dev/null +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelOrderLine.java @@ -0,0 +1,108 @@ +/* + * Copyright 2007-2012 forwardfire.net All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * 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 THE COPYRIGHT HOLDERS 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 + * THE COPYRIGHT HOLDER 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. + */ + +package net.forwardfire.vasc.test.frontend.data; + + +import java.util.Date; + +import net.forwardfire.vasc.annotations.VascDefaultValue; +import net.forwardfire.vasc.annotations.VascEntry; +import net.forwardfire.vasc.annotations.VascI18n; +import net.forwardfire.vasc.annotations.VascModelReference; +import net.forwardfire.vasc.annotations.VascStyle; +import net.forwardfire.vasc.validators.VascDateFuture; +import net.forwardfire.vasc.validators.VascObjectNotNull; +import net.forwardfire.vasc.validators.VascStringLength; + +/** + * TestModelOrderLine + * + * + * @author Willem Cazander + * @version 1.0 Feb 7, 2012 + */ +@VascEntry(headerName="OrderLine") +public class TestModelOrderLine { + + private TestModelOrder order = null; + private String name = null; + private Float price = null; + private Date date = null; + + /** + * @return the order + */ + public TestModelOrder getOrder() { + return order; + } + + /** + * @param order the order to set + */ + public void setOrder(TestModelOrder order) { + this.order = order; + } + + /** + * @return the date + */ + @VascDateFuture + public Date getDate() { + return date; + } + + /** + * @param date the date to set + */ + public void setDate(Date date) { + this.date = date; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the price + */ + public Float getPrice() { + return price; + } + + /** + * @param price the price to set + */ + public void setPrice(Float price) { + this.price = price; + } +} \ No newline at end of file diff --git a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java index caefd3d..3b771ec 100644 --- a/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java +++ b/vasc-test/vasc-test-frontend-data/src/main/java/net/forwardfire/vasc/test/frontend/data/TestModelVascDataSource.java @@ -26,6 +26,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.x4o.xml.element.ElementObjectPropertyValueException; +import org.x4o.xml.impl.DefaultElementObjectPropertyValue; + import net.forwardfire.vasc.backend.AbstractVascBackend; import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.core.VascEntry; @@ -45,20 +48,24 @@ import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel { +public class TestModelVascDataSource { - private List testModels = null; - private String nullLabel = null; - private String nullKeyValue = null; + //private List testModels = null; + public ListObjectVascDataSource orderModel = null; + public ListObjectVascDataSource orderLineModel = null; public TestModelVascDataSource() { - testModels = new ArrayList(200); + this(new ArrayList(200),new ArrayList(200)); + } + public TestModelVascDataSource(List testModels,List testModelLine) { + orderModel = new ListObjectVascDataSource(TestModelOrder.class,(List)testModels); + orderLineModel = new ListObjectVascDataSource(TestModelOrderLine.class,(List)testModelLine); } - + public void generatorData(int size) { - for (int i=0;i testModels) { - this.testModels=testModels; - } - public List execute(VascBackendState state) throws VascException { - if (state.getDataParameterKeys().contains("active")) { - List result = new ArrayList(testModels.size()/2); - for (TestModel tm:testModels) { - if (tm.getActive()!=null && tm.getActive().equals(state.getDataParameter("active"))) { - result.add(tm); - } - } - return result; - } else { - List result = new ArrayList(testModels.size()); - for (TestModel tm:testModels) { - result.add(tm); - } - return result; + + class ListObjectVascDataSource extends AbstractVascBackend { + private Class modelClass = null; + private List modelList = null; + private String nullLabel = null; + private String nullKeyValue = null; + + public ListObjectVascDataSource(Class modelClass,List modelList) { + this.modelClass=modelClass; + this.modelList=modelList; } - } - - public void persist(Object object) throws VascException { - testModels.add((TestModel)object); - } - - public Object merge(Object object) throws VascException { - if(testModels.contains(object)==false) { - testModels.add((TestModel)object); - } - return object; - } - - public void delete(Object object) throws VascException { - testModels.remove(object); - } - public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - return new BeanPropertyVascEntryFieldValue(field.getBackendName()); - } - - public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new BeanVascEntryRecordCreator(TestModel.class); - } - - // --- VascSelectItemModel interface - - public List getVascSelectItems(VascEntry entry) { - List res = new ArrayList(4); - for (Object o:testModels) { - TestModel t = (TestModel)o; - VascSelectItem i = new VascSelectItem(t.getName(),t); - res.add(i); + public List getObjectList() { + return modelList; + } + + public List execute(VascBackendState state) throws VascException { + if (state.getDataParameterKeys().isEmpty()==false) { + List result = new ArrayList(modelList.size()/2); + DefaultElementObjectPropertyValue helper = new DefaultElementObjectPropertyValue(); + for (Object row:modelList) { + boolean addRow = true; + for (String key:state.getDataParameterKeys()) { + Object keyValue = state.getDataParameter(key); + Object propValue = null; + try { + propValue = helper.getProperty(row, key); + } catch (ElementObjectPropertyValueException e) { + e.printStackTrace(); + } + if (keyValue==null && propValue==null) { + continue; + } + if (keyValue.equals(propValue)) { + continue; + } + addRow = false; + } + if (addRow) { + result.add(row); + } + } + return result; + } else { + List result = new ArrayList(modelList.size()); + for (Object row:modelList) { + result.add(row); + } + return result; + } + } + + public void persist(Object object) throws VascException { + modelList.add(object); + } + + public Object merge(Object object) throws VascException { + if(modelList.contains(object)==false) { + modelList.add(object); + } + return object; + } + + public void delete(Object object) throws VascException { + modelList.remove(object); + } + + public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { + return new BeanPropertyVascEntryFieldValue(field.getBackendName()); + } + + public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { + return new BeanVascEntryRecordCreator(modelClass); + } + + // --- VascSelectItemModel interface + /* + public List getVascSelectItems(VascEntry entry) { + List res = new ArrayList(4); + for (Object o:testModels) { + TestModelOrder t = (TestModelOrder)o; + VascSelectItem i = new VascSelectItem(t.getName(),t); + res.add(i); + } + return res; + }*/ + + /** + * @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 res; - } - /** - * @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; } } \ No newline at end of file diff --git a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java index 2103185..7df55be 100644 --- a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java +++ b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/ParameterTypeObjectConverter.java @@ -26,30 +26,41 @@ import java.util.Locale; import net.forwardfire.vasc.xpql.query.QueryParameterValue.QueryParameterType; -import org.x4o.xml.converters.ObjectConverter; -import org.x4o.xml.converters.ObjectConverterException; +import org.x4o.xml.conv.AbstractStringObjectConverter; +import org.x4o.xml.conv.ObjectConverter; +import org.x4o.xml.conv.ObjectConverterException; /** + * ParameterTypeObjectConverter * * @author Willem Cazander * @version 1.0 Jan 21, 2007 */ -public class ParameterTypeObjectConverter implements ObjectConverter { +public class ParameterTypeObjectConverter extends AbstractStringObjectConverter { - public Class getObjectClass() { + private static final long serialVersionUID = 40849496158706355L; + + public Class getObjectClassTo() { return QueryParameterType.class; } - public String convertToString(Object obj, Locale locale) { + public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException { return ((QueryParameterType)obj).name(); } - - public Object convertToObject(String str, Locale locale) throws ObjectConverterException { + + public Object convertStringTo(String str, Locale locale) throws ObjectConverterException { try { return QueryParameterType.valueOf(""+str); } catch (Exception ex) { throw new ObjectConverterException(this,"Could not convert to QueryParameterType value="+str,ex); } } + + @Override + public ObjectConverter clone() throws CloneNotSupportedException { + ParameterTypeObjectConverter result = new ParameterTypeObjectConverter(); + result.converters=cloneConverters(); + return result; + } } \ No newline at end of file diff --git a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java index bafb224..f07ff19 100644 --- a/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java +++ b/vasc-xpql/src/main/java/net/forwardfire/vasc/xpql/impl/x4o/QueryTypeObjectConverter.java @@ -26,29 +26,42 @@ import java.util.Locale; import net.forwardfire.vasc.xpql.query.Query.QueryType; -import org.x4o.xml.converters.ObjectConverter; -import org.x4o.xml.converters.ObjectConverterException; +import org.x4o.xml.conv.AbstractStringObjectConverter; +import org.x4o.xml.conv.ObjectConverter; +import org.x4o.xml.conv.ObjectConverterException; /** + * QueryTypeObjectConverter converts query type enum. + * + * todo: rm this for the enum conv. * * @author Willem Cazander * @version 1.0 Jan 21, 2007 */ -public class QueryTypeObjectConverter implements ObjectConverter { +public class QueryTypeObjectConverter extends AbstractStringObjectConverter { - public Class getObjectClass() { + private static final long serialVersionUID = 2383122486722789617L; + + public Class getObjectClassTo() { return QueryType.class; } - public String convertToString(Object obj, Locale locale) { + public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException { return ((QueryType)obj).name(); } - public Object convertToObject(String str, Locale locale) throws ObjectConverterException { + public Object convertStringTo(String str, Locale locale) throws ObjectConverterException { try { return QueryType.valueOf(""+str); } catch (Exception ex) { throw new ObjectConverterException(this,"Could not convert to QueryType value="+str,ex); } } + + @Override + public ObjectConverter clone() throws CloneNotSupportedException { + QueryTypeObjectConverter result = new QueryTypeObjectConverter(); + result.converters=cloneConverters(); + return result; + } } \ No newline at end of file