001    package org.apache.myfaces.tobago.example.reference;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.model.TreeState;
021    import org.apache.commons.logging.Log;
022    import org.apache.commons.logging.LogFactory;
023    
024    import javax.swing.tree.DefaultMutableTreeNode;
025    
026    public class TreeCommandController {
027    
028      private static final Log LOG = LogFactory.getLog(TreeCommandController.class);
029    
030    
031      private DefaultMutableTreeNode tree;
032      private TreeState state;
033    
034    
035      public TreeCommandController() {
036        tree = new DefaultMutableTreeNode("Category");
037        tree.insert(new DefaultMutableTreeNode("Sports"), 0);
038        tree.insert(new DefaultMutableTreeNode("Movies"), 0);
039        DefaultMutableTreeNode music = new DefaultMutableTreeNode("Music");
040        tree.insert(music, 0);
041        tree.insert(new DefaultMutableTreeNode("Games"), 0);
042        DefaultMutableTreeNode temp = new DefaultMutableTreeNode("Science");
043        temp.insert(
044            new DefaultMutableTreeNode("Geography"), 0);
045        temp.insert(
046            new DefaultMutableTreeNode("Mathematics"), 0);
047        DefaultMutableTreeNode temp2 = new DefaultMutableTreeNode("Astronomy");
048        temp2.insert(new DefaultMutableTreeNode("Education"), 0);
049        temp2.insert(new DefaultMutableTreeNode("Pictures"), 0);
050        temp.insert(temp2, 2);
051        tree.insert(temp, 2);
052        state = new TreeState();
053        state.addExpandState(tree);
054        state.addExpandState(temp);
055        state.setMarker(music);
056      }
057    
058      public String command() {
059        LOG.info(state.getMarker());
060        return null;
061      }
062    
063      public DefaultMutableTreeNode getTree() {
064        return tree;
065      }
066    
067      public void setTree(DefaultMutableTreeNode tree) {
068        this.tree = tree;
069      }
070    
071      public TreeState getState() {
072        return state;
073      }
074    
075      public void setState(TreeState state) {
076        this.state = state;
077      }
078    }