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:
042: package org.netbeans.modules.sun.manager.jbi.nodes;
043:
044: import com.sun.esb.management.common.ManagementRemoteException;
045: import java.util.Collections;
046: import java.util.logging.Level;
047: import javax.swing.Action;
048: import org.netbeans.modules.sun.manager.jbi.actions.RefreshAction;
049: import org.netbeans.modules.sun.manager.jbi.management.AppserverJBIMgmtController;
050: import org.netbeans.modules.sun.manager.jbi.util.Utils;
051: import org.openide.nodes.Children;
052: import org.openide.nodes.Node;
053: import org.openide.util.actions.SystemAction;
054:
055: /**
056: * Abstract super class for all container node in JBI Manager.
057: *
058: * @author jqian
059: */
060: public abstract class AppserverJBIMgmtContainerNode extends
061: AppserverJBIMgmtNode implements Refreshable {
062:
063: /**
064: *
065: */
066: public AppserverJBIMgmtContainerNode(
067: final AppserverJBIMgmtController controller,
068: final NodeType nodeType) {
069: super (controller, getChildren(controller, nodeType), nodeType);
070:
071: setDisplayName(nodeType.getDisplayName());
072:
073: String shortDescription = nodeType.getShortDescription();
074: // Use HTML version for tooltip.
075: setShortDescription(Utils.getTooltip(shortDescription));
076: // Use non-HTML version in the property sheet's description area.
077: setValue("nodeDescription", shortDescription); // NOI18N
078: }
079:
080: /**
081: * Return the actions associated with the menu drop down seen when
082: * a user right-clicks on an Applications node in the plugin.
083: *
084: * @param boolean true/false
085: * @return An array of Action objects.
086: */
087: @Override
088: public Action[] getActions(boolean flag) {
089: return new SystemAction[] { SystemAction
090: .get(RefreshAction.class) };
091: }
092:
093: /**
094: *
095: */
096: static Children getChildren(
097: final AppserverJBIMgmtController controller,
098: final NodeType type) {
099: return new JBIContainerChildren(controller, type);
100: }
101:
102: /**
103: *
104: *
105: */
106: public void refresh() {
107: setChildren(new JBIContainerChildren(
108: getAppserverJBIMgmtController(), getNodeType()));
109: JBIContainerChildren ch = (JBIContainerChildren) getChildren();
110: ch.updateKeys();
111: }
112:
113: /**
114: *
115: *
116: */
117: public static class JBIContainerChildren extends
118: Children.Keys<Node> {
119: NodeType type;
120: JBIContainerChildFactory cfactory;
121:
122: public JBIContainerChildren(
123: AppserverJBIMgmtController controller, NodeType type) {
124: if (controller == null) {
125: getLogger().log(Level.FINE,
126: "Controller for child factory " + "is null"); // NOI18N
127: getLogger().log(Level.FINE, "Type: " + type); // NOI18N
128: }
129: this .type = type;
130: this .cfactory = new JBIContainerChildFactory(controller);
131: }
132:
133: @Override
134: protected void addNotify() {
135: try {
136: setKeys(this .cfactory.getChildrenObject(getNode(),
137: this .type));
138: } catch (ManagementRemoteException e) {
139: getLogger().log(Level.FINE, e.getMessage(), e);
140: }
141: }
142:
143: @Override
144: protected void removeNotify() {
145: setKeys(Collections.EMPTY_SET);
146: }
147:
148: public void updateKeys() {
149: refresh();
150: }
151:
152: protected Node[] createNodes(Node obj) {
153: try {
154: return new Node[] { obj };
155: } catch (RuntimeException rex) {
156: getLogger().log(Level.FINE, rex.getMessage(), rex);
157: return new Node[] {};
158: } catch (Exception e) {
159: getLogger().log(Level.FINE, e.getMessage(), e);
160: return new Node[] {};
161: }
162: }
163: }
164: }
|