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.netbeans.api.project.Project;
043: import org.openide.WizardDescriptor;
044: import org.openide.util.Exceptions;
045: import org.openide.util.HelpCtx;
046:
047: import javax.swing.event.ChangeListener;
048: import java.awt.*;
049: import java.util.Collections;
050: import java.util.Map;
051:
052: /**
053: * @author David Kaspar
054: */
055: public class AddToPaletteWizardPanel2 implements WizardDescriptor.Panel {
056:
057: /**
058: * The visual component that displays this panel. If you need to access the
059: * component from this class, just use getComponent().
060: */
061: private AddToPaletteVisualPanel2 component;
062:
063: // Get the visual component for the panel. In this template, the component
064: // is kept separate. This can be more efficient: if the wizard is created
065: // but never displayed, or not all panels are displayed, it is better to
066: // create only those which really need to be visible.
067: public Component getComponent() {
068: if (component == null) {
069: component = new AddToPaletteVisualPanel2();
070: }
071: return component;
072: }
073:
074: public HelpCtx getHelp() {
075: return new HelpCtx(AddToPaletteWizardPanel2.class);
076: }
077:
078: public boolean isValid() {
079: // If it is always OK to press Next or Finish, then:
080: return true;
081: // If it depends on some condition (form filled out...), then:
082: // return someCondition();
083: // and when this condition changes (last form field filled in...) then:
084: // fireChangeEvent();
085: // and uncomment the complicated stuff below.
086: }
087:
088: public final void addChangeListener(ChangeListener l) {
089: }
090:
091: public final void removeChangeListener(ChangeListener l) {
092: }
093:
094: /*
095: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1);
096: public final void addChangeListener(ChangeListener l) {
097: synchronized (listeners) {
098: listeners.add(l);
099: }
100: }
101: public final void removeChangeListener(ChangeListener l) {
102: synchronized (listeners) {
103: listeners.remove(l);
104: }
105: }
106: protected final void fireChangeEvent() {
107: Iterator<ChangeListener> it;
108: synchronized (listeners) {
109: it = new HashSet<ChangeListener>(listeners).iterator();
110: }
111: ChangeEvent ev = new ChangeEvent(this);
112: while (it.hasNext()) {
113: it.next().stateChanged(ev);
114: }
115: }
116: */
117:
118: // You can use a settings object to keep track of state. Normally the
119: // settings object will be the WizardDescriptor, so you can use
120: // WizardDescriptor.getProperty & putProperty to store information entered
121: // by the user.
122: public void readSettings(Object settings) {
123: getComponent();
124: Project project = (Project) ((WizardDescriptor) settings)
125: .getProperty(AddToPaletteWizardAction.PROPERTY_PROJECT);
126: Map<String, ComponentInstaller.Item> items = null;
127: try {
128: items = ComponentInstaller.search(project);
129: } catch (Exception e) {
130: Exceptions.printStackTrace(e);
131: items = Collections.emptyMap();
132: }
133: ((WizardDescriptor) settings).putProperty(
134: AddToPaletteWizardAction.PROPERTY_ITEMS, items);
135: component.setItems(items.values());
136: }
137:
138: public void storeSettings(Object settings) {
139: ((WizardDescriptor) settings).putProperty(
140: AddToPaletteWizardAction.PROPERTY_TO_INSTALL, component
141: .getSelectedItems());
142: }
143:
144: }
|