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:
042: package org.netbeans.modules.form.wizard;
043:
044: import java.beans.*;
045: import javax.swing.event.*;
046: import org.netbeans.modules.form.*;
047:
048: /**
049: * The second panel of connection wizard - for selecting what to perform on
050: * the target component (set a property, call a method or execute some user code).
051: *
052: * @author Tomas Pavek
053: */
054:
055: class ConnectionWizardPanel2 implements
056: org.openide.WizardDescriptor.Panel {
057:
058: static final int METHOD_TYPE = 0;
059: static final int PROPERTY_TYPE = 1;
060: static final int CODE_TYPE = 2;
061:
062: private RADComponent targetComponent;
063:
064: private EventListenerList listenerList;
065:
066: private ConnectionPanel2 uiPanel;
067:
068: // -------
069:
070: ConnectionWizardPanel2(RADComponent target) {
071: targetComponent = target;
072: }
073:
074: RADComponent getTargetComponent() {
075: return targetComponent;
076: }
077:
078: int getActionType() {
079: return uiPanel != null ? uiPanel.getActionType() : -1;
080: }
081:
082: MethodDescriptor getSelectedMethod() {
083: return uiPanel != null ? uiPanel.getSelectedMethod() : null;
084: }
085:
086: PropertyDescriptor getSelectedProperty() {
087: return uiPanel != null ? uiPanel.getSelectedProperty() : null;
088: }
089:
090: // ----------
091: // WizardDescriptor.Panel implementation
092:
093: public java.awt.Component getComponent() {
094: if (uiPanel == null)
095: uiPanel = new ConnectionPanel2(this );
096: return uiPanel;
097: }
098:
099: public org.openide.util.HelpCtx getHelp() {
100: return new org.openide.util.HelpCtx("gui.connecting.target"); // NOI18N
101: }
102:
103: public boolean isValid() {
104: return getActionType() == CODE_TYPE
105: || getSelectedMethod() != null
106: || getSelectedProperty() != null;
107: }
108:
109: public void readSettings(java.lang.Object settings) {
110: }
111:
112: public void storeSettings(java.lang.Object settings) {
113: }
114:
115: public void addChangeListener(ChangeListener listener) {
116: if (listenerList == null)
117: listenerList = new EventListenerList();
118: listenerList.add(ChangeListener.class, listener);
119: }
120:
121: public void removeChangeListener(ChangeListener listener) {
122: if (listenerList != null)
123: listenerList.remove(ChangeListener.class, listener);
124: }
125:
126: // --------
127:
128: void fireStateChanged() {
129: if (listenerList == null)
130: return;
131:
132: ChangeEvent e = null;
133: Object[] listeners = listenerList.getListenerList();
134: for (int i = listeners.length - 2; i >= 0; i -= 2) {
135: if (listeners[i] == ChangeListener.class) {
136: if (e == null)
137: e = new ChangeEvent(this );
138: ((ChangeListener) listeners[i + 1]).stateChanged(e);
139: }
140: }
141: }
142: }
|