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: package org.netbeans.modules.collab.channel.filesharing.ui.actions;
042:
043: import org.openide.DialogDisplayer;
044: import org.openide.NotifyDescriptor;
045: import org.openide.filesystems.FileObject;
046: import org.openide.filesystems.FileSystem;
047: import org.openide.loaders.DataFolder;
048: import org.openide.loaders.DataObject;
049: import org.openide.nodes.Node;
050: import org.openide.util.HelpCtx;
051: import org.openide.util.NbBundle;
052: import org.openide.util.actions.CookieAction;
053:
054: import java.io.IOException;
055:
056: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
057: import org.netbeans.modules.collab.channel.filesharing.ui.ProjectsRootNode;
058: import org.netbeans.modules.collab.core.Debug;
059:
060: /**
061: *
062: */
063: public class NewFolderAction extends CookieAction {
064: ////////////////////////////////////////////////////////////////////////////
065: // Class variables
066: ////////////////////////////////////////////////////////////////////////////
067: public static final String NEW_FOLDER_ACTION = NbBundle.getMessage(
068: NewFolderAction.class, "LBL_NewFolderAction_ActionName"); //"Folder"
069:
070: ////////////////////////////////////////////////////////////////////////////
071: // Instant variables
072: ////////////////////////////////////////////////////////////////////////////
073: FilesharingContext context = null;
074: Node node = null;
075:
076: public NewFolderAction() {
077: }
078:
079: public NewFolderAction(FilesharingContext context, Node node) {
080: this .context = context;
081: this .node = node;
082: }
083:
084: /* public members */
085: public String getName() {
086: return NbBundle.getMessage(NewFolderAction.class,
087: "LBL_NewFolderAction_ActionName"); //NOI18N
088: }
089:
090: public HelpCtx getHelpCtx() {
091: return HelpCtx.DEFAULT_HELP;
092: }
093:
094: /* protected members */
095: protected Class[] cookieClasses() {
096: return new Class[] { DataFolder.class };
097: }
098:
099: protected int mode() {
100: return MODE_ANY; // allow creation of tests for multiple selected nodes (classes, packages)
101: }
102:
103: public boolean asynchronous() {
104: return true; // yes, this action should run asynchronously
105:
106: // would be better to rewrite it to synchronous (running in AWT thread),
107: // just replanning test generation to RequestProcessor
108: }
109:
110: /** Perform special enablement check in addition to the normal one.
111: * protected boolean enable (Node[] nodes) {
112: * if (! super.enable (nodes)) return false;
113: * if (...) ...;
114: * }
115: */
116: protected boolean enable(Node[] nodes) {
117: return true;
118: }
119:
120: /**
121: * Returns true iff the node represents a source file or package.
122: * @param node the Node to query
123: * @return true or false
124: */
125: private static boolean isEnabledOnNode(Node node) {
126: DataObject dob = (DataObject) node.getCookie(DataObject.class);
127: FileObject fo = null;
128:
129: if (dob != null) {
130: fo = dob.getPrimaryFile();
131: }
132:
133: if (fo == null) {
134: return false;
135: }
136:
137: return true;
138: }
139:
140: protected String iconResource() {
141: return "org/netbeans/modules/collab/channel/filesharing/resources/" //NOI18N
142: + "folder.gif"; //NOI18N
143: }
144:
145: protected void performAction(Node[] nodes) {
146: Debug.out.println(NEW_FOLDER_ACTION + ", actionPerformed"); //NoI18n
147:
148: NotifyDescriptor descriptor = new NotifyDescriptor.InputLine(
149: NbBundle.getMessage(NewFolderAction.class,
150: "MSG_NewFolderAction_NewFolderName"), NbBundle
151: .getMessage(NewFolderAction.class,
152: "MSG_NewFolderAction_NewFolderTitle"),
153: NotifyDescriptor.OK_CANCEL_OPTION,
154: NotifyDescriptor.PLAIN_MESSAGE);
155:
156: if (DialogDisplayer.getDefault().notify(descriptor) != NotifyDescriptor.OK_OPTION) {
157: return;
158: }
159:
160: final String folderName = ((NotifyDescriptor.InputLine) descriptor)
161: .getInputText();
162:
163: try {
164: FileSystem fs = context.getCollabFilesystem();
165: fs.runAtomicAction(new FileSystem.AtomicAction() {
166: public void run() throws IOException {
167: try {
168: Node projectNode = context.createProjectNode(
169: context.getLoginUser(),
170: ProjectsRootNode.SHARED_COMMON_DIR);
171:
172: if (projectNode != null) {
173: //expand node
174: context.getFilesystemExplorer()
175: .expandTreeNode(projectNode, "");
176:
177: DataObject d = (DataObject) node
178: .getCookie(DataObject.class);
179: FileObject fObj = null;
180:
181: if (node instanceof ProjectsRootNode
182: || node instanceof ProjectsRootNode.ProjectNode) {
183: fObj = ((ProjectsRootNode.ProjectNode) projectNode)
184: .getProjectDir();
185: } else if ((d != null)
186: && (d.getPrimaryFile() != null)) {
187: fObj = d.getPrimaryFile();
188: }
189:
190: //expand node
191: context.getFilesystemExplorer()
192: .expandTreeNode(node, "");
193:
194: //create folder
195: if (fObj != null) {
196: fObj.createFolder(folderName);
197: }
198: }
199: } catch (IOException iox) {
200: Debug.log("ProjectsRootNode",
201: "ProjectsRootNode, ex: " + iox);
202: iox.printStackTrace(Debug.out);
203: }
204: }
205: });
206: } catch (IOException iox) {
207: iox.printStackTrace(Debug.out);
208: }
209: }
210: }
|