001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: *
022: * Copyright 2005 Sun Microsystems, Inc.
023: *
024: * Licensed under the Apache License, Version 2.0 (the "License");
025: * you may not use this file except in compliance with the License.
026: * You may obtain a copy of the License at
027: *
028: * http://www.apache.org/licenses/LICENSE-2.0
029: *
030: * Unless required by applicable law or agreed to in writing, software
031: * distributed under the License is distributed on an "AS IS" BASIS,
032: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
033: * See the License for the specific language governing permissions and
034: * limitations under the License.
035: *
036: */
037: package org.netbeans.modules.jdbcwizard.wizards;
038:
039: import java.awt.BorderLayout;
040: import java.awt.Component;
041: import java.awt.event.ActionEvent;
042: import java.awt.event.ActionListener;
043: import java.util.ArrayList;
044: import java.util.Arrays;
045: import java.util.HashSet;
046: import java.util.List;
047: import java.util.Set;
048:
049: import javax.swing.JPanel;
050: import javax.swing.event.ChangeListener;
051:
052: import org.openide.NotifyDescriptor;
053: import org.openide.WizardDescriptor;
054: import org.openide.util.HelpCtx;
055:
056: /**
057: * Implements a two-list transfer panel with bulk add/remove capability.
058: *
059: * @author
060: */
061: public class JDBCWizardTransferPanel extends JPanel implements
062: ActionListener, WizardDescriptor.Panel {
063:
064: /**
065: *
066: */
067: private static final long serialVersionUID = 1L;
068:
069: /* Log4J category string */
070: private static final String LOG_CATEGORY = JDBCWizardTransferPanel.class
071: .getName();
072:
073: /* Set <ChangeListeners> */
074: private final Set listeners = new HashSet(1);
075:
076: private List selTableList = new ArrayList();
077:
078: private JDBCWizardTablePanel tablePanel;
079:
080: /** Creates a default instance of JDBCWizardTransferPanel. */
081: public JDBCWizardTransferPanel() {
082: }
083:
084: /**
085: * Creates a new instance of JDBCWizardTransferPanel using the given ListModels to initially
086: * populate the source and destination panels.
087: *
088: * @param title String to be displayed as title of this panel
089: * @param dsList List of DatabaseModels used to populate datasource panel
090: * @param destColl Collection of selected DatabaseModels
091: * @param sourceOTD true if this panel displays available selections for source OTDs; false if
092: * it displays available destination OTDs
093: */
094: public JDBCWizardTransferPanel(final String title) {
095: this ();
096: if (title != null && title.trim().length() != 0) {
097: this .setName(title);
098: }
099:
100: // final ArrayList testList = new ArrayList();
101: // this.tablePanel = new JDBCWizardTablePanel(testList);
102: //
103: // this.setLayout(new BorderLayout());
104: // this.add(this.tablePanel, BorderLayout.CENTER);
105: // JDBCWizardTransferPanel.this.tablePanel.resetTable(this.selTableList);
106: }
107:
108: /**
109: * Invoked whenever one of the transfer buttons is clicked.
110: *
111: * @param e ActionEvent to handle
112: */
113: public void actionPerformed(final ActionEvent e) {
114: // String cmd = e.getActionCommand();
115:
116: }
117:
118: /**
119: * @see org.openide.WizardDescriptor.Panel#addChangeListener
120: */
121: public void addChangeListener(final ChangeListener l) {
122: synchronized (this .listeners) {
123: this .listeners.add(l);
124: }
125: }
126:
127: /**
128: * @see org.openide.WizardDescriptor.Panel#getComponent
129: */
130: public Component getComponent() {
131: return this ;
132: }
133:
134: /**
135: * @see org.openide.WizardDescriptor.Panel#getHelp
136: */
137: public HelpCtx getHelp() {
138: // Show no Help button for this panel:
139: return new HelpCtx(JDBCWizardTransferPanel.class);
140:
141: }
142:
143: /**
144: * @see org.openide.WizardDescriptor.Panel#isValid
145: */
146: public boolean isValid() {
147: boolean returnVal = false;
148:
149: if (this .tablePanel.getTables().size() != 0) {
150: returnVal = true;
151: }
152: return returnVal;
153: }
154:
155: /**
156: * @see org.openide.WizardDescriptor.Panel#readSettings
157: */
158: public void readSettings(final Object settings) {
159: WizardDescriptor wizard = null;
160: if (settings instanceof JDBCWizardContext) {
161: final JDBCWizardContext wizardContext = (JDBCWizardContext) settings;
162: wizard = (WizardDescriptor) wizardContext
163: .getProperty(JDBCWizardContext.WIZARD_DESCRIPTOR);
164:
165: } else if (settings instanceof WizardDescriptor) {
166: wizard = (WizardDescriptor) settings;
167: }
168:
169: if (wizard != null
170: && WizardDescriptor.NEXT_OPTION.equals(wizard
171: .getValue())) {
172: final Object[] sources = (Object[]) wizard
173: .getProperty(JDBCWizardContext.SELECTEDTABLES);
174: this .selTableList = Arrays.asList(sources);
175: final ArrayList testList = new ArrayList();
176: this .tablePanel = new JDBCWizardTablePanel(testList);
177:
178: this .setLayout(new BorderLayout());
179: this .add(this .tablePanel, BorderLayout.CENTER);
180: JDBCWizardTransferPanel.this .tablePanel
181: .resetTable(this .selTableList);
182: }
183: }
184:
185: /**
186: * @see org.openide.WizardDescriptor.Panel#removeChangeListener
187: */
188: public void removeChangeListener(final ChangeListener l) {
189: synchronized (this .listeners) {
190: this .listeners.remove(l);
191: }
192: }
193:
194: /**
195: * @see org.openide.WizardDescriptor.Panel#storeSettings
196: */
197: public void storeSettings(final Object settings) {
198: WizardDescriptor wizard = null;
199: if (settings instanceof JDBCWizardContext) {
200: final JDBCWizardContext wizardContext = (JDBCWizardContext) settings;
201: wizard = (WizardDescriptor) wizardContext
202: .getProperty(JDBCWizardContext.WIZARD_DESCRIPTOR);
203:
204: } else if (settings instanceof WizardDescriptor) {
205: wizard = (WizardDescriptor) settings;
206: }
207:
208: final Object selectedOption = wizard.getValue();
209: if (NotifyDescriptor.CANCEL_OPTION == selectedOption
210: || NotifyDescriptor.CLOSED_OPTION == selectedOption) {
211: return;
212: }
213: if (selectedOption.toString().equals("PREVIOUS_OPTION")) {
214: this.remove(this.tablePanel);
215: this.selTableList = null;
216: return;
217: }
218: }
219:
220: }
|