001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.complexfield;
016:
017: import java.util.ArrayList;
018:
019: import javax.swing.tree.DefaultMutableTreeNode;
020:
021: import com.metaboss.applications.designstudio.designtree.MetaBossPackageTreeModel;
022:
023: /* Complex combobox tree model */
024:
025: public class ComplexModel extends MetaBossPackageTreeModel {
026: protected ArrayList mList = new ArrayList();
027:
028: public ComplexModel() {
029: super ();
030: }
031:
032: // find child node by caption
033: public DefaultMutableTreeNode findChildNodeByPartCaption(
034: String pCaption, boolean pReverse) {
035: return findChildNodeByPartCaption(getRootNode(), pCaption,
036: pReverse);
037: }
038:
039: public DefaultMutableTreeNode findChildNodeByPartCaption(
040: DefaultMutableTreeNode pParentNode, String pCaption,
041: boolean pReverse) {
042: if (pCaption != null && pParentNode != null) {
043: if (pCaption.compareTo(pParentNode.toString()) == 0)
044: return pParentNode;
045:
046: for (int i = 0; i < pParentNode.getChildCount(); i++) {
047: DefaultMutableTreeNode lNode = (DefaultMutableTreeNode) pParentNode
048: .getChildAt(i);
049: if (lNode.toString().compareToIgnoreCase(pCaption) == 0)
050: return lNode;
051: if (lNode.toString().toUpperCase().indexOf(
052: pCaption.toUpperCase()) > -1)
053: return lNode;
054:
055: if (pReverse) {
056: lNode = findChildNodeByPartCaption(lNode, pCaption,
057: pReverse);
058: if (lNode != null)
059: return lNode;
060: }
061: }
062: }
063: return null;
064: }
065:
066: // find next node
067: public DefaultMutableTreeNode findNext(
068: DefaultMutableTreeNode pNode, String pCaption) {
069: if (pNode != null) {
070: int lIndex = getNodeIndex(pNode);
071: if (lIndex > -1) {
072: for (int i = lIndex + 1; i < mList.size(); i++) {
073: DefaultMutableTreeNode lNode = (DefaultMutableTreeNode) mList
074: .get(i);
075: if (lNode.toString().compareToIgnoreCase(pCaption) == 0)
076: return lNode;
077: if (lNode.toString().toUpperCase().indexOf(
078: pCaption.toUpperCase()) > -1)
079: return lNode;
080: }
081: }
082: }
083: return null;
084: }
085:
086: // find next node
087: public DefaultMutableTreeNode findPrev(
088: DefaultMutableTreeNode pNode, String pCaption) {
089: if (pNode != null) {
090: int lIndex = getNodeIndex(pNode);
091: if (lIndex > -1) {
092: for (int i = lIndex - 1; i >= 0; i--) {
093: DefaultMutableTreeNode lNode = (DefaultMutableTreeNode) mList
094: .get(i);
095: if (lNode.toString().compareToIgnoreCase(pCaption) == 0)
096: return lNode;
097: if (lNode.toString().toUpperCase().indexOf(
098: pCaption.toUpperCase()) > -1)
099: return lNode;
100: }
101: }
102: }
103: return null;
104: }
105:
106: protected int getNodeIndex(DefaultMutableTreeNode pNode) {
107: if (pNode != null) {
108: for (int i = 0; i < mList.size(); i++) {
109: DefaultMutableTreeNode lNode = (DefaultMutableTreeNode) mList
110: .get(i);
111: if (lNode.equals(pNode))
112: return i;
113: }
114: }
115: return -1;
116: }
117:
118: protected void addNode(DefaultMutableTreeNode pParentNode,
119: DefaultMutableTreeNode lNode) {
120: pParentNode.add(lNode);
121: mList.add(lNode);
122: }
123: }
|