You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/11/05 05:00:15 UTC

svn commit: r471356 - in /tapestry/tapestry4/trunk: ./ .settings/ tapestry-framework/src/java/org/apache/tapestry/form/ tapestry-framework/src/test/org/apache/tapestry/form/

Author: jkuhnert
Date: Sat Nov  4 20:00:14 2006
New Revision: 471356

URL: http://svn.apache.org/viewvc?view=rev&rev=471356
Log:
Added new EnumPropertySelectionModel.

Added:
    tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.apt.core.prefs
    tapestry/tapestry4/trunk/.settings/org.eclipse.ltk.core.refactoring.prefs
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestEnumPropertySelectionModel.java
Modified:
    tapestry/tapestry4/trunk/.classpath
    tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.core.prefs
    tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs

Modified: tapestry/tapestry4/trunk/.classpath
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.classpath?view=diff&rev=471356&r1=471355&r2=471356
==============================================================================
Binary files - no diff available.

Added: tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.apt.core.prefs
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.apt.core.prefs?view=auto&rev=471356
==============================================================================
--- tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.apt.core.prefs (added)
+++ tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.apt.core.prefs Sat Nov  4 20:00:14 2006
@@ -0,0 +1,4 @@
+#Sat Nov 04 22:34:49 EST 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.apt.aptEnabled=true
+org.eclipse.jdt.apt.genSrcDir=.apt_generated

Modified: tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.core.prefs?view=diff&rev=471356&r1=471355&r2=471356
==============================================================================
--- tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.core.prefs (original)
+++ tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.core.prefs Sat Nov  4 20:00:14 2006
@@ -1,4 +1,4 @@
-#Fri Oct 20 11:36:37 EDT 2006
+#Sat Nov 04 22:38:04 EST 2006
 eclipse.preferences.version=1
 org.eclipse.jdt.core.builder.cleanOutputFolder=clean
 org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -52,6 +52,7 @@
 org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
 org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
 org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
 org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
 org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
 org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled

Modified: tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs?view=diff&rev=471356&r1=471355&r2=471356
==============================================================================
--- tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs (original)
+++ tapestry/tapestry4/trunk/.settings/org.eclipse.jdt.ui.prefs Sat Nov  4 20:00:14 2006
@@ -1,8 +1,7 @@
-#Fri Oct 20 11:35:48 EDT 2006
+#Sat Nov 04 22:34:49 EST 2006
 eclipse.preferences.version=1
 formatter_profile=_tapestry
 formatter_settings_version=10
-internal.default.compliance=default
 org.eclipse.jdt.ui.exception.name=ex
 org.eclipse.jdt.ui.gettersetter.use.is=true
 org.eclipse.jdt.ui.ignorelowercasenames=true
@@ -12,4 +11,4 @@
 org.eclipse.jdt.ui.ondemandthreshold=99
 org.eclipse.jdt.ui.overrideannotation=true
 org.eclipse.jdt.ui.staticondemandthreshold=99
-org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return Returns the ${bare_field_name}.\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} The ${bare_field_name} to set.\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false"
  context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// Copyright 2004, 2005 The Apache Software Foundation\r\n//\r\n// Licensed under the Apache License, Version 2.0 (the "License");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n//     http\://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an "AS IS" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="or
 g.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * &lt;p&gt;This class &lt;/p&gt;\r\n * &lt;ul&gt;\r\n * &lt;li&gt;&lt;/li&gt; \r\n * &lt;/ul&gt;\r\n *\r\n * @author ${user}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/** ${field} */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\r\n * {@inheritDoc}\r\n */</template><template 
 autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">// Copyright 2004, 2005 The Apache Software Foundation\r\n//\r\n// Licensed under the Apache License, Version 2.0 (the "License");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n//     http\://www.apache.org/licenses/LICENSE-2.0\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an "AS IS" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" 
 description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org
 .eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\
 ="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template></templates>
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return Returns the ${bare_field_name}.\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} The ${bare_field_name} to set.\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="f
 ilecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// Copyright 2004, 2005 The Apache Software Foundation\n//\n// Licensed under the Apache License, Version 2.0 (the "License");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http\://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an "AS IS" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.
 typecomment" name\="typecomment">/**\n * &lt;p&gt;This class &lt;/p&gt;\n * &lt;ul&gt;\n * &lt;li&gt;&lt;/li&gt; \n * &lt;/ul&gt;\n *\n * @author ${user}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/** ${field} */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * {@inheritDoc}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="f
 alse" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">// Copyright 2004, 2005 The Apache Software Foundation\n//\n// Licensed under the Apache License, Version 2.0 (the "License");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     http\://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an "AS IS" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.
 codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch 
 block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="
 true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template></templates>

Added: tapestry/tapestry4/trunk/.settings/org.eclipse.ltk.core.refactoring.prefs
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/.settings/org.eclipse.ltk.core.refactoring.prefs?view=auto&rev=471356
==============================================================================
--- tapestry/tapestry4/trunk/.settings/org.eclipse.ltk.core.refactoring.prefs (added)
+++ tapestry/tapestry4/trunk/.settings/org.eclipse.ltk.core.refactoring.prefs Sat Nov  4 20:00:14 2006
@@ -0,0 +1,3 @@
+#Sat Nov 04 22:34:49 EST 2006
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java?view=auto&rev=471356
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/EnumPropertySelectionModel.java Sat Nov  4 20:00:14 2006
@@ -0,0 +1,89 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry.form;
+
+
+/**
+ * Implementation of a property model that works off of native
+ * java enum types.
+ * 
+ * <p>
+ *  The enum label/values are all translated by calling Enum.toString() on your individual 
+ *  enum types, so it may be a good idea to provide a toString() method in your Enums if the
+ *  types aren't what you would prefer to display.
+ * </p>
+ */
+public class EnumPropertySelectionModel implements IPropertySelectionModel
+{
+    private Enum[] _set;
+    
+    public EnumPropertySelectionModel(Enum[] set)
+    {
+        _set = set;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String getLabel(int index)
+    {
+        if (index == 0)
+            return "None";
+        
+        return _set[index - 1].toString();
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Object getOption(int index)
+    {
+        if (index == 0)
+            return null;
+        
+        return _set[index - 1];
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getOptionCount()
+    {
+        return _set.length + 1;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getValue(int index)
+    {
+        if (index == 0)
+            return "None";
+        
+        return _set[index - 1].toString();
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Object translateValue(String value)
+    {
+        for (Enum e : _set) {
+            if (e.toString().equals(value))
+                return e;
+        }
+        
+        return null;
+    }
+}

Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestEnumPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestEnumPropertySelectionModel.java?view=auto&rev=471356
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestEnumPropertySelectionModel.java (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestEnumPropertySelectionModel.java Sat Nov  4 20:00:14 2006
@@ -0,0 +1,67 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry.form;
+
+import org.testng.annotations.Test;
+
+
+/**
+ * Tests functionaliy of {@link EnumPropertySelectionModel}.
+ * 
+ */
+@Test
+public class TestEnumPropertySelectionModel
+{
+    enum AbstractFormat
+    {
+        FreePaperOnly("Free Paper Only"),
+        ScientificPosterOnly("Scientific Poster Only"),
+        DemonstrationPosterOnly("Demonstration Poster Only"),
+        FreePaperorScientificPoster("Free Paper or Scientific Poster"),
+        FreePaperorDemonstrationPoster("Free Paper or Demonstration Poster"),
+        InstructionalCourse("Instructional Course");
+        
+        private final String category;
+        
+        AbstractFormat(String category){
+            this.category = category;
+        }
+        
+        public String toString()
+        {
+            return this.category;
+        }
+    }
+    
+    public void test_Simple_Enum()
+    {
+        EnumPropertySelectionModel ep = new EnumPropertySelectionModel(AbstractFormat.values());
+        
+        assert "None".equals(ep.getLabel(0));
+        
+        assert AbstractFormat.FreePaperOnly.toString().equals(ep.getLabel(1));
+        
+        assert AbstractFormat.FreePaperorDemonstrationPoster.equals(ep.getOption(5));
+        
+        assert AbstractFormat.values().length + 1 == ep.getOptionCount();
+        
+        assert "None".equals(ep.getValue(0));
+        
+        assert ep.getOption(0) == null;
+        
+        assert AbstractFormat.ScientificPosterOnly.toString().equals(ep.getValue(2));
+        
+        assert AbstractFormat.FreePaperOnly == ep.translateValue(AbstractFormat.FreePaperOnly.toString());
+    }
+}