You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(17) |
Jul
(13) |
Aug
(17) |
Sep
(25) |
Oct
(19) |
Nov
|
Dec
|
---|
From: <ja...@us...> - 2006-10-30 16:30:57
|
Revision: 91 http://svn.sourceforge.net/surveyforge/?rev=91&view=rev Author: javism Date: 2006-10-30 08:30:39 -0800 (Mon, 30 Oct 2006) Log Message: ----------- Removed the test created automatically by Eclipse Removed Paths: ------------- trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java Deleted: trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java =================================================================== --- trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java 2006-10-30 16:28:11 UTC (rev 90) +++ trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java 2006-10-30 16:30:39 UTC (rev 91) @@ -1,38 +0,0 @@ -package org.surveyforge; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-10-30 16:28:20
|
Revision: 90 http://svn.sourceforge.net/surveyforge/?rev=90&view=rev Author: javism Date: 2006-10-30 08:28:11 -0800 (Mon, 30 Oct 2006) Log Message: ----------- Pom updated Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-10-30 16:14:31 UTC (rev 89) +++ trunk/pom.xml 2006-10-30 16:28:11 UTC (rev 90) @@ -160,6 +160,7 @@ <module>surveyforge-core</module> <module>surveyforge-db</module> <module>surveyforge-runner</module> + <module>surveyforge-examples</module> </modules> <repositories> <repository> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-10-30 16:15:16
|
Revision: 89 http://svn.sourceforge.net/surveyforge/?rev=89&view=rev Author: javism Date: 2006-10-30 08:14:31 -0800 (Mon, 30 Oct 2006) Log Message: ----------- First version of the example Added Paths: ----------- trunk/surveyforge-examples/ trunk/surveyforge-examples/pom.xml trunk/surveyforge-examples/src/ trunk/surveyforge-examples/src/main/ trunk/surveyforge-examples/src/main/java/ trunk/surveyforge-examples/src/main/java/org/ trunk/surveyforge-examples/src/main/java/org/surveyforge/ trunk/surveyforge-examples/src/main/java/org/surveyforge/examples/ trunk/surveyforge-examples/src/main/java/org/surveyforge/examples/Example.java trunk/surveyforge-examples/src/main/resources/ trunk/surveyforge-examples/src/main/resources/META-INF/ trunk/surveyforge-examples/src/main/resources/META-INF/persistence.xml trunk/surveyforge-examples/src/test/ trunk/surveyforge-examples/src/test/java/ trunk/surveyforge-examples/src/test/java/org/ trunk/surveyforge-examples/src/test/java/org/surveyforge/ trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java Added: trunk/surveyforge-examples/pom.xml =================================================================== --- trunk/surveyforge-examples/pom.xml (rev 0) +++ trunk/surveyforge-examples/pom.xml 2006-10-30 16:14:31 UTC (rev 89) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <parent> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge</artifactId> + <version>0.1-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>surveyforge-examples</artifactId> + <name>SurveyForge Examples</name> + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-db</artifactId> + <version>0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + </dependency> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + </dependency> + <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + </dependency> + </dependencies> +</project> Property changes on: trunk/surveyforge-examples/pom.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-examples/src/main/java/org/surveyforge/examples/Example.java =================================================================== --- trunk/surveyforge-examples/src/main/java/org/surveyforge/examples/Example.java (rev 0) +++ trunk/surveyforge-examples/src/main/java/org/surveyforge/examples/Example.java 2006-10-30 16:14:31 UTC (rev 89) @@ -0,0 +1,147 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.examples; + +import java.util.Calendar; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import org.surveyforge.classification.Classification; +import org.surveyforge.classification.Family; +import org.surveyforge.classification.Item; +import org.surveyforge.classification.Level; +import org.surveyforge.classification.Version; +import org.surveyforge.core.metadata.domain.ClassificationValueDomain; +import org.surveyforge.core.metadata.domain.LogicalValueDomain; +import org.surveyforge.core.metadata.domain.QuantityValueDomain; +import org.surveyforge.core.metadata.domain.StringValueDomain; +import org.surveyforge.core.survey.Question; +import org.surveyforge.core.survey.Questionnaire; +import org.surveyforge.core.survey.QuestionnaireElement; +import org.surveyforge.core.survey.Study; +import org.surveyforge.util.InternationalizedString; + +/** + * @author jsegura + */ +public class Example + { + + /** + * @param args + */ + public static void main( String[] args ) + { + + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "surveyforge" ); + EntityManager entityManager = entityManagerFactory.createEntityManager( ); + + + /* Creation of an example family */ + Family exampleFamily = new Family( "exampleFamily" ); + Classification sexClassification = new Classification( exampleFamily, "sex Classification" ); + Version sexVersion = new Version( sexClassification, "sex Version", Calendar.getInstance( ).getTime( ) ); + Level sexLevel = new Level( sexVersion, "sex Level" ); + new Item( sexLevel, null, "1", "Male" ); + new Item( sexLevel, null, "2", "Female" ); + + Classification hobbyClassification = new Classification( exampleFamily, "hobby Classification" ); + Version hobbyVersion = new Version( hobbyClassification, "hobby Version", Calendar.getInstance( ).getTime( ) ); + Level hobbyLevel = new Level( hobbyVersion, "hobby Level" ); + new Item( hobbyLevel, null, "1", "Sports" ); + new Item( hobbyLevel, null, "2", "Computers" ); + new Item( hobbyLevel, null, "3", "Animals" ); + + + Study study = new Study( "exampleStudy" ); + study.setTitle( "SurveyForge example study" ); + study.setDescription( "This is an example study created to show SurveyForge" ); + + Questionnaire questionnaire = new Questionnaire( "exampleQuestionnaire", study ); + questionnaire.setTitle( "SurveyForge example questionnaire" ); + questionnaire.setDescription( "This is an example questionnaire created to show SurveyForge" ); + + QuestionnaireElement qe1 = new QuestionnaireElement( "NAME", new StringValueDomain( 0, 20 ) ); + qe1.setQuestion( new Question( "NAME", "Name" ) ); + questionnaire.addComponentElement( qe1 ); + + questionnaire.getSectionFeeds( ).get( 0 ).setTitle( "First Section" ); + + + QuestionnaireElement qe2 = new QuestionnaireElement( "SEX", new ClassificationValueDomain( sexLevel ) ); + qe2.setQuestion( new Question( "SEX", "Sex" ) ); + questionnaire.addComponentElement( qe2 ); + + QuestionnaireElement qe3 = new QuestionnaireElement( "AGE", new QuantityValueDomain( 2, 0 ) ); + qe3.setQuestion( new Question( "AGE", "Age" ) ); + questionnaire.addComponentElement( qe3 ); + + QuestionnaireElement qe4 = new QuestionnaireElement( "HOBBY", new ClassificationValueDomain( hobbyLevel ) ); + qe4.setQuestion( new Question( "HOBBY", "Hobby" ) ); + questionnaire.addComponentElement( qe4 ); + + InternationalizedString sectionTitle2 = new InternationalizedString( ); + sectionTitle2.setString( "Second section" ); + questionnaire.createSectionFeed( qe4, sectionTitle2 ); + + QuestionnaireElement qe5 = new QuestionnaireElement( "NUMBER", new QuantityValueDomain( 1, 0 ) ); + qe5.setQuestion( new Question( "NUMBER", "What's your preferred number?" ) ); + questionnaire.addComponentElement( qe5 ); + + + QuestionnaireElement qe6 = new QuestionnaireElement( "HAPPY", new LogicalValueDomain( ) ); + qe6.setQuestion( new Question( "HAPPY", "Are you happy?" ) ); + questionnaire.addComponentElement( qe6 ); + + questionnaire.createPageFeed( qe6 ); + + QuestionnaireElement qe7 = new QuestionnaireElement( "SAD", new LogicalValueDomain( ) ); + qe7.setQuestion( new Question( "SAD", "Are you sad?" ) ); + questionnaire.addComponentElement( qe7 ); + InternationalizedString sectionTitle3 = new InternationalizedString( ); + sectionTitle3.setString( "Third section" ); + questionnaire.createSectionFeed( qe7, sectionTitle3 ); + + + EntityTransaction transaction = entityManager.getTransaction( ); + transaction.begin( ); + + Query deleteFamily = entityManager.createQuery( "SELECT f FROM Family f WHERE f.identifier = :identifier" ); + deleteFamily.setParameter( "identifier", "exampleFamily" ); + if( !deleteFamily.getResultList( ).isEmpty( ) ) entityManager.remove( deleteFamily.getSingleResult( ) ); + Query deleteStudy = entityManager.createQuery( "SELECT s FROM Study s WHERE s.identifier = :identifier" ); + deleteStudy.setParameter( "identifier", "exampleStudy" ); + if( !deleteStudy.getResultList( ).isEmpty( ) ) entityManager.remove( deleteStudy.getSingleResult( ) ); + + entityManager.flush( ); + entityManager.persist( exampleFamily ); + entityManager.persist( study ); + transaction.commit( ); + entityManager.close( ); + + + } + } Property changes on: trunk/surveyforge-examples/src/main/java/org/surveyforge/examples/Example.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-examples/src/main/resources/META-INF/persistence.xml =================================================================== --- trunk/surveyforge-examples/src/main/resources/META-INF/persistence.xml (rev 0) +++ trunk/surveyforge-examples/src/main/resources/META-INF/persistence.xml 2006-10-30 16:14:31 UTC (rev 89) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + <persistence-unit name="surveyforge"> + <class>org.surveyforge.util.InternationalizedString</class> + + <class>org.surveyforge.classification.Family</class> + <class>org.surveyforge.classification.Classification</class> + <class>org.surveyforge.classification.Version</class> + <class>org.surveyforge.classification.Level</class> + <class>org.surveyforge.classification.Item</class> + + <class>org.surveyforge.core.survey.Study</class> + <class>org.surveyforge.core.survey.Questionnaire</class> + <class>org.surveyforge.core.survey.QuestionnaireElement</class> + <class>org.surveyforge.core.survey.Question</class> + <class>org.surveyforge.core.survey.Feed</class> + <class>org.surveyforge.core.survey.SectionFeed</class> + + <class>org.surveyforge.core.metadata.ValidationRule</class> + <class>org.surveyforge.core.metadata.Register</class> + <class>org.surveyforge.core.metadata.RegisterDataElement</class> + <class>org.surveyforge.core.metadata.ConceptualDataElement</class> + <class>org.surveyforge.core.metadata.DataElement</class> + <class>org.surveyforge.core.metadata.QuestionDataElement</class> + <class>org.surveyforge.core.metadata.ValueDomain</class> + <class>org.surveyforge.core.metadata.ObjectVariable</class> + <class>org.surveyforge.core.metadata.GlobalVariable</class> + <class>org.surveyforge.core.metadata.VariableFamily</class> + <class>org.surveyforge.core.metadata.StatisticalObjectType</class> + + <class>org.surveyforge.core.metadata.domain.ClassificationValueDomain</class> + <class>org.surveyforge.core.metadata.domain.LogicalValueDomain</class> + <class>org.surveyforge.core.metadata.domain.QuantityValueDomain</class> + <class>org.surveyforge.core.metadata.domain.StringValueDomain</class> + <class>org.surveyforge.core.metadata.domain.StructuredValueDomain</class> + <class>org.surveyforge.core.metadata.domain.AbstractValueDomain</class> + <class>org.surveyforge.core.metadata.domain.DateValueDomain</class> + + <class>org.surveyforge.core.data.RegisterData</class> + <class>org.surveyforge.core.data.ObjectData</class> + <class>org.surveyforge.core.data.Data</class> + + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> + <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /> + <property name="hibernate.connection.url" value="jdbc:postgresql://localhost/surveyforge" /> + <property name="hibernate.connection.username" value="postgres" /> + <property name="hibernate.connection.password" value="postgres" /> + </properties> + </persistence-unit> +</persistence> Property changes on: trunk/surveyforge-examples/src/main/resources/META-INF/persistence.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java =================================================================== --- trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java (rev 0) +++ trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java 2006-10-30 16:14:31 UTC (rev 89) @@ -0,0 +1,38 @@ +package org.surveyforge; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} Property changes on: trunk/surveyforge-examples/src/test/java/org/surveyforge/AppTest.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-24 15:30:46
|
Revision: 88 http://svn.sourceforge.net/surveyforge/?rev=88&view=rev Author: jgongo Date: 2006-10-24 08:30:30 -0700 (Tue, 24 Oct 2006) Log Message: ----------- Update of hibernate dependencies to 3.2.0.ga Modified Paths: -------------- trunk/pom.xml trunk/surveyforge-db/pom.xml trunk/surveyforge-runner/pom.xml Removed Paths: ------------- trunk/surveyforge-runner/src/main/resources/hibernate-entitymanager.jar trunk/surveyforge-runner/src/main/resources/javassist.jar trunk/surveyforge-runner/src/main/resources/jboss-archive-browsing.jar Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-10-24 15:28:17 UTC (rev 87) +++ trunk/pom.xml 2006-10-24 15:30:30 UTC (rev 88) @@ -90,7 +90,7 @@ <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh-external</artifactId> - <version>1.0-alpha-6</version> + <version>1.0-beta-1</version> </extension> </extensions> <pluginManagement> @@ -111,7 +111,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> - <!--<version>1.0-beta-1</version>--> + <version>1.0-beta-2</version> <configuration> <source>1.5</source> <target>1.5</target> @@ -174,6 +174,18 @@ <url>http://labs.openinput.com/maven/</url> </repository> </repositories> + <pluginRepositories> + <pluginRepository> + <id>Maven Snapshots</id> + <url>http://snapshots.maven.codehaus.org/maven2/</url> + <snapshots> + <enabled>true</enabled> + </snapshots> + <releases> + <enabled>false</enabled> + </releases> + </pluginRepository> + </pluginRepositories> <reporting> <plugins> <plugin> @@ -290,25 +302,13 @@ <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> - <version>3.2.0.cr1</version> - <exclusions> - <exclusion> - <groupId>javax.persistence</groupId> - <artifactId>ejb</artifactId> - </exclusion> - </exclusions> + <version>3.2.0.ga</version> </dependency> <dependency> - <groupId>hibernate</groupId> + <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> - <version>3.1beta1</version> + <version>3.2.0.ga</version> <scope>test</scope> - <exclusions> - <exclusion> - <groupId>javax.persistence</groupId> - <artifactId>ejb</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>postgresql</groupId> Modified: trunk/surveyforge-db/pom.xml =================================================================== --- trunk/surveyforge-db/pom.xml 2006-10-24 15:28:17 UTC (rev 87) +++ trunk/surveyforge-db/pom.xml 2006-10-24 15:30:30 UTC (rev 88) @@ -103,7 +103,7 @@ <classifier>jdk15</classifier> </dependency> <dependency> - <groupId>hibernate</groupId> + <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </dependency> </dependencies> Modified: trunk/surveyforge-runner/pom.xml =================================================================== --- trunk/surveyforge-runner/pom.xml 2006-10-24 15:28:17 UTC (rev 87) +++ trunk/surveyforge-runner/pom.xml 2006-10-24 15:30:30 UTC (rev 88) @@ -65,12 +65,10 @@ <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> </dependency> - <!-- <dependency> - <groupId>hibernate</groupId> + <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </dependency> - --> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> Deleted: trunk/surveyforge-runner/src/main/resources/hibernate-entitymanager.jar =================================================================== (Binary files differ) Deleted: trunk/surveyforge-runner/src/main/resources/javassist.jar =================================================================== (Binary files differ) Deleted: trunk/surveyforge-runner/src/main/resources/jboss-archive-browsing.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-24 15:28:31
|
Revision: 87 http://svn.sourceforge.net/surveyforge/?rev=87&view=rev Author: jgongo Date: 2006-10-24 08:28:17 -0700 (Tue, 24 Oct 2006) Log Message: ----------- Changed name of persistence unit Modified Paths: -------------- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-24 15:12:50 UTC (rev 86) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-24 15:28:17 UTC (rev 87) @@ -64,7 +64,7 @@ Frame frame = null; try { - EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "hivudvp" ); + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "surveyforge" ); entityManager = entityManagerFactory.createEntityManager( ); entityManager.setFlushMode( FlushModeType.COMMIT ); transaction = entityManager.getTransaction( ); Modified: trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml =================================================================== --- trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml 2006-10-24 15:12:50 UTC (rev 86) +++ trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml 2006-10-24 15:28:17 UTC (rev 87) @@ -2,7 +2,7 @@ <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> - <persistence-unit name="hivudvp"> + <persistence-unit name="surveyforge"> <class>org.surveyforge.util.InternationalizedString</class> <class>org.surveyforge.classification.Family</class> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-10-24 15:12:58
|
Revision: 86 http://svn.sourceforge.net/surveyforge/?rev=86&view=rev Author: javism Date: 2006-10-24 08:12:50 -0700 (Tue, 24 Oct 2006) Log Message: ----------- Support for DateValueDomain Modified Paths: -------------- trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml Modified: trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml =================================================================== --- trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml 2006-10-17 15:33:09 UTC (rev 85) +++ trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml 2006-10-24 15:12:50 UTC (rev 86) @@ -36,6 +36,7 @@ <class>org.surveyforge.core.metadata.domain.StringValueDomain</class> <class>org.surveyforge.core.metadata.domain.StructuredValueDomain</class> <class>org.surveyforge.core.metadata.domain.AbstractValueDomain</class> + <class>org.surveyforge.core.metadata.domain.DateValueDomain</class> <class>org.surveyforge.core.data.RegisterData</class> <class>org.surveyforge.core.data.ObjectData</class> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-10-17 15:33:34
|
Revision: 85 http://svn.sourceforge.net/surveyforge/?rev=85&view=rev Author: javism Date: 2006-10-17 08:33:09 -0700 (Tue, 17 Oct 2006) Log Message: ----------- BugFix: ValueDomain for dates and its tests. Issue: 1570019 Modified Paths: -------------- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml Added Paths: ----------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/DateValueDomain.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/domain/ trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/domain/DateValueDomainTest.java Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/DateValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/DateValueDomain.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/DateValueDomain.java 2006-10-17 15:33:09 UTC (rev 85) @@ -0,0 +1,126 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.core.metadata.domain; + +import java.io.Serializable; +import java.security.InvalidParameterException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.persistence.Entity; + +/** + * @author jsegura + */ +@Entity +public class DateValueDomain extends AbstractValueDomain + { + private static final long serialVersionUID = -7700790723958655600L; + + private SimpleDateFormat simpleDateFormat; + private String pattern = "dd/MM/yyyy"; + + private Date maxValue = null; + private Date minValue = null; + + public DateValueDomain( ) + { + simpleDateFormat = new SimpleDateFormat( pattern ); + } + + public SimpleDateFormat getFormat( ) + { + return simpleDateFormat; + } + + public void setPattern( String pattern ) + { + if( pattern != null ) + { + /* This will throw an exception if pattern is invalid */ + simpleDateFormat.applyPattern( pattern ); + this.pattern = pattern; + } + } + + public String getPattern( ) + { + return this.pattern; + } + + public Date getMaxValue( ) + { + return maxValue; + } + + public void setMaxValue( Date maxValue ) + { + if( maxValue != null && this.minValue != null ) + { + if( this.minValue.before( maxValue ) ) + this.maxValue = maxValue; + else + throw new InvalidParameterException( ); + } + else + this.maxValue = maxValue; + } + + public Date getMinValue( ) + { + return minValue; + } + + public void setMinValue( Date minValue ) + { + if( this.maxValue != null && minValue != null ) + { + if( minValue.before( this.maxValue ) ) + this.minValue = minValue; + else + throw new InvalidParameterException( ); + } + else + this.minValue = minValue; + } + + public boolean isValid( Serializable object ) + { + if( object instanceof Date ) + { + Date date = (Date) object; + if( this.getMaxValue( ) != null && date.after( this.getMaxValue( ) ) ) + return false; + else if( this.getMinValue( ) != null && date.before( this.getMinValue( ) ) ) + return false; + else + return true; + } + else + return false; + } + + public DateValueDomain clone( ) + { + return (DateValueDomain) super.clone( ); + } + } \ No newline at end of file Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/DateValueDomain.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/domain/DateValueDomainTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/domain/DateValueDomainTest.java (rev 0) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/domain/DateValueDomainTest.java 2006-10-17 15:33:09 UTC (rev 85) @@ -0,0 +1,105 @@ +/** + * + */ +package org.surveyforge.core.metadata.domain; + +import java.security.InvalidParameterException; +import java.util.Calendar; +import java.util.Date; + +import org.testng.Assert; +import org.testng.annotations.ExpectedExceptions; +import org.testng.annotations.Test; + +/** + * @author jsegura + */ +public class DateValueDomainTest + { + + @Test + public void DateValueDomainGettersSetters( ) + { + DateValueDomain domain = new DateValueDomain( ); + domain.getFormat( ); + Assert.assertNull( domain.getMaxValue( ) ); + Assert.assertNull( domain.getMinValue( ) ); + + Date before = new Date( Calendar.getInstance( ).getTimeInMillis( ) ); + Date later = new Date( Calendar.getInstance( ).getTimeInMillis( ) + 10000 ); + + + String pattern = "yyyy"; + domain.setPattern( pattern ); + Assert.assertEquals( pattern, domain.getPattern( ) ); + + domain.setMaxValue( later ); + Assert.assertNotNull( domain.getMaxValue( ) ); + Assert.assertEquals( later, domain.getMaxValue( ) ); + + domain.setMinValue( before ); + Assert.assertNotNull( domain.getMinValue( ) ); + Assert.assertEquals( before, domain.getMinValue( ) ); + + domain.setMaxValue( later ); + Assert.assertNotNull( domain.getMaxValue( ) ); + Assert.assertEquals( later, domain.getMaxValue( ) ); + + } + + @Test + public void DateValueDomainCreation( ) + { + new DateValueDomain( ); + } + + @Test + @ExpectedExceptions( {InvalidParameterException.class}) + public void DateValueDomainSetMaxValue( ) + { + DateValueDomain domain = new DateValueDomain( ); + Date before = new Date( Calendar.getInstance( ).getTimeInMillis( ) ); + Date later = new Date( Calendar.getInstance( ).getTimeInMillis( ) + 10000 ); + + domain.setMinValue( later ); + domain.setMaxValue( before ); + } + + @Test + @ExpectedExceptions( {InvalidParameterException.class}) + public void DateValueDomainSetMinValue( ) + { + DateValueDomain domain = new DateValueDomain( ); + Date before = new Date( Calendar.getInstance( ).getTimeInMillis( ) ); + Date later = new Date( Calendar.getInstance( ).getTimeInMillis( ) + 10000 ); + + domain.setMaxValue( before ); + domain.setMinValue( later ); + } + + @Test + public void validationInRange( ) + { + + Assert.assertTrue( new DateValueDomain( ).isValid( new Date( ) ) ); + Assert.assertFalse( new DateValueDomain( ).isValid( new String( ) ) ); + + DateValueDomain domain = new DateValueDomain( ); + Date now = new Date( Calendar.getInstance( ).getTimeInMillis( ) ); + Date later = new Date( Calendar.getInstance( ).getTimeInMillis( ) + 100000 ); + domain.setMinValue( later ); + Assert.assertFalse( domain.isValid( now ) ); + + domain = new DateValueDomain( ); + domain.setMaxValue( now ); + Assert.assertFalse( domain.isValid( later ) ); + } + + @Test + public void DateValueDomainClone( ) + { + new DateValueDomain( ).clone( ); + } + + + } \ No newline at end of file Property changes on: trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/domain/DateValueDomainTest.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Modified: trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml =================================================================== --- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-10-09 14:33:53 UTC (rev 84) +++ trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-10-17 15:33:09 UTC (rev 85) @@ -51,6 +51,7 @@ <mapping class="org.surveyforge.core.metadata.domain.StringValueDomain" /> <mapping class="org.surveyforge.core.metadata.domain.AbstractValueDomain" /> <mapping class="org.surveyforge.core.metadata.domain.StructuredValueDomain" /> + <mapping class="org.surveyforge.core.metadata.domain.DateValueDomain" /> <!-- package org.surveyforge.core.data --> <mapping class="org.surveyforge.core.data.RegisterData" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-10-09 14:34:09
|
Revision: 84 http://svn.sourceforge.net/surveyforge/?rev=84&view=rev Author: javism Date: 2006-10-09 07:33:53 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Support for InternationalizedString Issue: 1548431 Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-10-09 14:33:53 UTC (rev 84) @@ -22,7 +22,9 @@ package org.surveyforge.core.metadata; import java.io.Serializable; +import java.util.Locale; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -31,6 +33,7 @@ import javax.persistence.ManyToOne; import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; /** @@ -43,35 +46,35 @@ @Entity public class GlobalVariable implements Serializable { - private static final long serialVersionUID = 1661678204467740737L; + private static final long serialVersionUID = 1661678204467740737L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** A global variable is identified by a unique language independent identifier, which may typically be an abbreviation of its name. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** The official name of the global variable is provided by the owner of the variable. */ - @Column(length = 250) - private String name = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString name = new InternationalizedString( ); /** * Short general multilingual description of the global variable, including its purpose, its main subject areas etc. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** Family to which the global variable belongs. */ @ManyToOne @JoinColumn(name = "variableFamily_id", insertable = false, updatable = false) - private VariableFamily variableFamily; + private VariableFamily variableFamily; protected GlobalVariable( ) @@ -126,55 +129,127 @@ throw new NullPointerException( ); } + + public InternationalizedString getInternationalizedName( ) + { + return this.name; + } + /** - * Returns the name of the GlobalVariable. + * Returns the name of this Global Variable. * - * @return Returns the name. + * @return the name of this Global Variable for the default language. + * @see InternationalizedString#getString() */ public String getName( ) { - return this.name; + return this.name.getString( ); } /** - * Sets a new name to the GlobalVariable. + * Returns the name of this Global Variable for the given language. * - * @param name The name to set. - * @throws NullPointerException If the name is <code>null</code>. + * @param locale the language of the Global Variable to be returned. + * @return the name of this Global Variable for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getName( Locale locale ) + { + return this.name.getString( locale ); + } + + /** + * Sets the name of this Global Variable. The name must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param name the name of this Global Variable. + * @throws NullPointerException if the name is <code>null</code>. + */ public void setName( String name ) { if( name != null ) - this.name = name; + this.name.setString( name ); else throw new NullPointerException( ); } /** - * Returns the description of the GlobalVariable. + * Sets the name of this Global Variable for the given language. The language and name must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the name to be set. + * @param name the name of this Global Variable. + * @throws NullPointerException if the language or name are <code>null</code>. */ - public String getDescription( ) + public void setName( Locale locale, String name ) { + if( name != null ) + this.name.setString( locale, name ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description of the GlobalVariable. + * Returns the description of this Global Variable. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @return the description of this Global Variable for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Global Variable for the given language. + * + * @param locale the language of the Global Variable to be returned. + * @return the description of this Global Variable for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Global Variable. The description must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param description the description of this Global Variable. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Global Variable for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Global Variable. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Returns the {@link VariableFamily} of the GlobalVariable. * * @return Returns the variableFamily. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-10-09 14:33:53 UTC (rev 84) @@ -22,7 +22,9 @@ package org.surveyforge.core.metadata; import java.io.Serializable; +import java.util.Locale; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -31,6 +33,7 @@ import javax.persistence.ManyToOne; import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; /** * An object variable defines the concept of a variable in connection with a defined statistical object (e.g. the income of a person). @@ -62,11 +65,11 @@ @Column(unique = true, length = 50) private String identifier; /** The name is the official, language dependent name of the global variable, provided by the owner of the variable. */ - @Column(length = 250) - private String name = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString name = new InternationalizedString(); /** Short general multilingual description of the object variable, including its purpose, its main subject areas etc. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString(); /** * Each object variable belongs to a statistical object or unit. The object variable exists only in the context of the object * variable. @@ -121,55 +124,126 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedName( ) + { + return this.name; + } + /** - * Returns the name of the ObjectVariable. + * Returns the name of this Object Variable. * - * @return Returns the name. + * @return the name of this Object Variable for the default language. + * @see InternationalizedString#getString() */ public String getName( ) { - return this.name; + return this.name.getString( ); } /** - * Sets the name of the ObjectVariable. + * Returns the name of this Object Variable for the given language. * - * @param name The name to set. - * @throws NullPointerException If the name is <code>null</code>. + * @param locale the language of the Object Variable to be returned. + * @return the name of this Object Variable for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getName( Locale locale ) + { + return this.name.getString( locale ); + } + + /** + * Sets the name of this Object Variable. The name must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param name the name of this Object Variable. + * @throws NullPointerException if the name is <code>null</code>. + */ public void setName( String name ) { if( name != null ) - this.name = name; + this.name.setString( name ); else throw new NullPointerException( ); } /** - * Returns the description of the ObjectVariable. + * Sets the name of this Object Variable for the given language. The language and name must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the name to be set. + * @param name the name of this Object Variable. + * @throws NullPointerException if the language or name are <code>null</code>. */ - public String getDescription( ) + public void setName( Locale locale, String name ) { + if( name != null ) + this.name.setString( locale, name ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description to the ObjectVariable. + * Returns the description of this Object Variable. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @return the description of this Object Variable for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Object Variable for the given language. + * + * @param locale the language of the Object Variable to be returned. + * @return the description of this Object Variable for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Object Variable. The description must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param description the description of this Object Variable. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Object Variable for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Object Variable. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Returns the {@link StatisticalObjectType} this ObjectVariable belongs to. * * @return Returns the StatisticalObjectType. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-10-09 14:33:53 UTC (rev 84) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -38,6 +39,7 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.surveyforge.util.InternationalizedString; /** * Statistical objects or units may be real world objects (e.g. person, enterprise) or abstract objects like events or states (e.g. @@ -69,11 +71,11 @@ @Column(unique = true, length = 50) private String identifier; /** Unique name statistical unit. */ - @Column(length = 250) - private String name = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString name = new InternationalizedString( ); /** Short general multilingual description of the statistical object/unit, including its purpose, its main subject areas etc. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** A super-type is a generalisation of an object type. */ @ManyToOne @JoinColumn(name = "superType_id", insertable = false, updatable = false) @@ -127,55 +129,126 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedName( ) + { + return this.name; + } + /** - * Returns the name of the StatisticalObjectType. + * Returns the name of this Statistical Object Type. * - * @return Returns the name. + * @return the name of this Statistical Object Type for the default language. + * @see InternationalizedString#getString() */ public String getName( ) { - return this.name; + return this.name.getString( ); } /** - * Sets a new name to the StatisticalObjectType. + * Returns the name of this Statistical Object Type for the given language. * - * @param name The name to set. - * @throws NullPointerException If the name is <code>null</code>. + * @param locale the language of the Statistical Object Type to be returned. + * @return the name of this Statistical Object Type for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getName( Locale locale ) + { + return this.name.getString( locale ); + } + + /** + * Sets the name of this Statistical Object Type. The name must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param name the name of this Statistical Object Type. + * @throws NullPointerException if the name is <code>null</code>. + */ public void setName( String name ) { if( name != null ) - this.name = name; + this.name.setString( name ); else throw new NullPointerException( ); } /** - * Returns the description of the StatisticalObjectType. + * Sets the name of this Statistical Object Type for the given language. The language and name must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the name to be set. + * @param name the name of this Statistical Object Type. + * @throws NullPointerException if the language or name are <code>null</code>. */ - public String getDescription( ) + public void setName( Locale locale, String name ) { + if( name != null ) + this.name.setString( locale, name ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description for the StatisticalObjectType. + * Returns the description of this Statistical Object Type. * - * @param description The description to set. - * @throws NullPointerException If the name is <code>null</code>. + * @return the description of this Statistical Object Type for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Statistical Object Type for the given language. + * + * @param locale the language of the Statistical Object Type to be returned. + * @return the description of this Statistical Object Type for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Statistical Object Type. The description must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param description the description of this Statistical Object Type. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Statistical Object Type for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Statistical Object Type. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Return the super type of the StatisticalObjectType. * * @return Returns the superType. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-10-09 14:33:53 UTC (rev 84) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -33,10 +34,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.surveyforge.util.InternationalizedString; /** * A variable family groups a number of global variables that refer to a certain theme. @@ -46,34 +49,34 @@ @Entity public class VariableFamily implements Serializable { - private static final long serialVersionUID = 7344092827765295413L; + private static final long serialVersionUID = 7344092827765295413L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** A VariableFamily is identified by a unique identifier. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** * Detailed description of the VariableFamily. The description describes the theme of the {@link GlobalVariable}s included in the * family. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** The family have the list of all {@link GlobalVariable}s included in the theme. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "globalVariablesIndex") @JoinColumn(name = "variableFamily_id", nullable = false) - private List<GlobalVariable> globalVariables = new ArrayList<GlobalVariable>( ); + private List<GlobalVariable> globalVariables = new ArrayList<GlobalVariable>( ); protected VariableFamily( ) {} @@ -113,31 +116,66 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedDescription( ) + { + return this.description; + } + /** - * Returns the description of the family. + * Returns the description of this Variable Family. * - * @return Returns the description. + * @return the description of this Variable Family for the default language. + * @see InternationalizedString#getString() */ public String getDescription( ) { - return this.description; + return this.description.getString( ); } /** - * Sets a new description to the family. + * Returns the description of this Variable Family for the given language. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @param locale the language of the Variable Family to be returned. + * @return the description of this Variable Family for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Variable Family. The description must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param description the description of this Variable Family. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Variable Family for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Variable Family. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Returns the list of {@link GlobalVariable}s of the family. * * @return Returns the list of {@link GlobalVariable}s. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-10-09 14:33:53 UTC (rev 84) @@ -22,13 +22,17 @@ package org.surveyforge.core.survey; import java.io.Serializable; +import java.util.Locale; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.ManyToOne; import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; /** * The question contain the text for the question, with the sub questions being used to provide further information about the question. @@ -39,34 +43,33 @@ @Entity public class Question implements Serializable { - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 0L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** A question has a language independent identifier that identifies the question among all other globally defined questions. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** * The question contains the exact text of the question that has been asked to collect the data. The question text is language * dependent. */ - @Column(length = 250) - private String text = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString text = new InternationalizedString( ); /** The description contains explanatory notes to the question and/or an extended definition of the question's meaning. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); - protected Question( ) {} @@ -119,55 +122,125 @@ throw new NullPointerException( ); } + public InternationalizedString getInternationalizedText( ) + { + return this.text; + } + /** - * Returns the text of the question. + * Returns the text of this Question. * - * @return Returns the question. + * @return the text of this Question for the default language. + * @see InternationalizedString#getString() */ public String getText( ) { - return this.text; + return this.text.getString( ); } /** - * Sets the text of the Question. + * Returns the text of this Question for the given language. * - * @param text The text to set. - * @throws NullPointerException if the text is <code>null</code> or is empty. + * @param locale the language of the Question to be returned. + * @return the text of this Question for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getText( Locale locale ) + { + return this.text.getString( locale ); + } + + /** + * Sets the text of this Question. The text must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param text the text of this Question. + * @throws NullPointerException if the text is <code>null</code>. + */ public void setText( String text ) { if( text != null ) - this.text = text; + this.text.setString( text ); else throw new NullPointerException( ); } /** - * Returns the description of the Question. + * Sets the text of this Question for the given language. The language and text must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the text to be set. + * @param text the text of this Question. + * @throws NullPointerException if the language or text are <code>null</code>. */ - public String getDescription( ) + public void setText( Locale locale, String text ) { + if( text != null ) + this.text.setString( locale, text ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets the description text of the Question. + * Returns the description of this Question. * - * @param description The description to set. - * @throws NullPointerException if the description text is <code>null</code>. + * @return the description of this Question for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Question for the given language. + * + * @param locale the language of the Question to be returned. + * @return the description of this Question for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Question. The description must be non <code>null</code>, otherwise a {@link NullPointerException} + * is thrown. + * + * @param description the description of this Question. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } + /** + * Sets the description of this Question for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Question. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + @Override public boolean equals( Object object ) { Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-10-09 14:33:53 UTC (rev 84) @@ -27,9 +27,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; -import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -56,33 +56,33 @@ /** * */ - private static final long serialVersionUID = -357629851050021121L; + private static final long serialVersionUID = -357629851050021121L; /** A questionnaire has a title as provided by the owner or maintenance unit. */ - @Column(length = 250) - private String title = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString title = new InternationalizedString( ); /** * Detailed description of the questionnaire. The questionnaire description typically describes the underlying concept of the * questionnaire and basic principles. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** A questionnaire may have its content organized in pages. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "pageIndex") // @JoinColumn(name = "questionnaire_page_id") @JoinColumn(name = "questionnaire_page_id") - private List<Feed> pageFeeds = new ArrayList<Feed>( ); + private List<Feed> pageFeeds = new ArrayList<Feed>( ); /** A questionnaire may have its content organized in sections. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "sectionIndex") @JoinColumn(name = "questionnaire_section_id") - private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); + private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); /** A questionnaire is included in a Study. */ @ManyToOne @JoinColumn(name = "study_id", insertable = false, updatable = false) - private Study study; + private Study study; protected Questionnaire( ) @@ -106,56 +106,124 @@ } - // } + public InternationalizedString getInternationalizedTitle( ) + { + return this.title; + } + /** - * Returns the title of the questionnaire. + * Returns the title of this Questionnaire. * - * @return Returns the title. + * @return the title of this Questionnaire for the default language. + * @see InternationalizedString#getString() */ public String getTitle( ) { - return this.title; + return this.title.getString( ); } /** - * Sets the title of the Questionnaire. + * Returns the title of this Questionnaire for the given language. * - * @param title The title to set. - * @throws NullPointerException If the title is <code>null</code>. + * @param locale the language of the Questionnaire to be returned. + * @return the title of this Questionnaire for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getTitle( Locale locale ) + { + return this.title.getString( locale ); + } + + /** + * Sets the title of this Questionnaire. The title must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param title the title of this Questionnaire. + * @throws NullPointerException if the title is <code>null</code>. + */ public void setTitle( String title ) { if( title != null ) - this.title = title; + this.title.setString( title ); else throw new NullPointerException( ); } /** - * Returns the description of the questionnaire. + * Sets the title of this Questionnaire for the given language. The language and title must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the title to be set. + * @param title the title of this Questionnaire. + * @throws NullPointerException if the language or title are <code>null</code>. */ - public String getDescription( ) + public void setTitle( Locale locale, String title ) { + if( title != null ) + this.title.setString( locale, title ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets the description of the Questionnaire. + * Returns the description of this Questionnaire. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code> + * @return the description of this Questionnaire for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Questionnaire for the given language. + * + * @param locale the language of the Questionnaire to be returned. + * @return the description of this Questionnaire for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Questionnaire. The description must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param description the description of this Questionnaire. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Questionnaire for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Questionnaire. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + /** * Adds a new {@link Element} to he Questionnaire. * * @param element The element to add. Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java 2006-10-09 14:30:12 UTC (rev 83) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java 2006-10-09 14:33:53 UTC (rev 84) @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -33,10 +34,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.surveyforge.util.InternationalizedString; /** * Studies are used to document the concepts and production rules for statistical data. A statistical activity might describe @@ -48,40 +51,40 @@ @Entity public class Study implements Serializable { - private static final long serialVersionUID = -4089931270976596457L; + private static final long serialVersionUID = -4089931270976596457L; @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @SuppressWarnings("unused") @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** * A statistical activity is identified by a unique identifier, which may typically be an abbreviation of its title or a systematic * number. */ @Column(unique = true, nullable = false, length = 50) - private String identifier; + private String identifier; /** A statistical activity has a title as provided by the owner or maintenance unit. */ - @Column(length = 250) - private String title = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString title = new InternationalizedString( ); /** * Detailed description of the statistical activity. The activity description describes the actions performed in the frame of the * activity. */ - @Column(length = 500) - private String description = ""; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString description = new InternationalizedString( ); /** When the statistical activity includes a survey one or more questionnaires can be defined in the context of the activity. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "questionnairesIndex") @JoinColumn(name = "study_id", nullable = false) - private List<Questionnaire> questionnaires = new ArrayList<Questionnaire>( ); + private List<Questionnaire> questionnaires = new ArrayList<Questionnaire>( ); protected Study( ) {} @@ -121,55 +124,126 @@ throw new NullPointerException( ); } + + public InternationalizedString getInternationalizedTitle( ) + { + return this.title; + } + /** - * Returns the title of the Study. + * Returns the title of this Study. * - * @return Returns the title. + * @return the title of this Study for the default language. + * @see InternationalizedString#getString() */ public String getTitle( ) { - return this.title; + return this.title.getString( ); } /** - * Sets a new title to the Study. + * Returns the title of this Study for the given language. * - * @param title The title to set. - * @throws NullPointerException If the title is <code>null</code>. + * @param locale the language of the Study to be returned. + * @return the title of this Study for the given language. + * @see InternationalizedString#getString(Locale) */ + public String getTitle( Locale locale ) + { + return this.title.getString( locale ); + } + + /** + * Sets the title of this Study. The title must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param title the title of this Study. + * @throws NullPointerException if the title is <code>null</code>. + */ public void setTitle( String title ) { if( title != null ) - this.title = title; + this.title.setString( title ); else throw new NullPointerException( ); } /** - * Returns the description of the Study. + * Sets the title of this Study for the given language. The language and title must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. * - * @return Returns the description. + * @param locale the language of the title to be set. + * @param title the title of this Study. + * @throws NullPointerException if the language or title are <code>null</code>. */ - public String getDescription( ) + public void setTitle( Locale locale, String title ) { + if( title != null ) + this.title.setString( locale, title ); + else + throw new NullPointerException( ); + } + + + public InternationalizedString getInternationalizedDescription( ) + { return this.description; } /** - * Sets a new description to the Study. + * Returns the description of this Study. * - * @param description The description to set. - * @throws NullPointerException If the description is <code>null</code>. + * @return the description of this Study for the default language. + * @see InternationalizedString#getString() */ + public String getDescription( ) + { + return this.description.getString( ); + } + + /** + * Returns the description of this Study for the given language. + * + * @param locale the language of the Study to be returned. + * @return the description of this Study for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getDescription( Locale locale ) + { + return this.description.getString( locale ); + } + + /** + * Sets the description of this Study. The description must be non <code>null</code>, otherwise a {@link NullPointerException} is + * thrown. + * + * @param description the description of this Study. + * @throws NullPointerException if the description is <code>null</code>. + */ public void setDescription( String description ) { if( description != null ) - this.description = description; + this.description.setString( description ); else throw new NullPointerException( ); } /** + * Sets the description of this Study for the given language. The language and description must be non <code>null</code>, + * otherwise a {@link NullPointerException} is thrown. + * + * @param locale the language of the description to be set. + * @param description the description of this Study. + * @throws NullPointerException if the language or description are <code>null</code>. + */ + public void setDescription( Locale locale, String description ) + { + if( description != null ) + this.description.setString( locale, description ); + else + throw new NullPointerException( ); + } + + /** * Return the list of {@link Questionnaire}s included in the Study. * * @return Returns the questionnaires. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-09 14:30:20
|
Revision: 83 http://svn.sourceforge.net/surveyforge/?rev=83&view=rev Author: jgongo Date: 2006-10-09 07:30:12 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Dependency management for tango icons instead of JLFGR Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-10-09 14:27:32 UTC (rev 82) +++ trunk/pom.xml 2006-10-09 14:30:12 UTC (rev 83) @@ -322,9 +322,9 @@ <version>0.1-SNAPSHOT</version> </dependency> <dependency> - <groupId>com.sun</groupId> - <artifactId>jlfgr</artifactId> - <version>1.0</version> + <groupId>org.tango-project</groupId> + <artifactId>tango-icon-theme</artifactId> + <version>0.7.1</version> <scope>runtime</scope> </dependency> <dependency> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-09 14:27:56
|
Revision: 82 http://svn.sourceforge.net/surveyforge/?rev=82&view=rev Author: jgongo Date: 2006-10-09 07:27:32 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Initial support for saving and browsing samples Issue: 1570024 Modified Paths: -------------- trunk/surveyforge-runner/pom.xml trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java Added Paths: ----------- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Controller.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Frame.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/RunnerResourceBundle.java Removed Paths: ------------- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar trunk/surveyforge-runner/src/main/resources/org/ Modified: trunk/surveyforge-runner/pom.xml =================================================================== --- trunk/surveyforge-runner/pom.xml 2006-10-09 14:25:26 UTC (rev 81) +++ trunk/surveyforge-runner/pom.xml 2006-10-09 14:27:32 UTC (rev 82) @@ -80,6 +80,10 @@ <artifactId>openinput-tools-swing</artifactId> </dependency> <dependency> + <groupId>org.tango-project</groupId> + <artifactId>tango-icon-theme</artifactId> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> </dependency> Copied: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Controller.java (from rev 78, trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java) =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Controller.java (rev 0) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Controller.java 2006-10-09 14:27:32 UTC (rev 82) @@ -0,0 +1,549 @@ +/* + * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.runner; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; + +import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.Icon; +import javax.swing.InputVerifier; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JOptionPane; +import javax.swing.JFormattedTextField.AbstractFormatter; +import javax.swing.text.JTextComponent; + +import org.surveyforge.core.data.ObjectData; +import org.surveyforge.core.data.RegisterData; +import org.surveyforge.core.metadata.ValueDomain; +import org.surveyforge.core.survey.Questionnaire; +import org.surveyforge.core.survey.QuestionnaireElement; +import org.surveyforge.util.beans.Observable; + +import com.openinput.tools.swing.ArrayActionMap; +import com.openinput.tools.swing.ResourceBundleBackedAction; + +/** + * @author jgonzalez + */ +@Observable +public class Controller + { + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle( "org.surveyforge.runner.RunnerResourceBundle" ); + + public static final String MODIFIED_SAMPLE_DIALOG = "org.surveyforge.runner.Controller.modifiedSampleDialog"; + + public static final String NEW_SAMPLE_ACTION_NAME = "org.surveyforge.runner.Controller.newSampleAction"; + public static final String SAVE_SAMPLE_ACTION_NAME = "org.surveyforge.runner.Controller.saveSampleAction"; + + public static final String FIRST_SAMPLE_ACTION_NAME = "org.surveyforge.runner.Controller.firstSampleAction"; + public static final String LAST_SAMPLE_ACTION_NAME = "org.surveyforge.runner.Controller.lastSampleAction"; + public static final String NEXT_SAMPLE_ACTION_NAME = "org.surveyforge.runner.Controller.nextSampleAction"; + public static final String PREVIOUS_SAMPLE_ACTION_NAME = "org.surveyforge.runner.Controller.proviousSampleAction"; + + private Action[] supportedActionsArray; + private ActionMap supportedActions; + + private ValidationController validationController = new Controller.ValidationController( ); + private SelectionController selectionController = new Controller.SelectionController( ); + private RoutingController routingController = new Controller.RoutingController( ); + + private EntityManager entityManager; + private Frame frame; + private Questionnaire questionnaire; + private int currentSampleIndex; + + private Map<QuestionnaireElement, JComponent> elementToComponentMap; + private Map<JComponent, QuestionnaireElement> componentToElementMap; + + + public Controller( EntityManager entityManager, Frame frame ) + { + this.entityManager = entityManager; + this.frame = frame; + this.questionnaire = this.frame.getQuestionnaire( ); + + this.elementToComponentMap = this.frame.getElementToComponentMap( ); + this.componentToElementMap = this.frame.getComponentToElementMap( ); + + this.supportedActionsArray = new Action[] {new Controller.NewSampleAction( ), new Controller.SaveSampleAction( ), + new Controller.FirstSampleAction( ), new Controller.PreviousSampleAction( ), new Controller.NextSampleAction( ), + new Controller.LastSampleAction( )}; + this.supportedActions = new ArrayActionMap( this.supportedActionsArray ); + } + + public ActionMap getActions( ) + { + return this.supportedActions; + } + + public InputVerifier getValidationController( ) + { + return this.validationController; + } + + public FocusListener getSelectionController( ) + { + return this.selectionController; + } + + public ActionListener getRoutingController( ) + { + return this.routingController; + } + + public int getCurrentSampleIndex( ) + { + return this.currentSampleIndex; + } + + public void setCurrentSampleIndex( int currentSampleIndex ) + { + RegisterData registerData = this.questionnaire.getRegister( ).getRegisterData( ); + this.entityManager.refresh( registerData ); + if( currentSampleIndex != registerData.getObjectData( ).size( ) ) + this.frame.setObjectData( registerData.getObjectData( ).get( currentSampleIndex ) ); + this.currentSampleIndex = currentSampleIndex; + } + + /** + * @return <code>true</code> if the calling operation may go on, <code>false</code> otherwise. + */ + private boolean savePossiblyModifiedSample( ) throws RuntimeException + { + String questionTitle = RESOURCE_BUNDLE.getString( MODIFIED_SAMPLE_DIALOG + ".question.title" ); + String questionMessage = RESOURCE_BUNDLE.getString( MODIFIED_SAMPLE_DIALOG + ".question.message" ); + Object[] options = {RESOURCE_BUNDLE.getString( MODIFIED_SAMPLE_DIALOG + ".button.yes" ), + RESOURCE_BUNDLE.getString( MODIFIED_SAMPLE_DIALOG + ".button.no" ), + RESOURCE_BUNDLE.getString( MODIFIED_SAMPLE_DIALOG + ".button.cancel" )}; + + boolean sampleChanged = Controller.this.frame.getDataModel( ).isChanged( ); + int selectedOption; + if( sampleChanged ) + { + selectedOption = JOptionPane.showOptionDialog( Controller.this.frame, questionMessage, questionTitle, + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, (Icon) Controller.RESOURCE_BUNDLE + .getObject( "icon.dialog.warning" ), options, options[2] ); + } + else + selectedOption = 1; + + switch( selectedOption ) + { + case 0: + ActionMap actions = Controller.this.getActions( ); + SaveSampleAction saveSampleAction = (SaveSampleAction) actions.get( Controller.SAVE_SAMPLE_ACTION_NAME ); + saveSampleAction.saveSample( ); + return true; + + case 1: + ObjectData objectData = Controller.this.frame.getObjectData( ); + if( sampleChanged && objectData.getRegisterData( ) != null ) + { + Controller.this.entityManager.refresh( objectData ); + Controller.this.frame.setObjectData( objectData ); + } + return true; + + default: + return false; + } + } + + /** + * @author jgonzalez + */ + class NewSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -7347987080988646268L; + + public NewSampleAction( ) + { + super( Controller.NEW_SAMPLE_ACTION_NAME, Controller.RESOURCE_BUNDLE ); + } + + public void actionPerformed( ActionEvent e ) + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); + try + { + boolean proceed = Controller.this.savePossiblyModifiedSample( ); + if( proceed ) this.newSample( ); + } + catch( RuntimeException exc ) + { + // Do nothing, a dialog showing an error message has been already shown + // TODO: Confirm this + } + finally + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) ); + } + } + + public void newSample( ) + { + Questionnaire questionnaire = Controller.this.questionnaire; + RegisterData registerData = questionnaire.getRegister( ).getRegisterData( ); + ObjectData emptyObjectData = registerData.createEmptyObjectData( ); + Controller.this.frame.setObjectData( emptyObjectData ); + Controller.this.setCurrentSampleIndex( registerData.getObjectData( ).size( ) ); + } + } + + /** + * @author jgonzalez + */ + class SaveSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -7347987080988646268L; + + public SaveSampleAction( ) + { + super( Controller.SAVE_SAMPLE_ACTION_NAME, Controller.RESOURCE_BUNDLE ); + Controller.this.frame.getDataModel( ).addPropertyChangeListener( "changed", new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent event ) + { + SaveSampleAction.this.setEnabled( (Boolean) event.getNewValue( ) ); + } + } ); + this.setEnabled( false ); + } + + public void actionPerformed( ActionEvent e ) + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); + this.setEnabled( false ); + try + { + this.saveSample( ); + ((NewSampleAction) Controller.this.getActions( ).get( Controller.NEW_SAMPLE_ACTION_NAME )).newSample( ); + } + catch( RuntimeException exc ) + { + exc.printStackTrace( ); + this.setEnabled( true ); + } + finally + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) ); + } + } + + public void saveSample( ) throws RuntimeException + { + try + { + EntityTransaction transaction = Controller.this.entityManager.getTransaction( ); + transaction.begin( ); + + // TODO: We should make all the checks, and include this in RegisterData... so just testing + ObjectData objectData = Controller.this.frame.getObjectData( ); + RegisterData registerData = Controller.this.questionnaire.getRegister( ).getRegisterData( ); + if( objectData.getRegisterData( ) == null ) + { + // New sample + Controller.this.entityManager.refresh( registerData ); + registerData.addObjectData( objectData ); + } + else + { + // Modified sample + // TODO: Check correct values + } + transaction.commit( ); + } + catch( RuntimeException exc ) + { + JOptionPane.showMessageDialog( Controller.this.frame, "ERROR SAVING!!!!", "title", JOptionPane.ERROR_MESSAGE, + (Icon) Controller.RESOURCE_BUNDLE.getObject( "icon.dialog.error" ) ); + throw exc; + } + } + } + + /** + * @author jgonzalez + */ + class FirstSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -6986950258409902794L; + + public FirstSampleAction( ) + { + super( Controller.FIRST_SAMPLE_ACTION_NAME, Controller.RESOURCE_BUNDLE ); + Controller.this.addPropertyChangeListener( new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent evt ) + { + Controller.FirstSampleAction.this.setEnabled( Controller.this.getCurrentSampleIndex( ) != 0 ); + } + } ); + } + + public void actionPerformed( ActionEvent event ) + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); + boolean proceed = Controller.this.savePossiblyModifiedSample( ); + if( proceed ) Controller.this.setCurrentSampleIndex( 0 ); + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) ); + } + } + + /** + * @author jgonzalez + */ + class LastSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -4626085247870941473L; + + public LastSampleAction( ) + { + super( Controller.LAST_SAMPLE_ACTION_NAME, Controller.RESOURCE_BUNDLE ); + Controller.this.addPropertyChangeListener( new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent evt ) + { + int registerDataSize = Controller.this.questionnaire.getRegister( ).getRegisterData( ).getObjectData( ).size( ); + Controller.LastSampleAction.this.setEnabled( Controller.this.getCurrentSampleIndex( ) != registerDataSize - 1 ); + } + } ); + } + + public void actionPerformed( ActionEvent event ) + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); + boolean proceed = Controller.this.savePossiblyModifiedSample( ); + if( proceed ) + { + RegisterData registerData = Controller.this.questionnaire.getRegister( ).getRegisterData( ); + Controller.this.entityManager.refresh( registerData ); + int lastIndex = registerData.getObjectData( ).size( ) - 1; + Controller.this.setCurrentSampleIndex( lastIndex ); + } + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) ); + } + } + + /** + * @author jgonzalez + */ + class NextSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -2126442792714281158L; + + public NextSampleAction( ) + { + super( Controller.NEXT_SAMPLE_ACTION_NAME, Controller.RESOURCE_BUNDLE ); + Controller.this.addPropertyChangeListener( new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent evt ) + { + int registerDataSize = Controller.this.questionnaire.getRegister( ).getRegisterData( ).getObjectData( ).size( ); + Controller.NextSampleAction.this.setEnabled( Controller.this.getCurrentSampleIndex( ) < registerDataSize - 1 ); + } + } ); + } + + public void actionPerformed( ActionEvent event ) + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); + boolean proceed = Controller.this.savePossiblyModifiedSample( ); + if( proceed ) Controller.this.setCurrentSampleIndex( Controller.this.getCurrentSampleIndex( ) + 1 ); + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) ); + } + } + + /** + * @author jgonzalez + */ + class PreviousSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -9057003601613857118L; + + public PreviousSampleAction( ) + { + super( Controller.PREVIOUS_SAMPLE_ACTION_NAME, Controller.RESOURCE_BUNDLE ); + Controller.this.addPropertyChangeListener( new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent evt ) + { + Controller.PreviousSampleAction.this.setEnabled( Controller.this.getCurrentSampleIndex( ) != 0 ); + } + } ); + } + + public void actionPerformed( ActionEvent event ) + { + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); + boolean proceed = Controller.this.savePossiblyModifiedSample( ); + if( proceed ) Controller.this.setCurrentSampleIndex( Controller.this.getCurrentSampleIndex( ) - 1 ); + Controller.this.frame.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) ); + } + } + + /** + * @author jgonzalez + */ + class ValidationController extends InputVerifier + { + // private EntityManagerFactory entityManagerFactory; + private Color errorColor = new Color( 1.0f, 0.625f, 0.625f ); + private Map<JComponent, ValueDomain> validationCache = new HashMap<JComponent, ValueDomain>( ); + private Map<JComponent, Color> defaultBackground = new HashMap<JComponent, Color>( ); + + protected ValueDomain getValueDomain( JComponent component ) + { + if( !this.validationCache.containsKey( component ) ) + { + // EntityManager entityManager = entityManagerFactory.createEntityManager( ); + + QuestionnaireElement questionnaireElement = Controller.this.componentToElementMap.get( component ); + // entityManager.refresh( questionnaireElement ); + this.validationCache.put( component, questionnaireElement.getRegisterDataElement( ).getValueDomain( ) ); + + // entityManager.clear( ); + } + + return this.validationCache.get( component ); + } + + @Override + public boolean verify( JComponent component ) + { + // Get value from component + Object value = null; + if( component instanceof JFormattedTextField ) + { + // We must format the value manually, as the change still hasn't been committed + JFormattedTextField formattedComponent = (JFormattedTextField) component; + AbstractFormatter formatter = formattedComponent.getFormatter( ); + String textValue = formattedComponent.getText( ); + try + { + if( formatter != null ) + value = formatter.stringToValue( textValue ); + else + value = textValue; + } + catch( ParseException exc ) + { + // Cannot parse the value -> invalid value + this.showErrorStatus( component ); + return false; + } + } + else if( component instanceof JTextComponent ) + { + JTextComponent textComponent = (JTextComponent) component; + value = textComponent.getText( ); + } + + // Validate value using value domain + if( this.getValueDomain( component ).isValid( (Serializable) value ) ) + { + // We hava a valid value + this.showValidStatus( component ); + return true; + } + else + { + this.showErrorStatus( component ); + return false; + } + } + + /** + * @param component + */ + protected void showErrorStatus( JComponent component ) + { + if( !this.defaultBackground.containsKey( component ) ) this.defaultBackground.put( component, component.getBackground( ) ); + component.setBackground( this.errorColor ); + Toolkit.getDefaultToolkit( ).beep( ); + + // TODO: Include error messages in value domain + JOptionPane.showMessageDialog( component.getRootPane( ), "El valor introducido no es correcto.", "Error", + JOptionPane.ERROR_MESSAGE, (Icon) Controller.RESOURCE_BUNDLE.getObject( "icon.dialog.error" ) ); + } + + /** + * @param component + */ + protected void showValidStatus( JComponent component ) + { + if( this.defaultBackground.containsKey( component ) ) component.setBackground( this.defaultBackground.remove( component ) ); + } + } + + /** + * @author jgonzalez + */ + class SelectionController implements FocusListener + { + public void focusGained( FocusEvent event ) + { + Component component = event.getComponent( ); + if( component instanceof JTextComponent ) + { + JTextComponent textComponent = (JTextComponent) component; + textComponent.selectAll( ); + } + } + + public void focusLost( FocusEvent event ) + {} + } + + /** + * @author jgonzalez + */ + public class RoutingController implements ActionListener + { + /* + * (non-Javadoc) + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed( ActionEvent event ) + {} + } + } Copied: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Frame.java (from rev 78, trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java) =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Frame.java (rev 0) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/Frame.java 2006-10-09 14:27:32 UTC (rev 82) @@ -0,0 +1,417 @@ +/* + * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.runner; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.ResourceBundle; + +import javax.persistence.EntityManager; +import javax.swing.ActionMap; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JToolBar; +import javax.swing.border.TitledBorder; + +import org.surveyforge.classification.Item; +import org.surveyforge.classification.Level; +import org.surveyforge.core.data.ObjectData; +import org.surveyforge.core.metadata.DataElement; +import org.surveyforge.core.metadata.RegisterDataElement; +import org.surveyforge.core.metadata.ValueDomain; +import org.surveyforge.core.metadata.domain.ClassificationValueDomain; +import org.surveyforge.core.metadata.domain.QuantityValueDomain; +import org.surveyforge.core.survey.Feed; +import org.surveyforge.core.survey.Questionnaire; +import org.surveyforge.core.survey.QuestionnaireElement; +import org.surveyforge.core.survey.SectionFeed; +import org.surveyforge.util.jgoodies.JXPathPresentationModel; + +import com.jgoodies.binding.PresentationModel; +import com.jgoodies.binding.adapter.BasicComponentFactory; +import com.jgoodies.binding.adapter.ComboBoxAdapter; +import com.jgoodies.binding.value.AbstractConverter; +import com.jgoodies.binding.value.ValueModel; +import com.jgoodies.forms.builder.PanelBuilder; +import com.jgoodies.forms.layout.FormLayout; + +/** + * @author jgonzalez + */ +public class Frame extends JFrame + { + private static final long serialVersionUID = -2135625525102812393L; + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle( "org.surveyforge.runner.RunnerResourceBundle" ); + + private Controller controller; + + private Map<QuestionnaireElement, JComponent> elementToComponentMap = new HashMap<QuestionnaireElement, JComponent>( ); + private Map<JComponent, QuestionnaireElement> componentToElementMap = new HashMap<JComponent, QuestionnaireElement>( ); + + private Questionnaire questionnaire; + private ObjectData objectData; + private PresentationModel dataModel; + + /** + * @param entityManagerFactory + * @param questionnaire + * @throws IOException + */ + public Frame( EntityManager entityManager, Questionnaire questionnaire ) throws IOException + { + super( "QuestionnaireRunner - " + questionnaire.getTitle( ) ); + + this.questionnaire = questionnaire; + + this.setObjectData( null ); // Create a presentation model for correct action instantiation + + this.controller = new Controller( entityManager, this ); + ActionMap actions = this.controller.getActions( ); + Controller.NewSampleAction newSampleAction = (Controller.NewSampleAction) actions.get( Controller.NEW_SAMPLE_ACTION_NAME ); + newSampleAction.newSample( ); + + this.createUI( ); + } + + /** + * @return + */ + protected Questionnaire getQuestionnaire( ) + { + return this.questionnaire; + } + + /** + * @return + */ + protected ObjectData getObjectData( ) + { + return this.objectData; + } + + /** + * @param objectData + */ + protected void setObjectData( ObjectData objectData ) + { + this.objectData = objectData; + if( this.dataModel == null ) + this.dataModel = new JXPathPresentationModel( this.objectData ); + else + this.dataModel.setBean( this.objectData ); + } + + /** + * @return + */ + protected PresentationModel getDataModel( ) + { + return this.dataModel; + } + + /** + * @return + */ + protected Map<QuestionnaireElement, JComponent> getElementToComponentMap( ) + { + return this.elementToComponentMap; + } + + /** + * @return + */ + protected Map<JComponent, QuestionnaireElement> getComponentToElementMap( ) + { + return this.componentToElementMap; + } + + /** + * + */ + private void createUI( ) + { + this.createMenuBar( ); + this.createToolBar( ); + this.createQuestionnairePanel( ); + } + + private void createMenuBar( ) + { + JMenuBar menuBar = new JMenuBar( ); + + // Sample menu + JMenu sampleMenu = new JMenu( Frame.RESOURCE_BUNDLE.getString( "sampleMenu.title" ) ); + sampleMenu.setMnemonic( (Integer) Frame.RESOURCE_BUNDLE.getObject( "sampleMenu.mnemonic" ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( Controller.NEW_SAMPLE_ACTION_NAME ) ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( Controller.SAVE_SAMPLE_ACTION_NAME ) ) ); + menuBar.add( sampleMenu ); + sampleMenu.addSeparator( ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( Controller.FIRST_SAMPLE_ACTION_NAME ) ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( Controller.PREVIOUS_SAMPLE_ACTION_NAME ) ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( Controller.NEXT_SAMPLE_ACTION_NAME ) ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( Controller.LAST_SAMPLE_ACTION_NAME ) ) ); + + + this.setJMenuBar( menuBar ); + } + + private void createToolBar( ) + { + JToolBar toolbar = new JToolBar( ); + + JButton newButton = new JButton( this.controller.getActions( ).get( Controller.NEW_SAMPLE_ACTION_NAME ) ); + newButton.setText( "" ); + toolbar.add( newButton ); + JButton saveButton = new JButton( this.controller.getActions( ).get( Controller.SAVE_SAMPLE_ACTION_NAME ) ); + saveButton.setText( "" ); + toolbar.add( saveButton ); + + toolbar.addSeparator( ); + + JButton firstButton = new JButton( this.controller.getActions( ).get( Controller.FIRST_SAMPLE_ACTION_NAME ) ); + firstButton.setText( "" ); + toolbar.add( firstButton ); + JButton previousButton = new JButton( this.controller.getActions( ).get( Controller.PREVIOUS_SAMPLE_ACTION_NAME ) ); + previousButton.setText( "" ); + toolbar.add( previousButton ); + JButton nextButton = new JButton( this.controller.getActions( ).get( Controller.NEXT_SAMPLE_ACTION_NAME ) ); + nextButton.setText( "" ); + toolbar.add( nextButton ); + JButton lastButton = new JButton( this.controller.getActions( ).get( Controller.LAST_SAMPLE_ACTION_NAME ) ); + lastButton.setText( "" ); + toolbar.add( lastButton ); + + this.getContentPane( ).add( toolbar, BorderLayout.NORTH ); + } + + private void createQuestionnairePanel( ) + { + JTabbedPane pagesPane = new JTabbedPane( ); + this.getContentPane( ).add( pagesPane, BorderLayout.CENTER ); + + int pageNumber = 1; + for( Feed pageFeed : questionnaire.getPageFeeds( ) ) + { + pagesPane.addTab( "Page " + pageNumber, this.createPagePanel( questionnaire, pageFeed ) ); + pageNumber++; + } + } + + private JScrollPane createPagePanel( Questionnaire questionnaire, Feed pageFeed ) + { + JScrollPane pageScrollPane = new JScrollPane( ); + JPanel pagePanel = new JPanel( ); + pageScrollPane.setViewportView( pagePanel ); + pagePanel.setLayout( new BoxLayout( pagePanel, BoxLayout.PAGE_AXIS ) ); + + for( SectionFeed sectionFeed : questionnaire.getSectionsInPage( pageFeed ) ) + { + pagePanel.add( this.createSectionPanel( questionnaire, pageFeed, sectionFeed ) ); + } + pagePanel.add( Box.createVerticalGlue( ) ); + + return pageScrollPane; + } + + private JPanel createSectionPanel( Questionnaire questionnaire, Feed pageFeed, SectionFeed sectionFeed ) + { + StringBuffer rowSpecification = new StringBuffer( ); + for( int elementIndex = 0; elementIndex <= questionnaire.getComponentElements( ).size( ); elementIndex++ ) + rowSpecification.append( "3dlu, top:pref, 3dlu, pref, " ); + FormLayout sectionLayout = new FormLayout( "3dlu, max(150dlu;pref):grow, 5dlu, left:pref, 3dlu:grow", rowSpecification.toString( ) ); + PanelBuilder pageSectionPanelBuilder = new PanelBuilder( sectionLayout ); + pageSectionPanelBuilder.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.DARK_GRAY, 1 ), + sectionFeed.getTitle( ), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.DARK_GRAY ) ); + + boolean firstElement = true; + for( QuestionnaireElement element : questionnaire.getElementsInPageAndSection( pageFeed, sectionFeed ) ) + { + if( !firstElement ) + { + pageSectionPanelBuilder.nextLine( 2 ); + pageSectionPanelBuilder.addSeparator( "" ); + pageSectionPanelBuilder.nextLine( 2 ); + } + else + { + pageSectionPanelBuilder.nextLine( ); + firstElement = false; + } + + pageSectionPanelBuilder.nextColumn( ); // Needed to place cursor in correct column + if( element.getQuestion( ) != null ) + { + JTextArea questionText = new JTextArea( element.getQuestion( ).getText( ) ); + questionText.setFocusable( false ); + questionText.setEditable( false ); + questionText.setLineWrap( true ); + questionText.setWrapStyleWord( true ); + + pageSectionPanelBuilder.add( questionText ); + } + else + pageSectionPanelBuilder.nextColumn( 1 ); + pageSectionPanelBuilder.nextColumn( 2 ); + pageSectionPanelBuilder.add( this.createDataEntryComponent( element ) ); + } + + // JButton cambioModelo = new JButton( "Cambio" ); + // cambioModelo.addActionListener( new ActionListener( ) + // { + // public void actionPerformed( ActionEvent e ) + // { + // QuestionnaireRunner.TempQuestionnaire newData = new QuestionnaireRunner.TempQuestionnaire( ); + // newData.setAnyoNacimiento( 1950 ); + // newData.setMesNacimiento( 8 ); + // Frame.this.dataModel.setBean( newData ); + // } + // } ); + // pageSectionPanelBuilder.nextLine( ); + // pageSectionPanelBuilder.nextLine( ); + // pageSectionPanelBuilder.nextColumn( 3 ); + // pageSectionPanelBuilder.add( cambioModelo ); + + return pageSectionPanelBuilder.getPanel( ); + } + + private JComponent createDataEntryComponent( QuestionnaireElement element ) + { + if( element.getRegisterDataElement( ).getComponentElements( ).isEmpty( ) ) + { + // Simple question + String propertyName = Frame.computePropertyName( element.getRegisterDataElement( ) ); + ValueDomain valueDomain = element.getRegisterDataElement( ).getValueDomain( ); + if( valueDomain instanceof QuantityValueDomain ) + { + QuantityValueDomain quantityValueDomain = (QuantityValueDomain) valueDomain; + // JTextField field = new JTextField( quantityValueDomain.getPrecision( ) ); + JFormattedTextField field = BasicComponentFactory.createIntegerField( this.getDataModel( ).getModel( propertyName ) ); + field.setColumns( quantityValueDomain.getPrecision( ) ); + field.addFocusListener( this.controller.getSelectionController( ) ); + field.setInputVerifier( this.controller.getValidationController( ) ); + + this.elementToComponentMap.put( element, field ); + this.componentToElementMap.put( field, element ); + return field; + } + else if( valueDomain instanceof ClassificationValueDomain ) + { + final ClassificationValueDomain classificationValueDomain = (ClassificationValueDomain) valueDomain; + JPanel classificationPanel = new JPanel( new FlowLayout( FlowLayout.LEFT ) ); + // JComboBox classificationCombo = new JComboBox( classificationValueDomain.getLevel( ).getItems( ).toArray( ) ); + JComboBox classificationCombo = new JComboBox( new ComboBoxAdapter( classificationValueDomain.getLevel( ).getItems( ), + new Frame.ClassificationConverter( classificationValueDomain.getLevel( ), this.dataModel.getModel( propertyName ) ) ) ); + + // JTextField classificationCode = new JTextField( 5 ); + JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); + classificationCode.setColumns( 5 ); + + classificationCode.addFocusListener( this.controller.getSelectionController( ) ); + classificationCode.setInputVerifier( this.controller.getValidationController( ) ); + + classificationPanel.add( classificationCombo ); + classificationPanel.add( classificationCode ); + this.elementToComponentMap.put( element, classificationPanel ); + this.componentToElementMap.put( classificationCode, element ); + return classificationPanel; + } + else + { + // TODO: Throw an exception? + return new JTextField( "TODO", 10 ); + } + } + else + { + // Compuond question + return new JTextField( "TODO", 10 ); + } + } + + private static String computePropertyName( RegisterDataElement registerDataElement ) + { + List<String> identifiers = new LinkedList<String>( ); + + DataElement root = registerDataElement.getRootDataElement( ); + DataElement currentDataElement = registerDataElement; + while( !currentDataElement.equals( root ) ) + { + identifiers.add( 0, currentDataElement.getIdentifier( ) ); + currentDataElement = currentDataElement.getVariableStructure( ); + } + + StringBuffer propertyName = new StringBuffer( identifiers.get( 0 ) ); + for( String identifier : identifiers.subList( 1, identifiers.size( ) ) ) + { + propertyName.append( "/" ); + propertyName.append( identifier ); + } + + return propertyName.toString( ); + } + + public static class ClassificationConverter extends AbstractConverter + { + private static final long serialVersionUID = 5430851351776185423L; + + private Level level; + + public ClassificationConverter( Level level, ValueModel subject ) + { + super( subject ); + this.level = level; + } + + @Override + public Object convertFromSubject( Object subjectValue ) + { + return this.level.getItem( (String) subjectValue, false ); + } + + public void setValue( Object value ) + { + this.subject.setValue( value != null ? ((Item) value).getCode( ) : null ); + } + } + } Deleted: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-10-09 14:25:26 UTC (rev 81) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-10-09 14:27:32 UTC (rev 82) @@ -1,398 +0,0 @@ -/* - * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to - * the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - * - * $Id$ - */ -package org.surveyforge.runner; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.FlowLayout; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.persistence.EntityManagerFactory; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JFormattedTextField; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JToolBar; -import javax.swing.UIDefaults; -import javax.swing.UIManager; -import javax.swing.border.TitledBorder; -import javax.swing.plaf.ColorUIResource; - -import org.surveyforge.classification.Item; -import org.surveyforge.classification.Level; -import org.surveyforge.core.data.ObjectData; -import org.surveyforge.core.metadata.DataElement; -import org.surveyforge.core.metadata.RegisterDataElement; -import org.surveyforge.core.metadata.ValueDomain; -import org.surveyforge.core.metadata.domain.ClassificationValueDomain; -import org.surveyforge.core.metadata.domain.QuantityValueDomain; -import org.surveyforge.core.survey.Feed; -import org.surveyforge.core.survey.Questionnaire; -import org.surveyforge.core.survey.QuestionnaireElement; -import org.surveyforge.core.survey.SectionFeed; -import org.surveyforge.util.jgoodies.JXPathPresentationModel; - -import com.jgoodies.binding.PresentationModel; -import com.jgoodies.binding.adapter.BasicComponentFactory; -import com.jgoodies.binding.adapter.ComboBoxAdapter; -import com.jgoodies.binding.value.AbstractConverter; -import com.jgoodies.binding.value.ValueModel; -import com.jgoodies.forms.builder.PanelBuilder; -import com.jgoodies.forms.layout.FormLayout; - -/** - * @author jgonzalez - */ -public class QuestionnaireFrame extends JFrame - { - private static final long serialVersionUID = -2135625525102812393L; - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle( "org.surveyforge.runner.QuestionnaireRunnerResourceBundle" ); - - private QuestionnaireRunnerController controller; - - private Map<QuestionnaireElement, JComponent> elementToComponentMap = new HashMap<QuestionnaireElement, JComponent>( ); - private Map<JComponent, QuestionnaireElement> componentToElementMap = new HashMap<JComponent, QuestionnaireElement>( ); - - private EntityManagerFactory entityManagerFactory; - private Questionnaire questionnaire; - private ObjectData objectData; - private PresentationModel dataModel; - - /** - * @param entityManagerFactory - * @param questionnaire - * @throws IOException - */ - public QuestionnaireFrame( EntityManagerFactory entityManagerFactory, Questionnaire questionnaire ) throws IOException - { - super( "QuestionnaireRunner - " + questionnaire.getTitle( ) ); - - this.entityManagerFactory = entityManagerFactory; - this.questionnaire = questionnaire; - - this.setObjectData( questionnaire.getRegister( ).getRegisterData( ).createEmptyObjectData( ) ); - - this.controller = new QuestionnaireRunnerController( this.entityManagerFactory, this ); - - this.createUI( ); - } - - /** - * @return - */ - protected Questionnaire getQuestionnaire( ) - { - return this.questionnaire; - } - - /** - * @return - */ - protected ObjectData getObjectData( ) - { - return this.objectData; - } - - /** - * @param objectData - */ - protected void setObjectData( ObjectData objectData ) - { - this.objectData = objectData; - if( this.dataModel == null ) - this.dataModel = new JXPathPresentationModel( this.objectData ); - else - this.dataModel.setBean( this.objectData ); - } - - /** - * @return - */ - protected PresentationModel getDataModel( ) - { - return this.dataModel; - } - - /** - * @return - */ - protected Map<QuestionnaireElement, JComponent> getElementToComponentMap( ) - { - return this.elementToComponentMap; - } - - /** - * @return - */ - protected Map<JComponent, QuestionnaireElement> getComponentToElementMap( ) - { - return this.componentToElementMap; - } - - /** - * - */ - private void createUI( ) - { - this.createMenuBar( ); - this.createToolBar( ); - this.createQuestionnairePanel( ); - } - - private void createMenuBar( ) - { - JMenuBar menuBar = new JMenuBar( ); - - // Sample menu - JMenu sampleMenu = new JMenu( QuestionnaireFrame.RESOURCE_BUNDLE.getString( "sampleMenu.title" ) ); - sampleMenu.setMnemonic( (Integer) QuestionnaireFrame.RESOURCE_BUNDLE.getObject( "sampleMenu.mnemonic" ) ); - sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME ) ) ); - sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME ) ) ); - menuBar.add( sampleMenu ); - - this.setJMenuBar( menuBar ); - } - - private void createToolBar( ) - { - JToolBar toolbar = new JToolBar( ); - - JButton newButton = new JButton( this.controller.getActions( ).get( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME ) ); - newButton.setText( "" ); - toolbar.add( newButton ); - JButton saveButton = new JButton( this.controller.getActions( ).get( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME ) ); - saveButton.setText( "" ); - toolbar.add( saveButton ); - - this.getContentPane( ).add( toolbar, BorderLayout.NORTH ); - } - - private void createQuestionnairePanel( ) - { - JTabbedPane pagesPane = new JTabbedPane( ); - this.getContentPane( ).add( pagesPane, BorderLayout.CENTER ); - - int pageNumber = 1; - for( Feed pageFeed : questionnaire.getPageFeeds( ) ) - { - pagesPane.addTab( "Page " + pageNumber, this.createPagePanel( questionnaire, pageFeed ) ); - pageNumber++; - } - } - - private JScrollPane createPagePanel( Questionnaire questionnaire, Feed pageFeed ) - { - JScrollPane pageScrollPane = new JScrollPane( ); - JPanel pagePanel = new JPanel( ); - pageScrollPane.setViewportView( pagePanel ); - pagePanel.setLayout( new BoxLayout( pagePanel, BoxLayout.PAGE_AXIS ) ); - - for( SectionFeed sectionFeed : questionnaire.getSectionsInPage( pageFeed ) ) - { - pagePanel.add( this.createSectionPanel( questionnaire, pageFeed, sectionFeed ) ); - } - pagePanel.add( Box.createVerticalGlue( ) ); - - return pageScrollPane; - } - - private JPanel createSectionPanel( Questionnaire questionnaire, Feed pageFeed, SectionFeed sectionFeed ) - { - StringBuffer rowSpecification = new StringBuffer( ); - for( int elementIndex = 0; elementIndex <= questionnaire.getComponentElements( ).size( ); elementIndex++ ) - rowSpecification.append( "3dlu, top:pref, 3dlu, pref, " ); - FormLayout sectionLayout = new FormLayout( "3dlu, max(150dlu;pref):grow, 5dlu, left:pref, 3dlu:grow", rowSpecification.toString( ) ); - PanelBuilder pageSectionPanelBuilder = new PanelBuilder( sectionLayout ); - pageSectionPanelBuilder.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.DARK_GRAY, 1 ), - sectionFeed.getTitle( ), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.DARK_GRAY ) ); - - boolean firstElement = true; - for( QuestionnaireElement element : questionnaire.getElementsInPageAndSection( pageFeed, sectionFeed ) ) - { - if( !firstElement ) - { - pageSectionPanelBuilder.nextLine( 2 ); - pageSectionPanelBuilder.addSeparator( "" ); - pageSectionPanelBuilder.nextLine( 2 ); - } - else - { - pageSectionPanelBuilder.nextLine( ); - firstElement = false; - } - - pageSectionPanelBuilder.nextColumn( ); // Needed to place cursor in correct column - if( element.getQuestion( ) != null ) - { - JTextArea questionText = new JTextArea( element.getQuestion( ).getText( ) ); - questionText.setFocusable( false ); - questionText.setEditable( false ); - questionText.setLineWrap( true ); - questionText.setWrapStyleWord( true ); - - pageSectionPanelBuilder.add( questionText ); - } - else - pageSectionPanelBuilder.nextColumn( 1 ); - pageSectionPanelBuilder.nextColumn( 2 ); - pageSectionPanelBuilder.add( this.createDataEntryComponent( element ) ); - } - - // JButton cambioModelo = new JButton( "Cambio" ); - // cambioModelo.addActionListener( new ActionListener( ) - // { - // public void actionPerformed( ActionEvent e ) - // { - // QuestionnaireRunner.TempQuestionnaire newData = new QuestionnaireRunner.TempQuestionnaire( ); - // newData.setAnyoNacimiento( 1950 ); - // newData.setMesNacimiento( 8 ); - // QuestionnaireFrame.this.dataModel.setBean( newData ); - // } - // } ); - // pageSectionPanelBuilder.nextLine( ); - // pageSectionPanelBuilder.nextLine( ); - // pageSectionPanelBuilder.nextColumn( 3 ); - // pageSectionPanelBuilder.add( cambioModelo ); - - return pageSectionPanelBuilder.getPanel( ); - } - - private JComponent createDataEntryComponent( QuestionnaireElement element ) - { - if( element.getRegisterDataElement( ).getComponentElements( ).isEmpty( ) ) - { - // Simple question - String propertyName = QuestionnaireFrame.computePropertyName( element.getRegisterDataElement( ) ); - ValueDomain valueDomain = element.getRegisterDataElement( ).getValueDomain( ); - if( valueDomain instanceof QuantityValueDomain ) - { - QuantityValueDomain quantityValueDomain = (QuantityValueDomain) valueDomain; - // JTextField field = new JTextField( quantityValueDomain.getPrecision( ) ); - JFormattedTextField field = BasicComponentFactory.createIntegerField( this.getDataModel( ).getModel( propertyName ) ); - field.setColumns( quantityValueDomain.getPrecision( ) ); - field.addFocusListener( this.controller.getSelectionController( ) ); - field.setInputVerifier( this.controller.getValidationController( ) ); - - this.elementToComponentMap.put( element, field ); - this.componentToElementMap.put( field, element ); - return field; - } - else if( valueDomain instanceof ClassificationValueDomain ) - { - final ClassificationValueDomain classificationValueDomain = (ClassificationValueDomain) valueDomain; - JPanel classificationPanel = new JPanel( new FlowLayout( FlowLayout.LEFT ) ); - // JComboBox classificationCombo = new JComboBox( classificationValueDomain.getLevel( ).getItems( ).toArray( ) ); - JComboBox classificationCombo = new JComboBox( new ComboBoxAdapter( classificationValueDomain.getLevel( ).getItems( ), - new QuestionnaireFrame.ClassificationConverter( classificationValueDomain.getLevel( ), this.dataModel - .getModel( propertyName ) ) ) ); - - // JTextField classificationCode = new JTextField( 5 ); - JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); - classificationCode.setColumns( 5 ); - - classificationCode.addFocusListener( this.controller.getSelectionController( ) ); - classificationCode.setInputVerifier( this.controller.getValidationController( ) ); - - classificationPanel.add( classificationCombo ); - classificationPanel.add( classificationCode ); - this.elementToComponentMap.put( element, classificationPanel ); - this.componentToElementMap.put( classificationCode, element ); - return classificationPanel; - } - else - { - // TODO: Throw an exception? - return new JTextField( "TODO", 10 ); - } - } - else - { - // Compuond question - return new JTextField( "TODO", 10 ); - } - } - - private static String computePropertyName( RegisterDataElement registerDataElement ) - { - List<String> identifiers = new LinkedList<String>( ); - - DataElement root = registerDataElement.getRootDataElement( ); - DataElement currentDataElement = registerDataElement; - while( !currentDataElement.equals( root ) ) - { - identifiers.add( 0, currentDataElement.getIdentifier( ) ); - currentDataElement = currentDataElement.getVariableStructure( ); - } - - StringBuffer propertyName = new StringBuffer( identifiers.get( 0 ) ); - for( String identifier : identifiers.subList( 1, identifiers.size( ) ) ) - { - propertyName.append( "/" ); - propertyName.append( identifier ); - } - - return propertyName.toString( ); - } - - public static class ClassificationConverter extends AbstractConverter - { - private static final long serialVersionUID = 5430851351776185423L; - - private Level level; - - public ClassificationConverter( Level level, ValueModel subject ) - { - super( subject ); - this.level = level; - } - - @Override - public Object convertFromSubject( Object subjectValue ) - { - return this.level.getItem( (String) subjectValue, false ); - } - - public void setValue( Object value ) - { - this.subject.setValue( value != null ? ((Item) value).getCode( ) : null ); - } - } - } Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-09 14:25:26 UTC (rev 81) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-09 14:27:32 UTC (rev 82) @@ -27,6 +27,7 @@ import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; +import javax.persistence.FlushModeType; import javax.persistence.Persistence; import javax.persistence.Query; import javax.swing.JFrame; @@ -52,7 +53,7 @@ { // Likely PlasticXP is not in the class path; ignore. } - + // Default selection color UIDefaults defaults = UIManager.getDefaults( ); defaults.put( "TextField.selectionBackground", new ColorUIResource( Color.ORANGE ) ); @@ -60,11 +61,12 @@ EntityManager entityManager = null; EntityTransaction transaction = null; - QuestionnaireFrame questionnaireFrame = null; + Frame frame = null; try { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "hivudvp" ); entityManager = entityManagerFactory.createEntityManager( ); + entityManager.setFlushMode( FlushModeType.COMMIT ); transaction = entityManager.getTransaction( ); transaction.begin( ); @@ -72,17 +74,16 @@ questionnaireQuery.setParameter( "questionnaireIdentifier", args[0] ); if( !questionnaireQuery.getResultList( ).isEmpty( ) ) { - questionnaireFrame = new QuestionnaireFrame( entityManagerFactory, (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); - questionnaireFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); - questionnaireFrame.pack( ); + frame = new Frame( entityManager, (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); + frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + frame.pack( ); } } finally { - if( transaction != null ) transaction.commit( ); - if( entityManager != null ) entityManager.close( ); + if( transaction != null && transaction.isActive( ) ) transaction.commit( ); } - if( questionnaireFrame != null ) questionnaireFrame.setVisible( true ); + if( frame != null ) frame.setVisible( true ); } } Deleted: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java 2006-10-09 14:25:26 UTC (rev 81) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java 2006-10-09 14:27:32 UTC (rev 82) @@ -1,316 +0,0 @@ -/* - * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to - * the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - * - * $Id$ - */ -package org.surveyforge.runner; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.Serializable; -import java.text.ParseException; -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.persistence.EntityManagerFactory; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.InputVerifier; -import javax.swing.JComponent; -import javax.swing.JFormattedTextField; -import javax.swing.JOptionPane; -import javax.swing.JFormattedTextField.AbstractFormatter; -import javax.swing.text.JTextComponent; - -import org.surveyforge.core.data.ObjectData; -import org.surveyforge.core.metadata.ValueDomain; -import org.surveyforge.core.survey.Questionnaire; -import org.surveyforge.core.survey.QuestionnaireElement; - -import com.openinput.tools.swing.ArrayActionMap; -import com.openinput.tools.swing.ResourceBundleBackedAction; - -/** - * @author jgonzalez - */ -public class QuestionnaireRunnerController - { - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle( "org.surveyforge.runner.QuestionnaireRunnerResourceBundle" ); - - public static final String NEW_SAMPLE_ACTION_NAME = "org.surveyforge.runner.QuestionnaireRunnerController.newSampleAction"; - public static final String SAVE_SAMPLE_ACTION_NAME = "org.surveyforge.runner.QuestionnaireRunnerController.saveSampleAction"; - - private Action[] supportedActionsArray; - private ActionMap supportedActions; - - private ValidationController validationController = new QuestionnaireRunnerController.ValidationController( ); - private SelectionController selectionController = new QuestionnaireRunnerController.SelectionController( ); - private RoutingController routingController = new QuestionnaireRunnerController.RoutingController( ); - - private EntityManagerFactory entityManagerFactory; - private QuestionnaireFrame questionnaireFrame; - private Questionnaire ... [truncated message content] |
From: <jg...@us...> - 2006-10-09 14:25:36
|
Revision: 81 http://svn.sourceforge.net/surveyforge/?rev=81&view=rev Author: jgongo Date: 2006-10-09 07:25:26 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Several changes to make public API more friendly Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Data.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/ObjectData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Data.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Data.java 2006-10-09 13:10:55 UTC (rev 80) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Data.java 2006-10-09 14:25:26 UTC (rev 81) @@ -50,8 +50,8 @@ @Entity public class Data implements Serializable { - private static final long serialVersionUID = 0L; - + private static final long serialVersionUID = -2555299258079055098L; + @SuppressWarnings("unused") @Id @Column(length = 50) @@ -75,7 +75,7 @@ private boolean answered; private boolean applicable; - @ManyToOne(cascade = {CascadeType.ALL}) + @ManyToOne @JoinColumn(name = "enclosingData_id", insertable = false, updatable = false) private Data enclosingData; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/ObjectData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/ObjectData.java 2006-10-09 13:10:55 UTC (rev 80) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/ObjectData.java 2006-10-09 14:25:26 UTC (rev 81) @@ -56,7 +56,7 @@ /** * @param registerData The registerData to set. */ - public void setRegisterData( RegisterData registerData ) + protected void setRegisterData( RegisterData registerData ) { if( registerData != null ) { Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-10-09 13:10:55 UTC (rev 80) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-10-09 14:25:26 UTC (rev 81) @@ -60,7 +60,7 @@ @javax.persistence.Version private int lockingVersion; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) private Register register; @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @@ -100,34 +100,37 @@ /** * @param objectData The objectData to . */ - protected void addObjectData( ObjectData objectData ) + public void addObjectData( ObjectData objectData ) { - if( objectData != null ) - { - if( this.register.getKey( ).size( ) == 0 ) throw new IllegalArgumentException( ); - ArrayList<Integer> illegalList = new ArrayList<Integer>( ); - // TODO: Check validation rules and throw Exceptions if needed + if( objectData.getRegisterData( ) != null ) objectData.getRegisterData( ).removeObjectData( objectData ); + // TODO: Add data validation + this.objectData.add( objectData ); + } - if( this.register.getComponentElements( ).size( ) != objectData.getComponentData( ).size( ) ) - throw new IllegalArgumentException( ); - int index = 0; - for( Data data : objectData.getComponentData( ) ) - { - if( !this.register.getComponentElements( ).get( index ).getValueDomain( ).isValid( data.getData( ) ) ) - illegalList.add( index ); // TODO: Elaborate on this Exception - index++; - } - if( illegalList.size( ) == 0 ) this.objectData.add( objectData ); - } + /** + * @param objectData + */ + public void checkObjectData( ObjectData objectData ) + { + // TODO: Check validation rules and throw Exceptions if needed - else - throw new NullPointerException( ); + // TODO: Later activate this, deactivated to test load/save + // if( this.register.getKey( ).size( ) == 0 ) throw new IllegalArgumentException( ); + // if( this.register.getComponentElements( ).size( ) != objectData.getComponentData( ).size( ) ) + // throw new IllegalArgumentException( ); + // int index = 0; + // for( Data data : objectData.getComponentData( ) ) + // { + // if( !this.register.getComponentElements( ).get( index ).getValueDomain( ).isValid( data.getData( ) ) ) + // illegalList.add( index ); // TODO: Elaborate on this Exception + // index++; + // } } /** * @param objectData The objectData to . */ - protected void removeObjectData( ObjectData objectData ) + public void removeObjectData( ObjectData objectData ) { if( objectData != null ) this.objectData.remove( objectData ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-09 13:11:02
|
Revision: 80 http://svn.sourceforge.net/surveyforge/?rev=80&view=rev Author: jgongo Date: 2006-10-09 06:10:55 -0700 (Mon, 09 Oct 2006) Log Message: ----------- Initialization of support for property change support *before* constructor invocation Modified Paths: -------------- trunk/surveyforge-util/src/main/aspect/org/surveyforge/util/beans/JavaBeanAspect.aj Modified: trunk/surveyforge-util/src/main/aspect/org/surveyforge/util/beans/JavaBeanAspect.aj =================================================================== --- trunk/surveyforge-util/src/main/aspect/org/surveyforge/util/beans/JavaBeanAspect.aj 2006-10-05 14:28:03 UTC (rev 79) +++ trunk/surveyforge-util/src/main/aspect/org/surveyforge/util/beans/JavaBeanAspect.aj 2006-10-09 13:10:55 UTC (rev 80) @@ -82,7 +82,7 @@ } pointcut javaBeanCreation( JavaBean bean ) : target( bean ) && execution( (@Observable *).new(..) ); - after( JavaBean bean ) returning() : javaBeanCreation( bean ) + before( JavaBean bean ) : javaBeanCreation( bean ) { bean.pcs = new PropertyChangeSupport( bean ); bean.vcs = new VetoableChangeSupport( bean ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-05 14:28:13
|
Revision: 79 http://svn.sourceforge.net/surveyforge/?rev=79&view=rev Author: jgongo Date: 2006-10-05 07:28:03 -0700 (Thu, 05 Oct 2006) Log Message: ----------- 1. Added new repository 2. Added dependency management for jlfgr package Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-10-04 10:01:49 UTC (rev 78) +++ trunk/pom.xml 2006-10-05 14:28:03 UTC (rev 79) @@ -168,6 +168,11 @@ <url>https://maven-repository.dev.java.net/nonav/repository/</url> <layout>legacy</layout> </repository> + <repository> + <id>openinput.com</id> + <name>OPEN input Labs</name> + <url>http://labs.openinput.com/maven/</url> + </repository> </repositories> <reporting> <plugins> @@ -317,6 +322,12 @@ <version>0.1-SNAPSHOT</version> </dependency> <dependency> + <groupId>com.sun</groupId> + <artifactId>jlfgr</artifactId> + <version>1.0</version> + <scope>runtime</scope> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> <version>2.0.4</version> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-04 10:02:29
|
Revision: 78 http://svn.sourceforge.net/surveyforge/?rev=78&view=rev Author: jgongo Date: 2006-10-04 03:01:49 -0700 (Wed, 04 Oct 2006) Log Message: ----------- New version of runner with working binding and revamped MVC design Modified Paths: -------------- trunk/surveyforge-runner/pom.xml trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java Added Paths: ----------- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar trunk/surveyforge-runner/src/main/resources/org/ trunk/surveyforge-runner/src/main/resources/org/surveyforge/ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties Modified: trunk/surveyforge-runner/pom.xml =================================================================== --- trunk/surveyforge-runner/pom.xml 2006-10-04 09:10:26 UTC (rev 77) +++ trunk/surveyforge-runner/pom.xml 2006-10-04 10:01:49 UTC (rev 78) @@ -76,6 +76,10 @@ <artifactId>postgresql</artifactId> </dependency> <dependency> + <groupId>com.openinput.tools</groupId> + <artifactId>openinput-tools-swing</artifactId> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> </dependency> Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-10-04 09:10:26 UTC (rev 77) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-10-04 10:01:49 UTC (rev 78) @@ -21,27 +21,38 @@ */ package org.surveyforge.runner; +import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.FlowLayout; -import java.awt.Toolkit; +import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.ResourceBundle; +import javax.persistence.EntityManagerFactory; import javax.swing.BorderFactory; +import javax.swing.Box; import javax.swing.BoxLayout; -import javax.swing.InputVerifier; +import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; +import javax.swing.JFormattedTextField; import javax.swing.JFrame; -import javax.swing.JOptionPane; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; +import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.JToolBar; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.border.TitledBorder; +import javax.swing.plaf.ColorUIResource; import org.surveyforge.classification.Item; import org.surveyforge.classification.Level; @@ -70,45 +81,143 @@ */ public class QuestionnaireFrame extends JFrame { - private static final long serialVersionUID = -2135625525102812393L; + private static final long serialVersionUID = -2135625525102812393L; - private Questionnaire questionnaire; - private Map<QuestionnaireElement, Component> questionnaireComponents = new HashMap<QuestionnaireElement, Component>( ); - private ObjectData objectData; - private PresentationModel dataModel; + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle( "org.surveyforge.runner.QuestionnaireRunnerResourceBundle" ); - public QuestionnaireFrame( Questionnaire questionnaire ) + private QuestionnaireRunnerController controller; + + private Map<QuestionnaireElement, JComponent> elementToComponentMap = new HashMap<QuestionnaireElement, JComponent>( ); + private Map<JComponent, QuestionnaireElement> componentToElementMap = new HashMap<JComponent, QuestionnaireElement>( ); + + private EntityManagerFactory entityManagerFactory; + private Questionnaire questionnaire; + private ObjectData objectData; + private PresentationModel dataModel; + + /** + * @param entityManagerFactory + * @param questionnaire + * @throws IOException + */ + public QuestionnaireFrame( EntityManagerFactory entityManagerFactory, Questionnaire questionnaire ) throws IOException { - super( "QuestionnaireRunner" ); + super( "QuestionnaireRunner - " + questionnaire.getTitle( ) ); + this.entityManagerFactory = entityManagerFactory; this.questionnaire = questionnaire; + this.setObjectData( questionnaire.getRegister( ).getRegisterData( ).createEmptyObjectData( ) ); - JTabbedPane pagesPane = new JTabbedPane( ); - this.getContentPane( ).add( pagesPane ); + this.controller = new QuestionnaireRunnerController( this.entityManagerFactory, this ); - for( Feed pageFeed : questionnaire.getPageFeeds( ) ) - { - pagesPane.addTab( "Page", this.createPagePanel( questionnaire, pageFeed ) ); - } + this.createUI( ); } + /** + * @return + */ + protected Questionnaire getQuestionnaire( ) + { + return this.questionnaire; + } + + /** + * @return + */ protected ObjectData getObjectData( ) { return this.objectData; } + /** + * @param objectData + */ protected void setObjectData( ObjectData objectData ) { this.objectData = objectData; - this.dataModel = new JXPathPresentationModel( this.objectData ); + if( this.dataModel == null ) + this.dataModel = new JXPathPresentationModel( this.objectData ); + else + this.dataModel.setBean( this.objectData ); } + /** + * @return + */ protected PresentationModel getDataModel( ) { return this.dataModel; } + /** + * @return + */ + protected Map<QuestionnaireElement, JComponent> getElementToComponentMap( ) + { + return this.elementToComponentMap; + } + + /** + * @return + */ + protected Map<JComponent, QuestionnaireElement> getComponentToElementMap( ) + { + return this.componentToElementMap; + } + + /** + * + */ + private void createUI( ) + { + this.createMenuBar( ); + this.createToolBar( ); + this.createQuestionnairePanel( ); + } + + private void createMenuBar( ) + { + JMenuBar menuBar = new JMenuBar( ); + + // Sample menu + JMenu sampleMenu = new JMenu( QuestionnaireFrame.RESOURCE_BUNDLE.getString( "sampleMenu.title" ) ); + sampleMenu.setMnemonic( (Integer) QuestionnaireFrame.RESOURCE_BUNDLE.getObject( "sampleMenu.mnemonic" ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME ) ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME ) ) ); + menuBar.add( sampleMenu ); + + this.setJMenuBar( menuBar ); + } + + private void createToolBar( ) + { + JToolBar toolbar = new JToolBar( ); + + JButton newButton = new JButton( this.controller.getActions( ).get( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME ) ); + newButton.setText( "" ); + toolbar.add( newButton ); + JButton saveButton = new JButton( this.controller.getActions( ).get( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME ) ); + saveButton.setText( "" ); + toolbar.add( saveButton ); + + this.getContentPane( ).add( toolbar, BorderLayout.NORTH ); + } + + private void createQuestionnairePanel( ) + { + JTabbedPane pagesPane = new JTabbedPane( ); + this.getContentPane( ).add( pagesPane, BorderLayout.CENTER ); + + int pageNumber = 1; + for( Feed pageFeed : questionnaire.getPageFeeds( ) ) + { + pagesPane.addTab( "Page " + pageNumber, this.createPagePanel( questionnaire, pageFeed ) ); + pageNumber++; + } + } + private JScrollPane createPagePanel( Questionnaire questionnaire, Feed pageFeed ) { JScrollPane pageScrollPane = new JScrollPane( ); @@ -120,6 +229,7 @@ { pagePanel.add( this.createSectionPanel( questionnaire, pageFeed, sectionFeed ) ); } + pagePanel.add( Box.createVerticalGlue( ) ); return pageScrollPane; } @@ -127,10 +237,9 @@ private JPanel createSectionPanel( Questionnaire questionnaire, Feed pageFeed, SectionFeed sectionFeed ) { StringBuffer rowSpecification = new StringBuffer( ); - for( int elementIndex = 0; elementIndex <= questionnaire.getElements( ).size( ); elementIndex++ ) + for( int elementIndex = 0; elementIndex <= questionnaire.getComponentElements( ).size( ); elementIndex++ ) rowSpecification.append( "3dlu, top:pref, 3dlu, pref, " ); - FormLayout sectionLayout = new FormLayout( "3dlu, pref, 5dlu, left:pref, 3dlu:grow", rowSpecification.toString( ) ); - + FormLayout sectionLayout = new FormLayout( "3dlu, max(150dlu;pref):grow, 5dlu, left:pref, 3dlu:grow", rowSpecification.toString( ) ); PanelBuilder pageSectionPanelBuilder = new PanelBuilder( sectionLayout ); pageSectionPanelBuilder.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.DARK_GRAY, 1 ), sectionFeed.getTitle( ), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.DARK_GRAY ) ); @@ -152,7 +261,15 @@ pageSectionPanelBuilder.nextColumn( ); // Needed to place cursor in correct column if( element.getQuestion( ) != null ) - pageSectionPanelBuilder.addLabel( element.getQuestion( ).getText( ) ); + { + JTextArea questionText = new JTextArea( element.getQuestion( ).getText( ) ); + questionText.setFocusable( false ); + questionText.setEditable( false ); + questionText.setLineWrap( true ); + questionText.setWrapStyleWord( true ); + + pageSectionPanelBuilder.add( questionText ); + } else pageSectionPanelBuilder.nextColumn( 1 ); pageSectionPanelBuilder.nextColumn( 2 ); @@ -189,9 +306,13 @@ { QuantityValueDomain quantityValueDomain = (QuantityValueDomain) valueDomain; // JTextField field = new JTextField( quantityValueDomain.getPrecision( ) ); - JTextField field = BasicComponentFactory.createIntegerField( this.getDataModel( ).getModel( propertyName ) ); + JFormattedTextField field = BasicComponentFactory.createIntegerField( this.getDataModel( ).getModel( propertyName ) ); field.setColumns( quantityValueDomain.getPrecision( ) ); - this.questionnaireComponents.put( element, field ); + field.addFocusListener( this.controller.getSelectionController( ) ); + field.setInputVerifier( this.controller.getValidationController( ) ); + + this.elementToComponentMap.put( element, field ); + this.componentToElementMap.put( field, element ); return field; } else if( valueDomain instanceof ClassificationValueDomain ) @@ -204,41 +325,16 @@ .getModel( propertyName ) ) ) ); // JTextField classificationCode = new JTextField( 5 ); - final JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); + JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); classificationCode.setColumns( 5 ); - classificationCode.setInputVerifier( new InputVerifier( ) - { - Color defaultBackground = classificationCode.getBackground( ); - @Override - public boolean verify( JComponent component ) - { - if( classificationValueDomain.getLevel( ).includes( classificationCode.getText( ), false ) ) - { - classificationCode.setBackground( defaultBackground ); - return true; - } - else - { - classificationCode.setBackground( Color.RED ); - Toolkit.getDefaultToolkit( ).beep( ); - JOptionPane.showMessageDialog( classificationCode.getRootPane( ), - "El c\u00f3digo introducido no se encuentra entre las opciones disponibles.", "C\u00f3digo err\u00f3neo", - JOptionPane.ERROR_MESSAGE ); - return false; - } - } + classificationCode.addFocusListener( this.controller.getSelectionController( ) ); + classificationCode.setInputVerifier( this.controller.getValidationController( ) ); - @Override - public boolean shouldYieldFocus( JComponent input ) - { - return verify( input ); - } - } ); - classificationPanel.add( classificationCombo ); classificationPanel.add( classificationCode ); - this.questionnaireComponents.put( element, classificationPanel ); + this.elementToComponentMap.put( element, classificationPanel ); + this.componentToElementMap.put( classificationCode, element ); return classificationPanel; } else @@ -276,33 +372,12 @@ return propertyName.toString( ); } - // public static class ClassificationFormatter extends JFormattedTextField.AbstractFormatter - // { - // private Level level; - // - // public ClassificationFormatter( Level level ) - // { - // this.level = level; - // } - // - // @Override - // public Object stringToValue( String text ) throws ParseException - // { - // // TODO Auto-generated method stub - // return this.level.getItem( text, false ); - // } - // - // @Override - // public String valueToString( Object value ) throws ParseException - // { - // return value != null ? ((Item) value).getCode( ) : null; - // } - // } - // public static class ClassificationConverter extends AbstractConverter { - private Level level; + private static final long serialVersionUID = 5430851351776185423L; + private Level level; + public ClassificationConverter( Level level, ValueModel subject ) { super( subject ); Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-04 09:10:26 UTC (rev 77) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-04 10:01:49 UTC (rev 78) @@ -21,13 +21,18 @@ */ package org.surveyforge.runner; +import java.awt.Color; +import java.io.IOException; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import javax.persistence.Query; import javax.swing.JFrame; +import javax.swing.UIDefaults; import javax.swing.UIManager; +import javax.swing.plaf.ColorUIResource; import org.surveyforge.core.survey.Questionnaire; @@ -36,7 +41,7 @@ */ public class QuestionnaireRunner { - public static void main( String[] args ) + public static void main( String[] args ) throws IOException { try { @@ -47,6 +52,11 @@ { // Likely PlasticXP is not in the class path; ignore. } + + // Default selection color + UIDefaults defaults = UIManager.getDefaults( ); + defaults.put( "TextField.selectionBackground", new ColorUIResource( Color.ORANGE ) ); + defaults.put( "FormattedTextField.selectionBackground", new ColorUIResource( Color.ORANGE ) ); EntityManager entityManager = null; EntityTransaction transaction = null; @@ -62,7 +72,7 @@ questionnaireQuery.setParameter( "questionnaireIdentifier", args[0] ); if( !questionnaireQuery.getResultList( ).isEmpty( ) ) { - questionnaireFrame = new QuestionnaireFrame( (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); + questionnaireFrame = new QuestionnaireFrame( entityManagerFactory, (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); questionnaireFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); questionnaireFrame.pack( ); } Added: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java (rev 0) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,316 @@ +/* + * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.runner; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; + +import javax.persistence.EntityManagerFactory; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.InputVerifier; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JOptionPane; +import javax.swing.JFormattedTextField.AbstractFormatter; +import javax.swing.text.JTextComponent; + +import org.surveyforge.core.data.ObjectData; +import org.surveyforge.core.metadata.ValueDomain; +import org.surveyforge.core.survey.Questionnaire; +import org.surveyforge.core.survey.QuestionnaireElement; + +import com.openinput.tools.swing.ArrayActionMap; +import com.openinput.tools.swing.ResourceBundleBackedAction; + +/** + * @author jgonzalez + */ +public class QuestionnaireRunnerController + { + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle( "org.surveyforge.runner.QuestionnaireRunnerResourceBundle" ); + + public static final String NEW_SAMPLE_ACTION_NAME = "org.surveyforge.runner.QuestionnaireRunnerController.newSampleAction"; + public static final String SAVE_SAMPLE_ACTION_NAME = "org.surveyforge.runner.QuestionnaireRunnerController.saveSampleAction"; + + private Action[] supportedActionsArray; + private ActionMap supportedActions; + + private ValidationController validationController = new QuestionnaireRunnerController.ValidationController( ); + private SelectionController selectionController = new QuestionnaireRunnerController.SelectionController( ); + private RoutingController routingController = new QuestionnaireRunnerController.RoutingController( ); + + private EntityManagerFactory entityManagerFactory; + private QuestionnaireFrame questionnaireFrame; + private Questionnaire questionnaire; + + private Map<QuestionnaireElement, JComponent> elementToComponentMap; + private Map<JComponent, QuestionnaireElement> componentToElementMap; + + + public QuestionnaireRunnerController( EntityManagerFactory entityManagerFactory, QuestionnaireFrame questionnaireFrame ) + { + this.entityManagerFactory = entityManagerFactory; + this.questionnaireFrame = questionnaireFrame; + this.questionnaire = this.questionnaireFrame.getQuestionnaire( ); + + this.elementToComponentMap = this.questionnaireFrame.getElementToComponentMap( ); + this.componentToElementMap = this.questionnaireFrame.getComponentToElementMap( ); + + this.supportedActionsArray = new Action[] {new QuestionnaireRunnerController.NewSampleAction( ), + new QuestionnaireRunnerController.SaveSampleAction( )}; + this.supportedActions = new ArrayActionMap( this.supportedActionsArray ); + } + + public ActionMap getActions( ) + { + return this.supportedActions; + } + + public InputVerifier getValidationController( ) + { + return this.validationController; + } + + public FocusListener getSelectionController( ) + { + return this.selectionController; + } + + public ActionListener getRoutingController( ) + { + return this.routingController; + } + + /** + * @author jgonzalez + */ + class NewSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -7347987080988646268L; + + private final String questionTitle = RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".question.title" ); + private final String questionMessage = RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".question.message" ); + private final Object[] options = {RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".button.yes" ), + RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".button.no" ), + RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".button.cancel" )}; + + public NewSampleAction( ) + { + super( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME, QuestionnaireRunnerController.RESOURCE_BUNDLE ); + } + + public void actionPerformed( ActionEvent e ) + { + int selectedOption = 1; + if( QuestionnaireRunnerController.this.questionnaireFrame.getDataModel( ).isChanged( ) ) + { + selectedOption = JOptionPane.showOptionDialog( QuestionnaireRunnerController.this.questionnaireFrame, this.questionMessage, + this.questionTitle, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2] ); + } + + switch( selectedOption ) + { + case 0: + JOptionPane.showMessageDialog( QuestionnaireRunnerController.this.questionnaireFrame, "SAVING SAMPLE -- TODO!!!!" ); + + case 1: + Questionnaire questionnaire = QuestionnaireRunnerController.this.questionnaire; + ObjectData emptyObjectData = questionnaire.getRegister( ).getRegisterData( ).createEmptyObjectData( ); + QuestionnaireRunnerController.this.questionnaireFrame.setObjectData( emptyObjectData ); + break; + + default: + // Do nothing + break; + } + } + } + + /** + * @author jgonzalez + */ + class SaveSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -7347987080988646268L; + + public SaveSampleAction( ) + { + super( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME, QuestionnaireRunnerController.RESOURCE_BUNDLE ); + QuestionnaireRunnerController.this.questionnaireFrame.getDataModel( ).addPropertyChangeListener( "changed", + new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent event ) + { + SaveSampleAction.this.setEnabled( (Boolean) event.getNewValue( ) ); + } + } ); + this.setEnabled( false ); + } + + public void actionPerformed( ActionEvent e ) + { + JOptionPane.showMessageDialog( QuestionnaireRunnerController.this.questionnaireFrame, "SAVING SAMPLE -- TODO!!!!" ); + QuestionnaireRunnerController.this.questionnaireFrame.getDataModel( ).resetChanged( ); + } + } + + /** + * @author jgonzalez + */ + class ValidationController extends InputVerifier + { + // private EntityManagerFactory entityManagerFactory; + private Color errorColor = new Color( 1.0f, 0.625f, 0.625f ); + private Map<JComponent, ValueDomain> validationCache = new HashMap<JComponent, ValueDomain>( ); + private Map<JComponent, Color> defaultBackground = new HashMap<JComponent, Color>( ); + + protected ValueDomain getValueDomain( JComponent component ) + { + if( !this.validationCache.containsKey( component ) ) + { + // EntityManager entityManager = entityManagerFactory.createEntityManager( ); + + QuestionnaireElement questionnaireElement = QuestionnaireRunnerController.this.componentToElementMap.get( component ); + // entityManager.refresh( questionnaireElement ); + this.validationCache.put( component, questionnaireElement.getRegisterDataElement( ).getValueDomain( ) ); + + // entityManager.clear( ); + } + + return this.validationCache.get( component ); + } + + @Override + public boolean verify( JComponent component ) + { + // Get value from component + Object value = null; + if( component instanceof JFormattedTextField ) + { + // We must format the value manually, as the change still hasn't been committed + JFormattedTextField formattedComponent = (JFormattedTextField) component; + AbstractFormatter formatter = formattedComponent.getFormatter( ); + String textValue = formattedComponent.getText( ); + try + { + if( formatter != null ) + value = formatter.stringToValue( textValue ); + else + value = textValue; + } + catch( ParseException exc ) + { + // Cannot parse the value -> invalid value + this.showErrorStatus( component ); + return false; + } + } + else if( component instanceof JTextComponent ) + { + JTextComponent textComponent = (JTextComponent) component; + value = textComponent.getText( ); + } + + // Validate value using value domain + if( this.getValueDomain( component ).isValid( (Serializable) value ) ) + { + // We hava a valid value + this.showValidStatus( component ); + return true; + } + else + { + this.showErrorStatus( component ); + return false; + } + } + + /** + * @param component + */ + protected void showErrorStatus( JComponent component ) + { + if( !this.defaultBackground.containsKey( component ) ) this.defaultBackground.put( component, component.getBackground( ) ); + component.setBackground( this.errorColor ); + Toolkit.getDefaultToolkit( ).beep( ); + + // TODO: Include error messages in value domain + JOptionPane.showMessageDialog( component.getRootPane( ), "El valor introducido no es correcto.", "Error", + JOptionPane.ERROR_MESSAGE ); + } + + /** + * @param component + */ + protected void showValidStatus( JComponent component ) + { + if( this.defaultBackground.containsKey( component ) ) component.setBackground( this.defaultBackground.remove( component ) ); + } + } + + /** + * @author jgonzalez + */ + class SelectionController implements FocusListener + { + public void focusGained( FocusEvent event ) + { + Component component = event.getComponent( ); + if( component instanceof JTextComponent ) + { + JTextComponent textComponent = (JTextComponent) component; + textComponent.selectAll( ); + } + } + + public void focusLost( FocusEvent event ) + {} + } + + /** + * @author jgonzalez + */ + public class RoutingController implements ActionListener + { + /* + * (non-Javadoc) + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed( ActionEvent event ) + {} + } + } Property changes on: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java (rev 0) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,79 @@ +/* + * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.runner; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.ListResourceBundle; + +import javax.swing.ImageIcon; +import javax.swing.KeyStroke; + +/** + * @author jgonzalez + */ +public class QuestionnaireRunnerResourceBundle extends ListResourceBundle + { + private static Object[][] CONTENTS = + { + // Sample menu + {"sampleMenu.title", "Sample"}, + {"sampleMenu.mnemonic", KeyEvent.VK_S}, + + // New sample action + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".name", "New"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".shortDescription", "Creates a new sample"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".longDescription", "Creates a new sample"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".smallIcon", new ImageIcon( ClassLoader.getSystemResource( "toolbarButtonGraphics/general/New16.gif" ) )}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".actionCommandKey", QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".acceleratorKey", KeyStroke.getKeyStroke( KeyEvent.VK_N, ActionEvent.CTRL_MASK )}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".mnemonicKey", new Integer( KeyEvent.VK_N )}, + + // New sample action messages + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".question.title", "Modified sample"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".question.message", "The sample has been modified, do you want to save it?"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".button.yes", "Yes"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".button.no", "No"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".button.cancel", "Cancel"}, + + // Save sample action + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".name", "Save"}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".shortDescription", "Save current sample"}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".longDescription", "Save current sample"}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".smallIcon", new ImageIcon( ClassLoader.getSystemResource( "toolbarButtonGraphics/general/Save16.gif" ) )}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".actionCommandKey", QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".acceleratorKey", KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK )}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".mnemonicKey", new Integer( KeyEvent.VK_S )}, + + }; + + /* + * (non-Javadoc) + * + * @see java.util.ListResourceBundle#getContents() + */ + @Override + public Object[][] getContents( ) + { + return QuestionnaireRunnerResourceBundle.CONTENTS; + } + } Property changes on: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar =================================================================== (Binary files differ) Property changes on: trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties =================================================================== --- trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties (rev 0) +++ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,5 @@ +action.new.name=New +action.new.tip=Create new sample +#action.new.shortcut=CTRL+N +action.new.mnemonic=N +action.new.icon=/toolbarButtonGraphics/general/New24.gif Added: trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties =================================================================== --- trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties (rev 0) +++ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,5 @@ +action.new.name=Nuevo +action.new.tip=Crear nueva muestra +#action.new.shortcut=CTRL+N +action.new.mnemonic=N +action.new.icon=/toolbarButtonGraphics/general/New24.gif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-04 09:10:35
|
Revision: 77 http://svn.sourceforge.net/surveyforge/?rev=77&view=rev Author: jgongo Date: 2006-10-04 02:10:26 -0700 (Wed, 04 Oct 2006) Log Message: ----------- Added dependency management for OPEN input Swing tools Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-10-04 09:05:42 UTC (rev 76) +++ trunk/pom.xml 2006-10-04 09:10:26 UTC (rev 77) @@ -312,6 +312,11 @@ <scope>runtime</scope> </dependency> <dependency> + <groupId>com.openinput.tools</groupId> + <artifactId>openinput-tools-swing</artifactId> + <version>0.1-SNAPSHOT</version> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> <version>2.0.4</version> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-04 09:05:51
|
Revision: 76 http://svn.sourceforge.net/surveyforge/?rev=76&view=rev Author: jgongo Date: 2006-10-04 02:05:42 -0700 (Wed, 04 Oct 2006) Log Message: ----------- 1. Correct synchronization between bean and bean context 2. Bug fix in get/set value methods Modified Paths: -------------- trunk/surveyforge-util/src/main/java/org/surveyforge/util/jgoodies/JXPathBeanAdapter.java Modified: trunk/surveyforge-util/src/main/java/org/surveyforge/util/jgoodies/JXPathBeanAdapter.java =================================================================== --- trunk/surveyforge-util/src/main/java/org/surveyforge/util/jgoodies/JXPathBeanAdapter.java 2006-10-04 08:56:58 UTC (rev 75) +++ trunk/surveyforge-util/src/main/java/org/surveyforge/util/jgoodies/JXPathBeanAdapter.java 2006-10-04 09:05:42 UTC (rev 76) @@ -128,46 +128,46 @@ * <strong>Basic Examples:</strong> * * <pre> - * // Direct access, ignores changes - * Address address = new Address() - * JXPathBeanAdapter adapter = new JXPathBeanAdapter(address); - * adapter.setValue("street", "Broadway"); - * System.out.println(address.getStreet()); // Prints "Broadway" - * address.setStreet("Franz-Josef-Str."); - * System.out.println(adapter.getValue("street")); // Prints "Franz-Josef-Str." - * - * - * //Direct access, observes changes - * JXPathBeanAdapter adapter = new JXPathBeanAdapter(address, true); - * - * - * // Indirect access, ignores changes - * ValueHolder addressHolder = new ValueHolder(address1); - * JXPathBeanAdapter adapter = new JXPathBeanAdapter(addressHolder); - * adapter.setValue("street", "Broadway"); // Sets the street in address1 - * System.out.println(address1.getStreet()); // Prints "Broadway" - * adapter.setBean(address2); - * adapter.setValue("street", "Robert-Koch-Str."); // Sets the street in address2 - * System.out.println(address2.getStreet()); // Prints "Robert-Koch-Str." - * - * - * // Indirect access, observes changes - * ValueHolder addressHolder = new ValueHolder(); - * JXPathBeanAdapter adapter = new JXPathBeanAdapter(addressHolder, true); - * addressHolder.setValue(address1); - * address1.setStreet("Broadway"); - * System.out.println(adapter.getValue("street")); // Prints "Broadway" - * - * - * // Access through ValueModels - * Address address = new Address(); - * JXPathBeanAdapter adapter = new JXPathBeanAdapter(address); - * ValueModel streetModel = adapter.getValueModel("street"); - * ValueModel cityModel = adapter.getValueModel("city"); - * streetModel.setValue("Broadway"); - * System.out.println(address.getStreet()); // Prints "Broadway" - * address.setCity("Hamburg"); - * System.out.println(cityModel.getValue()); // Prints "Hamburg" + * // Direct access, ignores changes + * Address address = new Address() + * JXPathBeanAdapter adapter = new JXPathBeanAdapter(address); + * adapter.setValue("street", "Broadway"); + * System.out.println(address.getStreet()); // Prints "Broadway" + * address.setStreet("Franz-Josef-Str."); + * System.out.println(adapter.getValue("street")); // Prints "Franz-Josef-Str." + * + * + * //Direct access, observes changes + * JXPathBeanAdapter adapter = new JXPathBeanAdapter(address, true); + * + * + * // Indirect access, ignores changes + * ValueHolder addressHolder = new ValueHolder(address1); + * JXPathBeanAdapter adapter = new JXPathBeanAdapter(addressHolder); + * adapter.setValue("street", "Broadway"); // Sets the street in address1 + * System.out.println(address1.getStreet()); // Prints "Broadway" + * adapter.setBean(address2); + * adapter.setValue("street", "Robert-Koch-Str."); // Sets the street in address2 + * System.out.println(address2.getStreet()); // Prints "Robert-Koch-Str." + * + * + * // Indirect access, observes changes + * ValueHolder addressHolder = new ValueHolder(); + * JXPathBeanAdapter adapter = new JXPathBeanAdapter(addressHolder, true); + * addressHolder.setValue(address1); + * address1.setStreet("Broadway"); + * System.out.println(adapter.getValue("street")); // Prints "Broadway" + * + * + * // Access through ValueModels + * Address address = new Address(); + * JXPathBeanAdapter adapter = new JXPathBeanAdapter(address); + * ValueModel streetModel = adapter.getValueModel("street"); + * ValueModel cityModel = adapter.getValueModel("city"); + * streetModel.setValue("Broadway"); + * System.out.println(address.getStreet()); // Prints "Broadway" + * address.setCity("Hamburg"); + * System.out.println(cityModel.getValue()); // Prints "Hamburg" * </pre> * * <strong>Adapter Chain Example:</strong> <br> @@ -315,7 +315,7 @@ */ private PropertyChangeListener propertyChangeHandler; - private final JXPathContext beanContext; + private JXPathContext beanContext; // Instance creation **************************************************** @@ -920,7 +920,10 @@ */ private Object getValue0( Object bean, String propertyName ) { - return this.beanContext.getValue( propertyName ); + if( bean == this.getBean( ) ) + return this.beanContext.getValue( propertyName ); + else + return JXPathContext.newContext( bean ).getValue( propertyName ); // return getValue0( bean, getPropertyDescriptor( bean, propertyName ) ); } @@ -969,7 +972,10 @@ */ private void setValue0( Object bean, String propertyName, Object newValue ) throws PropertyVetoException { - this.beanContext.setValue( propertyName, newValue ); + if( bean == this.getBean( ) ) + this.beanContext.setValue( propertyName, newValue ); + else + JXPathContext.newContext( bean ).setValue( propertyName, newValue ); // setValue0( bean, getPropertyDescriptor( bean, propertyName ), newValue ); } @@ -1032,6 +1038,7 @@ public void propertyChange( PropertyChangeEvent evt ) { Object newBean = evt.getNewValue( ) != null ? evt.getNewValue( ) : getBean( ); + JXPathBeanAdapter.this.beanContext = JXPathContext.newContext( newBean ); setBean0( storedOldBean, newBean ); storedOldBean = newBean; } @@ -1084,35 +1091,31 @@ /** * Holds the name of the adapted property. */ - private final String propertyName; + private final String propertyName; /** * Holds the optional name of the property's getter. Used to create the PropertyDescriptor. Also used to reject potential misuse of * {@link JXPathBeanAdapter#getValueModel(String)} and {@link JXPathBeanAdapter#getValueModel(String, String, String)}. See the * latter methods for details. */ - final String getterName; + final String getterName; /** * Holds the optional name of the property's setter. Used to create the PropertyDescriptor. Also used to reject potential misuse of * {@link JXPathBeanAdapter#getValueModel(String)} and {@link JXPathBeanAdapter#getValueModel(String, String, String)}. See the * latter methods for details. */ - final String setterName; + final String setterName; /** * Describes the property accessor; basically a getter and setter. */ -// private PropertyDescriptor cachedPropertyDescriptor; - + // private PropertyDescriptor cachedPropertyDescriptor; /** * Holds the bean class associated with the cached property descriptor. */ -// private Class cachedBeanClass; - - + // private Class cachedBeanClass; // Instance Creation -------------------------------------------------- - SimplePropertyAdapter( String propertyName, String getterName, String setterName ) { this.propertyName = propertyName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-04 08:57:07
|
Revision: 75 http://svn.sourceforge.net/surveyforge/?rev=75&view=rev Author: jgongo Date: 2006-10-04 01:56:58 -0700 (Wed, 04 Oct 2006) Log Message: ----------- Accept Integer objects Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java 2006-10-04 08:56:17 UTC (rev 74) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/QuantityValueDomain.java 2006-10-04 08:56:58 UTC (rev 75) @@ -132,8 +132,15 @@ public boolean isValid( Serializable object ) { - if( object instanceof BigDecimal ) + if( object instanceof Integer ) { + BigDecimal quantity = new BigDecimal( (Integer) object ); + return quantity.scale( ) <= this.getScale( ) + && (quantity.precision( ) - quantity.scale( )) <= (this.getPrecision( ) - this.getScale( )) + && this.getMinimum( ).compareTo( quantity ) <= 0 && quantity.compareTo( this.getMaximum( ) ) <= 0; + } + else if( object instanceof BigDecimal ) + { BigDecimal quantity = (BigDecimal) object; return quantity.scale( ) <= this.getScale( ) && (quantity.precision( ) - quantity.scale( )) <= (this.getPrecision( ) - this.getScale( )) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-10-04 08:56:24
|
Revision: 74 http://svn.sourceforge.net/surveyforge/?rev=74&view=rev Author: jgongo Date: 2006-10-04 01:56:17 -0700 (Wed, 04 Oct 2006) Log Message: ----------- Search in just one level by default Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java 2006-09-29 15:28:51 UTC (rev 73) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/ClassificationValueDomain.java 2006-10-04 08:56:17 UTC (rev 74) @@ -38,14 +38,14 @@ @ManyToOne private Level level; - private boolean sublevelsAllowed = true; + private boolean sublevelsAllowed; protected ClassificationValueDomain( ) {}; public ClassificationValueDomain( Level level ) { - this( level, true ); + this( level, false ); } public ClassificationValueDomain( Level level, boolean sublevelsAllowed ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-10-03 02:26:52
|
Revision: 73 http://svn.sourceforge.net/surveyforge/?rev=73&view=rev Author: javism Date: 2006-09-29 08:28:51 -0700 (Fri, 29 Sep 2006) Log Message: ----------- Some changes in the inheritance of Questionnaire-QuestionnaireElement and some improvements in ValueDomain Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/AbstractValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/DataElementTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/RegisterTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-09-29 15:28:51 UTC (rev 73) @@ -35,12 +35,12 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; -import javax.persistence.Table; import javax.persistence.Transient; -import javax.persistence.UniqueConstraint; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; @@ -52,6 +52,7 @@ * @author jsegura */ @Entity +@Inheritance(strategy = InheritanceType.JOINED) public abstract class DataElement implements Serializable { private static final long serialVersionUID = 0L; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-09-29 15:28:51 UTC (rev 73) @@ -21,13 +21,11 @@ */ package org.surveyforge.core.metadata; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.persistence.CascadeType; -import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -38,19 +36,22 @@ import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.data.RegisterData; import org.surveyforge.core.metadata.domain.StructuredValueDomain; -import org.surveyforge.core.survey.Questionnaire; // TODO Elaborate on comments /** * @author jsegura */ @Entity -public class Register extends DataElement implements Serializable +public class Register extends RegisterDataElement { - private static final long serialVersionUID = 0L; /** + * + */ + private static final long serialVersionUID = -7481816596643587493L; + + /** * When defining hierarchical registers the hierarchy is expressed as master/detail relationship. The master register defines the * objects that consist of the details. */ @@ -78,10 +79,10 @@ @OneToOne(cascade = {CascadeType.ALL}) private RegisterData registerData; - /** */ - @OneToOne(mappedBy = "register", fetch = FetchType.LAZY, optional = true) - // @OneToOne(fetch = FetchType.LAZY) - private Questionnaire questionnaire; +// /** */ +// @OneToOne(mappedBy = "register", fetch = FetchType.LAZY, optional = true) +// // @OneToOne(fetch = FetchType.LAZY) +// private Questionnaire questionnaire; protected Register( ) @@ -94,9 +95,8 @@ */ public Register( String identifier ) { - this.setIdentifier( identifier ); + super( identifier, new StructuredValueDomain( ) ); this.registerData = new RegisterData( this ); - this.setValueDomain( new StructuredValueDomain( ) ); } /** @@ -142,48 +142,48 @@ if( detailRegister != null ) this.detailRegisters.remove( detailRegister ); } - @Override - public List<? extends RegisterDataElement> getComponentElements( ) - { - List<RegisterDataElement> componentElements = new ArrayList<RegisterDataElement>( ); - for( DataElement dataElement : super.getComponentElements( ) ) - componentElements.add( (RegisterDataElement) dataElement ); - return componentElements; - } + // @Override + // public List<? extends RegisterDataElement> getComponentElements( ) + // { + // List<RegisterDataElement> componentElements = new ArrayList<RegisterDataElement>( ); + // for( DataElement dataElement : super.getComponentElements( ) ) + // componentElements.add( (RegisterDataElement) dataElement ); + // return componentElements; + // } - @Override - public void addComponentElement( DataElement componentElement ) - { - if( !(componentElement instanceof RegisterDataElement) ) - throw new IllegalArgumentException( ); - else if( this.registerData.getObjectData( ).size( ) > 0 ) - throw new IllegalStateException( ); - else - super.addComponentElement( componentElement ); - } + // @Override + // public void addComponentElement( DataElement componentElement ) + // { + // if( !(componentElement instanceof RegisterDataElement) ) + // throw new IllegalArgumentException( ); + // else if( this.registerData.getObjectData( ).size( ) > 0 ) + // throw new IllegalStateException( ); + // else + // super.addComponentElement( componentElement ); + // } + // + // @Override + // public void removeComponentElement( DataElement componentElement ) + // { + // if( this.registerData.getObjectData( ).size( ) > 0 ) + // throw new IllegalStateException( ); + // else + // super.removeComponentElement( componentElement ); + // } + // + // @Override + // public void setComponentElements( List<? extends DataElement> componentElements ) + // { + // if( componentElements == null ) + // throw new NullPointerException( ); + // else if( this.registerData.getObjectData( ).size( ) > 0 ) + // throw new IllegalStateException( ); + // else if( this.key != null && !componentElements.containsAll( this.key ) ) + // throw new IllegalArgumentException( ); + // else + // super.setComponentElements( componentElements ); + // } - @Override - public void removeComponentElement( DataElement componentElement ) - { - if( this.registerData.getObjectData( ).size( ) > 0 ) - throw new IllegalStateException( ); - else - super.removeComponentElement( componentElement ); - } - - @Override - public void setComponentElements( List<? extends DataElement> componentElements ) - { - if( componentElements == null ) - throw new NullPointerException( ); - else if( this.registerData.getObjectData( ).size( ) > 0 ) - throw new IllegalStateException( ); - else if( this.key != null && !componentElements.containsAll( this.key ) ) - throw new IllegalArgumentException( ); - else - super.setComponentElements( componentElements ); - } - /** * @return Returns the key. */ @@ -213,15 +213,15 @@ return this.registerData; } - public Questionnaire getQuestionnaire( ) - { - return this.questionnaire; - } +// public Questionnaire getQuestionnaire( ) +// { +// return (Questionnaire) super.getQuestionnaireElement( ); +// } - public void setQuestionnaire( Questionnaire questionnaire ) - { - this.questionnaire = questionnaire; - } +// public void setQuestionnaire( Questionnaire questionnaire ) +// { +// this.questionnaire = questionnaire; +// } @Override public boolean equals( Object object ) Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-09-29 15:28:51 UTC (rev 73) @@ -31,7 +31,6 @@ import org.surveyforge.core.metadata.domain.AbstractValueDomain; import org.surveyforge.core.survey.Question; -import org.surveyforge.core.survey.QuestionnaireElement; /** * Register data elements define data elements for a register. In contrast to an abstract data element a register data element is @@ -54,8 +53,8 @@ @ManyToOne(optional = true) private Question question; - @OneToOne - private QuestionnaireElement questionnaireElement; +// @OneToOne +// private QuestionnaireElement questionnaireElement; protected RegisterDataElement( ) {}; @@ -182,18 +181,18 @@ /** * @return the questionnaireElement */ - public QuestionnaireElement getQuestionnaireElement( ) - { - return questionnaireElement; - } +// public QuestionnaireElement getQuestionnaireElement( ) +// { +// return questionnaireElement; +// } /** * @param questionnaireElement the questionnaireElement to set */ - public void setQuestionnaireElement( QuestionnaireElement questionnaireElement ) - { - this.questionnaireElement = questionnaireElement; - } +// public void setQuestionnaireElement( QuestionnaireElement questionnaireElement ) +// { +// this.questionnaireElement = questionnaireElement; +// } public AbstractValueDomain getValueDomain( ) { Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-09-29 15:28:51 UTC (rev 73) @@ -22,12 +22,17 @@ package org.surveyforge.core.metadata; import java.io.Serializable; +import java.util.List; +import org.surveyforge.core.metadata.domain.AbstractValueDomain; + /** * @author jsegura */ public interface ValueDomain { public boolean isValid( Serializable object ); + + public List<AbstractValueDomain> getSubDomains( ); } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/AbstractValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/AbstractValueDomain.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/domain/AbstractValueDomain.java 2006-09-29 15:28:51 UTC (rev 73) @@ -22,6 +22,8 @@ package org.surveyforge.core.metadata.domain; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; @@ -59,7 +61,12 @@ {} + public List<AbstractValueDomain> getSubDomains( ) + { + return new ArrayList<AbstractValueDomain>( ); + } + @Override public AbstractValueDomain clone( ) { Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-09-29 15:28:51 UTC (rev 73) @@ -32,20 +32,17 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; -import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.metadata.Register; import org.surveyforge.util.InternationalizedString; + /** * A questionnaire is a list of {@link Question}s used to recollect the data into a register. The questionnaire is included in almost * one {@link Study}. @@ -54,61 +51,38 @@ */ @Entity @Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"identifier", "study_id"})}) -public class Questionnaire implements Serializable +public class Questionnaire extends QuestionnaireElement { - private static final long serialVersionUID = 6844066269698434310L; - - @SuppressWarnings("unused") - @Id - @Column(length = 50) - @GeneratedValue(generator = "system-uuid") - @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; - /** Version for optimistic locking. */ - @SuppressWarnings("unused") - @javax.persistence.Version - private int lockingVersion; - /** - * A questionnaire is identified by an identifier, which is unique in the context of a statistical activity. It may typically be an - * abbreviation of its title or a systematic number. + * */ - @Column(nullable = false, length = 50) - private String identifier; + private static final long serialVersionUID = -357629851050021121L; /** A questionnaire has a title as provided by the owner or maintenance unit. */ @Column(length = 250) - private String title = ""; + private String title = ""; /** * Detailed description of the questionnaire. The questionnaire description typically describes the underlying concept of the * questionnaire and basic principles. */ @Column(length = 500) - private String description = ""; - /** A questionnaire consists of a number of questionnaire elements. Each element refers to a question. */ - @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @IndexColumn(name = "questionnairesIndex") - @JoinColumn(name = "questionnaire_id") - private List<QuestionnaireElement> elements = new ArrayList<QuestionnaireElement>( ); + private String description = ""; + /** A questionnaire may have its content organized in pages. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "pageIndex") // @JoinColumn(name = "questionnaire_page_id") @JoinColumn(name = "questionnaire_page_id") - private List<Feed> pageFeeds = new ArrayList<Feed>( ); + private List<Feed> pageFeeds = new ArrayList<Feed>( ); /** A questionnaire may have its content organized in sections. */ @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "sectionIndex") @JoinColumn(name = "questionnaire_section_id") - private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); + private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); - /** A questionnaire corresponds logically to a register, which describes the content of the data collection. */ - @OneToOne(fetch = FetchType.LAZY) - private Register register; - /** A questionnaire is included in a Study. */ @ManyToOne @JoinColumn(name = "study_id", insertable = false, updatable = false) - private Study study; + private Study study; protected Questionnaire( ) @@ -123,38 +97,17 @@ * @throws NullPointerException If the study is <code>null</code> or if the register is <code>null</code> or if the identifier is * <code>null</code> or is empty. */ - public Questionnaire( String identifier, Study study, Register register ) + public Questionnaire( String identifier, Study study ) { + // super( ); this.setIdentifier( identifier ); + this.registerDataElement = new Register( identifier ); this.setStudy( study ); - this.setRegister( register ); } - /** - * Returns the identifier of the Questionnaire. - * - * @return Returns the identifier. - */ - public String getIdentifier( ) - { - return this.identifier; - } + // } /** - * Sets the identifier of the Questionnaire. - * - * @param identifier The identifier to set. - * @throws NullPointerException If the register is <code>null</code> or if the identifier is <code>null</code> or is empty. - */ - public void setIdentifier( String identifier ) - { - if( identifier != null && !identifier.equals( "" ) ) - this.identifier = identifier; - else - throw new NullPointerException( ); - } - - /** * Returns the title of the questionnaire. * * @return Returns the title. @@ -203,17 +156,6 @@ } /** - * Return the list of {@link QuestionnaireElement}s included in this questionnaire. - * - * @return Returns the elements. - */ - public List<QuestionnaireElement> getElements( ) - { - return Collections.unmodifiableList( this.elements ); - } - - - /** * Adds a new {@link Element} to he Questionnaire. * * @param element The element to add. @@ -223,7 +165,7 @@ { if( element != null ) { - this.elements.add( element ); + super.addElement( element ); if( this.pageFeeds.isEmpty( ) ) this.createPageFeed( element ); if( this.sectionFeeds.isEmpty( ) ) this.createSectionFeed( element ); } @@ -241,7 +183,7 @@ { if( element != null ) { - int indexToRemove = this.elements.indexOf( element ); + int indexToRemove = this.getComponentElements( ).indexOf( element ); if( indexToRemove != -1 ) { Comparator<Feed> feedComparator = new Questionnaire.FeedComparator( ); @@ -252,7 +194,8 @@ if( pageFeedPosition >= 0 ) { this.pageFeeds.remove( pageFeedPosition ); - if( indexToRemove < this.elements.size( ) - 1 ) this.createPageFeed( this.elements.get( indexToRemove + 1 ) ); + if( indexToRemove < this.getComponentElements( ).size( ) - 1 ) + this.createPageFeed( this.getComponentElements( ).get( indexToRemove + 1 ) ); } SectionFeed sectionFeedToRemove = new SectionFeed( element ); @@ -261,11 +204,12 @@ if( sectionFeedPosition >= 0 ) { SectionFeed oldSectionFeed = this.sectionFeeds.remove( sectionFeedPosition ); - if( indexToRemove < this.elements.size( ) - 1 ) - this.createSectionFeed( this.elements.get( indexToRemove + 1 ), oldSectionFeed.getInternationalizedTitle( ) ); + if( indexToRemove < this.getComponentElements( ).size( ) - 1 ) + this + .createSectionFeed( this.getComponentElements( ).get( indexToRemove + 1 ), oldSectionFeed.getInternationalizedTitle( ) ); } - this.elements.remove( element ); + this.delElement( element ); } } else @@ -375,21 +319,23 @@ int pageNumber = this.pageFeeds.indexOf( pageFeed ); int sectionNumber = this.sectionFeeds.indexOf( sectionFeed ); - int firstElementIndex = Math.max( this.elements.indexOf( pageFeed.getFirstElement( ) ), this.elements.indexOf( sectionFeed - .getFirstElement( ) ) ); + int firstElementIndex = Math.max( this.getComponentElements( ).indexOf( pageFeed.getFirstElement( ) ), this + .getComponentElements( ).indexOf( sectionFeed.getFirstElement( ) ) ); - int lastElementInPageIndex = (pageNumber != this.pageFeeds.size( ) - 1) ? this.elements.indexOf( this.pageFeeds.get( - pageNumber + 1 ).getFirstElement( ) ) : Integer.MAX_VALUE; - int lastElementInSectionIndex = (sectionNumber != this.sectionFeeds.size( ) - 1) ? this.elements.indexOf( this.sectionFeeds.get( - sectionNumber + 1 ).getFirstElement( ) ) : Integer.MAX_VALUE; - int lastElementIndex = Math.min( Math.min( lastElementInPageIndex, lastElementInSectionIndex ), this.elements.size( ) ); + int lastElementInPageIndex = (pageNumber != this.pageFeeds.size( ) - 1) ? this.getComponentElements( ).indexOf( + this.pageFeeds.get( pageNumber + 1 ).getFirstElement( ) ) : Integer.MAX_VALUE; + int lastElementInSectionIndex = (sectionNumber != this.sectionFeeds.size( ) - 1) ? this.getComponentElements( ).indexOf( + this.sectionFeeds.get( sectionNumber + 1 ).getFirstElement( ) ) : Integer.MAX_VALUE; + int lastElementIndex = Math.min( Math.min( lastElementInPageIndex, lastElementInSectionIndex ), this.getComponentElements( ) + .size( ) ); - return Collections.unmodifiableList( this.elements.subList( firstElementIndex, lastElementIndex ) ); + return Collections.unmodifiableList( this.getComponentElements( ).subList( firstElementIndex, lastElementIndex ) ); } else throw new IllegalArgumentException( ); } + /** * Returns the {@link Register} of the questionnaire. * @@ -397,22 +343,9 @@ */ public Register getRegister( ) { - return this.register; + return (Register) this.getRegisterDataElement( ); } - /** - * Sets the register of the Questionnaire. - * - * @param register The register to set. - * @throws NullPointerException If the register is <code>null</code> - */ - public void setRegister( Register register ) - { - if( register != null ) - this.register = register; - else - throw new NullPointerException( ); - } /** * Return the study his questionnaire belongs to. @@ -461,8 +394,8 @@ public int compare( Feed feed1, Feed feed2 ) { - Integer firstPosition = Questionnaire.this.getElements( ).indexOf( feed1.getFirstElement( ) ); - Integer secondPosition = Questionnaire.this.getElements( ).indexOf( feed2.getFirstElement( ) ); + Integer firstPosition = Questionnaire.this.getComponentElements( ).indexOf( feed1.getFirstElement( ) ); + Integer secondPosition = Questionnaire.this.getComponentElements( ).indexOf( feed2.getFirstElement( ) ); return firstPosition.compareTo( secondPosition ); } } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-09-29 15:28:51 UTC (rev 73) @@ -32,6 +32,8 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -42,8 +44,9 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.metadata.RegisterDataElement; +import org.surveyforge.core.metadata.domain.AbstractValueDomain; +import org.surveyforge.core.metadata.domain.StructuredValueDomain; - /** * A questionnaire element is the link between the {@link Question} of the {@link Questionnaire} and the metadata layer represented by * the {@link RegisterDataElement}. @@ -51,10 +54,11 @@ * @author jsegura */ @Entity -@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"identifier", "questionnaire_id"})}) +@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"identifier", "upperElement_id"})}) +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class QuestionnaireElement implements Serializable { - private static final long serialVersionUID = -5920656314181190011L; + private static final long serialVersionUID = -5920656314181190011L; @SuppressWarnings("unused") @@ -68,59 +72,44 @@ @javax.persistence.Version private int lockingVersion; - /** A questionnaire element is identified by a unique identifier. */ + /** A SurveyElement is identified by a unique identifier. */ @Column(unique = true, length = 50) private String identifier; + /** Each questionnaire element has a {@link Question} that has the text and the structure of the question. */ @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - private Question question = null; + private Question question = null; /** A questionnaire element have a {@link RegisterDataElement} to have the info of the data. */ - @OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - private RegisterDataElement registerDataElement; + @OneToOne(cascade = {CascadeType.ALL}) + protected RegisterDataElement registerDataElement; /** Default answer if the question is not applicable. */ @Column(length = 50) - private String defaultNotApplicable = ""; + private String defaultNotApplicable = ""; /** Default answer if the question is not answered. */ @Column(length = 50) - private String defaultNotAnswered = ""; - /** This is the question that acts as a frame for a number of sub questions. */ + private String defaultNotAnswered = ""; + @ManyToOne - @JoinColumn(name = "upperQuestionnaireElement_id", insertable = false, updatable = false) - private QuestionnaireElement upperQuestionnaireElement = null; - /** A question referring to a complex fact can be divided in a number of sub questions. */ + @JoinColumn(name = "upperElement_id", insertable = false, updatable = false) + private QuestionnaireElement upperElement = null; + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @IndexColumn(name = "subQuestionnaireElementsIndex") - @JoinColumn(name = "upperQuestionnaireElement_id") - private List<QuestionnaireElement> subQuestionnaireElements = new ArrayList<QuestionnaireElement>( ); + @IndexColumn(name = "componentElementsIndex") + @JoinColumn(name = "upperElement_id") + private List<QuestionnaireElement> componentElements = new ArrayList<QuestionnaireElement>( ); protected QuestionnaireElement( ) {} - /** - * Creates a new instance of a QuestionnaireElement linked to the registerDataElement and identified by identifier. - * - * @param registerDataElement The {@link RegisterDataElement} the questionnaire element is linked to. - * @param identifier The identifier of the questionnaire element. - * @throws NullPointerException If the registerDataElement or the identifier are <code>null</code> and if the identifier is empty. - */ - public QuestionnaireElement( RegisterDataElement registerDataElement ) + public QuestionnaireElement( String identifier, AbstractValueDomain valueDomain ) { - this.setRegisterDataElement( registerDataElement ); - this.setIdentifier( registerDataElement.getIdentifier( ) ); + this.setIdentifier( identifier ); + this.registerDataElement = new RegisterDataElement( identifier, valueDomain ); } - public QuestionnaireElement( RegisterDataElement registerDataElement, QuestionnaireElement upperElement ) - { - this( registerDataElement ); - this.setUpperQuestionnaireElement( upperElement ); - } - - - /** - * Returns the identifier of the questionnaire element. - * - * @return Returns the identifier. + /* + * Returns the identifier of the SurveyElement. @return Returns the identifier. */ public String getIdentifier( ) { @@ -128,12 +117,12 @@ } /** - * Sets a new identifier for the questionnaire element. + * Sets the identifier of the SurveyElement. * * @param identifier The identifier to set. - * @throws NullPointerException If the identifier is <code>null</code> and if the identifier is empty. + * @throws NullPointerException If the register is <code>null</code> or if the identifier is <code>null</code> or is empty. */ - protected void setIdentifier( String identifier ) + public void setIdentifier( String identifier ) { if( identifier != null && !identifier.equals( "" ) ) this.identifier = identifier; @@ -162,7 +151,7 @@ } /** - * Return the {@link RegisterDataElement} this questionnaire element is linked to. + * / * Return the {@link RegisterDataElement} this questionnaire element is linked to. * * @return Returns the registerDataElement. */ @@ -172,29 +161,6 @@ } /** - * Sets a the new {@link RegisterDataElement} this questionnaire element is linked to. - * - * @param registerDataElement The registerDataElement to set. - * @throws If the registerDataElement is <code>null</code>; - */ - protected void setRegisterDataElement( RegisterDataElement registerDataElement ) - { - if( registerDataElement != null ) - { - // TODO remove old elements - this.registerDataElement = registerDataElement; - registerDataElement.setQuestionnaireElement( this ); - for( int i = 0; i < registerDataElement.getComponentElements( ).size( ); i++ ) - { - this.addSubQuestionnaireElement( new QuestionnaireElement( (RegisterDataElement) (registerDataElement.getComponentElements( ) - .get( i )) ) ); - } - } - else - throw new NullPointerException( ); - } - - /** * Returns the default answer for not applicable questions. * * @return Returns the default answer for not applicable questions. @@ -242,43 +208,91 @@ throw new NullPointerException( ); } - - public QuestionnaireElement getUpperQuestionnaireElement( ) + protected void setUpperElement( QuestionnaireElement upperElement ) { - return this.upperQuestionnaireElement; + if( this.getUpperElement( ) != null ) this.getUpperElement( ).removeElement( this ); + this.upperElement = upperElement; + if( this.getUpperElement( ) != null ) this.getUpperElement( ).addElement( this ); } - public void setUpperQuestionnaireElement( QuestionnaireElement upperQuestionnaireElement ) + public QuestionnaireElement getUpperElement( ) { - if( this.upperQuestionnaireElement != null ) this.upperQuestionnaireElement.removeSubQuestionnaireElement( this ); - this.upperQuestionnaireElement = upperQuestionnaireElement; - if( this.upperQuestionnaireElement != null ) this.upperQuestionnaireElement.addSubQuestionnaireElement( this ); + return this.upperElement; } - private void removeSubQuestionnaireElement( QuestionnaireElement subQuestionnaireElement ) + public List<QuestionnaireElement> getComponentElements( ) { - if( subQuestionnaireElement != null ) - this.subQuestionnaireElements.remove( subQuestionnaireElement ); + return Collections.unmodifiableList( this.componentElements ); + } + + /** + * @param componentElements The componentElements to set. + */ + public void addComponentElement( QuestionnaireElement componentElement ) + { + if( componentElement != null ) + { + if( !this.getComponentElements( ).contains( componentElement ) + && this.getRegisterDataElement( ).getValueDomain( ) instanceof StructuredValueDomain ) + { + componentElement.setUpperElement( this ); + // ((StructuredValueDomain) this.getValueDomain( )).addSubDomain( componentElement.getValueDomain( ) ); + } + else + throw new IllegalArgumentException( ); + } else throw new NullPointerException( ); } - public List<QuestionnaireElement> getSubQuestionnaireElementss( ) + + /** + * @param componentElement + */ + protected void addElement( QuestionnaireElement componentElement ) { - return Collections.unmodifiableList( this.subQuestionnaireElements ); + if( componentElement == null ) throw new NullPointerException( ); + if( this.getRegisterDataElement( ).getValueDomain( ) instanceof StructuredValueDomain ) + { + this.componentElements.add( componentElement ); + componentElement.upperElement = this; + this.getRegisterDataElement( ).addComponentElement( componentElement.getRegisterDataElement( ) ); + } + else + throw new IllegalArgumentException( ); } - - private void addSubQuestionnaireElement( QuestionnaireElement subQuestionnaireElement ) + /** + * @param componentElements The componentElements to set. + */ + public void removeComponentElement( QuestionnaireElement componentElement ) { - if( subQuestionnaireElement != null ) - this.subQuestionnaireElements.add( subQuestionnaireElement ); + if( componentElement != null ) + { + componentElement.setUpperElement( null ); + } else throw new NullPointerException( ); } + /** + * @param componentElement + */ + protected void removeElement( QuestionnaireElement componentElement ) + { + if( componentElement == null ) throw new NullPointerException( ); + if( this.getRegisterDataElement( ).getValueDomain( ) instanceof StructuredValueDomain ) + { + this.componentElements.remove( componentElement ); + componentElement.upperElement = null; + this.getRegisterDataElement( ).removeComponentElement( componentElement.getRegisterDataElement( ) ); + } + else + throw new IllegalArgumentException( ); + } + // TODO : Equals+hashcode // @Override // public boolean equals( Object object ) @@ -293,5 +307,4 @@ // { // return this.getStudy( ).hashCode( ) ^ this.getIdentifier( ).hashCode( ); // } - } Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/DataElementTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/DataElementTest.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/DataElementTest.java 2006-09-29 15:28:51 UTC (rev 73) @@ -66,8 +66,7 @@ public void RegisterDataElementCreationWithNullIdentifier( ) { LogicalValueDomain lvd = new LogicalValueDomain( ); - RegisterDataElement rde = new RegisterDataElement( null, lvd ); - + new RegisterDataElement( null, lvd ); } @Test @@ -75,9 +74,6 @@ public void RegisterCreationWithNullDomain( ) { LogicalValueDomain lvd = null; - RegisterDataElement rde = new RegisterDataElement( "id", lvd ); - + new RegisterDataElement( "id", lvd ); } - - } Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/RegisterTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/RegisterTest.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/RegisterTest.java 2006-09-29 15:28:51 UTC (rev 73) @@ -27,14 +27,14 @@ @ExpectedExceptions( {NullPointerException.class}) public void RegisterCreationWithNullIdentifier( ) { - Register register = new Register( null ); + new Register( null ); } @Test @ExpectedExceptions( {NullPointerException.class}) public void RegisterCreationWithEmptyIdentifier( ) { - Register register = new Register( "" ); + new Register( "" ); } Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java 2006-09-29 15:28:51 UTC (rev 73) @@ -29,7 +29,10 @@ import org.surveyforge.core.metadata.RegisterDataElement; import org.surveyforge.core.metadata.StatisticalObjectType; import org.surveyforge.core.metadata.domain.LogicalValueDomain; +import org.surveyforge.core.metadata.domain.StructuredValueDomain; +import org.testng.Assert; import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; /** * @author jsegura @@ -47,4 +50,27 @@ RegisterDataElement registerDataElement = new RegisterDataElement( "registerDataElement", conceptualDataElement ); return new Object[][] {new Object[] {registerDataElement}}; } + + @Test + public void Test( ) + { + + + QuestionnaireElement upperQE = new QuestionnaireElement( "upperQE", new StructuredValueDomain( ) ); + QuestionnaireElement q1 = new QuestionnaireElement( "qe1", new LogicalValueDomain( ) ); + QuestionnaireElement q2 = new QuestionnaireElement( "qe2", new LogicalValueDomain( ) ); + QuestionnaireElement q3 = new QuestionnaireElement( "qe3", new LogicalValueDomain( ) ); + QuestionnaireElement q4 = new QuestionnaireElement( "qe4", new LogicalValueDomain( ) ); + QuestionnaireElement q5 = new QuestionnaireElement( "qe5", new LogicalValueDomain( ) ); + upperQE.addComponentElement( q1 ); + upperQE.addComponentElement( q2 ); + upperQE.addComponentElement( q3 ); + upperQE.addComponentElement( q4 ); + upperQE.addComponentElement( q5 ); + Assert.assertEquals( 5, upperQE.getComponentElements( ).size( ) ); + Assert.assertEquals( 5, upperQE.getRegisterDataElement( ).getComponentElements( ).size( ) ); + Assert.assertEquals( 5, upperQE.getRegisterDataElement( ).getValueDomain( ).getSubDomains( ).size( ) ); + + + } } Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java 2006-09-21 13:56:29 UTC (rev 72) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java 2006-09-29 15:28:51 UTC (rev 73) @@ -21,7 +21,6 @@ */ package org.surveyforge.core.survey; -import org.surveyforge.core.metadata.Register; import org.testng.Assert; import org.testng.annotations.ExpectedExceptions; import org.testng.annotations.Test; @@ -35,35 +34,28 @@ @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithNullIdentifier( ) { - new Questionnaire( null, new Study( "id" ), new Register( "id" ) ); + new Questionnaire( null, new Study( "id" ) ); } @Test @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithEmptyIdentifier( ) { - new Questionnaire( "", new Study( "id" ), new Register( "id" ) ); + new Questionnaire( "", new Study( "id" ) ); } @Test @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithNullStudy( ) { - new Questionnaire( "id", null, new Register( "id" ) ); + new Questionnaire( "id", null ); } @Test - @ExpectedExceptions( {NullPointerException.class}) - public void questionnaireCreationWithNullRegister( ) - { - new Questionnaire( "id", new Study( "id" ), null ); - } - - @Test public void questionnaireGetIdentifier( ) { String id = "id"; - Questionnaire questionnaire = new Questionnaire( id, new Study( "id" ), new Register( "id" ) ); + Questionnaire questionnaire = new Questionnaire( id, new Study( "id" ) ); Assert.assertEquals( questionnaire.getIdentifier( ), id ); } @@ -72,14 +64,14 @@ public void questionnaireSetNullTitle( ) { - new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ).setTitle( null ); + new Questionnaire( "id", new Study( "id" ) ).setTitle( null ); } @Test public void questionnaireGetTitle( ) { - Questionnaire questionnaire = new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ); + Questionnaire questionnaire = new Questionnaire( "id", new Study( "id" ) ); questionnaire.setTitle( "title" ); Assert.assertEquals( questionnaire.getTitle( ), "title" ); } @@ -88,7 +80,7 @@ @ExpectedExceptions( {NullPointerException.class}) public void questionnaireSetNullDescription( ) { - new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ).setDescription( null ); + new Questionnaire( "id", new Study( "id" ) ).setDescription( null ); } @Test @@ -96,7 +88,7 @@ { String empty = ""; String desc = "desc"; - Questionnaire obj = new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ); + Questionnaire obj = new Questionnaire( "id", new Study( "id" ) ); obj.setDescription( desc ); Assert.assertTrue( obj.getDescription( ).equals( desc ) ); Assert.assertFalse( obj.getDescription( ).equals( "test" ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-09-21 13:56:35
|
Revision: 72 http://svn.sourceforge.net/surveyforge/?rev=72&view=rev Author: javism Date: 2006-09-21 06:56:29 -0700 (Thu, 21 Sep 2006) Log Message: ----------- Small fixes caused by the changes in revision 71 of Questionnaire.java Revision Links: -------------- http://svn.sourceforge.net/surveyforge/?rev=71&view=rev Modified Paths: -------------- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java 2006-09-21 13:16:44 UTC (rev 71) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java 2006-09-21 13:56:29 UTC (rev 72) @@ -35,35 +35,35 @@ @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithNullIdentifier( ) { - new Questionnaire( new Study( "id" ), new Register( "id" ), null ); + new Questionnaire( null, new Study( "id" ), new Register( "id" ) ); } @Test @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithEmptyIdentifier( ) { - new Questionnaire( new Study( "id" ), new Register( "id" ), "" ); + new Questionnaire( "", new Study( "id" ), new Register( "id" ) ); } @Test @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithNullStudy( ) { - new Questionnaire( null, new Register( "id" ), "id" ); + new Questionnaire( "id", null, new Register( "id" ) ); } @Test @ExpectedExceptions( {NullPointerException.class}) public void questionnaireCreationWithNullRegister( ) { - new Questionnaire( new Study( "id" ), null, "id" ); + new Questionnaire( "id", new Study( "id" ), null ); } @Test public void questionnaireGetIdentifier( ) { String id = "id"; - Questionnaire questionnaire = new Questionnaire( new Study( "id" ), new Register( "id" ), id ); + Questionnaire questionnaire = new Questionnaire( id, new Study( "id" ), new Register( "id" ) ); Assert.assertEquals( questionnaire.getIdentifier( ), id ); } @@ -72,14 +72,14 @@ public void questionnaireSetNullTitle( ) { - new Questionnaire( new Study( "id" ), new Register( "id" ), "id" ).setTitle( null ); + new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ).setTitle( null ); } @Test public void questionnaireGetTitle( ) { - Questionnaire questionnaire = new Questionnaire( new Study( "id" ), new Register( "id" ), "id" ); + Questionnaire questionnaire = new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ); questionnaire.setTitle( "title" ); Assert.assertEquals( questionnaire.getTitle( ), "title" ); } @@ -88,7 +88,7 @@ @ExpectedExceptions( {NullPointerException.class}) public void questionnaireSetNullDescription( ) { - new Questionnaire( new Study( "id" ), new Register( "id" ), "id" ).setDescription( null ); + new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ).setDescription( null ); } @Test @@ -96,7 +96,7 @@ { String empty = ""; String desc = "desc"; - Questionnaire obj = new Questionnaire( new Study( "id" ), new Register( "id" ), "id" ); + Questionnaire obj = new Questionnaire( "id", new Study( "id" ), new Register( "id" ) ); obj.setDescription( desc ); Assert.assertTrue( obj.getDescription( ).equals( desc ) ); Assert.assertFalse( obj.getDescription( ).equals( "test" ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-09-21 13:16:50
|
Revision: 71 http://svn.sourceforge.net/surveyforge/?rev=71&view=rev Author: javism Date: 2006-09-21 06:16:44 -0700 (Thu, 21 Sep 2006) Log Message: ----------- Fixed the parameters order in constructor. Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-09-20 15:28:07 UTC (rev 70) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-09-21 13:16:44 UTC (rev 71) @@ -123,11 +123,11 @@ * @throws NullPointerException If the study is <code>null</code> or if the register is <code>null</code> or if the identifier is * <code>null</code> or is empty. */ - public Questionnaire( Study study, Register register, String identifier ) + public Questionnaire( String identifier, Study study, Register register ) { + this.setIdentifier( identifier ); this.setStudy( study ); this.setRegister( register ); - this.setIdentifier( identifier ); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-09-20 15:28:40
|
Revision: 70 http://svn.sourceforge.net/surveyforge/?rev=70&view=rev Author: jgongo Date: 2006-09-20 08:28:07 -0700 (Wed, 20 Sep 2006) Log Message: ----------- First (very alpha) version of runner taking data from database Modified Paths: -------------- trunk/surveyforge-runner/pom.xml trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java Added Paths: ----------- trunk/surveyforge-runner/src/main/filters/ trunk/surveyforge-runner/src/main/filters/database.properties trunk/surveyforge-runner/src/main/resources/META-INF/ trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml trunk/surveyforge-runner/src/main/resources/hibernate-entitymanager.jar trunk/surveyforge-runner/src/main/resources/javassist.jar trunk/surveyforge-runner/src/main/resources/jboss-archive-browsing.jar Modified: trunk/surveyforge-runner/pom.xml =================================================================== --- trunk/surveyforge-runner/pom.xml 2006-09-20 15:26:41 UTC (rev 69) +++ trunk/surveyforge-runner/pom.xml 2006-09-20 15:28:07 UTC (rev 70) @@ -9,6 +9,15 @@ <artifactId>surveyforge-runner</artifactId> <name>SurveyForge questionnaire runner</name> <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <filters> + <filter>src/main/filters/database.properties</filter> + </filters> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> @@ -56,11 +65,17 @@ <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> </dependency> + <!-- <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-annotations</artifactId> + <groupId>hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> </dependency> + --> <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> </dependency> Added: trunk/surveyforge-runner/src/main/filters/database.properties =================================================================== --- trunk/surveyforge-runner/src/main/filters/database.properties (rev 0) +++ trunk/surveyforge-runner/src/main/filters/database.properties 2006-09-20 15:28:07 UTC (rev 70) @@ -0,0 +1,5 @@ +database.dialect=org.hibernate.dialect.PostgreSQLDialect +database.driver=org.postgresql.Driver +database.url=jdbc:postgresql://localhost/surveyforge +database.username=postgres +database.password=postgres Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-09-20 15:26:41 UTC (rev 69) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-09-20 15:28:07 UTC (rev 70) @@ -151,7 +151,10 @@ } pageSectionPanelBuilder.nextColumn( ); // Needed to place cursor in correct column - pageSectionPanelBuilder.addLabel( element.getQuestion( ).getText( ) ); + if( element.getQuestion( ) != null ) + pageSectionPanelBuilder.addLabel( element.getQuestion( ).getText( ) ); + else + pageSectionPanelBuilder.nextColumn( 1 ); pageSectionPanelBuilder.nextColumn( 2 ); pageSectionPanelBuilder.add( this.createDataEntryComponent( element ) ); } @@ -196,9 +199,9 @@ final ClassificationValueDomain classificationValueDomain = (ClassificationValueDomain) valueDomain; JPanel classificationPanel = new JPanel( new FlowLayout( FlowLayout.LEFT ) ); // JComboBox classificationCombo = new JComboBox( classificationValueDomain.getLevel( ).getItems( ).toArray( ) ); - JComboBox classificationCombo = new JComboBox( - new ComboBoxAdapter( classificationValueDomain.getLevel( ).getItems( ), new QuestionnaireFrame.ClassificationConverter( - classificationValueDomain.getLevel( ), this.dataModel.getModel( propertyName ) ) ) ); + JComboBox classificationCombo = new JComboBox( new ComboBoxAdapter( classificationValueDomain.getLevel( ).getItems( ), + new QuestionnaireFrame.ClassificationConverter( classificationValueDomain.getLevel( ), this.dataModel + .getModel( propertyName ) ) ) ); // JTextField classificationCode = new JTextField( 5 ); final JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); @@ -232,10 +235,6 @@ return verify( input ); } } ); - // JFormattedTextField classificationCode = new JFormattedTextField( new QuestionnaireFrame.ClassificationFormatter( - // classificationValueDomain.getLevel( ) ) ); - // PropertyConnector propertyConnector = new PropertyConnector( this.dataModel.getModel( "sexo" ), "value", classificationCode, - // "value" ); classificationPanel.add( classificationCombo ); classificationPanel.add( classificationCode ); Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-09-20 15:26:41 UTC (rev 69) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-09-20 15:28:07 UTC (rev 70) @@ -21,51 +21,21 @@ */ package org.surveyforge.runner; -import java.util.Arrays; -import java.util.GregorianCalendar; - +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; import javax.swing.JFrame; import javax.swing.UIManager; -import org.surveyforge.classification.Classification; -import org.surveyforge.classification.Family; -import org.surveyforge.classification.Item; -import org.surveyforge.classification.Level; -import org.surveyforge.classification.Version; -import org.surveyforge.core.metadata.Register; -import org.surveyforge.core.metadata.RegisterDataElement; -import org.surveyforge.core.metadata.domain.AbstractValueDomain; -import org.surveyforge.core.metadata.domain.ClassificationValueDomain; -import org.surveyforge.core.metadata.domain.QuantityValueDomain; -import org.surveyforge.core.metadata.domain.StructuredValueDomain; -import org.surveyforge.core.survey.Question; import org.surveyforge.core.survey.Questionnaire; -import org.surveyforge.core.survey.QuestionnaireElement; -import org.surveyforge.core.survey.Study; /** * @author jgonzalez */ public class QuestionnaireRunner { - public static Classification SEXO; - - static - { - GregorianCalendar calendar = new GregorianCalendar( ); - calendar.clear( ); - calendar.set( 2006, 0, 1 ); - - Family ceescat_hivudvp = new Family( "ceescat-hivudvp" ); - - QuestionnaireRunner.SEXO = new Classification( ceescat_hivudvp, "hivudvp-sexo" ); - Version sexoV = new Version( QuestionnaireRunner.SEXO, "sexo V1", calendar.getTime( ) ); - Level sexoL = new Level( sexoV, "sexo L1" ); - new Item( sexoL, null, "1", "Hombre" ); - new Item( sexoL, null, "2", "Mujer" ); - new Item( sexoL, null, "3", "Transexual" ); - } - public static void main( String[] args ) { try @@ -78,128 +48,31 @@ // Likely PlasticXP is not in the class path; ignore. } - QuestionnaireFrame questionnaireFrame = new QuestionnaireFrame( QuestionnaireRunner.getQuestionnaire( ) ); - questionnaireFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); - questionnaireFrame.pack( ); - questionnaireFrame.setVisible( true ); - } - - public static Questionnaire getQuestionnaire( ) - { - Level sexoL = QuestionnaireRunner.SEXO.getCurrentVersion( ).getLevels( ).get( 0 ); - - Register register = new Register( "register" ); - register.setIdentifier( "registroPrueba" ); - - AbstractValueDomain mesNacimientoValueDomain = new QuantityValueDomain( 2, 0 ); - AbstractValueDomain anyoNacimientoValueDomain = new QuantityValueDomain( 4, 0 ); - StructuredValueDomain fechaNacimientoValueDomain = new StructuredValueDomain( ); - fechaNacimientoValueDomain.addSubDomain( mesNacimientoValueDomain ); - fechaNacimientoValueDomain.addSubDomain( anyoNacimientoValueDomain ); - - RegisterDataElement mesNacimiento = new RegisterDataElement( "mesNacimiento", mesNacimientoValueDomain ); - RegisterDataElement anyoNacimiento = new RegisterDataElement( "anyoNacimiento", anyoNacimientoValueDomain ); -// RegisterDataElement fechaNacimiento = new RegisterDataElement( "fechaNacimiento", fechaNacimientoValueDomain ); -// fechaNacimiento.addComponentElement( mesNacimiento ); -// fechaNacimiento.addComponentElement( anyoNacimiento ); - RegisterDataElement sexo = new RegisterDataElement( "sexo", new ClassificationValueDomain( sexoL ) ); - -// register.setComponentElements( Arrays.asList( new RegisterDataElement[] {fechaNacimiento, sexo} ) ); - register.setComponentElements( Arrays.asList( new RegisterDataElement[] {mesNacimiento, anyoNacimiento, sexo} ) ); - - Study study = new Study( "study" ); - Questionnaire questionnaire = new Questionnaire( study, register, "questionnaire" ); - - Question pMesNacimiento = new Question( "pMesNacimiento" ); - pMesNacimiento.setText( "En qué mes naciste?" ); - QuestionnaireElement qMesNacimiento = new QuestionnaireElement( mesNacimiento ); - qMesNacimiento.setQuestion( pMesNacimiento ); - questionnaire.addElement( qMesNacimiento ); - - Question pAnyoNacimiento = new Question( "pAnyoNacimiento" ); - pAnyoNacimiento.setText( "En qué año naciste?" ); - QuestionnaireElement qAnyoNacimiento = new QuestionnaireElement( anyoNacimiento ); - qAnyoNacimiento.setQuestion( pAnyoNacimiento ); - questionnaire.addElement( qAnyoNacimiento ); - - Question pSexo = new Question( "pSexo" ); - pSexo.setText( "Sexo" ); - QuestionnaireElement qSexo = new QuestionnaireElement( sexo ); - qSexo.setQuestion( pSexo ); - questionnaire.addElement( qSexo ); - - return questionnaire; - } - - public static class TempQuestionnaire - { - private int mesNacimiento = 1; - private int anyoNacimiento = 1985; - // private QuestionnaireRunner.TempSexo sexo = new QuestionnaireRunner.TempSexo( ); - - private String sexo = QuestionnaireRunner.SEXO.getCurrentVersion( ).getLevels( ).get( 0 ).getItems( ).get( 2 ).getCode( ); - - public String getSexo( ) + EntityManager entityManager = null; + EntityTransaction transaction = null; + QuestionnaireFrame questionnaireFrame = null; + try { - System.out.println( "Devolviendo valor sexo: " + sexo ); - return sexo; - } + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory( "hivudvp" ); + entityManager = entityManagerFactory.createEntityManager( ); + transaction = entityManager.getTransaction( ); + transaction.begin( ); - public void setSexo( String sexo ) - { - System.out.println( "Nuevo valor sexo: " + sexo ); - this.sexo = sexo; + Query questionnaireQuery = entityManager.createQuery( "FROM Questionnaire q WHERE q.identifier = :questionnaireIdentifier" ); + questionnaireQuery.setParameter( "questionnaireIdentifier", args[0] ); + if( !questionnaireQuery.getResultList( ).isEmpty( ) ) + { + questionnaireFrame = new QuestionnaireFrame( (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); + questionnaireFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); + questionnaireFrame.pack( ); + } } - - public int getMesNacimiento( ) + finally { - System.out.println( "Devolviendo valor mes: " + mesNacimiento ); - return mesNacimiento; + if( transaction != null ) transaction.commit( ); + if( entityManager != null ) entityManager.close( ); } - public void setMesNacimiento( int mesNacimiento ) - { - System.out.println( "Nuevo valor mes: " + mesNacimiento ); - this.mesNacimiento = mesNacimiento; - } - - public int getAnyoNacimiento( ) - { - System.out.println( "Devolviendo valor anyo: " + anyoNacimiento ); - return anyoNacimiento; - } - - public void setAnyoNacimiento( int anyoNacimiento ) - { - System.out.println( "Nuevo valor anyo: " + anyoNacimiento ); - this.anyoNacimiento = anyoNacimiento; - } - - // public QuestionnaireRunner.TempSexo getSexo( ) - // { - // return sexo; - // } - // - // public void setSexo( QuestionnaireRunner.TempSexo sexo ) - // { - // this.sexo = sexo; - // } + if( questionnaireFrame != null ) questionnaireFrame.setVisible( true ); } - - public static class TempSexo - { - private String sexo = QuestionnaireRunner.SEXO.getCurrentVersion( ).getLevels( ).get( 0 ).getItems( ).get( 2 ).getCode( ); - - public String getSexo( ) - { - System.out.println( "Devolviendo valor sexo: " + sexo ); - return sexo; - } - - public void setSexo( String sexo ) - { - System.out.println( "Nuevo valor sexo: " + sexo ); - this.sexo = sexo; - } - } } Added: trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml =================================================================== --- trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml (rev 0) +++ trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml 2006-09-20 15:28:07 UTC (rev 70) @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + <persistence-unit name="hivudvp"> + <class>org.surveyforge.util.InternationalizedString</class> + + <class>org.surveyforge.classification.Family</class> + <class>org.surveyforge.classification.Classification</class> + <class>org.surveyforge.classification.Version</class> + <class>org.surveyforge.classification.Level</class> + <class>org.surveyforge.classification.Item</class> + + <class>org.surveyforge.core.survey.Study</class> + <class>org.surveyforge.core.survey.Questionnaire</class> + <class>org.surveyforge.core.survey.QuestionnaireElement</class> + <class>org.surveyforge.core.survey.Question</class> + <class>org.surveyforge.core.survey.Feed</class> + <class>org.surveyforge.core.survey.SectionFeed</class> + + <class>org.surveyforge.core.metadata.ValidationRule</class> + <class>org.surveyforge.core.metadata.Register</class> + <class>org.surveyforge.core.metadata.RegisterDataElement</class> + <class>org.surveyforge.core.metadata.ConceptualDataElement</class> + <class>org.surveyforge.core.metadata.DataElement</class> + <class>org.surveyforge.core.metadata.QuestionDataElement</class> + <class>org.surveyforge.core.metadata.ValueDomain</class> + <class>org.surveyforge.core.metadata.ObjectVariable</class> + <class>org.surveyforge.core.metadata.GlobalVariable</class> + <class>org.surveyforge.core.metadata.VariableFamily</class> + <class>org.surveyforge.core.metadata.StatisticalObjectType</class> + + <class>org.surveyforge.core.metadata.domain.ClassificationValueDomain</class> + <class>org.surveyforge.core.metadata.domain.LogicalValueDomain</class> + <class>org.surveyforge.core.metadata.domain.QuantityValueDomain</class> + <class>org.surveyforge.core.metadata.domain.StringValueDomain</class> + <class>org.surveyforge.core.metadata.domain.StructuredValueDomain</class> + <class>org.surveyforge.core.metadata.domain.AbstractValueDomain</class> + + <class>org.surveyforge.core.data.RegisterData</class> + <class>org.surveyforge.core.data.ObjectData</class> + <class>org.surveyforge.core.data.Data</class> + + <!-- + <properties> + <property name="hibernate.dialect" value="${database.dialect}" /> + <property name="hibernate.connection.driver_class" value="${database.driver}" /> + <property name="hibernate.connection.url" value="${database.url}" /> + <property name="hibernate.connection.username" value="${database.username}" /> + <property name="hibernate.connection.password" value="${database.password}" /> + </properties> + --> + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> + <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /> + <property name="hibernate.connection.url" value="jdbc:postgresql://localhost/surveyforge" /> + <property name="hibernate.connection.username" value="postgres" /> + <property name="hibernate.connection.password" value="postgres" /> + </properties> + </persistence-unit> +</persistence> \ No newline at end of file Property changes on: trunk/surveyforge-runner/src/main/resources/META-INF/persistence.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-runner/src/main/resources/hibernate-entitymanager.jar =================================================================== (Binary files differ) Property changes on: trunk/surveyforge-runner/src/main/resources/hibernate-entitymanager.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/surveyforge-runner/src/main/resources/javassist.jar =================================================================== (Binary files differ) Property changes on: trunk/surveyforge-runner/src/main/resources/javassist.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/surveyforge-runner/src/main/resources/jboss-archive-browsing.jar =================================================================== (Binary files differ) Property changes on: trunk/surveyforge-runner/src/main/resources/jboss-archive-browsing.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-09-20 15:26:48
|
Revision: 69 http://svn.sourceforge.net/surveyforge/?rev=69&view=rev Author: jgongo Date: 2006-09-20 08:26:41 -0700 (Wed, 20 Sep 2006) Log Message: ----------- PostgreSQL driver dependency Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-09-20 15:25:21 UTC (rev 68) +++ trunk/pom.xml 2006-09-20 15:26:41 UTC (rev 69) @@ -306,6 +306,12 @@ </exclusions> </dependency> <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>8.1-407.jdbc3</version> + <scope>runtime</scope> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> <version>2.0.4</version> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-09-20 15:25:28
|
Revision: 68 http://svn.sourceforge.net/surveyforge/?rev=68&view=rev Author: jgongo Date: 2006-09-20 08:25:21 -0700 (Wed, 20 Sep 2006) Log Message: ----------- Eager fetch of internationalized strings Modified Paths: -------------- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java Modified: trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java =================================================================== --- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-09-20 14:52:55 UTC (rev 67) +++ trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-09-20 15:25:21 UTC (rev 68) @@ -30,6 +30,7 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -57,7 +58,7 @@ @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; - @CollectionOfElements + @CollectionOfElements(fetch = FetchType.EAGER) @MapKey(columns = {@Column(name = "locale", length = 25)}) @Column(name = "string", length = 2500) private Map<Locale, String> strings = new HashMap<Locale, String>( ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-09-20 14:53:04
|
Revision: 67 http://svn.sourceforge.net/surveyforge/?rev=67&view=rev Author: javism Date: 2006-09-20 07:52:55 -0700 (Wed, 20 Sep 2006) Log Message: ----------- Bugfix in QuestionnaireElement-Question relation Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-09-20 13:41:39 UTC (rev 66) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-09-20 14:52:55 UTC (rev 67) @@ -72,8 +72,7 @@ @Column(unique = true, length = 50) private String identifier; /** Each questionnaire element has a {@link Question} that has the text and the structure of the question. */ - @ManyToOne(optional = true, cascade = {CascadeType.ALL}) - @JoinColumn(name = "question_id", insertable = false, updatable = false) + @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) private Question question = null; /** A questionnaire element have a {@link RegisterDataElement} to have the info of the data. */ @OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |