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