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.compapp.projects.jbi.ui;
043:
044: import org.netbeans.modules.compapp.projects.jbi.JbiProject;
045: import org.netbeans.modules.compapp.projects.jbi.ui.actions.JbiProjectCookie;
046: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiProjectProperties;
047:
048: import org.openide.filesystems.*;
049:
050: import org.openide.loaders.DataFolder;
051:
052: import org.openide.nodes.AbstractNode;
053: import org.openide.nodes.Node;
054:
055: import org.openide.util.HelpCtx;
056: import org.openide.util.NbBundle;
057: import org.openide.util.RequestProcessor;
058: import org.openide.util.Utilities;
059:
060: import org.openide.windows.IOProvider;
061: import org.openide.windows.OutputWriter;
062:
063: import java.awt.Image;
064: import java.awt.event.ActionEvent;
065:
066: import java.io.File;
067: import java.util.ArrayList;
068: import java.util.List;
069: import java.util.ResourceBundle;
070: import javax.swing.AbstractAction;
071:
072: import javax.swing.Action;
073: import org.netbeans.modules.compapp.projects.jbi.api.InternalProjectTypePlugin;
074: import org.netbeans.modules.compapp.projects.jbi.api.JbiInstalledProjectPluginInfo;
075: import org.netbeans.modules.compapp.projects.jbi.api.JbiProjectActionPerformer;
076: import org.netbeans.modules.compapp.projects.jbi.ui.actions.AddProjectAction;
077:
078: /**
079: * DOCUMENT ME!
080: *
081: * @author
082: * @version
083: */
084: public class JbiModuleViewNode extends AbstractNode {
085: private static Image JBI_MODULES_BADGE = Utilities
086: .loadImage(
087: "org/netbeans/modules/compapp/projects/jbi/ui/resources/compositeApplicationBadge.png",
088: true); // NOI18N
089: private final DataFolder aFolder;
090: private final JbiProject project;
091: private JbiModuleViewChildren children;
092:
093: /**
094: * Creates a new JbiModuleViewNode object.
095: *
096: * @param epp DOCUMENT ME!
097: * @param project DOCUMENT ME!
098: */
099: public JbiModuleViewNode(JbiProjectProperties epp,
100: JbiProject project) {
101: super (new JbiModuleViewChildren(project));
102: this .project = project;
103:
104: DataFolder projectFolder = null;
105: FileObject projectDir = project.getProjectDirectory();
106:
107: if (projectDir.isFolder()) {
108: projectFolder = DataFolder.findFolder(projectDir);
109: }
110:
111: this .aFolder = projectFolder;
112:
113: // Set FeatureDescriptor stuff:
114: setName("preferablyUniqueNameForThisNodeAmongSiblings"); // NOI18N or, super.setName if needed
115: setDisplayName(NbBundle.getMessage(JbiModuleViewNode.class,
116: "LBL_ModuleViewNode")); // NOI18N
117:
118: //setShortDescription(NbBundle.getMessage(JbiModuleViewNode.class, "HINT_LogicalViewNode"));
119: getCookieSet().add(new JbiProjectCookie(project));
120:
121: // set the model listener
122: FileChangeAdapter fca = new FileChangeAdapter() {
123: public void fileChanged(FileEvent ev) {
124: //log("ModView: Contents changed.");
125: RequestProcessor.getDefault().post(new Runnable() {
126: public void run() {
127: updateChildren();
128: }
129: });
130: }
131:
132: /**
133: * DOCUMENT ME!
134: *
135: * @param ev DOCUMENT ME!
136: */
137: public void fileAttributeChanged(FileAttributeEvent ev) {
138: //log("ModView: "+ev.getName() + ": " + ev.getOldValue() + " -> " + ev.getNewValue());
139: }
140: };
141:
142: File pf = FileUtil.toFile(project.getProjectDirectory());
143: File file = new File(pf.getPath() + "/nbproject/project.xml"); // NOI18N
144: FileObject modelFile = FileUtil.toFileObject(file);
145: modelFile.addFileChangeListener(fca);
146:
147: children = (JbiModuleViewChildren) this .getChildren();
148: }
149:
150: private void updateChildren() {
151: if (children != null) {
152: children.addNotify();
153: }
154:
155: //JbiModuleViewChildren ch = new JbiModuleViewChildren(project.getProjectProperties());
156: //this.setChildren(ch);
157: // ch.addNotify();
158: }
159:
160: /**
161: * DOCUMENT ME!
162: *
163: * @param type DOCUMENT ME!
164: *
165: * @return DOCUMENT ME!
166: */
167: public Image getIcon(int type) {
168: return computeIcon(false, type);
169: }
170:
171: /**
172: * DOCUMENT ME!
173: *
174: * @param type DOCUMENT ME!
175: *
176: * @return DOCUMENT ME!
177: */
178: public Image getOpenedIcon(int type) {
179: return computeIcon(true, type);
180: }
181:
182: private Image computeIcon(boolean opened, int type) {
183: if (aFolder != null) {
184: Node folderNode = aFolder.getNodeDelegate();
185: Image image = opened ? folderNode.getOpenedIcon(type)
186: : folderNode.getIcon(type);
187:
188: return Utilities
189: .mergeImages(image, JBI_MODULES_BADGE, 7, 7);
190: } else {
191: return JBI_MODULES_BADGE;
192: }
193: }
194:
195: // Create the popup menu:
196: public Action[] getActions(boolean context) {
197: ResourceBundle bundle = NbBundle
198: .getBundle(JbiModuleViewNode.class);
199: int actCnt = 0;
200: Action[] actions = null;
201: Action addJBIModule = new AbstractAction(bundle
202: .getString("LBL_AddProjectAction_Name"), null) {
203: public void actionPerformed(ActionEvent e) {
204: new AddProjectAction().perform(project);
205: }
206: };
207:
208: // Add Actions added by other modules.
209: JbiInstalledProjectPluginInfo plugins = JbiInstalledProjectPluginInfo
210: .getProjectPluginInfo();
211: List<JbiProjectActionPerformer> pluginActions = new ArrayList<JbiProjectActionPerformer>();
212:
213: if (plugins != null) {
214: List<InternalProjectTypePlugin> plist = plugins
215: .getUncategorizedProjectPluginList();
216: for (InternalProjectTypePlugin plugin : plist) {
217: List<JbiProjectActionPerformer> acts = plugin
218: .getProjectActions();
219: for (JbiProjectActionPerformer act : acts) {
220: if (act.getActionType().equalsIgnoreCase(
221: JbiProjectActionPerformer.ACT_ADD_PROJECT)) {
222: pluginActions.add(act);
223: }
224: }
225: }
226:
227: if (pluginActions.size() > 0) {
228: actions = new Action[pluginActions.size() + 1];
229: actions[actCnt++] = addJBIModule;
230: for (final JbiProjectActionPerformer act : pluginActions) {
231: actions[actCnt++] = new AbstractAction(act
232: .getLabel(), act.getIcon()) {
233: public void actionPerformed(ActionEvent e) {
234: act.perform(project);
235: }
236: };
237: }
238: }
239: }
240:
241: if (actions == null) {
242: actions = new Action[1];
243: actions[0] = addJBIModule;
244: }
245:
246: return actions;
247: }
248:
249: /**
250: * DOCUMENT ME!
251: *
252: * @return DOCUMENT ME!
253: */
254: public HelpCtx getHelpCtx() {
255: return HelpCtx.DEFAULT_HELP;
256:
257: // When you have help, change to:
258: // return new HelpCtx(LogicalViewNode.class);
259: }
260:
261: private void log(String str) {
262: OutputWriter out = IOProvider.getDefault().getStdOut();
263: out.println(str);
264: out.flush();
265: }
266:
267: public JbiProject getProject() {
268: return project;
269: }
270: }
|