source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/BeanUtil.java@ 858

Last change on this file since 858 was 858, checked in by tobias, on Apr 9, 2010 at 10:56:07 AM

visual design slightly modified. tree functions extended

File size: 2.7 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3
4
5import javax.faces.application.FacesMessage;
6import javax.faces.application.FacesMessage.Severity;
7import javax.faces.context.FacesContext;
8import javax.faces.model.SelectItem;
9import java.util.ResourceBundle;
10import java.util.Locale;
11
12
13
14//import org.apache.log4j.Logger;
15
16/*
17 * Helper class to encapsulate common bean methods.
18 * Managed beans will extend this class either directly or
19 * via a data structure helper class like TreeNavigation
20 */
21public class BeanUtil {
22 //Logging
23
24 //protected final Logger logger = Logger.getLogger(this.getClass());
25
26 //Messagebundles
27 public static String getProperty(String key){
28 String s = PropertyBundle.getProperty(key);
29 return s;
30 }
31
32 public static String[] getProperties(String key){
33 String[] suffix = {"ref", "type", "required", "def"};
34 String[] bundle = new String[4];
35 for (int i = 0; i < 4; i++) {
36 bundle[i] = BeanUtil.getProperty(key+"."+suffix[i]);
37 }
38 return bundle;
39 }
40 public static boolean getRequired(String type, String key){
41 String s = getFieldProperty(type, key, 2);
42 if (s.equals("true") )return true;
43 return false;
44 }
45 //getRenderer returns rendererType based on properties
46 public static String getRenderer(String type, String key){
47 return getFieldProperty(type, key, 1);
48 }
49 public static String getFieldProperty(String type, String key, int i){
50 String daemon = "director";
51 String res = "inputText";
52 if (type.startsWith("SD")){
53 daemon = "storagedaemon";
54 }
55 if (type.startsWith("FD")){
56 daemon = "filedaemon";
57 }
58 type = type.toLowerCase();
59 key = key.toLowerCase();
60 String result[] = getProperties((daemon+"."+type+"."+key));
61 if (i == 1) {
62 if (result[1].equals("boolean")){
63 return "radioGroup";
64 }
65 if (!(result[0].equals("0"))){
66 return "selectOneMenu";
67 }
68 return res;
69 }
70 if (i == 2) return result[2];
71 return res;
72 }
73
74 //Statusmeldungen an den Client
75 public static void setInfoMessage(String client, String message){
76 FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
77 }
78 public static void setErrorMessage(String client, String message){
79 FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
80 }
81
82 //Linkout to Bacula documentation
83 //ListItemsConfigView
84 //ListItemsTopologyView
85 //ListItemsJobSchedule
86
87 //GetParameterFromContext
88 public static String getRequestParameter(String name){
89 return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
90 }
91
92 public static String getAccessType(String type){
93 if (type.equals("jobdefs")) return "job";
94 return type;
95 }
96
97}
Note: See TracBrowser for help on using the repository browser.