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.identity.server.manager.ui;
043:
044: import java.awt.Image;
045: import java.beans.BeanInfo;
046: import java.util.Collection;
047: import javax.swing.Icon;
048: import javax.swing.ImageIcon;
049: import org.netbeans.modules.identity.profile.api.configurator.SecurityMechanism;
050: import org.netbeans.modules.identity.profile.api.configurator.SecurityMechanismHelper;
051: import org.netbeans.modules.identity.server.manager.api.ServerInstance;
052: import org.openide.filesystems.Repository;
053: import org.openide.loaders.DataFolder;
054: import org.openide.nodes.AbstractNode;
055: import org.openide.nodes.Children;
056: import org.openide.nodes.Node;
057: import org.openide.util.HelpCtx;
058: import org.openide.util.NbBundle;
059: import org.openide.util.Utilities;
060:
061: /**
062: * This class represents the Profiles node in the Runtime tab.
063: *
064: * Created on July 10, 2006, 6:10 PM
065: *
066: * @author ptliu
067: */
068: public class ProfilesNode extends AbstractNode {
069:
070: private static final String PROFILES_NODE_BADGE = "org/netbeans/modules/identity/server/manager/ui/resources/ProfilesNodeBadge.png";//NOI18N
071:
072: private static final Image ICON_BADGE = Utilities
073: .loadImage(PROFILES_NODE_BADGE);
074:
075: private static final String HELP_ID = "idmtools_am_config_am_sec_mech"; //NOI18N
076:
077: private static Icon folderIconCache;
078:
079: private static Icon openedFolderIconCache;
080:
081: /** Creates a new instance of ProfilesNode */
082: public ProfilesNode(ServerInstance instance) {
083: super (new ProfilesNodeChildren(instance));
084:
085: setName(""); //NOI18N
086: setDisplayName(NbBundle.getMessage(ProfilesNode.class,
087: "LBL_ProfilesNode"));
088: //setIconBaseWithExtension(PROFILES_NODE_ICON);
089: setShortDescription(NbBundle.getMessage(ProfilesNode.class,
090: "DESC_ProfilesNode"));
091: }
092:
093: public HelpCtx getHelpCtx() {
094: return new HelpCtx(HELP_ID);
095: }
096:
097: public Image getIcon(int type) {
098: return computeIcon(false, type);
099: }
100:
101: public Image getOpenedIcon(int type) {
102: return computeIcon(true, type);
103: }
104:
105: /**
106: * Returns Icon of folder on active platform
107: * @param opened should the icon represent opened folder
108: * @return the folder icon
109: */
110: static synchronized Icon getFolderIcon(boolean opened) {
111: if (openedFolderIconCache == null) {
112: Node n = DataFolder.findFolder(
113: Repository.getDefault().getDefaultFileSystem()
114: .getRoot()).getNodeDelegate();
115: openedFolderIconCache = new ImageIcon(n
116: .getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
117: folderIconCache = new ImageIcon(n
118: .getIcon(BeanInfo.ICON_COLOR_16x16));
119: }
120: if (opened) {
121: return openedFolderIconCache;
122: } else {
123: return folderIconCache;
124: }
125: }
126:
127: private Image computeIcon(boolean opened, int type) {
128: Icon icon = getFolderIcon(opened);
129: Image image = ((ImageIcon) icon).getImage();
130: image = Utilities.mergeImages(image, ICON_BADGE, 7, 7);
131: return image;
132: }
133:
134: private static class ProfilesNodeChildren extends Children.Keys {
135: private ServerInstance instance;
136:
137: public ProfilesNodeChildren(ServerInstance instance) {
138: this .instance = instance;
139: }
140:
141: protected void addNotify() {
142: updateKeys();
143: }
144:
145: protected Node[] createNodes(Object key) {
146: return new Node[] { new ProfileNode(
147: (SecurityMechanism) key, instance) };
148: }
149:
150: private void updateKeys() {
151: Collection<SecurityMechanism> secMechs = ((new SecurityMechanismHelper(
152: instance.getID()))).getAllWSPSecurityMechanisms();
153:
154: setKeys(secMechs);
155: }
156: }
157: }
|