Changeset 867 for vanHelsing/trunk


Ignore:
Timestamp:
Apr 26, 2010, 6:20:44 PM (14 years ago)
Author:
tobias
Message:

create Client function added

Location:
vanHelsing/trunk/gui
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • vanHelsing/trunk/gui/WebContent/menu.jspx

    r864 r867  
    2222                <ice:panelTab  label="Configuration">
    2323                            <ice:panelGroup style="float:top">
     24                                <ice:commandButton id="newClient"
     25                                        value="create client"
     26                                        actionListener="#{configurationBean.newClientButtonListener}" />
     27                                       
    2428                                <ice:commandButton id="newRes"
    2529                                    value="create resource"
    26                                     actionListener="#{configurationBean.newResourceListener}"/>
     30                                    actionListener="#{configurationBean.newResourceButtonListener}">
     31                                    </ice:commandButton>
     32                                   
    2733                                        <ice:commandButton id="reloadRes"
    2834                                                value="reload Tree"
    2935                                                actionListener="#{configurationBean.reloadResourceButtonListener}" />
     36                                       
    3037                                        <ice:commandButton id="saveRes"
    3138                                        value="update resource"
    3239                                        actionListener="#{configurationBean.saveButtonListener}"/>
     40                                       
    3341                                        <ice:commandButton id="deleteRes"
    3442                                                value="delete resource"
     
    5866                                                <ice:commandLink actionListener="#{configurationBean.userObjectItemNodeSelected}">
    5967                                                <f:param name="userObject.resId" value="#{item.userObject.userObject.resId}"/>
    60                                             <ice:outputText id="knoten" value="#{item.userObject.userObject.value}"/>
    61                                                         </ice:commandLink>
     68                                                <f:param name="userObject.resName" value="#{item.userObject.userObject.value}" />
     69                                                <ice:outputText id="knoten" value="#{item.userObject.userObject.value}"/>
     70                                                </ice:commandLink>
    6271                                        </ice:panelGroup>
    6372                                        </f:facet>
     
    101110                                        </ice:column>
    102111                                </ice:dataTable>
     112                                <ice:commandButton id="createResource"
     113                                        value="save"
     114                                        rendered="#{configurationBean.createResource eq true}"
     115                                        actionListener="#{configurationBean.saveClientButtonListener}" />
    103116                        </ice:panelGrid>
    104117                        </f:facet>
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/BeanUtil.java

    r865 r867  
    55import javax.faces.context.FacesContext;
    66import javax.faces.model.SelectItem;
     7
     8import edu.emory.mathcs.backport.java.util.Collections;
     9
     10import java.util.ArrayList;
    711import java.util.ResourceBundle;
    812import java.util.Locale;
     
    175179                return type;
    176180        }
    177 
     181        /**
     182         *
     183         * @param key   resource name
     184         * @return newRes       ArrayList of ViewItem
     185         */
     186        public static ArrayList<ViewItem> getTypeProperties(String key){
     187                ArrayList<ViewItem> newRes = new ArrayList<ViewItem>();
     188                ArrayList<ViewItem> newOptRes = new ArrayList<ViewItem>();
     189                ArrayList<String> properties = PropertyBundle.getTypeAttributes("director."+key);
     190               
     191                System.err.println(properties.size());
     192                ViewItem vi;
     193                for (String s : properties){
     194                        vi = new ViewItem();
     195                        vi.setRequired(BeanUtil.getRequired(key, s));
     196                        vi.setDataType(BeanUtil.getDataType(key, s));
     197                        vi.setKey(s);
     198                        vi.setRenderer(BeanUtil.getRenderer(key, s));
     199                        vi.setKeyValue(BeanUtil.getFieldProperty(key, s, 3));
     200                        if (vi.getRequired()){
     201                                newRes.add(vi);
     202                        } else {
     203                                newOptRes.add(vi);
     204                        }
     205                }
     206                newRes.addAll(newOptRes);
     207                return newRes;
     208        }
    178209}
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/Client.java

    r865 r867  
    99 * Client wraps access methods and data structure of the axis client
    1010 * @author tgoecke
    11  *
    1211 */
    1312public class Client {
     
    275274        /**
    276275         * creates a simple resource object at Van Helsing
    277          * @param replace       the object will be replaced if this parameter is set to true, otherwise the changed values will be updated
     276         * @param replace       this parameter is part of the ResourceInitialization object but will not be used by the create method
    278277         * @param rat   list of key value pairs of type ResourceAttributeType[]
    279278         * @param rinfo         ResourceInfo object containing identification information of the object
    280279         * @return      Id of the created simple resource
    281280         */
    282         public int createSimpleResource(boolean replace, ResourceAttributeType[] rat, ResourceInfo rinfo){
     281        public int createSimpleResource(ResourceAttributeType[] rat, ResourceInfo rinfo){
    283282               
    284283                ResourceInitialization ri = new ResourceInitialization();
    285                 ri.setReplace(replace);
     284                ri.setReplace(false);
    286285                ri.setResInfo(rinfo);
    287286                ri.setResAttribute(rat);
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/ConfigurationBean.java

    r864 r867  
    2222        private ArrayList<ViewItem> selectedObject;
    2323        private String selectedId;
     24        private String selectedName;
     25        private boolean createResource = false;
    2426
    2527        public ConfigurationBean() {
     
    8284                selectedObject = new ArrayList<ViewItem>();
    8385                String Id = BeanUtil.getRequestParameter("userObject.resId");
     86                String name = BeanUtil.getRequestParameter("userObject.resName");
    8487                String selected = BeanUtil.getRequestParameter("ice.event.shift");
    8588                node = getNode(Id, tree);
     
    169172                return null;
    170173        }
     174       
    171175        /**
    172176         *
    173177         * @param ae
    174178         */
     179        public void newClientButtonListener(ActionEvent ae){
     180                String type = "client";
     181                ArrayList newResource = new ArrayList<ViewItem>();
     182                ResourceInfo[] ri;
     183                int i;
     184                String s;
     185                selectedObject = BeanUtil.getTypeProperties(type);
     186                for (ViewItem vi : selectedObject){
     187                        vi.setRendererFlag(vi.getRenderer());
     188                        if (vi.getRenderer().equals("selectOneMenu")){
     189                                SelectItem[] keyValueList;
     190                                //TODO: implement getter for list of node types
     191                                Client c = new Client();
     192                                s = vi.getKey().replaceFirst(new Character(vi.getKey().charAt(0)).toString(),
     193                                                new Character(Character.toUpperCase(vi.getKey().charAt(0))).toString());
     194                               
     195                                ri = c.getListResources("bacula-dir", s);
     196                                if (ri != null){
     197                                        keyValueList = new SelectItem[ri.length];
     198                                        i = 0;
     199                                        for (ResourceInfo rinfo : ri){
     200                                                keyValueList[i] = new SelectItem();
     201                                                keyValueList[i].setValue(rinfo.getResName());
     202                                                keyValueList[i].setLabel(rinfo.getResName());
     203                                                i++;
     204                                        }
     205                                        vi.setKeyValueList(keyValueList);
     206                                }
     207                       
     208                        }
     209                        createResource = true;
     210                }
     211               
     212               
     213        }
     214       
    175215        public void newResourceButtonListener(ActionEvent ae){
    176216                DefaultMutableTreeNode node;
    177217                UserObjectItem userObject;
     218                String Id = BeanUtil.getRequestParameter("userObject.ResId");
     219                String value = BeanUtil.getRequestParameter("userObject.resName");
     220                String shift = BeanUtil.getRequestParameter("ice.event.shift");
    178221                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){
     222                System.out.println("value: "+value+" id: "+Id);
     223               
     224                if (value.equals("")){
    183225                        return;
    184226                }
    185                 node = getNode(Id, tree);
     227                //node = getNode(Id, tree);
     228                node = getNodeByName(value, tree);
    186229                String type = ((UserObjectItem) ((UserObjectItemType) node
    187230                                .getUserObject()).getUserObject()).getResType();
     
    189232                String[] val;
    190233                try{
    191                         String type2 = "de.dass_it.vanhelsing.gui.items." +  type + "Item";
     234                        //value contains the header of the subtree
     235                        String type2 = "de.dass_it.vanhelsing.gui.items." +  value + "Item";
    192236                        Class newClass = Class.forName(type2);
    193237                        for (Method m : newClass.getDeclaredMethods()){
     
    252296                BeanUtil.setInfoMessage(null, "Diese Methode ist noch nicht implementiert.");
    253297        }
     298        public void saveClientButtonListener(ActionEvent ae){
     299                Client c = new Client();
     300                String name = "";
     301                ResourceAttributeType[] rat = new ResourceAttributeType[selectedObject.size()];
     302                int i =0;
     303                for (ViewItem vi : selectedObject){
     304                        rat[i] = new ResourceAttributeType();
     305                        rat[i].setKey(vi.getKey());
     306                        rat[i].setValue(vi.getKeyValue());
     307                        i++;
     308                        if (vi.getKey().equals("name")){
     309                                name = vi.getKeyValue();
     310                        }
     311
     312                }
     313                int newResId = c.createSimpleResource(rat,
     314                                c.makeResourceInfo("bacula-dir", 0, name, "Client")
     315                                );
     316                System.err.println(newResId);
     317        }
    254318        /**
    255319         * **EXPERIMENTAL** writes the selected resource to the data tree of the web service.
     
    338402                return -1;
    339403        }
     404        public String getSelectedName(){
     405                if (selectedObject != null){
     406                        if (selectedObject.size() > 0){
     407                                return selectedObject.get(0).getResName();
     408                        }
     409                }
     410                return "";
     411        }
     412        public void setCreateResource(boolean b){
     413                this.createResource = b;
     414        }
     415        public boolean getCreateResource(){
     416                return createResource;
     417        }
    340418
    341419}
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/DataTree.java

    r865 r867  
    1111 * @author tgoecke
    1212 */
     13//TODO: labeling schema for header nodes
    1314public class DataTree {
    1415        private DefaultTreeModel tree;
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/JobScheduleBean.java

    r865 r867  
    5757                UserObjectItemFactory UOFactory = new UserObjectItemFactory();
    5858               
    59                 //UOFactory.createUserObjectItem(new ResourceAttributeType[], )
    60                 //dataTree.createNode(parent, userObject);
    6159        }
    6260        /**
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/PropertyBundle.java

    r865 r867  
    5858                        key = keySet.nextElement();
    5959                        if (key.startsWith(partialKey)){
    60                                 result.add(getProperty(key));
     60                                        result.add(getProperty(key));
    6161                        }
    6262                }
     
    6565                return result.toArray(new String[0]);
    6666        }
     67        public static ArrayList<String> getTypeAttributes(String partialKey){
     68                Enumeration<String> keySet = properties.getKeys();
     69                String key;
     70                ArrayList<String> result = new ArrayList<String>();
     71                String [] keyComponents;
     72                while(keySet.hasMoreElements()){
     73                        key = keySet.nextElement();
     74                        if (key.startsWith(partialKey)){
     75                                if (key.contains("type")){
     76                                        keyComponents = key.split("\\.");
     77                                        result.add(keyComponents[2]);
     78                                }
     79                        }
     80                }
     81                result.trimToSize();
     82                return result;
     83        }
    6784}
    6885
  • vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/TreeNavigation.java

    r865 r867  
    263263                return null;
    264264        }
     265       
     266        public DefaultMutableTreeNode getNodeByName(String value, DefaultTreeModel tree){
     267                DefaultMutableTreeNode root;
     268                DefaultMutableTreeNode node;
     269               
     270                root = (DefaultMutableTreeNode)tree.getRoot();
     271                Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration();
     272               
     273                while (e.hasMoreElements()){
     274                        node = e.nextElement();
     275                        if (value.equals( ((ItemType)(((UserObjectItemType)node.getUserObject()).getUserObject())).getValue() )){
     276                                return node;
     277                        }
     278                }
     279                return null;
     280        }
     281       
    265282        /**
    266283         * returns the UserObject of a node whose resId attribute matches id
Note: See TracChangeset for help on using the changeset viewer.