/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2008 Jonas Fonseca <fonseca@diku.dk> * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file. * * This particular file is subject to the "Classpath" exception as provided * by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.nbgit.ui.custom; import java.awt.Component; import java.awt.Dialog; import java.awt.event.ActionEvent; import java.text.MessageFormat; import javax.swing.Action; import javax.swing.JComponent; import org.nbgit.ui.ContextAction; import org.openide.DialogDisplayer; import org.openide.WizardDescriptor; public final class CustomWizardAction extends ContextAction { private WizardDescriptor.Panel<WizardDescriptor>[] panels; private CustomActionBuilder builder; CustomWizardAction(String name, CustomActionBuilder builder) { super(name, builder.getContext()); this.builder = builder; } @Override public boolean isEnabled() { return true; } protected void performAction(ActionEvent event) { WizardDescriptor wizard = new WizardDescriptor(getPanels()); // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() wizard.setTitleFormat(new MessageFormat("{0}")); wizard.setTitle((String) getValue(Action.NAME)); Dialog dialog = DialogDisplayer.getDefault().createDialog(wizard); dialog.setVisible(true); dialog.toFront(); boolean cancelled = wizard.getValue() != WizardDescriptor.FINISH_OPTION; if (!cancelled) { if (builder.isValid()) builder.build(); } } /** * Initialize panels representing individual wizard's steps and sets * various properties for them influencing wizard appearance. */ @SuppressWarnings("unchecked") private WizardDescriptor.Panel<WizardDescriptor>[] getPanels() { if (panels == null) { panels = new WizardDescriptor.Panel[] { new CustomWizardPanel(builder) }; String[] steps = new String[panels.length]; for (int i = 0; i < panels.length; i++) { Component c = panels[i].getComponent(); // Default step name to component name of panel. Mainly useful // for getting the name of the target chooser to appear in the // list of steps. steps[i] = c.getName(); if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Sets step number of a component jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Sets steps names for a panel jc.putClientProperty("WizardPanel_contentData", steps); // Turn on subtitle creation on each step jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // Show steps on the left side with the image on the background jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // Turn on numbering of all steps jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); } } } return panels; } }