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.websvc.saas.ui.nodes;
043:
044: import java.awt.datatransfer.Transferable;
045: import java.util.List;
046: import org.openide.util.HelpCtx;
047: import org.openide.util.actions.SystemAction;
048: import java.awt.Image;
049: import java.io.File;
050: import java.io.IOException;
051: import java.util.ArrayList;
052: import javax.swing.Action;
053: import org.netbeans.modules.websvc.saas.model.SaasGroup;
054: import org.netbeans.modules.websvc.saas.model.SaasServicesModel;
055: import org.netbeans.modules.websvc.saas.spi.SaasNodeActionsProvider;
056: import org.netbeans.modules.websvc.saas.ui.actions.AddGroupAction;
057: import org.netbeans.modules.websvc.saas.ui.actions.AddServiceAction;
058: import org.netbeans.modules.websvc.saas.ui.actions.DeleteGroupAction;
059: import org.netbeans.modules.websvc.saas.ui.actions.RenameGroupAction;
060: import org.netbeans.modules.websvc.saas.util.SaasUtil;
061: import org.openide.filesystems.FileObject;
062: import org.openide.filesystems.FileUtil;
063: import org.openide.loaders.DataFolder;
064: import org.openide.nodes.AbstractNode;
065: import org.openide.util.Utilities;
066: import org.openide.util.datatransfer.PasteType;
067: import org.openide.util.lookup.AbstractLookup;
068: import org.openide.util.lookup.InstanceContent;
069:
070: /**
071: * Node representing Group of Web Services
072: * @author nam
073: */
074: public class SaasGroupNode extends AbstractNode {
075: private final SaasGroup group;
076:
077: public SaasGroupNode(SaasGroup group) {
078: this (group, new InstanceContent());
079: }
080:
081: protected SaasGroupNode(SaasGroup group, InstanceContent content) {
082: super (new SaasGroupNodeChildren(group), new AbstractLookup(
083: content));
084: this .group = group;
085: content.add(group);
086: }
087:
088: @Override
089: public String getName() {
090: return group.getName();
091: }
092:
093: @Override
094: public void setName(String name) {
095: if (group.isUserDefined()) {
096: super .setName(name);
097: group.setName(name);
098: }
099: }
100:
101: @Override
102: public boolean canRename() {
103: return group.isUserDefined();
104: }
105:
106: private Image getUserDirFolderImage(int type) {
107: FileObject folder = FileUtil.toFileObject(new File(System
108: .getProperty("netbeans.user"))); //NOI18N
109: if (folder != null) {
110: DataFolder df = DataFolder.findFolder(folder);
111: if (df != null) {
112: return df.getNodeDelegate().getIcon(type);
113: }
114: }
115: return null;
116: }
117:
118: private Image vendorIcon = null;
119:
120: private Image getVendorIcon(int type) {
121: if (vendorIcon == null && group.getServices().size() > 0) {
122: vendorIcon = SaasUtil.loadIcon(group, type);
123: }
124: return vendorIcon;
125: }
126:
127: @Override
128: public Image getIcon(int type) {
129: Image icon = getVendorIcon(type);
130: if (icon != null) {
131: return icon;
132: }
133: Image standardFolderImage = getUserDirFolderImage(type);
134: if (standardFolderImage != null) {
135: return standardFolderImage;
136: }
137: return Utilities
138: .loadImage("org/netbeans/modules/websvc/saas/resources/folder-closed.png");
139: }
140:
141: @Override
142: public Image getOpenedIcon(int type) {
143: Image icon = getVendorIcon(type);
144: if (icon != null) {
145: return icon;
146: }
147: Image standardFolderImage = getUserDirFolderImage(type);
148: if (standardFolderImage != null) {
149: return standardFolderImage;
150: }
151: return Utilities
152: .loadImage("org/netbeans/modules/websvc/saas/resources/folder-open.png");
153: }
154:
155: @Override
156: public Action[] getActions(boolean context) {
157: List<Action> actions = SaasNode.getActions(getLookup());
158: actions.add(SystemAction.get(AddServiceAction.class));
159: actions.add(SystemAction.get(AddGroupAction.class));
160: actions.add(SystemAction.get(DeleteGroupAction.class));
161: actions.add(SystemAction.get(RenameGroupAction.class));
162: return actions.toArray(new Action[actions.size()]);
163: }
164:
165: @Override
166: public boolean canDestroy() {
167: return group.isUserDefined();
168: }
169:
170: @Override
171: public void destroy() throws IOException {
172: SaasServicesModel.getInstance().removeGroup(group);
173: super .destroy();
174: }
175:
176: @Override
177: public HelpCtx getHelpCtx() {
178: return new HelpCtx("websvcGroupNode");
179: }
180:
181: @Override
182: protected void createPasteTypes(final Transferable t,
183: List<PasteType> s) {
184: //TODO review original
185: }
186:
187: }
|