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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.websvc.saas.ui.nodes;
041:
042: import java.beans.PropertyChangeEvent;
043: import java.beans.PropertyChangeListener;
044: import java.util.Collections;
045: import java.util.List;
046: import org.netbeans.modules.websvc.saas.model.Saas;
047: import org.netbeans.modules.websvc.saas.model.SaasServicesModel;
048: import org.openide.nodes.AbstractNode;
049: import org.openide.nodes.Children;
050: import org.openide.nodes.Node;
051: import org.openide.util.NbBundle;
052: import org.openide.util.WeakListeners;
053:
054: /**
055: *
056: * @author nam
057: */
058: public abstract class SaasNodeChildren<T> extends Children.Keys<T>
059: implements PropertyChangeListener {
060: protected Saas saas;
061:
062: public SaasNodeChildren(Saas saas) {
063: this .saas = saas;
064: SaasServicesModel model = SaasServicesModel.getInstance();
065: model.addPropertyChangeListener(WeakListeners.propertyChange(
066: this , model));
067: }
068:
069: public void propertyChange(PropertyChangeEvent evt) {
070: if (evt.getSource() == saas
071: && evt.getPropertyName().equals(Saas.PROP_STATE)) {
072: updateKeys();
073: }
074: }
075:
076: public Saas getSaas() {
077: return saas;
078: }
079:
080: @Override
081: protected void addNotify() {
082: saas.toStateReady(false);
083: updateKeys();
084: super .addNotify();
085: }
086:
087: @Override
088: protected void removeNotify() {
089: List<T> emptyList = Collections.emptyList();
090: setKeys(emptyList);
091: super .removeNotify();
092: }
093:
094: protected abstract void updateKeys();
095:
096: protected static final Object[] WAIT_HOLDER = new Object[] { new Object() };
097:
098: protected static Node[] getWaitNode() {
099: AbstractNode wait = new AbstractNode(Children.LEAF);
100: wait.setName(NbBundle.getMessage(WsdlSaasNodeChildren.class,
101: "NODE_LOAD_MSG"));
102: wait
103: .setIconBaseWithExtension("org/netbeans/modules/websvc/saas/ui/resources/wait.gif"); // NOI18N
104: return new Node[] { wait };
105: }
106:
107: public boolean needsWaiting() {
108: return saas.getState() == Saas.State.INITIALIZING;
109: }
110: }
|