001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.mapper.tree.spi;
021:
022: import java.util.List;
023:
024: /**
025: * The SPI interface for constructing different hierarchy.
026: * It is used by the BPEL mapper for building left and right trees.
027: *
028: * An external code can provide an instance of such interface
029: * to show required tree.
030: *
031: * @author nk160297
032: */
033: public interface MapperTreeModel<TreeItem> extends
034: MapperTreeExtensionModel<TreeItem> {
035:
036: /**
037: * This object can be used as a root by various trees.
038: */
039: static final Object TREE_ROOT = new Object() {
040: @Override
041: public String toString() {
042: return "Tree_Root"; // NOI18N
043: }
044: };
045:
046: /**
047: * Returns the root of the tree. Returns <code>null</code>
048: * only if the tree has no nodes.
049: *
050: * It is not guaranteed that repeated call will return the same object.
051: *
052: * @return the root of the tree
053: */
054: TreeItem getRoot();
055:
056: /**
057: * Provides a list of extension models.
058: *
059: * @return
060: */
061: List<MapperTreeExtensionModel> getExtensionModelList();
062:
063: class Utils {
064:
065: // Look for extension model by the specified class
066: public static <CL extends MapperTreeExtensionModel> CL findExtensionModel(
067: MapperTreeModel treeModel, Class<CL> modelClass) {
068: List<MapperTreeExtensionModel> extTreeModelList = treeModel
069: .getExtensionModelList();
070: for (MapperTreeExtensionModel extTreeModel : extTreeModelList) {
071: if (modelClass.isInstance(extTreeModel)) {
072: return modelClass.cast(extTreeModel);
073: }
074: }
075: //
076: return null;
077: }
078: }
079:
080: //
081: // Change Events
082: // TODO: implement a bit later
083: //
084:
085: // /**
086: // * Adds a listener for the <code>TreeModelEvent</code>
087: // * posted after the tree changes.
088: // *
089: // * @param l the listener to add
090: // * @see #removeTreeModelListener
091: // */
092: // void addTreeModelListener(TreeModelListener l);
093: //
094: // /**
095: // * Removes a listener previously added with
096: // * <code>addTreeModelListener</code>.
097: // *
098: // * @see #addTreeModelListener
099: // * @param l the listener to remove
100: // */
101: // void removeTreeModelListener(TreeModelListener l);
102:
103: }
|