[830] | 1 | package de.dass_it.vanhelsing.gui;
|
---|
[832] | 2 |
|
---|
[844] | 3 | import java.lang.reflect.Method;
|
---|
[848] | 4 | import java.util.ArrayList;
|
---|
[844] | 5 |
|
---|
[848] | 6 | import javax.faces.event.ActionEvent;
|
---|
[857] | 7 | import javax.faces.event.ValueChangeEvent;
|
---|
[858] | 8 | import javax.faces.model.SelectItem;
|
---|
[832] | 9 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
| 10 | import javax.swing.tree.DefaultTreeModel;
|
---|
[844] | 11 | import de.dass_it.vanhelsing.gui.items.*;
|
---|
| 12 | import de.dass_it.www.vanhelsing.*;
|
---|
| 13 | import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
|
---|
| 14 | import de.dass_it.www.vanhelsing.VanHelsingStub.*;
|
---|
[848] | 15 |
|
---|
[864] | 16 | /**
|
---|
| 17 | * List all Bacula configuration components by name.
|
---|
[830] | 18 | */
|
---|
[832] | 19 | public class ConfigurationBean extends TreeNavigation {
|
---|
[844] | 20 |
|
---|
[832] | 21 | private DefaultTreeModel tree;
|
---|
[848] | 22 | private ArrayList<ViewItem> selectedObject;
|
---|
[858] | 23 | private String selectedId;
|
---|
[844] | 24 |
|
---|
[854] | 25 | public ConfigurationBean() {
|
---|
| 26 | init();
|
---|
| 27 | }
|
---|
[864] | 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 | */
|
---|
[854] | 33 | private void init(){
|
---|
[832] | 34 | DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
---|
[844] | 35 | DefaultMutableTreeNode header;
|
---|
[847] | 36 | DefaultMutableTreeNode leaf;
|
---|
[844] | 37 | String type;
|
---|
| 38 | ListResourcesType lrt;
|
---|
[847] | 39 | GetResourceType grt;
|
---|
[844] | 40 | DefaultMutableTreeNode myNode;
|
---|
| 41 | ResourceInfo[] ri;
|
---|
[847] | 42 | SimpleResource sr;
|
---|
[854] | 43 |
|
---|
[844] | 44 | Client c = new Client();
|
---|
[862] | 45 | setTree(super.createTree(root, BeanUtil.getProperty("nodes").split(","), "Configuration"));
|
---|
[844] | 46 |
|
---|
[858] | 47 |
|
---|
[854] | 48 | for (int i = 0; i < tree.getChildCount(root); i++) {
|
---|
| 49 | header = (DefaultMutableTreeNode) tree.getChild(root, i);
|
---|
| 50 | type = ((UserObjectItemType) header.getUserObject())
|
---|
| 51 | .getUserObject().getResType();
|
---|
[844] | 52 | lrt = new ListResourcesType();
|
---|
| 53 | lrt.setDirector("bacula-dir");
|
---|
| 54 | lrt.setResourceType(type);
|
---|
| 55 | ri = c.getListResources(lrt);
|
---|
[854] | 56 | if (ri == null || ri.length == 0)
|
---|
| 57 | continue;
|
---|
| 58 | for (int j = 0; j < ri.length; j++) {
|
---|
[844] | 59 | myNode = addNode(header, type, ri[j]);
|
---|
[849] | 60 | grt = new GetResourceType();
|
---|
| 61 | grt.setDirector(lrt.getDirector());
|
---|
| 62 | grt.setResId(ri[j].getResId());
|
---|
| 63 | sr = c.getSimpleResource(grt);
|
---|
| 64 | myNode = addNode(myNode, type, sr.getResourceAttributeType());
|
---|
[854] | 65 | if (myNode != null) {
|
---|
[844] | 66 | header.add(myNode);
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
[858] | 69 | }
|
---|
[854] | 70 | }
|
---|
[847] | 71 |
|
---|
[864] | 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 | */
|
---|
[854] | 79 | public void userObjectItemNodeSelected(ActionEvent ae) {
|
---|
[848] | 80 | DefaultMutableTreeNode node;
|
---|
| 81 | UserObjectItem userObject;
|
---|
[849] | 82 | selectedObject = new ArrayList<ViewItem>();
|
---|
[848] | 83 | String Id = BeanUtil.getRequestParameter("userObject.resId");
|
---|
[858] | 84 | String selected = BeanUtil.getRequestParameter("ice.event.shift");
|
---|
[848] | 85 | node = getNode(Id, tree);
|
---|
[858] | 86 | if (selected.equals("true")){
|
---|
| 87 | ((UserObjectItemType)node.getUserObject()).switchSelected();
|
---|
| 88 | }
|
---|
[854] | 89 | String type = ((UserObjectItem) ((UserObjectItemType) node
|
---|
| 90 | .getUserObject()).getUserObject()).getResType();
|
---|
| 91 | String resName = ((ItemType)((UserObjectItem) ((UserObjectItemType) node
|
---|
| 92 | .getUserObject()).getUserObject())).getResName();
|
---|
| 93 | String director = ((ItemType)((UserObjectItem) ((UserObjectItemType) node
|
---|
| 94 | .getUserObject()).getUserObject())).getDirector();
|
---|
| 95 | String classType = "de.dass_it.vanhelsing.gui.items." + type + "Item";
|
---|
[858] | 96 | String accessType = BeanUtil.getAccessType(type.toLowerCase());
|
---|
[849] | 97 | try {
|
---|
[854] | 98 | UserObjectItem item = ((UserObjectItemType) (node.getUserObject()))
|
---|
| 99 | .getUserObject();
|
---|
| 100 | Class c = ((UserObjectItemType) (node.getUserObject()))
|
---|
| 101 | .getUserObject().getClass();
|
---|
| 102 | Method[] m = c.getDeclaredMethods();
|
---|
| 103 | String keyValue;
|
---|
| 104 | String key;
|
---|
| 105 | ViewItem vi;
|
---|
| 106 | for (Method n : m) {
|
---|
| 107 | if (n.getName().startsWith("get")) {
|
---|
| 108 | keyValue = (String) n.invoke(item, (Object[]) null);
|
---|
| 109 | if (keyValue == null)
|
---|
| 110 | continue;
|
---|
| 111 | key = n.getName().substring(3);
|
---|
| 112 | vi = new ViewItem();
|
---|
| 113 | vi.setResId(new Integer(Id));
|
---|
| 114 | vi.setKey(key);
|
---|
| 115 | vi.setKeyValue(keyValue);
|
---|
| 116 | vi.setResType(type);
|
---|
| 117 | vi.setResName(resName);
|
---|
| 118 | vi.setDirector(director);
|
---|
[858] | 119 | vi.setRendererFlag(BeanUtil.getRenderer(accessType, key));
|
---|
| 120 | vi.setRequired(BeanUtil.getRequired(accessType, key));
|
---|
| 121 | if (vi.getSelectOneMenu() != null){
|
---|
| 122 | DefaultMutableTreeNode[] dmtn = getChildNodes(tree, vi.getKey());
|
---|
| 123 | if (dmtn != null) {
|
---|
| 124 | SelectItem[] si = new SelectItem[dmtn.length];
|
---|
| 125 | String objectType;
|
---|
| 126 | for (int i = 0; i < dmtn.length; i++){
|
---|
| 127 | UserObjectItem nodeObject = ((UserObjectItemType)dmtn[i].getUserObject()).getUserObject();
|
---|
| 128 | objectType = "de.dass_it.vanhelsing.gui.items." + vi.getKey() +"Item";
|
---|
| 129 | Class subClass = Class.forName(objectType);
|
---|
| 130 | Class myClass = nodeObject.getClass().asSubclass(subClass);
|
---|
| 131 | Method o = myClass.getMethod("getName", (Class[])null);
|
---|
| 132 | si[i] = new SelectItem((String)o.invoke(nodeObject, (Object[])null),
|
---|
| 133 | (String)o.invoke(nodeObject, (Object[])null));
|
---|
| 134 |
|
---|
| 135 | }
|
---|
| 136 | vi.setKeyValueList(si);
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
[854] | 139 | selectedObject.add(vi);
|
---|
| 140 | }
|
---|
| 141 | selectedObject.trimToSize();
|
---|
[849] | 142 | }
|
---|
[854] | 143 | } catch (Exception e) {
|
---|
[849] | 144 | e.printStackTrace();
|
---|
| 145 | }
|
---|
[848] | 146 | }
|
---|
[864] | 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 | */
|
---|
[858] | 155 | private DefaultMutableTreeNode[] getChildNodes(DefaultTreeModel tree2, String key) {
|
---|
| 156 | DefaultMutableTreeNode[] dmtn;
|
---|
| 157 | DefaultMutableTreeNode root = (DefaultMutableTreeNode)tree2.getRoot();
|
---|
| 158 | DefaultMutableTreeNode node;
|
---|
| 159 | for (int i = 0; i< root.getChildCount(); i++){
|
---|
| 160 | node = (DefaultMutableTreeNode)root.getChildAt(i);
|
---|
| 161 | if (((UserObjectItemType)(node.getUserObject())).getUserObject().getResType().equals(key)){
|
---|
| 162 | dmtn = new DefaultMutableTreeNode[node.getChildCount()];
|
---|
| 163 | for (int j = 0; j < node.getChildCount(); j++){
|
---|
| 164 | dmtn[j] = (DefaultMutableTreeNode)node.getChildAt(j);
|
---|
| 165 | }
|
---|
| 166 | return dmtn;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | return null;
|
---|
| 170 | }
|
---|
[864] | 171 | /**
|
---|
| 172 | *
|
---|
| 173 | * @param ae
|
---|
| 174 | */
|
---|
[854] | 175 | public void newResourceButtonListener(ActionEvent ae){
|
---|
[858] | 176 | DefaultMutableTreeNode node;
|
---|
| 177 | UserObjectItem userObject;
|
---|
| 178 | selectedObject = new ArrayList<ViewItem>();
|
---|
| 179 | String Id = BeanUtil.getRequestParameter("userObject.ResId");
|
---|
| 180 | String shift = BeanUtil.getRequestParameter("ice.event.shift");
|
---|
| 181 | System.err.println(shift);
|
---|
| 182 | if (Id == null){
|
---|
| 183 | return;
|
---|
| 184 | }
|
---|
| 185 | node = getNode(Id, tree);
|
---|
| 186 | String type = ((UserObjectItem) ((UserObjectItemType) node
|
---|
| 187 | .getUserObject()).getUserObject()).getResType();
|
---|
| 188 | ViewItem vi;
|
---|
| 189 | String[] val;
|
---|
| 190 | try{
|
---|
| 191 | String type2 = "de.dass_it.vanhelsing.gui.items." + type + "Item";
|
---|
| 192 | Class newClass = Class.forName(type2);
|
---|
| 193 | for (Method m : newClass.getDeclaredMethods()){
|
---|
| 194 | if (m.getName().startsWith("get")) {
|
---|
| 195 | vi = new ViewItem();
|
---|
| 196 | vi.setKey(m.getName().substring(3));
|
---|
| 197 | vi.setRendererFlag(BeanUtil.getRenderer(type, vi.getKey()));
|
---|
| 198 | if (vi.getSelectOneMenu() != null){
|
---|
| 199 | DefaultMutableTreeNode[] dmtn = getChildNodes(tree, vi.getKey());
|
---|
| 200 | if (dmtn != null) {
|
---|
| 201 | SelectItem[] si = new SelectItem[dmtn.length];
|
---|
| 202 | String objectType;
|
---|
| 203 | for (int i = 0; i < dmtn.length; i++){
|
---|
| 204 | UserObjectItem nodeObject = ((UserObjectItemType)dmtn[i].getUserObject()).getUserObject();
|
---|
| 205 | objectType = "de.dass_it.vanhelsing.gui.items." + vi.getKey() +"Item";
|
---|
| 206 | Class subClass = Class.forName(objectType);
|
---|
| 207 | Class myClass = nodeObject.getClass().asSubclass(subClass);
|
---|
| 208 | Method o = myClass.getMethod("getName", (Class[])null);
|
---|
| 209 | si[i] = new SelectItem((String)o.invoke(nodeObject, (Object[])null),
|
---|
| 210 | (String)o.invoke(nodeObject, (Object[])null));
|
---|
| 211 |
|
---|
| 212 | }
|
---|
| 213 | vi.setKeyValueList(si);
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | if (vi.getInputText() != null){
|
---|
| 217 | vi.setValue(BeanUtil.getProperty("director."+type+"."+vi.getKey()+".def"));
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 | } catch (Exception e){
|
---|
| 222 | e.printStackTrace();
|
---|
| 223 | }
|
---|
[856] | 224 |
|
---|
[854] | 225 | }
|
---|
[864] | 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 |
|
---|
[857] | 241 | public void userObjectItemOptionSelected(ValueChangeEvent vce){
|
---|
| 242 |
|
---|
| 243 | }
|
---|
[864] | 244 | /**
|
---|
| 245 | * repeat the entire construction process of the data tree
|
---|
| 246 | * @param ae
|
---|
| 247 | */
|
---|
[858] | 248 | public void reloadResourceButtonListener(ActionEvent ae){
|
---|
| 249 | init();
|
---|
| 250 | }
|
---|
| 251 | public void deleteResourceButtonListener(ActionEvent ae){
|
---|
| 252 | BeanUtil.setInfoMessage(null, "Diese Methode ist noch nicht implementiert.");
|
---|
| 253 | }
|
---|
[864] | 254 | /**
|
---|
| 255 | * **EXPERIMENTAL** writes the selected resource to the data tree of the web service.
|
---|
| 256 | *
|
---|
| 257 | * @param ae ActionEvent contains relevant information
|
---|
| 258 | */
|
---|
[854] | 259 | public void saveButtonListener(ActionEvent ae) {
|
---|
[858] | 260 | if (selectedObject == null){
|
---|
| 261 | BeanUtil.setInfoMessage(null, "bitte eine Resource zum Ändern auswählen");
|
---|
| 262 | } else {
|
---|
| 263 | Client c = new Client();
|
---|
| 264 | ResourceInfo ri = new ResourceInfo();
|
---|
| 265 | SetSimpleResourceResponse s2r2;
|
---|
| 266 | ri.setDirector( selectedObject.get(0).getDirector() );
|
---|
| 267 | ri.setResId( selectedObject.get(0).getResId() );
|
---|
| 268 | ri.setResName( selectedObject.get(0).getResName() );
|
---|
| 269 | ri.setResType( selectedObject.get(0).getResType() );
|
---|
| 270 | // ResourceAttribute
|
---|
| 271 | String key, value;
|
---|
| 272 | ResourceAttributeType[] ra = new ResourceAttributeType[selectedObject.size()];
|
---|
| 273 | for (int i = 0; i < selectedObject.size(); i++) {
|
---|
| 274 | key = selectedObject.get(i).getKey();
|
---|
| 275 | value = selectedObject.get(i).getKeyValue();
|
---|
| 276 | ra[i] = new ResourceAttributeType();
|
---|
| 277 | ra[i].setKey(key);
|
---|
| 278 | ra[i].setValue(value);
|
---|
| 279 | }
|
---|
[860] | 280 | ResourceInitialization rinit = new ResourceInitialization();
|
---|
| 281 | rinit.setResInfo(ri);
|
---|
| 282 | rinit.setResAttribute(ra);
|
---|
| 283 | rinit.setReplace(true);
|
---|
| 284 | s2r2 = c.setSimpleResource(rinit);
|
---|
[858] | 285 | System.err.println("Status setSimpleRes: "+s2r2.getStatus());
|
---|
| 286 | BeanUtil.setErrorMessage(null, "Status setSimpleRessource: "+s2r2.getStatus());
|
---|
| 287 |
|
---|
| 288 | /*String status = s2r2.getStatus();
|
---|
| 289 | if (selectedObject.get(0) != null){
|
---|
| 290 | selectedObject.get(0).setResId(s2r2.getResId());
|
---|
| 291 | }*/
|
---|
| 292 | // TODO: write ResId to selectedObject
|
---|
| 293 | // selectedObject.get(0).setResId(grt.getResId());
|
---|
| 294 | // valueChangeEffect.setFired(false);
|
---|
[854] | 295 | }
|
---|
| 296 | }
|
---|
[864] | 297 | /**
|
---|
| 298 | * Setter method for the tree attribute
|
---|
| 299 | * @param tree tree contains the DefaultTreeModel for the data tree
|
---|
| 300 | */
|
---|
[832] | 301 | public void setTree(DefaultTreeModel tree) {
|
---|
| 302 | this.tree = tree;
|
---|
| 303 | }
|
---|
[864] | 304 | /**
|
---|
| 305 | * getter method for the tree attribute
|
---|
| 306 | * @return tree tree contains the DefaultTreeModel for the data tree
|
---|
| 307 | */
|
---|
[832] | 308 | public DefaultTreeModel getTree() {
|
---|
| 309 | return tree;
|
---|
| 310 | }
|
---|
[864] | 311 |
|
---|
| 312 | /**
|
---|
| 313 | * gettter method for the selectedObject attribute
|
---|
| 314 | * @return selectedObject selectedObject contains the data object of the selected leaf node.
|
---|
| 315 | */
|
---|
[849] | 316 | public ArrayList<ViewItem> getSelectedObject() {
|
---|
[848] | 317 | return selectedObject;
|
---|
| 318 | }
|
---|
[864] | 319 |
|
---|
| 320 | /**
|
---|
| 321 | * setter method for the selectedObject attribute
|
---|
| 322 | * @param selectedObject selectedObject contains the data object of the selected leaf node
|
---|
| 323 | */
|
---|
[849] | 324 | public void setSelectedObject(ArrayList<ViewItem> selectedObject) {
|
---|
[848] | 325 | this.selectedObject = selectedObject;
|
---|
| 326 | }
|
---|
[864] | 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 | */
|
---|
[858] | 332 | public int getSelectedId(){
|
---|
| 333 | if (selectedObject != null){
|
---|
| 334 | if (selectedObject.size() > 0){
|
---|
| 335 | return selectedObject.get(0).getResId();
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 | return -1;
|
---|
| 339 | }
|
---|
[854] | 340 |
|
---|
[830] | 341 | }
|
---|