2
0
Fork 0

Made unittest data backend for frontends and improved swing frontend.

Worked on metamodel backend and some other fixes.
This commit is contained in:
Willem Cazander 2012-05-03 17:13:36 +02:00
parent 1c308a684a
commit a25e98f5d5
65 changed files with 2820 additions and 499 deletions

View file

@ -321,6 +321,13 @@
<url>http://repository.ops4j.org/maven2/</url> <url>http://repository.ops4j.org/maven2/</url>
<snapshots><enabled>false</enabled></snapshots> <snapshots><enabled>false</enabled></snapshots>
</repository> </repository>
<repository>
<id>eobjects-metamodel</id>
<name>eobjects.org</name>
<layout>default</layout>
<url>http://repo.eobjects.org</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories> </repositories>
<!-- DistributionManagement --> <!-- DistributionManagement -->

View file

@ -56,7 +56,11 @@ public class LdapConnectionProviderImpl implements LdapConnectionProvider {
} }
return lc; return lc;
} catch (Exception e) { } 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);
}
} }
} }

View file

@ -17,8 +17,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eobjects.metamodel</groupId> <groupId>org.eobjects.metamodel</groupId>
<artifactId>MetaModel-core</artifactId> <artifactId>MetaModel-full</artifactId>
<version>2.1</version> <version>3.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -23,17 +23,21 @@
package net.forwardfire.vasc.backend.metamodel; package net.forwardfire.vasc.backend.metamodel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.DataSet;
import org.eobjects.metamodel.data.Row; import org.eobjects.metamodel.data.Row;
import org.eobjects.metamodel.query.Query; import org.eobjects.metamodel.query.Query;
import org.eobjects.metamodel.query.SelectItem; import org.eobjects.metamodel.query.SelectItem;
import org.eobjects.metamodel.schema.Schema; import org.eobjects.metamodel.schema.Schema;
import org.eobjects.metamodel.schema.Table; import org.eobjects.metamodel.schema.Table;
import org.eobjects.metamodel.update.RowUpdationBuilder;
import net.forwardfire.vasc.backend.AbstractVascBackend; import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.backend.VascBackendState;
@ -53,13 +57,23 @@ import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
*/ */
public class MetaModelVascBackend extends AbstractVascBackend { public class MetaModelVascBackend extends AbstractVascBackend {
private DataContext dataContext = null; private MetaModelDataContextProvider dataContextProvider = null;
private UpdateableDataContext dataContext = null;
private String table = 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<Object> execute(VascBackendState state) throws VascException { public List<Object> execute(VascBackendState state) throws VascException {
UpdateableDataContext dataContext = getUpdateableDataContext();
Schema schema = dataContext.getDefaultSchema(); Schema schema = dataContext.getDefaultSchema();
Table t = schema.getTableByName(table); Table t = schema.getTableByName(table);
//dataContext.query().from("").select("").where("").
Query q = dataContext.query().from(t).select(t.getColumns()).toQuery(); Query q = dataContext.query().from(t).select(t.getColumns()).toQuery();
DataSet ds = dataContext.executeQuery(q); DataSet ds = dataContext.executeQuery(q);
List<Object> result = new ArrayList<Object>(50); List<Object> result = new ArrayList<Object>(50);
@ -78,13 +92,52 @@ public class MetaModelVascBackend extends AbstractVascBackend {
} }
public void persist(Object object) throws VascException { 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<String, Object> nestedObj = new HashMap<String, Object>();
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 { public Object merge(Object object) throws VascException {
final Map<String,Object> map = (Map<String,Object>)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; return object;
} }
@SuppressWarnings("unchecked")
public void delete(Object object) throws VascException { public void delete(Object object) throws VascException {
final Map<String,Object> map = (Map<String,Object>)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) { public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
@ -94,4 +147,46 @@ public class MetaModelVascBackend extends AbstractVascBackend {
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MapVascEntryRecordCreator(); 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;
}
} }

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
<eld:elementClass tag="metaModelBackend" objectClassName="net.forwardfire.vasc.backend.metamodel.MetaModelVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
<eld:elementClass tag="mongodbDataContext" objectClassName="net.forwardfire.vasc.backend.metamodel.MetaModelDataContextMongodb"/>
<eld:elementClass tag="csvDataContext" objectClassName="net.forwardfire.vasc.backend.metamodel.MetaModelDataContextCsv"/>
</eld:root>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>
Vasc namespace for the metamodel backend
</comment>
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-metamodel.eld">vasc-backend-metamodel.eld</entry>
</properties>

View file

@ -53,6 +53,13 @@ abstract public class AbstractVascBackend implements VascBackend {
this.id=id; this.id=id;
} }
/**
* @see net.forwardfire.vasc.backend.VascBackend#isReadOnly()
*/
public boolean isReadOnly() {
return false;
}
/** /**
* @see net.forwardfire.vasc.backend.VascBackend#isPageable() * @see net.forwardfire.vasc.backend.VascBackend#isPageable()
*/ */

View file

@ -44,6 +44,8 @@ public interface VascBackend {
public List<Object> execute(VascBackendState state) throws VascException; public List<Object> execute(VascBackendState state) throws VascException;
public boolean isReadOnly();
public void persist(Object object) throws VascException; public void persist(Object object) throws VascException;
public Object merge(Object object) throws VascException; public Object merge(Object object) throws VascException;

View file

@ -22,6 +22,8 @@
package net.forwardfire.vasc.backend; package net.forwardfire.vasc.backend;
import java.util.List;
/** /**
* *
@ -31,4 +33,6 @@ package net.forwardfire.vasc.backend;
public interface VascBackendController { public interface VascBackendController {
public VascBackend getVascBackendById(String id); public VascBackend getVascBackendById(String id);
public List<String> getVascBackendIds();
} }

View file

@ -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<Object> execute(VascBackendState state) throws VascException {
List<Object> result = new ArrayList<Object>(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;
}
}

View file

@ -51,6 +51,13 @@ abstract public class AbstractVascBackendProxy implements VascBackend {
this.backend=backend; 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) * @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/ */

View file

@ -22,12 +22,8 @@
package net.forwardfire.vasc.backend.proxy; package net.forwardfire.vasc.backend.proxy;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendState; 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.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
/** /**
* Simple text search * Simple text search
* *
@ -82,6 +76,9 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy {
for (VascEntryField field:entry.getVascEntryFields()) { for (VascEntryField field:entry.getVascEntryFields()) {
VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field); VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field);
Object value = fieldValue.getValue(field, record); Object value = fieldValue.getValue(field, record);
if (value==null) {
continue; // can't search null values.
}
String r = value.toString().toLowerCase(); String r = value.toString().toLowerCase();
if (r.contains(searchString)) { if (r.contains(searchString)) {
search.add(record); search.add(record);

View file

@ -33,9 +33,6 @@ import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue; import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
/** /**
* Add an sortware sort an a backend * Add an sortware sort an a backend
* *
@ -66,14 +63,15 @@ public class VascBackendProxySort extends AbstractVascBackendProxy {
try { try {
final VascEntryField field = entry.getVascEntryFieldById(state.getSortField()); final VascEntryField field = entry.getVascEntryFieldById(state.getSortField());
final VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field.clone()); final VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field.clone());
Collections.sort(result, new Comparator() { Collections.sort(result, new Comparator<Object>() {
@SuppressWarnings("rawtypes")
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
try { try {
Comparable c1 = null; Comparable c1 = null;
Comparable c2 = null; Comparable c2 = null;
if (field.getDisplayName()!=null) { if (field.getDisplayName()!=null) {
c1 = (Comparable)fieldValue.getDisplayValue(field, o1); c1 = fieldValue.getDisplayValue(field, o1);
c2 = (Comparable)fieldValue.getDisplayValue(field, o2); c2 = fieldValue.getDisplayValue(field, o2);
} else { } else {
c1 = (Comparable)fieldValue.getValue(field, o1); c1 = (Comparable)fieldValue.getValue(field, o1);
c2 = (Comparable)fieldValue.getValue(field, o2); c2 = (Comparable)fieldValue.getValue(field, o2);

View file

@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.x4o.xml.conv.ObjectConverter;
import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.validators.VascValidator; import net.forwardfire.vasc.validators.VascValidator;
@ -45,6 +47,7 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType {
protected Class<?> autoDetectClass = null; protected Class<?> autoDetectClass = null;
protected List<VascValidator> vascValidators = null; protected List<VascValidator> vascValidators = null;
protected Map<String,String> properties = null; protected Map<String,String> properties = null;
protected ObjectConverter objectConverter = null;
protected Object dataObject = null; protected Object dataObject = null;
protected String uiComponentId = null; protected String uiComponentId = null;
@ -215,4 +218,18 @@ abstract public class AbstractVascEntryFieldType implements VascEntryFieldType {
VascValueModel model = new VascValueModel(); VascValueModel model = new VascValueModel();
return model; return model;
} }
/**
* @return the objectConverter
*/
public ObjectConverter getObjectConverter() {
return objectConverter;
}
/**
* @param objectConverter the objectConverter to set
*/
public void setObjectConverter(ObjectConverter objectConverter) {
this.objectConverter = objectConverter;
}
} }

View file

@ -403,7 +403,9 @@ public interface VascEntry extends Cloneable,Serializable {
public void addListOption(VascEntryField listOption); public void addListOption(VascEntryField listOption);
public void removeListOption(VascEntryField listOption);
public List<VascEntryField> getListOptions(); public List<VascEntryField> getListOptions();
public VascEntryField getListOptionById(String listOptionId);
public void addVascBackendFilter(VascBackendFilter filter); public void addVascBackendFilter(VascBackendFilter filter);

View file

@ -377,7 +377,7 @@ public interface VascEntryField extends Cloneable,Serializable {
public void setGraphable(Boolean graphable); public void setGraphable(Boolean graphable);
/** /**
* Force impl to have public clone methode * Force impl to have public clone method
* @return * @return
* @throws CloneNotSupportedException * @throws CloneNotSupportedException
*/ */

View file

@ -25,6 +25,8 @@ package net.forwardfire.vasc.core;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import org.x4o.xml.conv.ObjectConverter;
import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.validators.VascValidator; 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 VascUIComponent provideEditorUIComponent(int index,VascEntryField entryField) throws VascException;
public VascValueModel provideEditorVascValueModel(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 * Force impl to have public clone methode
* @return * @return

View file

@ -35,4 +35,6 @@ public interface VascEntryFieldTypeController {
public VascEntryFieldType getVascEntryFieldTypeById(String id); public VascEntryFieldType getVascEntryFieldTypeById(String id);
public List<String> getVascEntryFieldTypeIds(); public List<String> getVascEntryFieldTypeIds();
public VascEntryFieldType getVascEntryFieldTypeByClass(Class<?> clazz);
} }

View file

@ -26,6 +26,7 @@ import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascException;
/** /**
* VascOptionValueModelListener to handle editors which sets entry parameter values.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 May 21, 2009 * @version 1.0 May 21, 2009

View file

@ -24,21 +24,21 @@ package net.forwardfire.vasc.impl;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Locale;
import org.x4o.xml.conv.ObjectConverterException;
import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascEntryFieldSet; import net.forwardfire.vasc.core.VascEntryFieldSet;
import net.forwardfire.vasc.core.VascEntryFieldType;
import net.forwardfire.vasc.core.VascEntryFinalizer; import net.forwardfire.vasc.core.VascEntryFinalizer;
import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.VascLinkEntry; import net.forwardfire.vasc.core.VascLinkEntry;
import net.forwardfire.vasc.core.VascLinkEntryType; import net.forwardfire.vasc.core.VascLinkEntryType;
import net.forwardfire.vasc.core.actions.VascAction; import net.forwardfire.vasc.core.actions.VascAction;
/** /**
* Checks for minimal needed stuff * Checks for minimal needed stuff
* and fills up the rest. * and fills up the rest.
@ -79,7 +79,7 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
// Check if backendId is valid // Check if backendId is valid
VascBackend back = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() ); VascBackend back = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() );
if (back==null) { 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); vef.setEditReadOnly(false);
} }
/* moved to fillVascEntryFrontend
if (vef.getVascEntryFieldValue()==null) { if (vef.getVascEntryFieldValue()==null) {
VascBackend back2 = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() ); VascBackend back2 = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() );
vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef)); vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef));
} }
*/
if (vef.getVascEntryFieldType()==null) { if (vef.getVascEntryFieldType()==null) {
Object defValue = vef.getDefaultValue(); Object defValue = vef.getDefaultValue();
if (defValue != null) { if (defValue != null) {
for (String typeId: vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeIds()) { vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeByClass(defValue.getClass()));
VascEntryFieldType type = vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById(typeId);
Class<?> autoClass = type.getAutoDetectClass();
if (autoClass!=null && autoClass.isAssignableFrom(defValue.getClass())) {
vef.setVascEntryFieldType(type);
break;
}
}
} }
if (vef.getVascEntryFieldType()==null) { if (vef.getVascEntryFieldType()==null) {
vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextField")); vef.setVascEntryFieldType(vascController.getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextField"));
@ -257,6 +252,19 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
//vef.setStyleList("vasc.entry."+id+"."+vid+".styleEdit"); //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()) { //for (VascValidator vv:vef.getVascValidators()) {
//} //}
} }
@ -363,6 +371,18 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer {
//VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() ); //VascBackend back2 = vascController.getVascBackendControllerResolver().getVascBackendController().getVascBackendById( entry.getBackendId() );
//vef.setVascEntryFieldValue(back2.provideVascEntryFieldValue(vef)); //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);
}
}
} }

View file

@ -22,7 +22,10 @@
package net.forwardfire.vasc.impl; package net.forwardfire.vasc.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.forwardfire.vasc.backend.VascBackend; import net.forwardfire.vasc.backend.VascBackend;
@ -62,5 +65,14 @@ public class DefaultVascBackendController implements VascBackendControllerLocal
} }
backends.put(backend.getId(), backend); backends.put(backend.getId(), backend);
} }
public List<String> getVascBackendIds() {
List<String> result = new ArrayList<String>(50);
for (String id:backends.keySet()) {
result.add(id);
}
Collections.sort(result); // lets do abc for consistance behauvior.
return result;
}
} }

View file

@ -824,6 +824,19 @@ public class DefaultVascEntry implements VascEntry {
return listOptions; 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) { public void addVascBackendFilter(VascBackendFilter filter) {
backendFilters.add(filter); backendFilters.add(filter);

View file

@ -37,7 +37,9 @@ import net.forwardfire.vasc.backend.proxy.VascBackendProxyTimerLogger;
import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascEntryControllerLocal;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.frontend.VascFrontendData; import net.forwardfire.vasc.frontend.VascFrontendData;
import net.forwardfire.vasc.impl.actions.AddRowAction; import net.forwardfire.vasc.impl.actions.AddRowAction;
import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction; import net.forwardfire.vasc.impl.actions.CSVExportGlobalAction;
@ -139,20 +141,26 @@ public class DefaultVascFactory {
static public void fillVascControllerLocalEntries(VascEntryControllerLocal c,VascController con) throws VascException { static public void fillVascControllerLocalEntries(VascEntryControllerLocal c,VascController con) throws VascException {
for (String id:c.getVascEntryIds()) { for (String id:c.getVascEntryIds()) {
VascEntry entry = c.getMasterVascEntryById(id); VascEntry entry = c.getMasterVascEntryById(id);
if (entry.isVascDisplayOnly()==false) {
if (entry.isVascAdminCreate()) { // hackje for calling multiple times on same entries.
entry.addRowAction(new AddRowAction()); 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.addGlobalAction(new XMLExportGlobalAction());
entry.addRowAction(new EditRowAction()); entry.addGlobalAction(new CSVExportGlobalAction());
} entry.addGlobalAction(new RefreshDataGlobalAction());
if (entry.isVascAdminDelete()) { }
entry.addRowAction(new DeleteRowAction());
}
}
entry.addGlobalAction(new XMLExportGlobalAction());
entry.addGlobalAction(new CSVExportGlobalAction());
entry.addGlobalAction(new RefreshDataGlobalAction());
/* /*
DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver(resourceBundle); DefaultVascEntryResourceResolver t = new DefaultVascEntryResourceResolver(resourceBundle);
@ -208,6 +216,14 @@ public class DefaultVascFactory {
VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry); VascBackend backend = DefaultVascFactory.getProxyVascBackend(entry);
frontendData.getVascEntryState().setVascBackend(backend); frontendData.getVascEntryState().setVascBackend(backend);
frontendData.getVascEntryState().setVascEntry(entry); 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.setVascFrontendPager(new DefaultVascFrontendPager(entry));
frontendData.setVascFrontendActions(new DefaultVascFrontendActions(entry)); frontendData.setVascFrontendActions(new DefaultVascFrontendActions(entry));
} }

View file

@ -26,6 +26,7 @@ import java.util.Date;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.forwardfire.vasc.backend.VascBackendFilter; import net.forwardfire.vasc.backend.VascBackendFilter;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException; import net.forwardfire.vasc.core.VascException;
@ -170,21 +171,33 @@ public class DefaultVascFrontendActions implements VascFrontendActions {
public void refreshData() { public void refreshData() {
entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_READ, null); entry.getVascFrontendData().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_READ, null);
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null);
VascBackendState backendState = entry.getVascFrontendData().getVascEntryState().getVascBackendState();
try { try {
// check and correct max page size // check and correct max page size
if (entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()>entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()) { if (backendState.getPageSize() > backendState.getPageSizeMax()) {
entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()); backendState.setPageSize(backendState.getPageSizeMax());
} }
// Sets parameters to backend state
for (String key:entry.getEntryParameterKeys()) { for (String key:entry.getEntryParameterKeys()) {
Object value = entry.getEntryParameter(key); Object value = entry.getEntryParameter(key);
entry.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(key, value); backendState.setDataParameter(key, value);
} }
entry.getVascFrontendData().getVascEntryState().setEntryDataList(entry.getVascFrontendData().getVascEntryState().getVascBackend().execute(entry.getVascFrontendData().getVascEntryState().getVascBackendState()));
// also update total every time // Execute to get data.
Long total = entry.getVascFrontendData().getVascEntryState().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState()); 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); 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) { } catch (Exception e) {
entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e);
} }

View file

@ -26,8 +26,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; 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.VascEntry;
import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException; 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.core.ui.VascUIComponent;
import net.forwardfire.vasc.frontend.VascFrontendHelper; import net.forwardfire.vasc.frontend.VascFrontendHelper;
/** /**
* *
* @author Willem Cazander * @author Willem Cazander

View file

@ -148,7 +148,7 @@ public class DefaultVascFrontendPager implements VascFrontendPager {
if (total==null) { if (total==null) {
return result; // no pages 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++) { for (int i=0;i<=pages;i++) {
VascBackendPageNumber pn = new VascBackendPageNumber(i); VascBackendPageNumber pn = new VascBackendPageNumber(i);
if (state.getPageIndex()==i) { if (state.getPageIndex()==i) {

View file

@ -40,6 +40,9 @@ public class DefaultVascEntryFieldType extends AbstractVascEntryFieldType {
public VascEntryFieldType clone() throws CloneNotSupportedException { public VascEntryFieldType clone() throws CloneNotSupportedException {
DefaultVascEntryFieldType clone = new DefaultVascEntryFieldType(); DefaultVascEntryFieldType clone = new DefaultVascEntryFieldType();
clone.id=id; clone.id=id;
if (objectConverter!=null) {
clone.objectConverter=objectConverter.clone();
}
clone.autoDetectClass=autoDetectClass; clone.autoDetectClass=autoDetectClass;
clone.uiComponentId=uiComponentId; clone.uiComponentId=uiComponentId;
clone.inputMask=inputMask; clone.inputMask=inputMask;

View file

@ -100,4 +100,16 @@ public class DefaultVascEntryFieldTypeController implements VascEntryFieldTypeCo
Collections.sort(result); // lets do abc for consistance behauvior. Collections.sort(result); // lets do abc for consistance behauvior.
return result; 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;
}
} }

View file

@ -33,6 +33,8 @@ import net.forwardfire.vasc.core.VascEntryFieldType;
import org.xml.sax.SAXException; 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.core.X4OParser;
import org.x4o.xml.element.Element; import org.x4o.xml.element.Element;
@ -63,8 +65,13 @@ public class FieldTypeParser extends X4OParser {
public List<VascEntryFieldType> getTypes() { public List<VascEntryFieldType> getTypes() {
List<VascEntryFieldType> result = new ArrayList<VascEntryFieldType>(4); List<VascEntryFieldType> result = new ArrayList<VascEntryFieldType>(4);
DefaultObjectConverterProvider convProvider = new DefaultObjectConverterProvider(true);
for (Element e:getElementContext().getRootElement().getChilderen()) { for (Element e:getElementContext().getRootElement().getChilderen()) {
VascEntryFieldType a = (VascEntryFieldType)e.getElementObject(); 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); result.add(a);
} }
return result; return result;

View file

@ -43,6 +43,7 @@ public class VascSelectItemModelStringEnum implements VascSelectItemModel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Object data = null; private Object data = null;
private Class<?> enumClass = null;
private String nullLabel = null; private String nullLabel = null;
private String nullKeyValue = null; private String nullKeyValue = null;
private Boolean returnKeyValue = null; private Boolean returnKeyValue = null;
@ -54,6 +55,12 @@ public class VascSelectItemModelStringEnum implements VascSelectItemModel {
public List<VascSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException { public List<VascSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException {
List<VascSelectItem> result = new ArrayList<VascSelectItem>(100); List<VascSelectItem> result = new ArrayList<VascSelectItem>(100);
if (enumClass!=null) {
for (Object o:enumClass.getEnumConstants()) {
String value = o.toString();
result.add(new VascSelectItem(value,value,value));
}
}
if (data==null) { if (data==null) {
return result; return result;
} }
@ -143,4 +150,18 @@ public class VascSelectItemModelStringEnum implements VascSelectItemModel {
public void setUseParentFields(Boolean useParentFields) { public void setUseParentFields(Boolean useParentFields) {
this.useParentFields = 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;
}
} }

View file

@ -16,7 +16,7 @@
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntryFieldType" <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntryFieldType"
childClass="net.forwardfire.vasc.validators.VascValidator" childClass="net.forwardfire.vasc.validators.VascValidator"
method="addVascValidator"/> method="addVascValidator"/>
<eld:elementClass tag="dateFutureValidator" objectClassName="net.forwardfire.vasc.validators.VascDateFutureValidator"/> <eld:elementClass tag="dateFutureValidator" objectClassName="net.forwardfire.vasc.validators.VascDateFutureValidator"/>
<eld:elementClass tag="datePastValidator" objectClassName="net.forwardfire.vasc.validators.VascDatePastValidator"/> <eld:elementClass tag="datePastValidator" objectClassName="net.forwardfire.vasc.validators.VascDatePastValidator"/>
<eld:elementClass tag="intSizeValidator" objectClassName="net.forwardfire.vasc.validators.VascIntSizeValidator"/> <eld:elementClass tag="intSizeValidator" objectClassName="net.forwardfire.vasc.validators.VascIntSizeValidator"/>
@ -28,4 +28,27 @@
<eld:elementClass tag="stringRegexValidator" objectClassName="net.forwardfire.vasc.validators.VascStringRegexValidator"/> <eld:elementClass tag="stringRegexValidator" objectClassName="net.forwardfire.vasc.validators.VascStringRegexValidator"/>
<eld:elementClass tag="stringZipCodeValidator" objectClassName="net.forwardfire.vasc.validators.VascStringZipCodeValidator"/> <eld:elementClass tag="stringZipCodeValidator" objectClassName="net.forwardfire.vasc.validators.VascStringZipCodeValidator"/>
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntryFieldType"
childClass="org.x4o.xml.conv.ObjectConverter"
method="setObjectConverter"/>
<eld:elementRefectionBindingHandler parentClass="org.x4o.xml.conv.ObjectConverter"
childClass="org.x4o.xml.conv.ObjectConverter"
method="addObjectConverter"/>
<eld:elementClass tag="beanConverter" elementClassName="org.x4o.xml.impl.lang.BeanElement"
description="Define an loadable in bean.class for an ObjectConverter."
/>
<eld:elementClass tag="booleanConverter" objectClassName="org.x4o.xml.conv.text.BooleanConverter" />
<eld:elementClass tag="byteConverter" objectClassName="org.x4o.xml.conv.text.ByteConverter" />
<eld:elementClass tag="characterConverter" objectClassName="org.x4o.xml.conv.text.CharacterConverter" />
<eld:elementClass tag="doubleConverter" objectClassName="org.x4o.xml.conv.text.DoubleConverter" />
<eld:elementClass tag="floatConverter" objectClassName="org.x4o.xml.conv.text.FloatConverter" />
<eld:elementClass tag="IntegerConverter" objectClassName="org.x4o.xml.conv.text.IntegerConverter" />
<eld:elementClass tag="LongConverter" objectClassName="org.x4o.xml.conv.text.LongConverter" />
<eld:elementClass tag="UrlConverter" objectClassName="org.x4o.xml.conv.text.URLConverter" />
<eld:elementClass tag="ClassConverter" objectClassName="org.x4o.xml.conv.text.ClassConverter" />
<eld:elementClass tag="EnumConverter" objectClassName="org.x4o.xml.conv.text.EnumConverter" />
</eld:root> </eld:root>

View file

@ -3,7 +3,7 @@
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.VascEntryFieldSet" method="addVascEntryFieldSet"/> <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.VascEntryFieldSet" method="addVascEntryFieldSet"/>
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.VascLinkEntry" method="addVascLinkEntry"/> <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.VascLinkEntry" method="addVascLinkEntry"/>
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.VascBackendFilter" method="addVascBackendFilter"/> <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.backend.VascBackendFilter" method="addVascBackendFilter"/>
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.actions.GlobalVascAction" method="addGlobalAction"/> <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.actions.GlobalVascAction" method="addGlobalAction"/>
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.actions.RowVascAction" method="addRowAction"/> <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.actions.RowVascAction" method="addRowAction"/>
<eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.actions.ColumnVascAction" method="addColumnAction"/> <eld:elementRefectionBindingHandler parentClass="net.forwardfire.vasc.core.VascEntry" childClass="net.forwardfire.vasc.core.actions.ColumnVascAction" method="addColumnAction"/>
@ -32,7 +32,11 @@
<eld:elementClass tag="vascSelectItemEntryParameter" elementClassName="net.forwardfire.vasc.impl.x4o.VascLinkEntryParameterElement"/> <eld:elementClass tag="vascSelectItemEntryParameter" elementClassName="net.forwardfire.vasc.impl.x4o.VascLinkEntryParameterElement"/>
<eld:elementClass tag="vascSelectItemModelString" objectClassName="net.forwardfire.vasc.impl.ui.VascSelectItemModelStringEnum"/> <eld:elementClass tag="vascSelectItemModelString" objectClassName="net.forwardfire.vasc.impl.ui.VascSelectItemModelStringEnum"/>
<eld:elementClass tag="vascSelectItemModelEnum" objectClassName="net.forwardfire.vasc.impl.ui.VascSelectItemModelStringEnum"/> <eld:elementClass tag="vascSelectItemModelEnum" objectClassName="net.forwardfire.vasc.impl.ui.VascSelectItemModelStringEnum">
<eld:elementClassAttribute attributeName="enumClass">
<eld:attributeClassConverter/>
</eld:elementClassAttribute>
</eld:elementClass>
<eld:elementClass tag="fieldSet" objectClassName="net.forwardfire.vasc.impl.DefaultVascEntryFieldSet" elementClassName="net.forwardfire.vasc.impl.x4o.VascEntryFieldSetElement"> <eld:elementClass tag="fieldSet" objectClassName="net.forwardfire.vasc.impl.DefaultVascEntryFieldSet" elementClassName="net.forwardfire.vasc.impl.x4o.VascEntryFieldSetElement">
@ -71,4 +75,8 @@
<eld:elementClass tag="stringZipCodeValidator" objectClassName="net.forwardfire.vasc.validators.VascStringZipCodeValidator"/> <eld:elementClass tag="stringZipCodeValidator" objectClassName="net.forwardfire.vasc.validators.VascStringZipCodeValidator"/>
<eld:elementClass tag="virtualVascBackend" objectClassName="net.forwardfire.vasc.backend.VirtualVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
</eld:root> </eld:root>

View file

@ -21,12 +21,12 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>

View file

@ -7,7 +7,6 @@
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>vasc-demo-swing</artifactId> <artifactId>vasc-demo-swing</artifactId>
<groupId>net.forwardfire.vasc.demo</groupId>
<name>vasc-demo-swing</name> <name>vasc-demo-swing</name>
<description>vasc-demo-swing</description> <description>vasc-demo-swing</description>
<dependencies> <dependencies>
@ -31,6 +30,11 @@
<artifactId>vasc-backend-mongodb</artifactId> <artifactId>vasc-backend-mongodb</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-backend-metamodel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>net.forwardfire.vasc</groupId> <groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-backend-jdbc</artifactId> <artifactId>vasc-backend-jdbc</artifactId>
@ -41,5 +45,15 @@
<artifactId>juel</artifactId> <artifactId>juel</artifactId>
<version>${juel.version}</version> <version>${juel.version}</version>
</dependency> </dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.19</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -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();
}
}
}

View file

@ -22,115 +22,38 @@
package net.forwardfire.vasc.demo.swing; 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 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.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal;
import net.forwardfire.vasc.core.VascEntryField; 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 { public class SwingStartup {
private JMainFrame mainFrame = null;
private VascManager vascManager = null;
public static void main(String[] argu){ public static void main(String[] argu){
JFrame.setDefaultLookAndFeelDecorated(false);
try { try {
VascEntry entry = getVascTable(); SwingStartup s = new SwingStartup();
s.init();
SwingStartup s = new SwingStartup(); s.open();
JFrame frame = s.viewEntry(entry);
while (frame.isVisible()) {
Thread.sleep(100000);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public JFrame viewEntry(final VascEntry entry) throws Exception { public void init() throws Exception {
// get GUI vascManager = new VascManager();
JFrame frame = new JFrame(); vascManager.start();
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);
// render mainFrame = new JMainFrame(vascManager);
render.initEntry(entry);
render.renderView();
// get data
entry.getVascFrontendData().getVascFrontendActions().refreshData();
// view
frame.pack();
frame.setVisible(true);
return frame;
} }
public void open() throws Exception {
mainFrame.setVisible(true);
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;
} }
static void printEntry(VascEntry e) throws Exception { static void printEntry(VascEntry e) throws Exception {

View file

@ -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;
}
}

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<x4o:root xmlns:v="http://vasc.forwardfire.net/eld/vasc-lang.eld" <x4o:root xmlns:v="http://vasc.forwardfire.net/eld/vasc-lang.eld"
xmlns:mm="http://vasc.forwardfire.net/eld/vasc-backend-metamodel.eld"
xmlns:m="http://vasc.forwardfire.net/eld/vasc-backend-mongodb.eld" xmlns:m="http://vasc.forwardfire.net/eld/vasc-backend-mongodb.eld"
xmlns:l="http://vasc.forwardfire.net/eld/vasc-backend-ldap.eld" xmlns:l="http://vasc.forwardfire.net/eld/vasc-backend-ldap.eld"
xmlns:j="http://vasc.forwardfire.net/eld/vasc-backend-jdbc.eld" xmlns:j="http://vasc.forwardfire.net/eld/vasc-backend-jdbc.eld"
@ -7,6 +8,54 @@
> >
<mm:csvDataContext
el.id="metaDS_csv"
file="/tmp/csv_people.csv"
/>
<mm:metaModelBackend
id="meta_people_backend"
dataContextProvider="${metaDS_csv}"
table="csv_people"
tableId="id"
/>
<v:entry id="meta_people" backendId="meta_people_backend">
<v:field id="id" list="false"/>
<v:field id="name"/>
<v:field id="age"/>
<v:field id="gender" vascEntryFieldType="ListField">
<v:vascSelectItemModelString data="male,female,unknown"/>
</v:field>
</v:entry>
<mm:mongodbDataContext
el.id="metaDS_mongodb"
hostname="localhost"
database="lefiona"
/>
<mm:metaModelBackend
id="meta_profiles_backend"
dataContextProvider="${metaDS_mongodb}"
table="dg2_profiles"
tableId="_id"
/>
<v:entry id="meta_profiles" backendId="meta_profiles_backend">
<v:field id="_id" readOnly="true" list="false"/>
<v:field id="url"/>
<v:field id="name"/>
<v:field id="active" vascEntryFieldType="BooleanField"/>
<v:field id="body_text" list="false" vascEntryFieldType="TextAreaField"/>
<v:field id="profile_type" vascEntryFieldType="ListField">
<v:vascSelectItemModelString data="MALE,FEMALE,BOTH"/>
</v:field>
<v:field id="send_jokers" vascEntryFieldType="IntegerField"/>
<v:field id="run_date" vascEntryFieldType="DateField"/>
</v:entry>
<m:mongodbConnectionProvider <m:mongodbConnectionProvider
el.id="lefiona_connection" el.id="lefiona_connection"
hostname="localhost" hostname="localhost"
@ -51,23 +100,23 @@
<j:jdbcConnectionProvider <j:jdbcConnectionProvider
el.id="dbDatafeeds" el.id="dbRssFeeds"
driverClassName="org.postgresql.Driver" driverClassName="org.postgresql.Driver"
dbUrl="jdbc:postgresql://localhost/datafeeds_dev" dbUrl="jdbc:postgresql://localhost/vasc_testpg"
dbUser="test" dbUser="test"
dbPassword="eephoh2O" dbPassword="test"
/> />
<j:jdbcBackend <j:jdbcBackend
id="dbStreams" id="rssChannelDB"
jdbcConnectionProvider="${dbDatafeeds}" jdbcConnectionProvider="${dbRssFeeds}"
idColumnName="id" idColumnName="id"
sqlList="SELECT * FROM stream LIMIT 100" sqlList="SELECT * FROM channel LIMIT 100"
sqlDelete="DELETE FROM stream WHERE id = ?0" sqlDelete="DELETE FROM channel WHERE id = ?0"
sqlPersist="INSERT INTO stream (name,url,importing,etc) VALUES (?0,?1,?2,?3,?4)" sqlPersist="INSERT INTO channel (name,url,importing,etc) VALUES (?0,?1,?2,?3,?4)"
sqlMerge="UPDATE stream (name,url) VALUE (?0,?1)" sqlMerge="UPDATE channel (name,url) VALUE (?0,?1)"
/> />
<v:entry id="streams" backendId="dbStreams"> <v:entry id="rssChannel" backendId="rssChannelDB">
<v:field id="id" readOnly="true"/> <v:field id="id" readOnly="true"/>
<v:field id="name"/> <v:field id="name"/>
<v:field id="url"/> <v:field id="url"/>
@ -79,13 +128,13 @@
<v:field id="column_mapping" list="false"/> <v:field id="column_mapping" list="false"/>
</v:entry> </v:entry>
<!--
<l:ldapConnectionProvider <l:ldapConnectionProvider
el.id="ldapSudoers" el.id="ldapSudoers"
ldapHost="localhost" ldapHost="localhost"
bindUser="uid=admin-sudo,ou=services,dc=example,dc=nl" bindUser="uid=admin-sudo,ou=services,dc=example,dc=nl"
bindPass="adminSudo" bindPass="test"
/> />
<l:ldapBackend <l:ldapBackend
id="ldapBackendSudoers" id="ldapBackendSudoers"
@ -100,6 +149,8 @@
<v:field id="sudoCommand" vascEntryFieldType="MultiTextField"/> <v:field id="sudoCommand" vascEntryFieldType="MultiTextField"/>
<v:field id="sudoHost" vascEntryFieldType="MultiTextField"/> <v:field id="sudoHost" vascEntryFieldType="MultiTextField"/>
<v:field id="sudoUser" vascEntryFieldType="MultiTextField"/> <v:field id="sudoUser" vascEntryFieldType="MultiTextField"/>
-->
<!-- <!--
<v:ldapNextIdFunction name="nextUidNumber" ldapFilter="(&(objectClass=posixGroup))" ldapAttribute="gidnumber"/> <v:ldapNextIdFunction name="nextUidNumber" ldapFilter="(&(objectClass=posixGroup))" ldapAttribute="gidnumber"/>
@ -112,19 +163,22 @@
<v:link fieldName="gidNumber" viewController="ldapGroups" parameterName="group_key,${baseDn}"/> <v:link fieldName="gidNumber" viewController="ldapGroups" parameterName="group_key,${baseDn}"/>
<v:detail fieldName="gidNumber" detailController="${ldapGroups}"/> <v:detail fieldName="gidNumber" detailController="${ldapGroups}"/>
--> -->
<!--
</v:entry> </v:entry>
<l:ldapConnectionProvider <l:ldapConnectionProvider
el.id="ldapUsers" el.id="ldapUsers"
ldapHost="10.11.12.96" ldapHost="10.11.12.96"
bindUser="uid=libnss,ou=services,dc=dutchworks,dc=nl" bindUser="uid=libnss,ou=services,dc=example,dc=nl"
bindPass="superN" bindPass="test"
/> />
<l:ldapBackend <l:ldapBackend
id="ldapBackendUsers" id="ldapBackendUsers"
ldapConnectionProvider="${ldapUsers}" ldapConnectionProvider="${ldapUsers}"
baseDN="ou=users,dc=dutchworks,dc=nl" baseDN="ou=users,dc=example,dc=nl"
keyAttribute="uid" keyAttribute="uid"
ldapFilter="(&amp;(objectClass=posixAccount))" ldapFilter="(&amp;(objectClass=posixAccount))"
/> />
@ -155,7 +209,7 @@
el.id="ldapMachines" el.id="ldapMachines"
ldapHost="localhost" ldapHost="localhost"
bindUser="uid=samba,ou=services,dc=example,dc=nl" bindUser="uid=samba,ou=services,dc=example,dc=nl"
bindPass="superS" bindPass="test"
/> />
<l:ldapBackend <l:ldapBackend
id="ldapBackendMachines" id="ldapBackendMachines"
@ -170,7 +224,7 @@
<v:field id="sambaSID" /> <v:field id="sambaSID" />
<v:field id="uidNumber" /> <v:field id="uidNumber" />
</v:entry> </v:entry>
-->
<!-- <!--
@ -221,7 +275,7 @@ Master
<v:ldapConnection el.id="sudoers" x4o.templates="ldapServerTemplate"> <v:ldapConnection el.id="sudoers" x4o.templates="ldapServerTemplate">
<x4o:property name="user" value="uid=admin-sudo,ou=services,dc=example,dc=nl"/> <x4o:property name="user" value="uid=admin-sudo,ou=services,dc=example,dc=nl"/>
<x4o:property name="pass" value="adminSudo"/> <x4o:property name="pass" value="test"/>
<x4o:property name="baseDn" value="ou=sudoers,dc=example,dc=nl"/> <x4o:property name="baseDn" value="ou=sudoers,dc=example,dc=nl"/>
</v:ldapConnection> </v:ldapConnection>
@ -234,7 +288,7 @@ Master
</x4o:template> </x4o:template>
<x4o:template el.id="sambaUserSchema"> <x4o:template el.id="sambaUserSchema">
<v:field name="sambaSID" fieldEditor="textField" edit="false" list="false" view="false" create="false" defaultValue="S-1-5-21-1200182392-965607725-1867741125-514"/> <v:field name="sambaSID" fieldEditor="textField" edit="false" list="false" view="false" create="false" defaultValue="S-1-5-21-123523482392-923323723-12323323235-514"/>
<v:field name="sambaGroupType" v.defaultValue="2"/> <v:field name="sambaGroupType" v.defaultValue="2"/>
</x4o:template> </x4o:template>

View file

@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<x4o:root xmlns:v="http://vasc.forwardfire.net/eld/vasc-lang.eld"
xmlns:x4o="http://eld.x4o.org/eld/x4o-lang.eld"
>
<v:virtualVascBackend id="vascEntryBackend" vascController="${vascController}" vascType="entry"/>
<v:entry id="vascEntry" backendId="vascEntryBackend">
<v:field id="id"/>
<v:field id="backendId"/>
<v:field id="name"/>
<v:field id="helpId" list="false"/>
<v:field id="image" list="false"/>
<v:field id="listDescription" list="false"/>
<v:field id="listImage" list="false"/>
<v:field id="editDescription" list="false"/>
<v:field id="editImage" list="false"/>
<v:field id="deleteDescription" list="false"/>
<v:field id="deleteImage" list="false"/>
<v:field id="createDescription" list="false"/>
<v:field id="createImage" list="false"/>
<v:field id="primaryKeyFieldId" list="false"/>
<v:field id="displayNameFieldId" list="false"/>
<v:field id="vascDisplayOnly" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="vascAdminList" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="vascAdminEdit" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="vascAdminCreate" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="vascAdminDelete" list="false" vascEntryFieldType="BooleanField"/>
<v:link id="VascEntryField" vascEntryId="VascEntryFieldLink">
<v:linkEntryCreateFieldValue valueFieldId="vascEntry"/>
<v:linkEntryParameter name="entry_id" valueFieldId="id"/>
</v:link>
<v:link id="VascEntryFieldSet" vascEntryId="VascEntryFieldSetLink">
<v:linkEntryParameter name="entry_id" valueFieldId="id"/>
</v:link>
<v:link id="VascLinkEntry" vascEntryId="VascLinkEntryLink">
<v:linkEntryCreateFieldValue valueFieldId="vascEntry"/>
<v:linkEntryParameter name="entry_id" valueFieldId="id"/>
</v:link>
<v:link id="VascListOption" vascEntryId="VascListOptionLink">
<v:linkEntryCreateFieldValue valueFieldId="vascEntry"/>
<v:linkEntryParameter name="entry_id" valueFieldId="id"/>
</v:link>
</v:entry>
<v:virtualVascBackend id="VascEntryFieldLinkBackend" vascController="${vascController}" vascType="field" />
<v:entry id="VascEntryFieldLink" backendId="VascEntryFieldLinkBackend">
<v:field id="id"/>
<v:field id="backendName" list="false"/>
<v:field id="displayName" list="false"/>
<v:field id="vascEntryFieldType" list="false" editReadOnly="true"/>
<v:field id="vascEntryFieldValue" list="false" editReadOnly="true"/>
<v:field id="name"/>
<v:field id="description" list="false"/>
<v:field id="helpId" list="false"/>
<v:field id="image" list="false"/>
<v:field id="orderIndex" vascEntryFieldType="IntegerField"/>
<v:field id="defaultValue"/>
<v:field id="sizeList" list="false" vascEntryFieldType="IntegerField"/>
<v:field id="sizeEdit" list="false" vascEntryFieldType="IntegerField"/>
<v:field id="styleList" list="false"/>
<v:field id="styleEdit" list="false"/>
<v:field id="choices" list="false"/>
<v:field id="choicesAsRadio" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="view" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="optional" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="create" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="edit" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="editReadOnly" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="editBlank" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="list" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="rolesCreate" list="false"/>
<v:field id="rolesEdit" list="false"/>
<v:field id="rolesEditReadOnly" list="false"/>
<v:field id="rolesList" list="false"/>
<v:field id="sortable" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="sumable" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="graphable" list="false" vascEntryFieldType="BooleanField"/>
<!-- private List<VascValidator> vascValidators = null; -->
</v:entry>
<v:virtualVascBackend id="VascEntryFieldSetLinkBackend" vascController="${vascController}" vascType="fieldset" />
<v:entry id="VascEntryFieldSetLink" backendId="VascEntryFieldSetLinkBackend">
<v:field id="id"/>
<v:field id="name"/>
<v:field id="description" list="false"/>
<v:field id="helpId" list="false"/>
<v:field id="image" list="false"/>
<v:field id="styleList" list="false"/>
<v:field id="styleEdit" list="false"/>
<v:field id="collapsed" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="optional" list="false" vascEntryFieldType="BooleanField"/>
<!-- private List<String> vascEntryFieldIds = null; -->
</v:entry>
<v:virtualVascBackend id="VascLinkEntryLinkBackend" vascController="${vascController}" vascType="linkentries" />
<v:entry id="VascLinkEntryLink" backendId="VascLinkEntryLinkBackend">
<v:field id="id"/>
<v:field id="vascEntryId"/>
<v:field id="vascLinkEntryType" list="false" vascEntryFieldType="ListField">
<v:vascSelectItemModelEnum enumClass="net.forwardfire.vasc.core.VascLinkEntryType"/>
</v:field>
<v:field id="doActionId" list="false"/>
<v:field id="name" list="false"/>
<!--
private Map<String,String> entryParameterFieldIds = new HashMap<String,String>(3);
private Map<String,String> entryCreateFieldValues = new HashMap<String,String>(3);
-->
</v:entry>
<v:virtualVascBackend id="VascListOptionLinkBackend" vascController="${vascController}" vascType="listoptions" />
<v:entry id="VascListOptionLink" backendId="VascListOptionLinkBackend">
<v:field id="id"/>
<v:field id="name"/>
<v:field id="description" list="false"/>
<v:field id="helpId" list="false"/>
<v:field id="image" list="false"/>
<v:field id="styleList" list="false"/>
<v:field id="styleEdit" list="false"/>
<v:field id="collapsed" list="false" vascEntryFieldType="BooleanField"/>
<v:field id="optional" list="false" vascEntryFieldType="BooleanField"/>
<!-- private List<String> vascEntryFieldIds = null; -->
</v:entry>
<!--
<m:mongodbConnectionProvider
el.id="lefiona_connection"
hostname="localhost"
database="lefiona"
/>
<m:mongodbBackend
id="dg2_smiles_backend"
connectionProvider="${lefiona_connection}"
collection="dg2_smiles"
/>
<v:entry id="dg2_smiles" backendId="dg2_smiles_backend">
<v:field id="_id" readOnly="true" list="false"/>
<v:field id="text" vascEntryFieldType="TextAreaField"/>
<v:field id="profile_type" vascEntryFieldType="ListField">
<v:vascSelectItemModelString data="MALE,FEMALE,BOTH"/>
</v:field>
<v:field id="cron_type" vascEntryFieldType="ListField">
<v:vascSelectItemModelString data="BASE,DAILY,WEEKLY,MONTLY"/>
</v:field>
<v:field id="group"/>
<v:field id="active" vascEntryFieldType="BooleanField"/>
</v:entry>
<m:mongodbBackend
id="dg2_profiles_backend"
connectionProvider="${lefiona_connection}"
collection="dg2_profiles"
/>
<v:entry id="dg2_profiles" backendId="dg2_profiles_backend">
<v:field id="_id" readOnly="true" list="false"/>
<v:field id="url"/>
<v:field id="name"/>
<v:field id="active" vascEntryFieldType="BooleanField"/>
<v:field id="body_text" list="false" vascEntryFieldType="TextAreaField"/>
<v:field id="profile_type" vascEntryFieldType="ListField">
<v:vascSelectItemModelString data="MALE,FEMALE,BOTH"/>
</v:field>
<v:field id="send_jokers" vascEntryFieldType="IntegerField"/>
<v:field id="run_date" vascEntryFieldType="DateField"/>
</v:entry>
-->
</x4o:root>

View file

@ -49,12 +49,7 @@ public class SwingPagerPanel extends JPanel implements VascEntryFrontendEventLis
public SwingPagerPanel(VascEntry vascEntry) { public SwingPagerPanel(VascEntry vascEntry) {
this.vascEntry=vascEntry; this.vascEntry=vascEntry;
//result = this;
result = new JPanel(); result = new JPanel();
// result.setBackground(Color.green);
//result.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
add(result); add(result);
vascEntry.getVascFrontendData().addVascEntryFrontendEventListener(this); vascEntry.getVascFrontendData().addVascEntryFrontendEventListener(this);
} }

View file

@ -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<JPanel,JFrame> panels = new HashMap<JPanel,JFrame>(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);
}
}
}

View file

@ -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);
}

View file

@ -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<tabbedPane.getTabCount();i++) {
Object tab = tabbedPane.getComponentAt(i);
if (pane==tab) {
tabbedPane.removeTabAt(i);
break;
}
}
}
}

View file

@ -28,17 +28,18 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SpringLayout; import javax.swing.SpringLayout;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascLinkEntry;
import net.forwardfire.vasc.core.ui.VascColumnValueModelListener; import net.forwardfire.vasc.core.ui.VascColumnValueModelListener;
import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.core.ui.VascValueModel;
import net.forwardfire.vasc.impl.DefaultVascFactory;
/** /**
* SwingVascEditDialog renders vasc entry edit dialog * SwingVascEditDialog renders vasc entry edit dialog
@ -46,7 +47,7 @@ import net.forwardfire.vasc.core.ui.VascValueModel;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Mar 21, 2007 * @version 1.0 Mar 21, 2007
*/ */
public class SwingVascEditDialog extends JDialog { public class SwingVascEditDialog extends JPanel {
private static final long serialVersionUID = 10L; private static final long serialVersionUID = 10L;
private String headerText = null; private String headerText = null;
@ -55,70 +56,102 @@ public class SwingVascEditDialog extends JDialog {
private Object bean = null; private Object bean = null;
private VascEntry entry = null; private VascEntry entry = null;
private SwingVascFrontend swingFrontend = null; private SwingVascFrontend swingFrontend = null;
private SwingPanelIntegration panels = null;
private JPanel editView = null;
public SwingVascEditDialog(SwingVascFrontend swingFrontend,JComponent parent,VascEntry entry,Object bean,String beanValue) throws Exception { public SwingVascEditDialog(SwingVascFrontend swingFrontend,JPanel editView,VascEntry entry,Object bean,String beanValue,SwingPanelIntegration panels) throws Exception {
super(); super();
this.headerText = "vasc.dialog.edit.message"; this.headerText = "vasc.dialog.edit.message";
this.headerTextValue = beanValue; this.headerTextValue = beanValue;
this.bean = bean; this.bean = bean;
this.entry = entry; this.entry = entry;
this.swingFrontend=swingFrontend; this.swingFrontend=swingFrontend;
this.panels=panels;
this.editView=editView;
setTitle(swingFrontend.i18n("vasc.dialog.edit.title")); setLayout(new BorderLayout());
setModal(true); add(createHeader(), BorderLayout.NORTH);
add(createBody(), BorderLayout.CENTER);
JPanel pane = new JPanel(); add(createFooter(), BorderLayout.SOUTH);
pane.setLayout(new BorderLayout());
editView.add(this);
}
protected JPanel createHeader() {
JPanel header = new JPanel(); JPanel header = new JPanel();
createHeader(header);
pane.add(header,BorderLayout.NORTH);
JPanel body = new JPanel();
createBody(body);
pane.add(body,BorderLayout.CENTER);
JPanel footer = new JPanel();
createFooter(footer);
pane.add(footer,BorderLayout.SOUTH);
add(pane);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
//Ensure the text field always gets the first focus.
//addComponentListener(new ComponentAdapter() {
// public void componentShown(ComponentEvent ce) {
// textField.requestFocusInWindow();
// }
/// });
pack();
setLocationRelativeTo(parent);
setResizable(false);
}
public Object openDialog() {
setVisible(true);
return result;
}
public void createHeader(JPanel header) {
JLabel l = new JLabel(); JLabel l = new JLabel();
l.setText(swingFrontend.i18n(headerText,headerTextValue)); l.setText(swingFrontend.i18n(headerText,headerTextValue));
l.setFont(new Font(null,Font.BOLD, 14)); l.setFont(new Font(null,Font.BOLD, 14));
//l.setToolTipText(i18n(headerText)); //l.setToolTipText(i18n(headerText));
header.add(l); header.add(l);
for (final VascLinkEntry vle:entry.getVascLinkEntries()) {
JButton but = new JButton(vle.getName());
but.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
VascController vc = entry.getVascFrontendData().getVascController();
VascEntry ee = vc.getVascEntryController().getVascEntryById(vle.getVascEntryId()).clone();
DefaultVascFactory.fillVascEntryFrontend(ee, vc, DefaultVascFactory.getDefaultVascFrontendData(null));
// Set parameters
try {
Object selected = bean;
for (String parameterName:vle.getEntryParameterFieldIdKeys()) {
String fieldId = vle.getEntryParameterFieldId(parameterName);
VascEntryField v = ee.getVascEntryFieldById(fieldId);
if (v==null) {
System.out.println("Could nog get VascEntryField for fieldID: "+fieldId);
continue;
}
if (v.getVascEntryFieldValue()==null) {
System.out.println("Could not get VascEntryFieldValue for fieldID: "+fieldId);
continue;
}
Object selectedValue = v.getVascEntryFieldValue().getValue(v, selected);
// set data parameter on new vasc entry
ee.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(parameterName, selectedValue);
System.out.println("Setting link parameter: "+parameterName+" with: "+selectedValue);
}
for (String fieldId:vle.getEntryCreateFieldValueKeys()) {
String selectedfieldId = vle.getEntryParameterFieldId(fieldId);
Object selectedValue = selected;
if (selectedfieldId!=null) {
VascEntryField v = ee.getVascEntryFieldById(selectedfieldId);
selectedValue = v.getVascEntryFieldValue().getValue(v, selected);
}
// create listener for new objects
//entry.getVascFrontendData().addVascEntryFrontendEventListener(new CreateEntryFieldValuesListener2(fieldId,selectedValue));
}
} catch (Exception eee) {
throw new RuntimeException("error: "+eee.getMessage(),eee);
}
panels.createNewVascView(ee);
} catch (Exception eee) {
eee.printStackTrace();
}
}
});
header.add(but);
}
return header;
} }
public void createBody(JPanel body) throws Exception { protected JPanel createBody() throws Exception {
JPanel body = new JPanel();
body.setLayout(new SpringLayout()); body.setLayout(new SpringLayout());
int column = 0; int column = 0;
for (VascEntryField c:entry.getVascEntryFields()) { for (VascEntryField c:entry.getVascEntryFields()) {
if (c.getEdit()==false) { if (c.getEdit()==false) {
continue; continue;
} }
//if (c.isEditReadOnly()==true) { //if (c.isEditReadOnly()==true) {
for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) { for (int i=0;i<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
@ -142,10 +175,10 @@ public class SwingVascEditDialog extends JDialog {
} }
//JComponent, rows, cols, initX, initY ,xPad, yPad //JComponent, rows, cols, initX, initY ,xPad, yPad
SpringUtilities.makeCompactGrid(body, column,2, 6,6, 6,6); SpringUtilities.makeCompactGrid(body, column,2, 6,6, 6,6);
return body;
} }
public void createFooter(JPanel footer) { public JPanel createFooter() {
JPanel footer = new JPanel();
JButton saveButton = new JButton(); JButton saveButton = new JButton();
saveButton.setIcon(swingFrontend.getImageIcon("vasc.dialog.save.image")); saveButton.setIcon(swingFrontend.getImageIcon("vasc.dialog.save.image"));
saveButton.setText(swingFrontend.i18n("vasc.dialog.save.name")); saveButton.setText(swingFrontend.i18n("vasc.dialog.save.name"));
@ -155,8 +188,15 @@ public class SwingVascEditDialog extends JDialog {
//if(entry.getVascFrontendData().getVascFrontendHelper().validateObject(entry, bean)) { //if(entry.getVascFrontendData().getVascFrontendHelper().validateObject(entry, bean)) {
// return; // return;
//} //}
result = bean; result = bean;
setVisible(false);
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(result);
entry.getVascFrontendData().getVascFrontendActions().mergeObject();
panels.closeVascView(editView, SwingVascEditDialog.this.entry);
//setVisible(false);
} }
}); });
footer.add(saveButton); footer.add(saveButton);
@ -168,9 +208,11 @@ public class SwingVascEditDialog extends JDialog {
cancelButton.addActionListener(new ActionListener() { cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
result = null; result = null;
setVisible(false); panels.closeVascView(editView, SwingVascEditDialog.this.entry);
//setVisible(false);
} }
}); });
footer.add(cancelButton); footer.add(cancelButton);
return footer;
} }
} }

View file

@ -32,6 +32,8 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@ -63,6 +65,7 @@ import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.actions.GlobalVascAction; import net.forwardfire.vasc.core.actions.GlobalVascAction;
import net.forwardfire.vasc.core.actions.RowVascAction; import net.forwardfire.vasc.core.actions.RowVascAction;
import net.forwardfire.vasc.core.entry.VascEntryExporter; import net.forwardfire.vasc.core.entry.VascEntryExporter;
import net.forwardfire.vasc.core.ui.VascOptionValueModelListener;
import net.forwardfire.vasc.core.ui.VascUIComponent; import net.forwardfire.vasc.core.ui.VascUIComponent;
import net.forwardfire.vasc.core.ui.VascValueModel; import net.forwardfire.vasc.core.ui.VascValueModel;
@ -87,10 +90,14 @@ public class SwingVascFrontend extends AbstractVascFrontend {
private Logger logger = null; private Logger logger = null;
private JComponent parent = null; private JComponent parent = null;
private boolean initOnce = true; private boolean initOnce = true;
private Map<RowVascAction,JButton> rowActions = null;
private SwingPanelIntegration panels = null;
public SwingVascFrontend(JComponent parent) { public SwingVascFrontend(JComponent parent,SwingPanelIntegration panels) {
logger = Logger.getLogger(SwingVascFrontend.class.getName()); logger = Logger.getLogger(SwingVascFrontend.class.getName());
this.parent=parent; this.parent=parent;
this.panels=panels;
rowActions = new HashMap<RowVascAction,JButton>(5);
} }
/** /**
@ -159,14 +166,10 @@ public class SwingVascFrontend extends AbstractVascFrontend {
beanValue=beanValue.substring(0, 30); beanValue=beanValue.substring(0, 30);
} }
} }
SwingVascEditDialog dialog = new SwingVascEditDialog(this,parent,entry,rowBean,beanValue); JPanel editPanel = panels.initVascView();
Object result = dialog.openDialog(); SwingVascEditDialog dialog = new SwingVascEditDialog(this,editPanel,entry,rowBean,beanValue,panels);
logger.finest("OPEN closed : "+result);
if(result==null) { panels.openVascView(editPanel,entry);
return;
}
entry.getVascFrontendData().getVascEntryState().setEntryDataObject(result);
entry.getVascFrontendData().getVascFrontendActions().mergeObject();
} }
public void renderDelete() throws Exception { public void renderDelete() throws Exception {
@ -309,8 +312,8 @@ public class SwingVascFrontend extends AbstractVascFrontend {
VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c); VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c)); model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
model.addListener(new VascOptionValueModelListener(c));
model.setValue(c.getDefaultValue()); model.setValue(c.getDefaultValue());
//model.addListener(new VascColumnValueModelListener(c,bean));
Object g = editor.createComponent(entry,c,model,body); Object g = editor.createComponent(entry,c,model,body);
column++; column++;
@ -320,6 +323,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
body.add(new JLabel()); // fill :( body.add(new JLabel()); // fill :(
} }
} }
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
// add search // add search
column++; column++;
@ -327,10 +331,17 @@ public class SwingVascFrontend extends AbstractVascFrontend {
body.add(searchLabel); body.add(searchLabel);
final JTextField searchField = new JTextField(); final JTextField searchField = new JTextField();
body.add(searchField); 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"); JButton searchButton = new JButton("Search");
searchButton.addActionListener(new ActionListener() { searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
entry.getVascFrontendData().getVascFrontendActions().searchAction(searchField.getText()); String searchText = searchField.getText();
entry.getVascFrontendData().getVascFrontendActions().searchAction(searchText);
} }
}); });
body.add(searchButton); body.add(searchButton);
@ -396,7 +407,7 @@ public class SwingVascFrontend extends AbstractVascFrontend {
counter++; counter++;
} }
table.getSelectionModel().addListSelectionListener(new EntrySectionListener(table)); table.getSelectionModel().addListSelectionListener(new EntrySectionListener(table));
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.addMouseListener(new MouseAdapter() { table.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) { if (e.getClickCount() == 2) {
@ -428,40 +439,16 @@ public class SwingVascFrontend extends AbstractVascFrontend {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
TableColumnModel colModel = table.getColumnModel(); TableColumnModel colModel = table.getColumnModel();
int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); 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); TableColumn tc = colModel.getColumn(columnModelIndex);
VascEntryField field = (VascEntryField)tc.getHeaderValue(); VascEntryField field = (VascEntryField)tc.getHeaderValue();
//VascEntry entry = comp.getVascEntry(); entry.getVascFrontendData().getVascFrontendActions().sortAction(field);
//VascEntryField field = entry.getVascEntryFieldById(fieldIdString); sortOrder = entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending();
sortField = field.getId();
entry.getVascFrontendData().getVascFrontendActions().sortAction(field); try {
entry.getVascFrontendData().getVascFrontend().renderView();
sortOrder = entry.getVascFrontendData().getVascEntryState().getVascBackendState().isSortAscending(); } catch (Exception ee) {
sortField = field.getId(); entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, ee);
}
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));
table.repaint(); table.repaint();
} }
} }
@ -474,7 +461,33 @@ public class SwingVascFrontend extends AbstractVascFrontend {
if (e.getValueIsAdjusting()) { if (e.getValueIsAdjusting()) {
return; 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(); int rowIndex = table.getSelectedRow();
if (rowIndex!=-1) { if (rowIndex!=-1) {
// temp; gets index by sorter // temp; gets index by sorter
//rowIndex = tableSorter.modelIndex(rowIndex); //rowIndex = tableSorter.modelIndex(rowIndex);
@ -529,6 +542,10 @@ public class SwingVascFrontend extends AbstractVascFrontend {
but.setToolTipText(i18n(action.getDescription())); but.setToolTipText(i18n(action.getDescription()));
but.setIcon(getImageIcon(action.getImage())); but.setIcon(getImageIcon(action.getImage()));
but.addActionListener(new RowActionListener(action)); but.addActionListener(new RowActionListener(action));
if (action.getId().contains("add")==false) {
but.setEnabled(false);
}
rowActions.put(action, but);
panel.add(but); panel.add(but);
} }
bottomPanel.add(panel,BorderLayout.SOUTH); bottomPanel.add(panel,BorderLayout.SOUTH);

View file

@ -104,7 +104,7 @@ public class SwingVascTableModel extends AbstractTableModel implements VascEntry
} }
public VascFrontendEventType[] getEventTypes() { public VascFrontendEventType[] getEventTypes() {
VascFrontendEventType[] result = {VascFrontendEventType.POST_UPDATE,VascFrontendEventType.POST_READ}; VascFrontendEventType[] result = {VascFrontendEventType.POST_UPDATE,VascFrontendEventType.POST_READ,VascFrontendEventType.POST_DELETE};
return result; return result;
} }
} }

View file

@ -52,7 +52,9 @@ public class SwingBoolean implements VascUIComponent {
public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException { public Object createComponent(VascEntry table,VascEntryField entryField,VascValueModel model,Object gui) throws VascException {
checkBox = new JCheckBox(); checkBox = new JCheckBox();
orgBackgroundColor = checkBox.getBackground(); 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); ((JComponent)gui).add(checkBox);
checkBox.addActionListener(new SelectActionListener(model,table)); checkBox.addActionListener(new SelectActionListener(model,table));
return checkBox; return checkBox;

View file

@ -22,53 +22,30 @@
package net.forwardfire.vasc; 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.VascController;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal; 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.impl.DefaultVascFactory;
import net.forwardfire.vasc.test.frontend.data.TestModelEntry; import net.forwardfire.vasc.test.frontend.data.TestModelData;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* Tests a simple x4o xml language. * SwingTestTabbed shows interfaces in frames.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jul 24, 2006 * @version 1.0 Jul 24, 2006
*/ */
public class SwingTest extends TestCase { 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 { public void testNull() throws Exception {
assertEquals(true, true); assertEquals(true, true);
//main(new String[] {}); //main(new String[] {});
} }
public static void main(String[] argu){ public static void main(String[] argu){
JFrame.setDefaultLookAndFeelDecorated(false);
SwingTest s = new SwingTest(); SwingTest s = new SwingTest();
try { try {
s.open(); s.open();
@ -78,69 +55,13 @@ public class SwingTest extends TestCase {
} }
public void open() throws Exception { 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(); VascEntry ve = testData.getTestEntry(vc);
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)); DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null));
spi.createNewVascView(ve);
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;
} }
} }

View file

@ -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);
}
}

View file

@ -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){}
}
}

View file

@ -329,7 +329,7 @@ public class SwtVascFrontend extends AbstractVascFrontend {
net.forwardfire.vasc.core.ui.VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option); net.forwardfire.vasc.core.ui.VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option);
model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option)); model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option));
model.addListener(new VascOptionValueModelListener(option)); model.addListener(new VascOptionValueModelListener(option));
model.setValue(null); model.setValue(option.getDefaultValue());
model.addListener(new VascValueModelListener() { model.addListener(new VascValueModelListener() {
public void valueUpdate(VascValueModel model) throws VascException { public void valueUpdate(VascValueModel model) throws VascException {
entry.getVascFrontendData().getVascFrontendActions().refreshData();// mm entry.getVascFrontendData().getVascFrontendActions().refreshData();// mm

View file

@ -28,7 +28,7 @@ import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal; import net.forwardfire.vasc.core.VascEntryControllerLocal;
import net.forwardfire.vasc.frontends.swt.SwtVascFrontend; import net.forwardfire.vasc.frontends.swt.SwtVascFrontend;
import net.forwardfire.vasc.impl.DefaultVascFactory; 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.Display;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
@ -45,7 +45,7 @@ import junit.framework.TestCase;
*/ */
public class SWTTest extends TestCase { public class SWTTest extends TestCase {
private TestModelEntry entry = null; private TestModelData testData = null;
public void setUp() throws Exception { public void setUp() throws Exception {
} }
@ -70,13 +70,12 @@ public class SWTTest extends TestCase {
// define redering and render // define redering and render
SwtVascFrontend render = new SwtVascFrontend(shell); SwtVascFrontend render = new SwtVascFrontend(shell);
entry = new TestModelEntry(); testData = new TestModelData();
VascController vc = entry.getTestVascController(); VascController vc = testData.getTestVascController();
VascEntry ve = entry.createVascEntry(vc); testData.createVascEntries(vc,(VascEntryControllerLocal)vc.getVascEntryController());
((VascEntryControllerLocal)vc.getVascEntryController()).addVascEntry(ve,vc);
DefaultVascFactory.fillVascControllerLocalEntries((VascEntryControllerLocal) vc.getVascEntryController(), vc); VascEntry ve = testData.getTestEntry(vc);
DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null)); DefaultVascFactory.fillVascEntryFrontend(ve, vc, DefaultVascFactory.getDefaultVascFrontendData(null));
ve.getVascFrontendData().getVascFrontendActions().refreshData(); ve.getVascFrontendData().getVascFrontendActions().refreshData();
render.initEntry(ve); render.initEntry(ve);
render.renderView(); render.renderView();

View file

@ -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; package net.forwardfire.vasc.frontends.web.jsf;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry; 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.frontend.VascFrontendData;
import net.forwardfire.vasc.impl.DefaultVascFactory; import net.forwardfire.vasc.impl.DefaultVascFactory;
/**
* AbstractJSFVascFacesControllerBase for making jsf frontend.
*
* @author Willem Cazander
* @version 1.0 Dec 21, 2011
*/
public abstract class AbstractJSFVascFacesControllerBase { public abstract class AbstractJSFVascFacesControllerBase {
abstract VascFrontendData getNewVascFrontendData(); abstract VascFrontendData getNewVascFrontendData();

View file

@ -325,6 +325,10 @@ abstract public class AbstractJSFVascFacesControllerEJB extends AbstractJSFVascF
Object result = vascManager.invokeBackendMethod(backendId, "isTotalSummary", args); Object result = vascManager.invokeBackendMethod(backendId, "isTotalSummary", args);
return (Boolean)result; return (Boolean)result;
} }
public boolean isReadOnly() {
return false;
}
} }
/** /**

View file

@ -29,15 +29,14 @@ import javax.el.ValueExpression;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import net.forwardfire.vasc.core.VascEntry; 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; 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 { public class JSFVascEntryEventListener implements VascEntryFrontendEventListener {
@ -59,6 +58,7 @@ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener
public void vascEvent(VascEntry entry,Object dataNotUsed) { public void vascEvent(VascEntry entry,Object dataNotUsed) {
/* moved to fillVascEntryFrontend
try { try {
for (VascEntryField field:entry.getVascEntryFields()) { for (VascEntryField field:entry.getVascEntryFields()) {
if (field.getVascEntryFieldValue()==null) { if (field.getVascEntryFieldValue()==null) {
@ -73,6 +73,7 @@ public class JSFVascEntryEventListener implements VascEntryFrontendEventListener
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
*/
List<Object> data = entry.getVascFrontendData().getVascEntryState().getEntryDataList(); List<Object> data = entry.getVascFrontendData().getVascEntryState().getEntryDataList();
List<Object> result = new ArrayList<Object>(data.size()); List<Object> result = new ArrayList<Object>(data.size());
int index = 0; int index = 0;

View file

@ -64,7 +64,7 @@ import net.forwardfire.vasc.impl.actions.EditRowAction;
/** /**
* * JSFVascEntrySupportBean add EL support for renderer.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Sep 10, 2009 * @version 1.0 Sep 10, 2009
@ -1012,7 +1012,7 @@ class JSFVascSupportI18nMapController implements Map<String,String> {
return null; return null;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("rawtypes")
public void putAll(Map m) { public void putAll(Map m) {
} }

View file

@ -27,6 +27,7 @@ import java.lang.reflect.Method;
import net.forwardfire.vasc.backend.VascBackendControllerLocal; import net.forwardfire.vasc.backend.VascBackendControllerLocal;
import net.forwardfire.vasc.core.VascController; import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryControllerLocal;
import net.forwardfire.vasc.core.VascEntryField; import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.impl.DefaultVascEntry; import net.forwardfire.vasc.impl.DefaultVascEntry;
import net.forwardfire.vasc.impl.DefaultVascEntryField; import net.forwardfire.vasc.impl.DefaultVascEntryField;
@ -37,24 +38,32 @@ import net.forwardfire.vasc.impl.DefaultVascFactory;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Aug 2, 2007 * @version 1.0 Aug 2, 2007
*/ */
public class TestModelEntry { public class TestModelData {
public VascController getTestVascController() throws Exception { public VascController getTestVascController() throws Exception {
VascController c = DefaultVascFactory.getDefaultVascController(1234L,"Nice UserName","user","role_admin"); VascController c = DefaultVascFactory.getDefaultVascController(1234L,"Nice UserName","user","role_admin");
// for test // for test
TestModelVascDataSource backend = new TestModelVascDataSource(); TestModelVascDataSource backends = new TestModelVascDataSource();
backend.generatorData(10876); backends.generatorData(10876);
backend.setId("testBackend");
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backend); backends.orderModel.setId("orderModelBackend");
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backends.orderModel);
backends.orderLineModel.setId("orderLineModelBackend");
((VascBackendControllerLocal)c.getVascBackendController()).addVascBackend(backends.orderLineModel);
return c; 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(); VascEntry ve = new DefaultVascEntry();
ve.setId("testEntry"); ve.setId("orderModel");
ve.setBackendId("testBackend"); ve.setBackendId("orderModelBackend");
VascEntryField field = new DefaultVascEntryField(); VascEntryField field = new DefaultVascEntryField();
field.setId("name"); field.setId("name");
@ -89,9 +98,34 @@ public class TestModelEntry {
field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField")); field.setVascEntryFieldType(vc.getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField"));
field.setBackendName("active"); field.setBackendName("active");
field.setDefaultValue("true"); // obj does also work ! we are first need to fix string defaults. field.setDefaultValue("true"); // obj does also work ! we are first need to fix string defaults.
ve.addListOption(field); 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 { static void printEntry(VascEntry e) throws Exception {

View file

@ -42,16 +42,31 @@ import net.forwardfire.vasc.validators.VascStringLength;
* @version 1.0 Mar 28, 2007 * @version 1.0 Mar 28, 2007
*/ */
@VascEntry(headerName="En een tooltip op het model") @VascEntry(headerName="En een tooltip op het model")
public class TestModel { public class TestModelOrder {
private Integer id = null;
private String name = null; private String name = null;
private String description = null; private String description = null;
private Float price = null; private Float price = null;
private Boolean active = null; private Boolean active = null;
private Date date = null; private Date date = null;
private TestModel testModel = null; private TestModelOrder testModel = null;
private String hexColor = null; private String hexColor = null;
//private Node nonEditorField = 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 * @return the date
@ -60,7 +75,7 @@ public class TestModel {
public Date getDate() { public Date getDate() {
return date; return date;
} }
/** /**
* @param date the date to set * @param date the date to set
*/ */
@ -125,11 +140,11 @@ public class TestModel {
@VascObjectNotNull @VascObjectNotNull
@VascModelReference @VascModelReference
@VascI18n(image="/resources/images/gabelfresser.gif") @VascI18n(image="/resources/images/gabelfresser.gif")
public TestModel getTestModel() { public TestModelOrder getTestModel() {
return testModel; return testModel;
} }
public void setTestModel(TestModel testModel) { public void setTestModel(TestModelOrder testModel) {
this.testModel = testModel; this.testModel = testModel;
} }

View file

@ -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;
}
}

View file

@ -26,6 +26,9 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; 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.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState; import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.core.VascEntry; import net.forwardfire.vasc.core.VascEntry;
@ -45,20 +48,24 @@ import net.forwardfire.vasc.impl.entry.BeanVascEntryRecordCreator;
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Mar 21, 2007 * @version 1.0 Mar 21, 2007
*/ */
public class TestModelVascDataSource extends AbstractVascBackend implements VascSelectItemModel { public class TestModelVascDataSource {
private List<TestModel> testModels = null; //private List<TestModelOrder> testModels = null;
private String nullLabel = null; public ListObjectVascDataSource orderModel = null;
private String nullKeyValue = null; public ListObjectVascDataSource orderLineModel = null;
public TestModelVascDataSource() { public TestModelVascDataSource() {
testModels = new ArrayList<TestModel>(200); this(new ArrayList<TestModelOrder>(200),new ArrayList<TestModelOrderLine>(200));
}
public TestModelVascDataSource(List<TestModelOrder> testModels,List<TestModelOrderLine> testModelLine) {
orderModel = new ListObjectVascDataSource(TestModelOrder.class,(List)testModels);
orderLineModel = new ListObjectVascDataSource(TestModelOrderLine.class,(List)testModelLine);
} }
public void generatorData(int size) { public void generatorData(int size) {
for (int i=0;i<size;i++) { for (int i=0;i<size/3;i++) {
TestModel t = new TestModel(); TestModelOrder t = new TestModelOrder();
t.setDate(new Date()); t.setDate(new Date());
t.setDescription("Some long text in this...."); t.setDescription("Some long text in this....");
t.setName("BeanName_"+i); t.setName("BeanName_"+i);
@ -68,96 +75,138 @@ public class TestModelVascDataSource extends AbstractVascBackend implements Vasc
} else { } else {
t.setActive(true); t.setActive(true);
} }
if (testModels.isEmpty()==false) { if (orderModel.getObjectList().isEmpty()==false) {
t.setTestModel((TestModel)testModels.get(0)); t.setTestModel((TestModelOrder)orderModel.getObjectList().get(0));
}
orderModel.getObjectList().add(t);
for (int ii=0;ii<size/1000;ii++) {
TestModelOrderLine line = new TestModelOrderLine();
line.setDate(new Date());
line.setName("OrderLine"+ii);
line.setPrice(new Float(123+ii));
line.setOrder(t);
orderLineModel.getObjectList().add(line);
} }
testModels.add(t);
} }
} }
public TestModelVascDataSource(List<TestModel> testModels) {
this.testModels=testModels;
}
public List<Object> execute(VascBackendState state) throws VascException {
if (state.getDataParameterKeys().contains("active")) { class ListObjectVascDataSource extends AbstractVascBackend {
List<Object> result = new ArrayList<Object>(testModels.size()/2); private Class<?> modelClass = null;
for (TestModel tm:testModels) { private List<Object> modelList = null;
if (tm.getActive()!=null && tm.getActive().equals(state.getDataParameter("active"))) { private String nullLabel = null;
result.add(tm); private String nullKeyValue = null;
}
} public ListObjectVascDataSource(Class<?> modelClass,List<Object> modelList) {
return result; this.modelClass=modelClass;
} else { this.modelList=modelList;
List<Object> result = new ArrayList<Object>(testModels.size());
for (TestModel tm:testModels) {
result.add(tm);
}
return result;
} }
}
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) { public List<Object> getObjectList() {
return new BeanPropertyVascEntryFieldValue(field.getBackendName()); return modelList;
} }
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { public List<Object> execute(VascBackendState state) throws VascException {
return new BeanVascEntryRecordCreator(TestModel.class); if (state.getDataParameterKeys().isEmpty()==false) {
} List<Object> result = new ArrayList<Object>(modelList.size()/2);
DefaultElementObjectPropertyValue helper = new DefaultElementObjectPropertyValue();
// --- VascSelectItemModel interface for (Object row:modelList) {
boolean addRow = true;
public List<VascSelectItem> getVascSelectItems(VascEntry entry) { for (String key:state.getDataParameterKeys()) {
List<VascSelectItem> res = new ArrayList<VascSelectItem>(4); Object keyValue = state.getDataParameter(key);
for (Object o:testModels) { Object propValue = null;
TestModel t = (TestModel)o; try {
VascSelectItem i = new VascSelectItem(t.getName(),t); propValue = helper.getProperty(row, key);
res.add(i); } 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<Object> result = new ArrayList<Object>(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<VascSelectItem> getVascSelectItems(VascEntry entry) {
List<VascSelectItem> res = new ArrayList<VascSelectItem>(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;
} }
} }

View file

@ -26,30 +26,41 @@ import java.util.Locale;
import net.forwardfire.vasc.xpql.query.QueryParameterValue.QueryParameterType; import net.forwardfire.vasc.xpql.query.QueryParameterValue.QueryParameterType;
import org.x4o.xml.converters.ObjectConverter; import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.converters.ObjectConverterException; import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/** /**
* ParameterTypeObjectConverter
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 21, 2007 * @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; return QueryParameterType.class;
} }
public String convertToString(Object obj, Locale locale) { public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((QueryParameterType)obj).name(); return ((QueryParameterType)obj).name();
} }
public Object convertToObject(String str, Locale locale) throws ObjectConverterException { public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try { try {
return QueryParameterType.valueOf(""+str); return QueryParameterType.valueOf(""+str);
} catch (Exception ex) { } catch (Exception ex) {
throw new ObjectConverterException(this,"Could not convert to QueryParameterType value="+str,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;
}
} }

View file

@ -26,29 +26,42 @@ import java.util.Locale;
import net.forwardfire.vasc.xpql.query.Query.QueryType; import net.forwardfire.vasc.xpql.query.Query.QueryType;
import org.x4o.xml.converters.ObjectConverter; import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.converters.ObjectConverterException; 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 * @author Willem Cazander
* @version 1.0 Jan 21, 2007 * @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; return QueryType.class;
} }
public String convertToString(Object obj, Locale locale) { public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((QueryType)obj).name(); return ((QueryType)obj).name();
} }
public Object convertToObject(String str, Locale locale) throws ObjectConverterException { public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try { try {
return QueryType.valueOf(""+str); return QueryType.valueOf(""+str);
} catch (Exception ex) { } catch (Exception ex) {
throw new ObjectConverterException(this,"Could not convert to QueryType value="+str,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;
}
} }