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-2007 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: package org.netbeans.modules.etl.ui.view.wizards;
042:
043: import java.awt.BorderLayout;
044: import java.awt.event.ActionEvent;
045: import java.util.ArrayList;
046: import java.util.Collection;
047: import java.util.HashSet;
048: import java.util.Iterator;
049: import java.util.List;
050: import java.util.Set;
051:
052: import javax.swing.JPanel;
053: import javax.swing.event.ChangeListener;
054:
055: import org.netbeans.modules.sql.framework.model.SQLDBModel;
056: import org.netbeans.modules.sql.framework.model.SQLDBTable;
057: import org.netbeans.modules.sql.framework.model.SQLJoinView;
058: import org.netbeans.modules.sql.framework.model.SourceTable;
059: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
060: import org.netbeans.modules.sql.framework.ui.view.join.JoinMainPanel;
061: import org.netbeans.modules.sql.framework.ui.view.join.ListTransferPanel;
062: import org.openide.NotifyDescriptor;
063: import org.openide.WizardDescriptor;
064: import org.openide.util.HelpCtx;
065:
066: /**
067: * @author radval
068: */
069: public class ETLCollaborationWizardJoinPanel extends JPanel implements
070: WizardDescriptor.Panel {
071:
072: private ETLCollaborationWizard etlCWizard;
073:
074: // JoinMainPanel
075: private JoinMainPanel joinMainPanel;
076:
077: /* Set <ChangeListeners> */
078: private final Set listeners = new HashSet(1);
079:
080: /** Creates a new instance of ETLCollaborationWizardJoinPanel */
081: public ETLCollaborationWizardJoinPanel(
082: ETLCollaborationWizard owner, String title, IGraphView view) {
083: this .etlCWizard = owner;
084: if (title != null && title.trim().length() != 0) {
085: setName(title);
086: }
087:
088: this .setLayout(new BorderLayout());
089:
090: joinMainPanel = new JoinMainPanel(view, false);
091: joinMainPanel.reset(view);
092:
093: this .add(joinMainPanel, BorderLayout.CENTER);
094: this .joinMainPanel.setDividerLocation(210);
095: joinMainPanel.setPreviewModifiable(true);
096: }
097:
098: /**
099: * Add a listener to changes of the panel's validity.
100: *
101: * @param l the listener to add
102: * @see #isValid
103: */
104: public void addChangeListener(ChangeListener l) {
105: listeners.add(l);
106: }
107:
108: /**
109: * Get the component displayed in this panel.
110: *
111: * @return the component
112: */
113: public java.awt.Component getComponent() {
114: return this ;
115: }
116:
117: /**
118: * Help for this panel. When the panel is active, this is used as the help for the
119: * wizard dialog.
120: *
121: * @return the help or <code>null</code> if no help is supplied
122: */
123: public HelpCtx getHelp() {
124: return HelpCtx.DEFAULT_HELP;
125: }
126:
127: /**
128: * Test whether the panel is finished and it is safe to proceed to the next one. If
129: * the panel is valid, the "Next" (or "Finish") button will be enabled.
130: * <p>
131: * <strong>Tip: </strong> if your panel is actually the component itself (so
132: * {@link #getComponent}returns <code>this</code>), be sure to specifically
133: * override this method, as the unrelated implementation in
134: * {@link java.awt.Component#isValid}if not overridden could cause your wizard to
135: * behave erratically.
136: *
137: * @return <code>true</code> if the user has entered satisfactory information
138: */
139: @Override
140: public boolean isValid() {
141: return true;
142: }
143:
144: /**
145: * Provides the wizard panel with the current data--either the default data or
146: * already-modified settings, if the user used the previous and/or next buttons. This
147: * method can be called multiple times on one instance of
148: * <code>WizardDescriptor.Panel</code>.
149: * <p>
150: * The settings object is originally supplied to
151: * {@link WizardDescriptor#WizardDescriptor(WizardDescriptor.Iterator,Object)}. In
152: * the case of a <code>TemplateWizard.Iterator</code> panel, the object is in fact
153: * the <code>TemplateWizard</code>.
154: *
155: * @param settings the object representing wizard panel state
156: * @exception IllegalStateException if the the data provided by the wizard are not
157: * valid.
158: */
159: public void readSettings(Object settings) {
160: this .joinMainPanel.setDividerLocation(210);
161: Set sTables = new HashSet();
162: List sourceDb = etlCWizard.getSelectedSourceDb();
163: Iterator it = sourceDb.iterator();
164:
165: while (it.hasNext()) {
166: SQLDBModel dbModel = (SQLDBModel) it.next();
167: List tables = dbModel.getTables();
168: Iterator tableIt = tables.iterator();
169: while (tableIt.hasNext()) {
170: Object table = tableIt.next();
171: if (table instanceof SQLDBTable
172: && ((SQLDBTable) table).isEditable()
173: && ((SQLDBTable) table).isSelected()) {
174: sTables.add(table);
175: }
176: }
177: }
178:
179: List existingTargetTables = this .joinMainPanel.getTargetList();
180: sTables.removeAll(existingTargetTables);
181: this .joinMainPanel.setSourceList(new ArrayList(sTables));
182: }
183:
184: /**
185: * Remove a listener to changes of the panel's validity.
186: *
187: * @param l the listener to remove
188: */
189: public void removeChangeListener(ChangeListener l) {
190: this .listeners.remove(l);
191: }
192:
193: public void setSourceList(Collection sList) {
194: joinMainPanel.setSourceList(sList);
195: }
196:
197: public void setTargetList(Collection tList) {
198: joinMainPanel.setTargetList(tList);
199: }
200:
201: /**
202: * Provides the wizard panel with the opportunity to update the settings with its
203: * current customized state. Rather than updating its settings with every change in
204: * the GUI, it should collect them, and then only save them when requested to by this
205: * method. Also, the original settings passed to {@link #readSettings}should not be
206: * modified (mutated); rather, the object passed in here should be mutated according
207: * to the collected changes, in case it is a copy. This method can be called multiple
208: * times on one instance of <code>WizardDescriptor.Panel</code>.
209: * <p>
210: * The settings object is originally supplied to
211: * {@link WizardDescriptor#WizardDescriptor(WizardDescriptor.Iterator,Object)}. In
212: * the case of a <code>TemplateWizard.Iterator</code> panel, the object is in fact
213: * the <code>TemplateWizard</code>.
214: *
215: * @param settings the object representing wizard panel state
216: */
217: public void storeSettings(Object settings) {
218: SQLJoinView joinView = this .joinMainPanel.getSQLJoinView();
219:
220: if (joinView != null && joinView.getSQLJoinTables().size() > 1) {
221: WizardDescriptor wizard = null;
222: if (settings instanceof ETLWizardContext) {
223: ETLWizardContext wizardContext = (ETLWizardContext) settings;
224: wizard = (WizardDescriptor) wizardContext
225: .getProperty(ETLWizardContext.WIZARD_DESCRIPTOR);
226: } else if (settings instanceof WizardDescriptor) {
227: wizard = (WizardDescriptor) settings;
228: }
229:
230: Object selectedOption = wizard.getValue();
231: if (NotifyDescriptor.CANCEL_OPTION == selectedOption
232: || NotifyDescriptor.CLOSED_OPTION == selectedOption) {
233: return;
234: } else if (WizardDescriptor.PREVIOUS_OPTION == selectedOption) {
235: // Null out any references to join views.
236: wizard.putProperty(ETLCollaborationWizard.JOIN_VIEW,
237: null);
238: wizard
239: .putProperty(
240: ETLCollaborationWizard.JOIN_VIEW_VISIBLE_COLUMNS,
241: null);
242:
243: // Mark any tables associated with the current join view as selected and
244: // editable.
245: List joinSourceTables = joinView.getSourceTables();
246: List sourceDb = (List) wizard
247: .getProperty(ETLCollaborationWizard.SOURCE_DB);
248: Iterator it = sourceDb.iterator();
249: while (it.hasNext()) {
250: SQLDBModel dbModel = (SQLDBModel) it.next();
251: Iterator sIt = joinSourceTables.iterator();
252: while (sIt.hasNext()) {
253: SourceTable sTable = (SourceTable) sIt.next();
254: if (dbModel.equals(sTable.getParent())) {
255: sTable.setEditable(true);
256: sTable.setSelected(true);
257: }
258: }
259: }
260:
261: ListTransferPanel tp = joinMainPanel
262: .getListTransferPanel();
263: tp.actionPerformed(new ActionEvent(tp,
264: ActionEvent.ACTION_PERFORMED,
265: ListTransferPanel.LBL_REMOVE_ALL));
266:
267: // Zero out the source and target transfer panel lists.
268: this .joinMainPanel.setSourceList(new ArrayList());
269: this .joinMainPanel.setTargetList(new ArrayList());
270: } else { // Next or finish option
271: wizard.putProperty(ETLCollaborationWizard.JOIN_VIEW,
272: joinView);
273: wizard
274: .putProperty(
275: ETLCollaborationWizard.JOIN_VIEW_VISIBLE_COLUMNS,
276: this .joinMainPanel
277: .getTableColumnNodes());
278:
279: // NOW MARK TABLES WHICH ARE IN JOIN VIEW AS UNSELECTED AND UNEDITABLE
280: List joinSourceTables = joinView.getSourceTables();
281: List sourceDb = (List) wizard
282: .getProperty(ETLCollaborationWizard.SOURCE_DB);
283: Iterator it = sourceDb.iterator();
284: while (it.hasNext()) {
285: SQLDBModel dbModel = (SQLDBModel) it.next();
286: Iterator sIt = joinSourceTables.iterator();
287: while (sIt.hasNext()) {
288: SourceTable sTable = (SourceTable) sIt.next();
289: if (dbModel.equals(sTable.getParent())) {
290: sTable.setEditable(false);
291: sTable.setSelected(false);
292: }
293: }
294: }
295: }
296: }
297: }
298: }
|