Package DisplayProject

Source Code of DisplayProject.TreeViewModel

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Hashtable;

import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeWillExpandListener;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.ExpandVetoException;
import javax.swing.tree.TreeNode;

import DisplayProject.actions.WidgetState;
import DisplayProject.events.ClientEventManager;
import Framework.ParameterHolder;

/**
* This model is used by {@link javax.swing.JTree} to provide the same semantics as the Forte TreeView control.
*/
@SuppressWarnings("serial")
public class TreeViewModel extends DefaultTreeModel implements
        TreeSelectionListener, TreeExpansionListener, TreeWillExpandListener, PropertyChangeListener {

    private JTree _theTree;

    public void treeCollapsed(TreeExpansionEvent event) {
        this.fireCollapsed(event);

    }
    public void treeExpanded(TreeExpansionEvent event) {
        this.fireExpanded(event);

    }
    public TreeViewModel(TreeNode root) {
        super(root);
    }
    public TreeViewModel(TreeNode root, boolean asksAllowsChildren) {
        super(root, asksAllowsChildren);
    }
    public void valueChanged(TreeSelectionEvent e) {
        Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
        if (e.getOldLeadSelectionPath() != null)
            qq_Params.put( "OldNode", new ParameterHolder(e.getOldLeadSelectionPath().getLastPathComponent()) );
        else
            qq_Params.put( "OldNode", new ParameterHolder() ); // Always have a value for "OldNode" to stop any null errors.
        if (e.getNewLeadSelectionPath() != null
            qq_Params.put( "NewNode", new ParameterHolder(e.getNewLeadSelectionPath().getLastPathComponent() ));
        else
            qq_Params.put( "NewNode", new ParameterHolder() ); // Always have a value for "OldNode" to stop any null errors.
        qq_Params.put( "OldRowNumber", new ParameterHolder(0) );
        if (e.getPath() != null)
            qq_Params.put( "NewRowNumber", new ParameterHolder(e.getPath().getPathCount()) );
        else
            qq_Params.put( "NewRowNumber", new ParameterHolder(0) );
        ClientEventManager.postEvent( e.getSource(), "AfterCurrentNodeChange", qq_Params );

    }

    public void fireChange() {
        this.reload();
        //nodeStructureChanged((DisplayNode)this.getRoot());

    }


    public void propertyChange(PropertyChangeEvent arg0) {
        fireChange();

    }
    public void setRoot(TreeNode root) {
      super.setRoot(root);

      if(this._theTree != null){
        ((DisplayNode)root).setUserObject(this._theTree);
      }
    }

    public void setTree(JTree tree){
        this._theTree = tree;

        if(this.getRoot() != null){
            ((DisplayNode)this.getRoot()).setUserObject(tree);
        }

    }
//    public JTree getTree(){
//        return this._theTree;
//    }
    public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        this.fireCollapsed(event);

    }
    public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
        this.fireExpanded(event);
    }
    private void fireCollapsed(TreeExpansionEvent event) {
      // CraigM:12/06/2008 - Don't post expand / collapse for inactive fields
      if (WidgetState.get(this._theTree) != Constants.FS_INACTIVE) {
          Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
          DisplayNode dn  = ((DisplayNode)event.getPath().getPath()[event.getPath().getPathCount()-1]);
          qq_Params.put( "Folder", new ParameterHolder(dn) );
          ClientEventManager.postEvent( event.getSource(), "RequestFolderClose", qq_Params );
      }
    }
    private void fireExpanded(TreeExpansionEvent event) {
      // CraigM:12/06/2008 - Don't post expand / collapse for inactive fields
      if (WidgetState.get(this._theTree) != Constants.FS_INACTIVE) {
          Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
          DisplayNode dn  = ((DisplayNode)event.getPath().getPath()[event.getPath().getPathCount()-1]);
          qq_Params.put( "Folder", new ParameterHolder(dn) );
          ClientEventManager.postEvent( event.getSource(), "RequestFolderOpen", qq_Params );
      }
    }
}
TOP

Related Classes of DisplayProject.TreeViewModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.