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.loaders.DataFolder;
044: import org.openide.nodes.Node;
045: import org.openide.util.HelpCtx;
046: import org.openide.util.NbBundle;
047: import org.openide.util.actions.CookieAction;
048: import org.openide.util.actions.Presenter;
049: import org.openide.util.actions.SystemAction;
050:
051: import java.awt.Component;
052:
053: import javax.swing.JMenu;
054: import javax.swing.JMenuItem;
055: import javax.swing.JPopupMenu;
056: import javax.swing.JToolBar;
057:
058: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
059:
060: /**
061: *
062: */
063: public class CreateNonProjectAction extends CookieAction implements
064: Presenter.Menu, Presenter.Popup, Presenter.Toolbar {
065: ////////////////////////////////////////////////////////////////////////////
066: // Instant variables
067: ////////////////////////////////////////////////////////////////////////////
068:
069: /** List of system actions to be displayed within this one's toolbar or submenu. */
070: private SystemAction[] grouped = null;
071:
072: public CreateNonProjectAction(FilesharingContext context, Node node) {
073: init(context, node);
074: }
075:
076: private void init(FilesharingContext context, Node node) {
077: grouped = new SystemAction[] {
078: new NewFileAction(context, node),
079: new NewFolderAction(context, node) };
080: }
081:
082: protected Class[] cookieClasses() {
083: return new Class[] { DataFolder.class };
084: }
085:
086: protected int mode() {
087: return MODE_ALL;
088: }
089:
090: protected void performAction(org.openide.nodes.Node[] node) {
091: // do nothing; should not be called
092: }
093:
094: public String getName() {
095: return NbBundle.getMessage(CreateNonProjectAction.class,
096: "LBL_TestsAction_Name");
097: }
098:
099: protected String iconResource() {
100: return "org/netbeans/modules/collab/channel/filesharing/resources/" //NOI18N
101: + "createNew.gif"; //NOI18N
102: }
103:
104: public HelpCtx getHelpCtx() {
105: return new HelpCtx(CreateNonProjectAction.class);
106: }
107:
108: public JMenuItem getMenuPresenter() {
109: JMenu menu = new LazyMenu(getName());
110:
111: return menu;
112: }
113:
114: public JMenuItem getPopupPresenter() {
115: JMenu menu = new JMenu(getName());
116:
117: // Conventional not to set an icon here.
118: for (int i = 0; i < grouped.length; i++) {
119: SystemAction action = grouped[i];
120:
121: if (action == null) {
122: menu.addSeparator();
123: } else if (action instanceof Presenter.Popup) {
124: menu
125: .add(((Presenter.Popup) action)
126: .getPopupPresenter());
127: }
128: }
129:
130: return menu;
131: }
132:
133: public Component getToolbarPresenter() {
134: JToolBar toolbar = new JToolBar( /* In JDK 1.3 you may add: getName () */
135: );
136:
137: for (int i = 0; i < grouped.length; i++) {
138: SystemAction action = grouped[i];
139:
140: if (action == null) {
141: toolbar.addSeparator();
142: } else if (action instanceof Presenter.Toolbar) {
143: toolbar.add(((Presenter.Toolbar) action)
144: .getToolbarPresenter());
145: }
146: }
147:
148: return toolbar;
149: }
150:
151: /**
152: * Lazy menu which when added to its parent menu, will begin creating the
153: * list of submenu items and finding their presenters.
154: */
155: private final class LazyMenu extends JMenu {
156: public LazyMenu(String name) {
157: super (name);
158: }
159:
160: public JPopupMenu getPopupMenu() {
161: if (getItemCount() == 0) {
162: for (int i = 0; i < grouped.length; i++) {
163: SystemAction action = grouped[i];
164:
165: if (action == null) {
166: addSeparator();
167: } else if (action instanceof Presenter.Menu) {
168: add(((Presenter.Menu) action)
169: .getMenuPresenter());
170: }
171: }
172: }
173:
174: return super.getPopupMenu();
175: }
176: }
177: }
|