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: * VWPContentActions.java
043: *
044: * Created on April 15, 2007, 10:24 PM
045: *
046: * To change this template, choose Tools | Template Manager
047: * and open the template in the editor.
048: */
049:
050: package org.netbeans.modules.visualweb.navigation;
051:
052: import java.awt.event.ActionEvent;
053: import java.awt.event.KeyEvent;
054: import java.lang.ref.WeakReference;
055: import javax.swing.AbstractAction;
056: import javax.swing.Action;
057: import javax.swing.KeyStroke;
058: import org.netbeans.modules.web.jsf.navigation.pagecontentmodel.PageContentItem;
059: import org.openide.util.NbBundle;
060:
061: /**
062: *
063: * @author joelle
064: */
065: public class VWPContentActions {
066: //
067: // /** Creates a new instance of VWPContentActions
068: // * @param facesModel
069: // */
070: public VWPContentActions(VWPContentModel vwpContentModel) {
071: setVwpContentModel(vwpContentModel);
072: // handleAddCommandButton.putValue("NAME", addButton);
073: // handleAddCommandLink.putValue("NAME", addHyperlink);
074: // handleAddImageHyperLink.putValue("NAME", addImageHyperlink);
075: }
076:
077: public Action[] getVWPContentModelActions() {
078: Action[] actions = new Action[] { handleAddCommandButton,
079: handleAddCommandLink, handleAddImageHyperLink };
080: return actions;
081: }
082:
083: public PageContentItem item;
084:
085: public Action[] getVWPContentItemActions(PageContentItem item) {
086: Action openHandleAction = new OpenHandleAction(item);
087: return new Action[] { new OpenHandleAction(item) };
088: }
089:
090: /*PageContentModel Actions*/
091: private final static String addButton = NbBundle.getMessage(
092: VWPContentActions.class, "MSG_AddButton");
093: private final static String addHyperlink = NbBundle.getMessage(
094: VWPContentActions.class, "MSG_AddHyperlink");
095: private final static String addImageHyperlink = NbBundle
096: .getMessage(VWPContentActions.class,
097: "MSG_AddImageHyperlink");
098:
099: /*PageContentItem Actions*/
100: private final static String openHandler = NbBundle.getMessage(
101: VWPContentActions.class, "MSG_OpenHandler");
102:
103: private Action handleAddCommandButton = new HandleAddCommandButton();
104:
105: public final class HandleAddCommandButton extends AbstractAction {
106: public HandleAddCommandButton() {
107: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
108: KeyEvent.VK_B, 0));
109: putValue(NAME, addButton);
110: }
111:
112: public void actionPerformed(ActionEvent ev) {
113:
114: getVwpContentModel()
115: .addPageBean(VWPContentUtilities.BUTTON);
116: }
117: };
118:
119: private Action handleAddCommandLink = new HandleAddCommandLink();
120:
121: public final class HandleAddCommandLink extends AbstractAction {
122: public HandleAddCommandLink() {
123: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
124: KeyEvent.VK_L, 0));
125: putValue(NAME, addHyperlink);
126: }
127:
128: public void actionPerformed(ActionEvent e) {
129: getVwpContentModel().addPageBean(
130: VWPContentUtilities.HYPERLINK);
131: }
132: };
133:
134: private Action handleAddImageHyperLink = new HandleAddImageHyperLink();
135:
136: public final class HandleAddImageHyperLink extends AbstractAction {
137: public HandleAddImageHyperLink() {
138: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
139: KeyEvent.VK_I, 0));
140: putValue(NAME, addImageHyperlink);
141: }
142:
143: public void actionPerformed(ActionEvent e) {
144: getVwpContentModel().addPageBean(
145: VWPContentUtilities.IMAGE_HYPERLINK);
146: }
147: };
148:
149: public final class OpenHandleAction extends AbstractAction {
150: private final PageContentItem item;
151:
152: public OpenHandleAction(PageContentItem item) {
153: this .item = item;
154: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
155: KeyEvent.VK_O, 0));
156: putValue(NAME, openHandler);
157: }
158:
159: public void actionPerformed(ActionEvent ev) {
160: getVwpContentModel().openPageHandler(item);
161:
162: }
163: }
164:
165: private WeakReference<VWPContentModel> refVWPContentModel;
166:
167: private VWPContentModel getVwpContentModel() {
168: VWPContentModel vwpContentModel = null;
169: if (refVWPContentModel != null) {
170: vwpContentModel = refVWPContentModel.get();
171: }
172: return vwpContentModel;
173: }
174:
175: private void setVwpContentModel(VWPContentModel vwpContentModel) {
176: refVWPContentModel = new WeakReference<VWPContentModel>(
177: vwpContentModel);
178: }
179:
180: }
|