Changeset 864 for vanHelsing/trunk/gui/src
- Timestamp:
- Apr 16, 2010, 5:55:54 PM (15 years ago)
- Location:
- vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/BeanUtil.java
r862 r864 1 1 package de.dass_it.vanhelsing.gui; 2 3 4 2 5 3 import javax.faces.application.FacesMessage; … … 9 7 import java.util.ResourceBundle; 10 8 import java.util.Locale; 11 12 9 import java.util.HashMap; 13 10 14 11 //import org.apache.log4j.Logger; 15 12 16 /* 13 /** 17 14 * Helper class to encapsulate common bean methods. 18 15 * Managed beans will extend this class either directly or … … 20 17 */ 21 18 public class BeanUtil { 22 //Logging 23 24 //protected final Logger logger = Logger.getLogger(this.getClass()); 25 26 //Messagebundles 27 public static String getProperty(String key){ 19 // Logging 20 21 // protected final Logger logger = Logger.getLogger(this.getClass()); 22 23 // Messagebundles 24 /** 25 * getter method for a property value 26 * @param key key of the queried property, e.g. director.client.name.type 27 * @return s value of the property 28 */ 29 public static String getProperty(String key) { 28 30 String s = PropertyBundle.getProperty(key); 29 31 return s; 30 32 } 31 32 public static String[] getProperties(String key){ 33 String[] suffix = {"ref", "type", "required", "def"}; 33 /** 34 * 35 * @param key key contains the key value of the set of properties for a given attribute<br/> 36 * except for the suffix which defines the content type of the property. 37 * @return bundle contains all four properties of an attribute 38 */ 39 public static String[] getProperties(String key) { 40 String[] suffix = { "ref", "type", "required", "def" }; 34 41 String[] bundle = new String[4]; 35 42 for (int i = 0; i < 4; i++) { 36 bundle[i] = BeanUtil.getProperty(key +"."+suffix[i]);43 bundle[i] = BeanUtil.getProperty(key + "." + suffix[i]); 37 44 } 38 45 return bundle; 39 46 } 40 public static boolean getRequired(String type, String key){ 47 /** 48 * 49 * @param type resource type of the attribute, like Client 50 * @param key attribute name of the resource, like Port 51 * @return true if the field is required or false 52 */ 53 public static boolean getRequired(String type, String key) { 41 54 String s = getFieldProperty(type, key, 2); 42 if (s.equals("true") )return true; 55 if (s.equals("true")) 56 return true; 43 57 return false; 44 58 } 45 public static String getDataType(String type, String key){ 59 /** 60 * returns the data type of a given attribute. 61 * @param type resource type of the attribute, like Client 62 * @param key attribute name of the resource, like Port 63 * @return data type of the attribute 64 */ 65 public static String getDataType(String type, String key) { 46 66 return getFieldProperty(type, key, 1); 47 67 } 48 //getRenderer returns rendererType based on properties 49 public static String getRenderer(String type, String key){ 68 69 // getRenderer returns rendererType based on properties 70 /** 71 * returns the renderer for a given attribute 72 * @param type resource type of the attribute, like Client 73 * @param key attribute name of the resource, like Port 74 * @return "inputText", "radioGroup" or "selectOneMenu" 75 * 76 */ 77 public static String getRenderer(String type, String key) { 50 78 return getFieldProperty(type, key, 0); 51 79 } 52 public static String getFieldProperty(String type, String key, int i){ 80 /** 81 * returns properties for a given attribute depending on the value of i. 82 * One should use the getter method for the property. 83 * @param type resource type of the attribute, like Client 84 * @param key attribute name of the resource, like Port 85 * @param i i maybe between 0 and 3. The return value of the method is selected by the value of i 86 * @return one of the four properties as a String of a given attribute. 87 */ 88 public static String getFieldProperty(String type, String key, int i) { 53 89 String daemon = "director"; 54 90 String res = "inputText"; 55 if (type.startsWith("SD")) {91 if (type.startsWith("SD")) { 56 92 daemon = "storagedaemon"; 57 93 } 58 if (type.startsWith("FD")) {94 if (type.startsWith("FD")) { 59 95 daemon = "filedaemon"; 60 96 } … … 62 98 key = key.toLowerCase(); 63 99 key = key.replaceAll(" ", ""); 64 String result[] = getProperties((daemon +"."+type+"."+key));100 String result[] = getProperties((daemon + "." + type + "." + key)); 65 101 if (i == 0) { 66 if (result[1].equals("boolean")) {67 return "radioGroup"; 102 if (result[1].equals("boolean")) { 103 return "radioGroup"; 68 104 } 69 if (!(result[0].equals("0"))) {105 if (!(result[0].equals("0"))) { 70 106 return "selectOneMenu"; 71 } 107 } 72 108 return res; 73 109 } 74 if (i == 2) return result[2]; 75 if (i == 1) return result[1]; 76 if (i == 3) return result[3]; 110 if (i == 2) 111 return result[2]; 112 if (i == 1) 113 return result[1]; 114 if (i == 3) 115 return result[3]; 77 116 return res; 78 117 } 79 80 //Statusmeldungen an den Client 81 public static void setInfoMessage(String client, String message){ 82 FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); 83 } 84 public static void setErrorMessage(String client, String message){ 85 FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message)); 86 } 87 88 //Linkout to Bacula documentation 89 //ListItemsConfigView 90 //ListItemsTopologyView 91 //ListItemsJobSchedule 92 93 //GetParameterFromContext 94 public static String getRequestParameter(String name){ 95 return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name); 118 119 // Statusmeldungen an den Client 120 /** 121 * sends an information type message to the message field at the bottom of the screen 122 * @param client could contain an identifier of a client. value can be set to null 123 * @param message the message to be displayed at the clients view 124 */ 125 public static void setInfoMessage(String client, String message) { 126 FacesContext.getCurrentInstance().addMessage(client, 127 new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); 96 128 } 97 98 public static String getAccessType(String type){ 99 if (type.equals("jobdefs")) return "job"; 129 /** 130 * sends an error type message to the message field at the bottom of the screen 131 * @param client could contain an identifier of a client. value can be set to null 132 * @param message the message to be displayed at the clients view 133 */ 134 public static void setErrorMessage(String client, String message) { 135 FacesContext.getCurrentInstance() 136 .addMessage( 137 client, 138 new FacesMessage(FacesMessage.SEVERITY_ERROR, message, 139 message)); 140 } 141 142 // Linkout to Bacula documentation 143 // ListItemsConfigView 144 // ListItemsTopologyView 145 // ListItemsJobSchedule 146 147 // GetParameterFromContext 148 /** 149 * returns values of a given parameter of the FacesContext 150 * @param name name of the parameter e.g. the id of a parameter in the view. 151 * @return value of a given parameter 152 */ 153 public static String getRequestParameter(String name) { 154 return (String) FacesContext.getCurrentInstance().getExternalContext() 155 .getRequestParameterMap().get(name); 156 } 157 /** 158 * translation method for resource or object names. 159 * @param type untranslated name 160 * @return translated name if there is a translation. Otherwise type will be returned. 161 */ 162 public static String getAccessType(String type) { 163 String result = new String(); 164 HashMap<String, String> map = new HashMap<String, String>(); 165 map.put("jobdefs", "job"); 166 map.put("SDStorage", "Storage"); 167 map.put("Storage", "SDStorage"); 168 map.put("SDDevice", "Device"); 169 map.put("Device", "SDDevice"); 170 map.put("SDDevice", "Device"); 171 result = map.get(type); 172 if (result != null) 173 return result; 100 174 return type; 101 175 } 102 176 103 177 } -
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/Client.java
r862 r864 4 4 import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*; 5 5 import de.dass_it.www.vanhelsing.VanHelsingStub.*; 6 6 /** 7 * Client wraps the access 8 * @author tgoecke 9 * 10 */ 7 11 public class Client { 8 12 public ResourceInfo[] getListResources(String director, String resource){ … … 88 92 return stub; 89 93 } 90 public static void main(String args[]){91 Client c = new Client();92 ListResourcesType lrt = new ListResourcesType();93 lrt.setDirector("bacula-dir");94 lrt.setResourceType("JobDefs");95 96 ResourceInfo[] rinfo = c.getListResources(lrt);97 98 System.err.println("!!!rinfo!!!");99 for (int i = 0; i < rinfo.length && rinfo.length > 0; i++){100 System.err.println(rinfo[i].getDirector());101 System.err.println(rinfo[i].getResId());102 System.err.println(rinfo[i].getResName());103 System.err.println(rinfo[i].getResType());104 }105 106 GetResourceType grt = new GetResourceType();107 grt.setDirector("bacula-dir");108 grt.setResId(117);109 110 SimpleResource sr = new SimpleResource();111 sr = c.getSimpleResource(grt);112 113 System.err.println("!!sr!!");114 System.err.println(sr.getResourceInfo().getDirector());115 System.err.println(sr.getResourceInfo().getResId());116 System.err.println(sr.getResourceInfo().getResName());117 System.err.println(sr.getResourceInfo().getResType());118 119 for (int i = 0; i < sr.getResourceAttributeType().length; i++){120 System.err.print("\nKey: ");121 System.err.print((sr.getResourceAttributeType())[i].getKey());122 System.err.print("\nValue: ");123 System.err.print((sr.getResourceAttributeType())[i].getValue());124 }125 126 }127 128 94 } -
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/ConfigurationBean.java
r862 r864 14 14 import de.dass_it.www.vanhelsing.VanHelsingStub.*; 15 15 16 /* 17 * List all Bacula configuration components by name 16 /** 17 * List all Bacula configuration components by name. 18 18 */ 19 19 public class ConfigurationBean extends TreeNavigation { … … 26 26 init(); 27 27 } 28 29 /** 30 * init() builds the data tree of the configuration view. The heading nodes are read from the properties file. 31 * the web service will be queried for each heading node(e.g. client). 32 */ 28 33 private void init(){ 29 34 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); … … 36 41 ResourceInfo[] ri; 37 42 SimpleResource sr; 38 // ((ClientItem)selectedObject).setName("ClientNameTest");39 43 40 44 Client c = new Client(); 41 /*String[] nodes = { "Director", "Storage", "Autochanger",42 "Client", "FileSet", "FDClient", "Schedule", "SDStorage",43 "Console", "Catalog", "SDDevice", "Job", "JobDefs", "Messages",44 "Pool" }; */45 // String[] nodes = {"Client"};46 45 setTree(super.createTree(root, BeanUtil.getProperty("nodes").split(","), "Configuration")); 47 46 48 // \forall header wird eine ResourceList[] angefragt49 47 50 48 for (int i = 0; i < tree.getChildCount(root); i++) { … … 59 57 continue; 60 58 for (int j = 0; j < ri.length; j++) { 61 // myNode = null;62 59 myNode = addNode(header, type, ri[j]); 63 // Node mit Daten befüllen64 60 grt = new GetResourceType(); 65 61 grt.setDirector(lrt.getDirector()); … … 72 68 } 73 69 } 74 /* 75 * for (int i = 0; i < tree.getChildCount(root); i++){ header = 76 * (DefaultMutableTreeNode)tree.getChild(root, i); 77 * 78 * for (int j = 0; j < tree.getChildCount(header); j++){ leaf = 79 * (DefaultMutableTreeNode)tree.getChild(header, j); type = 80 * ((UserObjectItemType 81 * )leaf.getUserObject()).getUserObject().getResType(); grt = new 82 * GetResourceType(); grt.setDirector("bacula-dir"); 83 * grt.setResId(((ItemType 84 * )(((UserObjectItemType)leaf.getUserObject()).getUserObject 85 * ())).getResId()); sr = c.getSimpleResource(grt); 86 * sr.getResourceAttributeType(); myNode = addNode(leaf, type, 87 * sr.getResourceAttributeType()); if (myNode != null){ 88 * leaf.add(myNode); } 89 * 90 * } } 91 */ 92 93 } 94 95 70 } 71 72 /** 73 * transfers the selected (by attribute resId) dataobject (resource) into an ArrayList of ViewItems.<br/> 74 * Each ViewItem contain the key value pair and the rendering type. If the attribute is rendered as a 75 * selectOneMenu, the values for the selectOneMenu will be read from the data tree. 76 * 77 * @param ae ActionEvent which contains relevant information about the component tree. the variable is not used. 78 */ 96 79 public void userObjectItemNodeSelected(ActionEvent ae) { 97 80 DefaultMutableTreeNode node; … … 112 95 String classType = "de.dass_it.vanhelsing.gui.items." + type + "Item"; 113 96 String accessType = BeanUtil.getAccessType(type.toLowerCase()); 114 // Daten aus dem UserObjectItem extrahieren115 97 try { 116 98 UserObjectItem item = ((UserObjectItemType) (node.getUserObject())) … … 163 145 } 164 146 } 147 /** 148 * return an array of nodes of a given resource type 149 * 150 * @param tree2 copy of the data tree 151 * @param key name of the requested resource type 152 * @return dmtn array of nodes of a given resource type 153 * @return null null object there are no nodes of the requested type 154 */ 165 155 private DefaultMutableTreeNode[] getChildNodes(DefaultTreeModel tree2, String key) { 166 156 DefaultMutableTreeNode[] dmtn; … … 179 169 return null; 180 170 } 171 /** 172 * 173 * @param ae 174 */ 181 175 public void newResourceButtonListener(ActionEvent ae){ 182 176 DefaultMutableTreeNode node; … … 215 209 si[i] = new SelectItem((String)o.invoke(nodeObject, (Object[])null), 216 210 (String)o.invoke(nodeObject, (Object[])null)); 217 //System.err.println("si[i]"+si[i].getLabel());218 211 219 212 } … … 231 224 232 225 } 226 /** 227 * **EXPERIMENTAL** returns type of the selected resource. 228 * The method is used for an evaluation about dynamic navigation. 229 * @param ae ActionEvent contains relevant information about the jsf component tree. 230 * @return viewName name of the resource type of the selected data tree node 231 */ 232 public String newResourceListener(ActionEvent ae){ 233 if (selectedObject != null && selectedObject.size() > 0){ 234 String resType = selectedObject.get(0).getResType(); 235 String viewName = BeanUtil.getAccessType(resType); 236 return viewName; 237 } 238 return ""; 239 } 240 233 241 public void userObjectItemOptionSelected(ValueChangeEvent vce){ 234 242 235 243 } 236 244 /** 245 * repeat the entire construction process of the data tree 246 * @param ae 247 */ 237 248 public void reloadResourceButtonListener(ActionEvent ae){ 238 249 init(); … … 241 252 BeanUtil.setInfoMessage(null, "Diese Methode ist noch nicht implementiert."); 242 253 } 243 254 /** 255 * **EXPERIMENTAL** writes the selected resource to the data tree of the web service. 256 * 257 * @param ae ActionEvent contains relevant information 258 */ 244 259 public void saveButtonListener(ActionEvent ae) { 245 260 if (selectedObject == null){ … … 280 295 } 281 296 } 282 297 /** 298 * Setter method for the tree attribute 299 * @param tree tree contains the DefaultTreeModel for the data tree 300 */ 283 301 public void setTree(DefaultTreeModel tree) { 284 302 this.tree = tree; 285 303 } 286 304 /** 305 * getter method for the tree attribute 306 * @return tree tree contains the DefaultTreeModel for the data tree 307 */ 287 308 public DefaultTreeModel getTree() { 288 309 return tree; 289 310 } 290 311 312 /** 313 * gettter method for the selectedObject attribute 314 * @return selectedObject selectedObject contains the data object of the selected leaf node. 315 */ 291 316 public ArrayList<ViewItem> getSelectedObject() { 292 317 return selectedObject; 293 318 } 294 319 320 /** 321 * setter method for the selectedObject attribute 322 * @param selectedObject selectedObject contains the data object of the selected leaf node 323 */ 295 324 public void setSelectedObject(ArrayList<ViewItem> selectedObject) { 296 325 this.selectedObject = selectedObject; 297 326 } 327 328 /** 329 * getter method for the resId attribute of the selectedObject i.e. the selected leaf node of the data tree 330 * @return id resId attribute of the selected object 331 */ 298 332 public int getSelectedId(){ 299 333 if (selectedObject != null){ -
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/ConstraintViolationException.java
r862 r864 1 1 package de.dass_it.vanhelsing.gui; 2 2 3 public class constraintValidationException extends Exception {3 public class ConstraintViolationException extends Exception { 4 4 5 5 } -
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/DataTree.java
r862 r864 2 2 3 3 import java.util.Enumeration; 4 5 4 import javax.swing.tree.DefaultMutableTreeNode; 6 5 import javax.swing.tree.DefaultTreeModel; 7 8 6 import de.dass_it.vanhelsing.gui.items.ConcreteUserObjectItem; 9 import de.dass_it.vanhelsing.gui.items.ItemType;10 7 import de.dass_it.vanhelsing.gui.items.UserObjectItem; 11 8 import de.dass_it.vanhelsing.gui.items.UserObjectItemType; … … 19 16 public void setTree(String name){ 20 17 setRoot(new DefaultMutableTreeNode()); 21 tree = new DefaultTreeModel(root);22 UserObjectItemType userType = new UserObjectItemType( root);18 setTree(new DefaultTreeModel(getRoot())); 19 UserObjectItemType userType = new UserObjectItemType(getRoot()); 23 20 ConcreteUserObjectItem obj = new ConcreteUserObjectItem(); 24 root.setUserObject(userType);21 getRoot().setUserObject(userType); 25 22 userType.setUserObject(obj); 26 23 userType.setLeaf(false); … … 66 63 return null; 67 64 } 68 public DefaultMutableTreeNode deleteNode(DefaultMutableTreeNode node) throws constraintValidationException{69 if (node.getChildCount()>0) throw new constraintValidationException();65 public DefaultMutableTreeNode deleteNode(DefaultMutableTreeNode node) throws ConstraintViolationException{ 66 if (node.getChildCount()>0) throw new ConstraintViolationException(); 70 67 DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); 71 68 parent.remove(node); -
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/JobScheduleBean.java
r862 r864 6 6 import de.dass_it.www.vanhelsing.VanHelsingStub.*; 7 7 import de.dass_it.vanhelsing.gui.items.ConcreteUserObjectItem; 8 import javax.faces.context.FacesContext; 8 9 9 10 /* 10 * JobSchedule will list all schedules and the jobs which are associated with a given schedule. 11 * JobSchedule will list all schedules and the jobs which are associated 12 * with a given schedule. 11 13 */ 12 14 public class JobScheduleBean { … … 17 19 init(); 18 20 } 21 19 22 private void init(){ 20 23 Client c = new Client(); 21 24 UserObjectItemFactory UOFactory = new UserObjectItemFactory(); 22 23 25 ResourceInfo riSched[]; 24 26 ResourceInfo riJobs[]; 25 27 SimpleResource sr; 26 28 DefaultMutableTreeNode parent; 27 28 29 dataTree = new DataTree(); 29 30 dataTree.setTree("JobSchedule"); 30 31 32 //TODO: Director auslesen 33 riSched = c.getListResources("bacula-dir", "Schedule"); 31 riSched = c.getListResources(BeanUtil.getProperty("defaultdirector"), "Schedule"); 34 32 for (ResourceInfo rinfo : riSched){ 35 33 parent = dataTree.createNode(dataTree.getRoot(), 36 34 UOFactory.createUserObjectItem(rinfo)); 37 38 35 riJobs = c.getListResources(rinfo.getDirector(), "Job"); 39 36 for (ResourceInfo rJobs : riJobs){ 40 41 37 sr = c.getSimpleResource(rJobs.getDirector(), rJobs.getResId()); 42 38 for (ResourceAttributeType rat : sr.getResourceAttributeType()){ … … 64 60 } 65 61 public void deleteNodeListener(ActionEvent ae){ 66 BeanUtil.setInfoMessage(null, "Die Methode ist noch nicht implementiert"); 62 DefaultMutableTreeNode node; 63 ae.getComponent().getAttributes(); 64 65 String idString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("UserObject.resId"); 66 String name = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("UserObject.resName"); 67 67 68 if (idString == null && name != null && !name.equals("")){ 69 node = dataTree.getNodeByName(name); 70 try{ 71 node = dataTree.deleteNode(node); 72 }catch (ConstraintViolationException ecv){ 73 System.err.println(ecv.toString()); 74 } 75 } else if (idString != null) { 76 node = dataTree.getNodeById(new Integer(idString).intValue()); 77 try { 78 node = dataTree.deleteNode(node); 79 } catch (ConstraintViolationException ecv) { 80 ecv.printStackTrace(); 81 } 82 } else { 83 BeanUtil.setInfoMessage(null, "Knoten kann nicht referenziert werden"); 84 } 85 dataTree.getTree().reload(); 68 86 } 69 87 public void reloadTreeListener(ActionEvent ae){ … … 71 89 } 72 90 public void selectNode(ActionEvent ae){ 73 BeanUtil.setInfoMessage(null, "Die Methode ist noch nicht implementiert"); 91 //BeanUtil.setInfoMessage(null, "Die Methode ist noch nicht implementiert"); 92 74 93 } 75 94 -
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/messages_en.properties
r862 r864 1 d irector = bacula-dir1 defaultdirector = bacula-dir 2 2 nodes = Director,Storage,Autochanger,Client,FileSet,FDClient,Schedule,SDStorage,Console,Catalog,SDDevice,Job,JobDefs,Messages,Pool 3 3 director.director.name.ref = 0
Note:
See TracChangeset
for help on using the changeset viewer.