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-2007 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: package com.sun.jsfcl.std.reference;
042:
043: import java.util.List;
044:
045: /**
046: * @author eric
047: *
048: * TODO To change the template for this generated type comment go to
049: * Window - Preferences - Java - Code Generation - Code and Comments
050: */
051: public class CompositeReferenceData extends ReferenceData {
052:
053: protected BaseReferenceData baseReferenceData;
054: protected List itemsSorted;
055: protected ProjectAttachedReferenceData projectReferenceData;
056: protected Object projectVersionMarker;
057: protected DesignPropertyAttachedReferenceData livePropertyReferenceData;
058:
059: /**
060: * @param manager
061: * @param definer
062: */
063: public CompositeReferenceData(
064: ReferenceDataManager manager,
065: String name,
066: ReferenceDataDefiner definer,
067: BaseReferenceData baseReferenceData,
068: ProjectAttachedReferenceData projectReferenceData,
069: DesignPropertyAttachedReferenceData livePropertyReferenceData) {
070:
071: super (manager, definer, name);
072: this .name = name;
073: this .baseReferenceData = baseReferenceData;
074: this .projectReferenceData = projectReferenceData;
075: if (projectReferenceData != null) {
076: definer = projectReferenceData.getDefiner();
077: }
078: this .livePropertyReferenceData = livePropertyReferenceData;
079: }
080:
081: public void add(ReferenceDataItem item) {
082:
083: if (projectReferenceData != null) {
084: projectReferenceData.add(item);
085: invalidateItemsCache();
086: }
087: }
088:
089: public boolean canAddRemoveItems() {
090:
091: if (projectReferenceData != null
092: && projectReferenceData.canAddRemoveItems()) {
093: return true;
094: }
095: return false;
096: }
097:
098: /* (non-Javadoc)
099: * @see com.sun.jsfcl.std.reference.ReferenceData#addToItems(java.util.List)
100: */
101: protected void defineItems() {
102:
103: if (baseReferenceData != null) {
104: items.addAll(baseReferenceData.getItems());
105: }
106: if (projectReferenceData != null) {
107: items.addAll(projectReferenceData.getItems());
108: }
109: if (livePropertyReferenceData != null) {
110: items.addAll(livePropertyReferenceData.getItems());
111: }
112: }
113:
114: public List getItems() {
115:
116: if (items != null
117: && projectReferenceData != null
118: && projectReferenceData.getVersionMarker() != projectVersionMarker) {
119: invalidateItemsCache();
120: projectVersionMarker = projectReferenceData
121: .getVersionMarker();
122: }
123: return super .getItems();
124: }
125:
126: public List getItemsSorted() {
127:
128: if (itemsSorted != null
129: && projectReferenceData != null
130: && projectReferenceData.getVersionMarker() != projectVersionMarker) {
131: invalidateItemsCache();
132: }
133: if (itemsSorted == null) {
134: itemsSorted = ReferenceDataItem.sorted(getItems());
135: }
136: return itemsSorted;
137: }
138:
139: public void invalidateItemsCache() {
140:
141: super .invalidateItemsCache();
142: itemsSorted = null;
143: }
144:
145: public void invalidateDesignContextRelatedCaches() {
146:
147: if (livePropertyReferenceData != null) {
148: livePropertyReferenceData.invalidateItemsCache();
149: invalidateItemsCache();
150: }
151: }
152:
153: public void remove(ReferenceDataItem item) {
154:
155: if (projectReferenceData != null) {
156: projectReferenceData.remove(item);
157: invalidateItemsCache();
158: }
159: }
160:
161: }
|