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: */package org.netbeans.modules.vmd.midp.palette.wizard;
041:
042: import org.openide.DialogDisplayer;
043: import org.openide.WizardDescriptor;
044: import org.openide.util.HelpCtx;
045: import org.openide.util.NbBundle;
046: import org.openide.util.actions.CallableSystemAction;
047: import org.netbeans.modules.vmd.api.model.DesignDocument;
048: import org.netbeans.modules.vmd.api.model.common.ActiveDocumentSupport;
049: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
050:
051: import javax.swing.*;
052: import java.awt.*;
053: import java.text.MessageFormat;
054: import java.util.Map;
055: import java.util.List;
056:
057: /**
058: * @author David Kaspar
059: */
060: public final class AddToPaletteWizardAction extends
061: CallableSystemAction {
062:
063: static final String PROPERTY_PROJECT = "project"; // NOI18N
064: static final String PROPERTY_ITEMS = "items"; // NOI18N
065: static final String PROPERTY_TO_INSTALL = "toInstall"; // NOI18N
066:
067: private WizardDescriptor.Panel[] panels;
068:
069: public AddToPaletteWizardAction() {
070: putValue(Action.NAME, NbBundle.getMessage(
071: AddToPaletteWizardAction.class,
072: "NAME_AddToPaletteWizard")); // NOI18N
073: putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(
074: AddToPaletteWizardAction.class,
075: "DESC_AddToPaletteWizard")); // NOI18N
076: }
077:
078: public void performAction() {
079: DesignDocument document = ActiveDocumentSupport.getDefault()
080: .getActiveDocument();
081: if (document == null) {
082: return;
083: }
084:
085: if (!MidpDocumentSupport.PROJECT_TYPE_MIDP.equals(document
086: .getDocumentInterface().getProjectType()))
087: return;
088:
089: WizardDescriptor wizardDescriptor = new WizardDescriptor(
090: getPanels());
091: // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
092: wizardDescriptor.setTitleFormat(new MessageFormat("{0}")); // NOI18N
093: wizardDescriptor.setTitle(NbBundle.getMessage(
094: AddToPaletteWizardAction.class,
095: "TITLE_AddToPaletteWizard")); // NOI18N
096: Dialog dialog = DialogDisplayer.getDefault().createDialog(
097: wizardDescriptor);
098: dialog.getAccessibleContext().setAccessibleName(
099: NbBundle.getMessage(AddToPaletteWizardAction.class,
100: "TITLE_AddToPaletteWizard")); //NOI18N
101: dialog.getAccessibleContext().setAccessibleDescription(
102: NbBundle.getMessage(AddToPaletteWizardAction.class,
103: "TITLE_AddToPaletteWizard")); //NOI18N
104: dialog.setVisible(true);
105: dialog.toFront();
106: boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
107:
108: if (!cancelled) {
109: ComponentInstaller
110: .install(
111: (Map<String, ComponentInstaller.Item>) wizardDescriptor
112: .getProperty(PROPERTY_ITEMS),
113: (List<ComponentInstaller.Item>) wizardDescriptor
114: .getProperty(PROPERTY_TO_INSTALL));
115: }
116: }
117:
118: /**
119: * Initialize panels representing individual wizard's steps and sets
120: * various properties for them influencing wizard appearance.
121: */
122: private WizardDescriptor.Panel[] getPanels() {
123: if (panels == null) {
124: panels = new WizardDescriptor.Panel[] {
125: new AddToPaletteWizardPanel1(),
126: new AddToPaletteWizardPanel2() };
127: String[] steps = new String[panels.length];
128: for (int i = 0; i < panels.length; i++) {
129: Component c = panels[i].getComponent();
130: // Default step name to component name of panel. Mainly useful
131: // for getting the name of the target chooser to appear in the
132: // list of steps.
133: steps[i] = c.getName();
134: if (c instanceof JComponent) { // assume Swing components
135: JComponent jc = (JComponent) c;
136: // Sets step number of a component
137: jc.putClientProperty(
138: "WizardPanel_contentSelectedIndex",
139: new Integer(i)); // NOI18N
140: // Sets steps names for a panel
141: jc.putClientProperty("WizardPanel_contentData",
142: steps); // NOI18N
143: // Turn on subtitle creation on each step
144: jc.putClientProperty("WizardPanel_autoWizardStyle",
145: Boolean.TRUE); // NOI18N
146: // Show steps on the left side with the image on the background
147: jc.putClientProperty(
148: "WizardPanel_contentDisplayed",
149: Boolean.TRUE); // NOI18N
150: // Turn on numbering of all steps
151: jc.putClientProperty("WizardPanel_contentNumbered",
152: Boolean.TRUE); // NOI18N
153: }
154: }
155: }
156: return panels;
157: }
158:
159: public String getName() {
160: return NbBundle.getMessage(AddToPaletteWizardAction.class,
161: "DISP_AddToPaletteWizard"); // NOI18N
162: }
163:
164: public String iconResource() {
165: return null;
166: }
167:
168: public HelpCtx getHelpCtx() {
169: return new HelpCtx(AddToPaletteWizardAction.class);
170: }
171:
172: protected boolean asynchronous() {
173: return false;
174: }
175:
176: }
|