Author: pete.muir(a)jboss.org
Date: 2010-06-16 14:25:53 -0400 (Wed, 16 Jun 2010)
New Revision: 6456
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
examples/trunk/jsf/pastecode/src/main/resources/META-INF/persistence.xml
examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml
Log:
Use enum for Themes
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java 2010-06-16
18:13:17 UTC (rev 6455)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java 2010-06-16
18:25:53 UTC (rev 6456)
@@ -23,7 +23,6 @@
import java.util.List;
-import javax.annotation.PostConstruct;
import javax.ejb.EJBException;
import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
@@ -41,28 +40,22 @@
private String brush;
- private String theme;
+ private Theme theme;
private boolean secured = false;
- @Inject LanguageManager data;
+ @Inject
+ private CodeFragmentManager codeFragmentManager;
- transient @Inject CodeFragmentManager eao;
-
public Paster()
{
- }
-
- @PostConstruct
- public void postConstruct()
- {
this.code = new CodeFragment();
- this.theme = "shThemeDefault.css";
+ this.theme = Theme.DEFAULT;
}
public String paste()
{
- this.codeId = eao.addCodeFragment(code, secured);
+ this.codeId = codeFragmentManager.addCodeFragment(code, secured);
return "success";
}
@@ -76,7 +69,7 @@
public void loadCode()
{
- this.code = eao.getCodeFragment(codeId);
+ this.code = codeFragmentManager.getCodeFragment(codeId);
if (this.code == null)
throw new EJBException("Could not read entity with given id value");
@@ -86,7 +79,7 @@
public List<CodeFragment> getCodes()
{
- return eao.getRecentCodeFragments();
+ return codeFragmentManager.getRecentCodeFragments();
}
public String getCodeId()
@@ -99,16 +92,16 @@
this.codeId = codeId;
}
- public String getTheme()
+ public Theme getTheme()
{
return theme;
}
-
- public void setTheme(String theme)
+
+ public void setTheme(Theme theme)
{
this.theme = theme;
}
-
+
public String getBrush()
{
return brush;
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java 2010-06-16
18:13:17 UTC (rev 6455)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java 2010-06-16
18:25:53 UTC (rev 6456)
@@ -21,7 +21,7 @@
*/
package org.jboss.weld.examples.pastecode.session;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -34,19 +34,15 @@
{
// The supported themes
- private final List<String> themes;
+ private final List<Theme> themes;
public ThemeManager()
{
- this.themes = new ArrayList<String>();
- for (Theme theme : Theme.values())
- {
- this.themes.add(theme.getName());
- }
+ this.themes = Arrays.asList(Theme.values());
}
@Produces @Named
- public List<String> getThemes()
+ public List<Theme> getThemes()
{
return Collections.unmodifiableList(themes);
}
Modified: examples/trunk/jsf/pastecode/src/main/resources/META-INF/persistence.xml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/resources/META-INF/persistence.xml 2010-06-16
18:13:17 UTC (rev 6455)
+++ examples/trunk/jsf/pastecode/src/main/resources/META-INF/persistence.xml 2010-06-16
18:25:53 UTC (rev 6456)
@@ -7,7 +7,7 @@
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/pastecodeDatasource</jta-data-source>
<properties>
- <property name="hibernate.hbm2ddl.auto"
value="create-drop"/> <!-- create-drop update-->
+ <property name="hibernate.hbm2ddl.auto"
value="create-drop"/>
<property name="hibernate.show_sql" value="false"/>
</properties>
</persistence-unit>
Modified: examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml 2010-06-16 18:13:17 UTC
(rev 6455)
+++ examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml 2010-06-16 18:25:53 UTC
(rev 6456)
@@ -42,7 +42,7 @@
<h:panelGroup>
<h:outputLabel for="theme" value="Choose theme: "/>
<h:selectOneMenu id="theme" value="#{paster.theme}"
onchange="chooseStyle(this.value);"> <!-- this.form.submit() -->
- <f:selectItems value="#{themes}"/>
+ <f:selectItems value="#{themes}" var="theme"
itemLabel="#{theme.name}" itemValue="#{theme.name}" />
</h:selectOneMenu>
<a href="download?id=#{code.hash == null ? code.id : code.hash}"
style="text-decoration: none;"><input type="button"
value="Download file" /></a>
</h:panelGroup>