Package DisplayProject.actions

Source Code of DisplayProject.actions.OutlineSelectedNodes

/*
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.actions;

import java.awt.Component;
import java.util.List;

import DisplayProject.Array_Of_DisplayNode;
import DisplayProject.DisplayNode;
import DisplayProject.controls.ListView;
import DisplayProject.controls.OutlineField;
import Framework.ErrorMgr;
import Framework.UsageException;
/**
* Gets the selected nodes in an OutlienField or ListView
* NOTE: does not allow the setting of the selected nodes
*/
public class OutlineSelectedNodes extends PendingAction {
    private Array_Of_DisplayNode<DisplayNode> value;

    public OutlineSelectedNodes(Component pComponent, Array_Of_DisplayNode<DisplayNode> pValue) {
        super(pComponent);
        this.value = pValue;
    }
    public Array_Of_DisplayNode<DisplayNode> getValue() {
        return this.value;
    }
    public void performAction() {
      // CraigM:27/08/2008 - Implemented for ListView
      if (this._component instanceof ListView) {
        ListView lv = (ListView)this._component;
        lv.clearSelectedNodes();
       
        for (DisplayNode node : value) {
          lv.selectNode(node);
        }
      }
      // TF:08/08/2009:Implemented for outline fields
      else if (this._component instanceof OutlineField) {
        OutlineField of = (OutlineField)this._component;
        of.setSelectedNodes(value);
      }
      else {
          UsageException ux = new UsageException("OutlineSelectedNodes.performAction() is not implemented");
          ErrorMgr.addError(ux);
          throw ux;
      }
    }
    public static void set(Component comp, Array_Of_DisplayNode<DisplayNode> value){
        ActionMgr.addAction(new OutlineSelectedNodes(comp, value));
    }

    @SuppressWarnings("unchecked")
  public static Array_Of_DisplayNode<DisplayNode> get(Component comp){
      return get(comp, Array_Of_DisplayNode.class);
    }
   
    @SuppressWarnings("unchecked")
  public static <T extends List<DisplayNode>> T get(Component comp, Class<T> pArrayType) {
      T result;
        OutlineSelectedNodes action = ActionMgr.getAction(comp, OutlineSelectedNodes.class);

        if (pArrayType == null) {
        throw new NullPointerException("pArrayType cannot be null");
      }
       
        if (action != null) {
          if (pArrayType.isAssignableFrom(action.getValue().getClass())) {
            return (T)action.getValue();
          }
          else {
            try {
              result = pArrayType.newInstance();
            }
            catch (Exception e) {
              result = (T)new Array_Of_DisplayNode<DisplayNode>();
            }
            result.addAll(action.getValue());
          }
        }
        else {
          try {
            result = pArrayType.newInstance();
          }
          catch (Exception e) {
            result = (T)new Array_Of_DisplayNode<DisplayNode>();
          }
          if (comp instanceof ListView) {
            Array_Of_DisplayNode<DisplayNode> nodes = ((ListView)comp).getSelectedNodes();
            result.addAll(nodes);
          }
          else if (comp instanceof OutlineField) {
            Array_Of_DisplayNode<DisplayNode> nodes = ((OutlineField)comp).getSelectedNodes();
            result.addAll(nodes);
          }
          else {
                UsageException ux = new UsageException("OutlineSelectedNodes.get() is not implemented for type " + comp.getClass().getName());
              ErrorMgr.addError(ux);
              throw ux;
          }
      }
      return result;
    }
}
TOP

Related Classes of DisplayProject.actions.OutlineSelectedNodes

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.