001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.vmd.api.inspector.common;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.List;
047: import org.netbeans.modules.vmd.api.inspector.InspectorFolder;
048: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
049: import org.netbeans.modules.vmd.api.model.DesignComponent;
050: import org.netbeans.modules.vmd.api.model.DesignDocument;
051: import org.netbeans.modules.vmd.api.model.PropertyValue;
052: import org.netbeans.modules.vmd.api.model.TypeID;
053:
054: /**
055: *
056: * @author Karol Harezlak
057: */
058: /**
059: * Implementation of InspectorOrderingController. This class sorts InspectorFolders in the Mobility Visual Designer Navigator
060: * according of their position in the property array. It means when this presenter is
061: * attached to the DesignComponent then DesignComponents from indicated array property of this
062: * DesignComponent will be displayed in Mobility Visual Designer Navigator in the same
063: * order like in array.
064: */
065: public class ArrayPropertyOrderingController implements
066: InspectorOrderingController {
067:
068: private String propertyName;
069: private Integer order;
070: private TypeID supportedTypeID;
071:
072: /**
073: * Creates ArrayPropertyOrderingController.
074: * @parma propertyName property name of DesignComponent array property
075: * @param order Insteger number of the ordering controller, higher number means higher position in the tree branch
076: * @param supportedTypeID TypeID accepted by this ordering controller, all TypeIDs which inherits from
077: * given TypeID are also accepted by this ordering controller
078: */
079: public ArrayPropertyOrderingController(String propertyName,
080: Integer order, TypeID supportedTypeID) {
081: this .propertyName = propertyName;
082: this .order = order;
083: this .supportedTypeID = supportedTypeID;
084: }
085:
086: /**
087: * Returns ordered List of InspectorFolders.
088: * @param component current DesignComponent
089: * @parma folders InspectorFolders to sort
090: * @raturn ordered List of InspectorFolders
091: */
092: public List<InspectorFolder> getOrdered(DesignComponent component,
093: Collection<InspectorFolder> folders) {
094: List<InspectorFolder> orderedList = new ArrayList<InspectorFolder>(
095: folders.size());
096: List<PropertyValue> array = component
097: .readProperty(propertyName).getArray();
098: if (array == null) {
099: return orderedList;
100: }
101: for (PropertyValue value : array) {
102: DesignComponent itemsComponent = value.getComponent();
103: for (InspectorFolder f : folders) {
104: if (f.getComponentID().equals(
105: itemsComponent.getComponentID())) {
106: orderedList.add(f);
107: break;
108: }
109: }
110: }
111:
112: return orderedList;
113: }
114:
115: /**
116: * Returns order Integer number for list of folders sorted by method getOrdered.
117: * Higher Integer number means that sorted list of folders has higher priority when
118: * it's necessary to order not only folders but also lists (List<InspectorFolder>) of sorted folders
119: * in the same tree branch. For example if in the same tree branch there is two or more InspectorOrderingController
120: * then ordered lists need to be ordered by Integer number returns by this method.
121: *
122: * @return Integer number, when null then sorted list has lowest possible priority
123: */
124: public Integer getOrder() {
125: return order;
126: }
127:
128: /**
129: * Checks if given TypeId is supported by this ordering controller.
130: * @param document current DesignDocument
131: * @param typeID typeID to check
132: * @return Boolen.TRUE when TypyID is supported, Boolean.FALSE when TypeID is
133: * not supported
134: */
135: public boolean isTypeIDSupported(DesignDocument document,
136: TypeID typeID) {
137: if (document.getDescriptorRegistry().isInHierarchy(
138: supportedTypeID, typeID)) {
139: return true;
140: }
141: return false;
142: }
143: }
|