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;
043:
044: import java.util.Collection;
045: import java.util.Collections;
046: import java.util.WeakHashMap;
047: import org.netbeans.modules.vmd.api.model.Debug;
048: import org.netbeans.modules.vmd.api.model.DesignComponent;
049: import org.netbeans.modules.vmd.api.model.DesignDocument;
050: import org.netbeans.modules.vmd.inspector.InspectorManagerView;
051: import org.netbeans.modules.vmd.inspector.InspectorWrapperTree;
052: import org.openide.util.WeakSet;
053:
054: /**
055: *
056: * @author Karol Harezlak
057: */
058: /**
059: * This class store information about DesigneComponents to update in the Mobility Visual Designer Navigator.
060: * When registry contains any DesignComponents then scans all DesignComponents for
061: * folders attached to the added DesignComponents through InspectorFolderPresenter and
062: * updating them in the structure of Navigator. After end of the update registry all DesignComponents are removed from registry.
063: * Mobility Visual Designer Navigator updates its self automatically on following events:
064: * <ul>
065: * <li>DesignComponent removed from the DesignDocument</li>
066: * <li>DesignComponent added to the DesignDocument</li>
067: * <li>DesignComponent chenged in the DesignDocument</li>
068: * <li>DesignComponent added to the DesignDocument</li>
069: * </ul>
070: * If it's necessary to update some DesignComponents in the Navigator at some
071: * other event or any other reason, simply add necessary DesignComponents to this registry
072: */
073: public final class InspectorRegistry {
074:
075: private static WeakHashMap<DesignDocument, InspectorRegistry> registryMap;
076: private WeakSet<DesignComponent> components = new WeakSet<DesignComponent>();
077:
078: /**
079: * Returns instance of InspectorRegistry for given DesignDocument.
080: * @param DesignDocument
081: */
082: public static InspectorRegistry getInstance(DesignDocument document) {
083: if (registryMap == null) {
084: registryMap = new WeakHashMap<DesignDocument, InspectorRegistry>();
085: }
086: if (registryMap.get(document) == null) {
087: registryMap.put(document, new InspectorRegistry());
088: }
089: return registryMap.get(document);
090: }
091:
092: private InspectorRegistry() {
093: }
094:
095: /**
096: * Add DesignComponent to update in the Mobility Designer Navigator.
097: * @param DesignComponent component to update
098: */
099: public void addComponent(DesignComponent component) {
100: components.add(component);
101: }
102:
103: /**
104: * Returns Collection of DesignComponents to update.
105: * @return Collection of DesignComponents to update or Collections.EMTY_SET when registry is empty
106: */
107: @SuppressWarnings(value="unchecked")
108: // NOI18N
109: public Collection<DesignComponent> getComponentsToUpdate() {
110: if (components == null) {
111: return Collections.EMPTY_SET;
112: }
113: return Collections.unmodifiableCollection(components);
114: }
115:
116: /**
117: * DO NOT USE THIS METHOD. This method is only accessible from class InspectorWrapperTree.
118: */
119: public void cleanUpRegistry() {
120: if (!Debug.isFriend(InspectorManagerView.class)) {
121: throw new IllegalStateException(
122: "This method is only accessible from class InspectorWrapperTree"); //NOI18N
123: }
124: if (components != null) {
125: components.clear();
126: }
127: }
128:
129: /**
130: * DO NOT USE THIS METHOD. This method is only accessible from class InspectorWrapperTree.
131: */
132: public void remove(Collection<DesignComponent> components) {
133: if (!Debug.isFriend(InspectorWrapperTree.class)) {
134: throw new IllegalStateException(
135: "This method is only accessible from class InspectorWrapperTree"); //NOI18N
136: }
137: if ((this .components != null && this .components.size() > 0)
138: && (components != null && components.size() == 0)) {
139: this.components.removeAll(components);
140: }
141: }
142: }
|