/*
Copyright (c) 2003-2008 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 javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import DisplayProject.DisplayNode;
import DisplayProject.JListView;
import DisplayProject.TreeViewModel;
import DisplayProject.controls.ListView;
import DisplayProject.controls.OutlineField;
import Framework.ErrorMgr;
import Framework.UsageException;
/**
* Gets and sets the RootNode of a JTree, ListView or OutlineField
*
*/
@SuppressWarnings("deprecation")
public class RootNode extends PendingAction {
private DisplayNode value;
public RootNode(Component pComponent, DisplayNode pValue) {
super(pComponent);
this.value = pValue;
}
public DisplayNode getValue() {
return this.value;
}
public void performAction() {
if (this._component instanceof JTree) {
// TF:4/8/07: Reset the tree's model to correctly populate it.
((JTree)this._component).setModel(new TreeViewModel(this.value));
//PM:12/10/07 select the root node this forces the scrollpant to the top left
if (this.value != null)
((JTree)this._component).setSelectionPath(new TreePath(this.value));
}
else if (this._component instanceof JListView) {
UsageException errorVar = new UsageException("Set RootNode on JListView is not implemented");
ErrorMgr.addError(errorVar);
throw errorVar;
}
else if (this._component instanceof ListView)
((ListView)this._component).setRootNode(this.value);
else // it is an outline field
((OutlineField)this._component).setRoot(this.value);
}
public static void set(Component comp, DisplayNode value){
if (value != null) {
value.setUserObject(comp);
}
ActionMgr.addAction(new RootNode(comp, value));
}
public static DisplayNode get(Component comp){
RootNode action = ActionMgr.getAction(comp, RootNode.class);
if (action != null) {
return action.getValue();
}
if (comp instanceof JTree){
TreeModel aModel = ((JTree)comp).getModel();
if (aModel != null) {
return ((DisplayNode)aModel.getRoot());
}
}
if (comp instanceof ListView){
return ((ListView)comp).getRootNode();
}
if (comp instanceof OutlineField){
return((OutlineField)comp).getRoot(true);
}
if (comp instanceof JListView){
return null;
}
if (comp instanceof JTable)
return null;
else // it is a JListView
return null;
}
}