[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 |
|
---|
[868] | 6 | import javax.faces.context.FacesContext;
|
---|
[848] | 7 | import javax.faces.event.ActionEvent;
|
---|
[857] | 8 | import javax.faces.event.ValueChangeEvent;
|
---|
[858] | 9 | import javax.faces.model.SelectItem;
|
---|
[832] | 10 | import javax.swing.tree.DefaultMutableTreeNode;
|
---|
| 11 | import javax.swing.tree.DefaultTreeModel;
|
---|
[844] | 12 | import de.dass_it.vanhelsing.gui.items.*;
|
---|
| 13 | import de.dass_it.www.vanhelsing.*;
|
---|
| 14 | import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
|
---|
| 15 | import de.dass_it.www.vanhelsing.VanHelsingStub.*;
|
---|
[848] | 16 |
|
---|
[864] | 17 | /**
|
---|
| 18 | * List all Bacula configuration components by name.
|
---|
[830] | 19 | */
|
---|
[871] | 20 | public class ConfigurationBean implements IViewBean{
|
---|
[868] | 21 |
|
---|
| 22 |
|
---|
| 23 | private DataTree dataTree;
|
---|
| 24 | private ConcreteUserObjectItem selectedObject;
|
---|
| 25 | private boolean createResource;
|
---|
[858] | 26 | private String selectedId;
|
---|
[844] | 27 |
|
---|
[854] | 28 | public ConfigurationBean() {
|
---|
| 29 | init();
|
---|
| 30 | }
|
---|
[864] | 31 |
|
---|
| 32 | /**
|
---|
| 33 | * init() builds the data tree of the configuration view. The heading nodes are read from the properties file.
|
---|
| 34 | * the web service will be queried for each heading node(e.g. client).
|
---|
| 35 | */
|
---|
[854] | 36 | private void init(){
|
---|
[868] | 37 | DefaultMutableTreeNode parent;
|
---|
| 38 | ResourceInfo resItems[];
|
---|
[847] | 39 | SimpleResource sr;
|
---|
[844] | 40 | Client c = new Client();
|
---|
[868] | 41 | UserObjectItemFactory UOFactory = new UserObjectItemFactory();
|
---|
| 42 | setDataTree(new DataTree());
|
---|
| 43 | dataTree.setTree("Configuration");
|
---|
| 44 | for (String name : BeanUtil.getProperty("nodes").split(",")){
|
---|
| 45 | parent = dataTree.createNode(dataTree.getRoot(),
|
---|
| 46 | UOFactory.createUserObjectItem(
|
---|
| 47 | c.makeResourceInfo(BeanUtil.getProperty("defaultdirector"), -1, name, name)
|
---|
| 48 | )
|
---|
| 49 | );
|
---|
| 50 | resItems = c.getListResources(BeanUtil.getProperty("defaultdirector"), name);
|
---|
| 51 | if (resItems != null){
|
---|
| 52 | for (ResourceInfo rinfo : resItems){
|
---|
| 53 | sr = c.getSimpleResource(rinfo.getDirector(), rinfo.getResId());
|
---|
| 54 | if (sr != null){
|
---|
| 55 | //TODO: discard the SimpleResource ResInfo return value and work with the query object
|
---|
| 56 | dataTree.createNode(parent,
|
---|
| 57 | UOFactory.createUserObjectItem(
|
---|
| 58 | sr.getResourceAttributeType(), rinfo));
|
---|
| 59 | }
|
---|
[844] | 60 | }
|
---|
| 61 | }
|
---|
[868] | 62 | }
|
---|
| 63 | dataTree.createKeyValueLists();
|
---|
| 64 | dataTree.updateUserObjects();
|
---|
[871] | 65 | createResource = false;
|
---|
| 66 | selectedObject = null;
|
---|
[854] | 67 | }
|
---|
[868] | 68 |
|
---|
[864] | 69 | /**
|
---|
| 70 | * transfers the selected (by attribute resId) dataobject (resource) into an ArrayList of ViewItems.<br/>
|
---|
| 71 | * Each ViewItem contain the key value pair and the rendering type. If the attribute is rendered as a
|
---|
| 72 | * selectOneMenu, the values for the selectOneMenu will be read from the data tree.
|
---|
| 73 | *
|
---|
| 74 | * @param ae ActionEvent which contains relevant information about the component tree. the variable is not used.
|
---|
| 75 | */
|
---|
[868] | 76 | public void renderResource(ActionEvent ae){
|
---|
[848] | 77 | DefaultMutableTreeNode node;
|
---|
[868] | 78 | String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("userObject.resId");
|
---|
| 79 | int numId = new Integer(id);
|
---|
| 80 | String name = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("userObject.resName");
|
---|
| 81 | if (numId > 0){
|
---|
| 82 | node = dataTree.getNodeById(numId);
|
---|
| 83 | selectedObject = (ConcreteUserObjectItem)((UserObjectItemType)(node.getUserObject())).getUserObject();
|
---|
| 84 | } else {
|
---|
| 85 | node = dataTree.getNodeByName(name);
|
---|
| 86 | selectedObject = (ConcreteUserObjectItem)((UserObjectItemType)(node.getUserObject())).getUserObject();
|
---|
| 87 | }
|
---|
[871] | 88 | createResource = false;
|
---|
[868] | 89 | }
|
---|
[871] | 90 |
|
---|
[864] | 91 | /**
|
---|
[871] | 92 | * reads the properties of a given resource to create a resource object
|
---|
[864] | 93 | * @param ae
|
---|
| 94 | */
|
---|
[871] | 95 | public void newResourceButtonListener(ActionEvent ae){
|
---|
| 96 | String type = "Client";
|
---|
| 97 | UserObjectItemFactory UOFactory = new UserObjectItemFactory();
|
---|
| 98 | selectedObject = (ConcreteUserObjectItem)UOFactory.createUserObjectItem(type);
|
---|
| 99 | for (ViewItem vi : selectedObject.getViewItemList()){
|
---|
| 100 | if(vi.getSelectOneMenu()){
|
---|
| 101 | vi.setKeyValueList(dataTree.getKeyValueList().get(vi.getKey()));
|
---|
[867] | 102 | }
|
---|
[871] | 103 | if (vi.getRadioGroup()){
|
---|
| 104 | vi.setKeyValueList(dataTree.getKeyValueList().get("trueFalse"));
|
---|
[858] | 105 | }
|
---|
| 106 | }
|
---|
[871] | 107 | createResource = true;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | public void newClientButtonListener(ActionEvent ae){
|
---|
| 111 | newResourceButtonListener(ae);
|
---|
| 112 | }
|
---|
[857] | 113 | public void userObjectItemOptionSelected(ValueChangeEvent vce){
|
---|
[871] | 114 | System.err.println("vce.oldValue: " +vce.getOldValue()+" vce.newValue: "+vce.getNewValue());
|
---|
[857] | 115 |
|
---|
| 116 | }
|
---|
[864] | 117 | /**
|
---|
| 118 | * repeat the entire construction process of the data tree
|
---|
| 119 | * @param ae
|
---|
| 120 | */
|
---|
[858] | 121 | public void reloadResourceButtonListener(ActionEvent ae){
|
---|
| 122 | init();
|
---|
| 123 | }
|
---|
| 124 | public void deleteResourceButtonListener(ActionEvent ae){
|
---|
| 125 | BeanUtil.setInfoMessage(null, "Diese Methode ist noch nicht implementiert.");
|
---|
| 126 | }
|
---|
[864] | 127 | /**
|
---|
[871] | 128 | * save the currently selected object
|
---|
| 129 | * @param ae
|
---|
[864] | 130 | */
|
---|
[871] | 131 | public void saveClientButtonListener(ActionEvent ae){
|
---|
| 132 | if (createResource){
|
---|
[858] | 133 | Client c = new Client();
|
---|
[871] | 134 | SimpleResource sr;
|
---|
| 135 | UserObjectItemFactory UOFactory = new UserObjectItemFactory();
|
---|
| 136 | for (ViewItem vi : selectedObject.getViewItemList()){
|
---|
| 137 | if(vi.getKey().equals("name")){
|
---|
| 138 | selectedObject.setResName(vi.getKeyValue());
|
---|
| 139 | }
|
---|
[858] | 140 | }
|
---|
[871] | 141 | int newResId =
|
---|
| 142 | c.createSimpleResource(c.makeResAttrTypeArray(selectedObject.getViewItemList()),
|
---|
| 143 | c.makeResourceInfo(selectedObject.getDirector(), selectedObject.getResId(),
|
---|
| 144 | selectedObject.getResName(), selectedObject.getResType()));
|
---|
| 145 | BeanUtil.setInfoMessage(null, "Neue Resource erzeugt (Id: "+newResId+")");
|
---|
| 146 | //neue Resource einlesen und in den Baum eintragen
|
---|
| 147 | //sr = c.getSimpleResource(selectedObject.getDirector(), newResId);
|
---|
| 148 | sr = new SimpleResource();
|
---|
| 149 | sr.setResourceAttributeType(c.makeResAttrTypeArray(selectedObject.getViewItemList()));
|
---|
| 150 | sr.setResourceInfo(c.makeResourceInfo(selectedObject.getDirector(), selectedObject.getResId(),
|
---|
| 151 | selectedObject.getResName(), selectedObject.getResType()));
|
---|
| 152 | dataTree.createNode(dataTree.getNodeByName("Client"),
|
---|
| 153 | UOFactory.createUserObjectItem(sr.getResourceAttributeType(),
|
---|
| 154 | sr.getResourceInfo()));
|
---|
| 155 | dataTree.updateUserObjects();
|
---|
[854] | 156 | }
|
---|
[871] | 157 | }
|
---|
| 158 |
|
---|
[864] | 159 | /**
|
---|
| 160 | * Setter method for the tree attribute
|
---|
| 161 | * @param tree tree contains the DefaultTreeModel for the data tree
|
---|
| 162 | */
|
---|
[868] | 163 | public void setDataTree(DataTree dataTree) {
|
---|
| 164 | this.dataTree = dataTree;
|
---|
[832] | 165 | }
|
---|
[864] | 166 | /**
|
---|
| 167 | * getter method for the tree attribute
|
---|
| 168 | * @return tree tree contains the DefaultTreeModel for the data tree
|
---|
| 169 | */
|
---|
[868] | 170 | public DataTree getDataTree() {
|
---|
| 171 | return dataTree;
|
---|
[832] | 172 | }
|
---|
[868] | 173 |
|
---|
| 174 | public void createNodeButtonListener(ActionEvent ae) {
|
---|
| 175 | // TODO Auto-generated method stub
|
---|
| 176 |
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | public void deleteNodeButtonListener(ActionEvent ae) {
|
---|
| 180 | // TODO Auto-generated method stub
|
---|
| 181 |
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | public void readNodeButtonListener(ActionEvent ae) {
|
---|
| 186 | // TODO Auto-generated method stub
|
---|
| 187 |
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | public void selectNode(ActionEvent ae) {
|
---|
| 191 | // TODO Auto-generated method stub
|
---|
| 192 |
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | public void updateNodeButtonListener(ActionEvent ae) {
|
---|
| 196 | // TODO Auto-generated method stub
|
---|
| 197 |
|
---|
| 198 | }
|
---|
[864] | 199 |
|
---|
| 200 | /**
|
---|
| 201 | * gettter method for the selectedObject attribute
|
---|
| 202 | * @return selectedObject selectedObject contains the data object of the selected leaf node.
|
---|
| 203 | */
|
---|
[868] | 204 | public ConcreteUserObjectItem getSelectedObject() {
|
---|
[848] | 205 | return selectedObject;
|
---|
| 206 | }
|
---|
[864] | 207 |
|
---|
| 208 | /**
|
---|
| 209 | * setter method for the selectedObject attribute
|
---|
| 210 | * @param selectedObject selectedObject contains the data object of the selected leaf node
|
---|
| 211 | */
|
---|
[868] | 212 | public void setSelectedObject(ConcreteUserObjectItem selectedObject) {
|
---|
[848] | 213 | this.selectedObject = selectedObject;
|
---|
| 214 | }
|
---|
[864] | 215 |
|
---|
| 216 | /**
|
---|
| 217 | * getter method for the resId attribute of the selectedObject i.e. the selected leaf node of the data tree
|
---|
| 218 | * @return id resId attribute of the selected object
|
---|
| 219 | */
|
---|
[858] | 220 | public int getSelectedId(){
|
---|
| 221 | if (selectedObject != null){
|
---|
[868] | 222 | return selectedObject.getResId();
|
---|
[858] | 223 | }
|
---|
| 224 | return -1;
|
---|
| 225 | }
|
---|
[868] | 226 | /*public String getSelectedName(){
|
---|
[867] | 227 | if (selectedObject != null){
|
---|
| 228 | if (selectedObject.size() > 0){
|
---|
| 229 | return selectedObject.get(0).getResName();
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | return "";
|
---|
[868] | 233 | }*/
|
---|
[867] | 234 | public void setCreateResource(boolean b){
|
---|
| 235 | this.createResource = b;
|
---|
| 236 | }
|
---|
| 237 | public boolean getCreateResource(){
|
---|
| 238 | return createResource;
|
---|
| 239 | }
|
---|
[854] | 240 |
|
---|
[830] | 241 | }
|
---|