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.io.IOException;
040: import java.util.ArrayList;
041: import java.util.Collection;
042: import java.util.Collections;
043: import java.util.HashSet;
044: import java.util.Iterator;
045: import java.util.List;
046: import java.util.MissingResourceException;
047: import java.util.Set;
048: import javax.swing.SwingUtilities;
049: import org.netbeans.api.project.Project;
050: import org.netbeans.api.project.ProjectUtils;
051: import org.netbeans.api.project.SourceGroup;
052: import org.netbeans.api.project.Sources;
053: import org.netbeans.spi.project.ui.templates.support.Templates;
054: import org.openide.ErrorManager;
055: import org.openide.WizardDescriptor;
056: import org.openide.cookies.OpenCookie;
057: import org.openide.filesystems.FileObject;
058: import org.openide.loaders.DataFolder;
059: import org.openide.loaders.DataObject;
060: import org.openide.nodes.Node;
061: import org.openide.util.NbBundle;
062:
063: /**
064: * Wizard to collect name and participating tables information to be used in creating a new JDBC
065: * collaboration.
066: */
067: public class JDBCCollaborationWizard extends JDBCWizard {
068: /**
069: *
070: *
071: */
072: public JDBCCollaborationWizard() {
073: }
074:
075: class Descriptor extends JDBCWizardDescriptor {
076: public Descriptor(final WizardDescriptor.Iterator iter) {
077: super (iter, JDBCCollaborationWizard.this .context);
078: }
079: }
080:
081: class WizardIterator extends JDBCWizardIterator {
082: private WizardDescriptor.Panel collaborationNamePanel;
083:
084: private JDBCWizardSelectionPanel dataSelectionPanel;
085:
086: private JNDINameFinishPanel jndiNamePanel;
087:
088: private List panels;
089:
090: private JDBCWizardTransferPanel sourceTableSelectionPanel;
091:
092: private JDBCCollaborationWizard mWizard;
093:
094: public WizardIterator(final JDBCCollaborationWizard wizard) {
095: this .mWizard = wizard;
096:
097: this .collaborationNamePanel = new JDBCWizardNameFinishPanel(
098: JDBCCollaborationWizard.this , NbBundle.getMessage(
099: JDBCCollaborationWizard.class,
100: "TITLE_tblwizard_name"));
101:
102: }
103:
104: public String name() {
105: return "";
106: }
107:
108: public void initialize(final WizardDescriptor wiz) {
109: this .mWizard.setDescriptor(wiz);
110: super .initialize(wiz);
111: }
112:
113: /**
114: * Overrides parent implementation to test for duplicate collab name before advancing to
115: * next panel, and skip join panel if fewer than two source tables are selected.
116: *
117: * @see org.openide.WizardDescriptor.Iterator#nextPanel
118: */
119: public void nextPanel() {
120: if (this .current().equals(this .sourceTableSelectionPanel)) { // Currently in source OTDs panel.
121: final JDBCWizardTransferPanel xferPanel = (JDBCWizardTransferPanel) this
122: .current();
123:
124: }
125:
126: super .nextPanel(); // Otherwise allow advance.
127:
128: }
129:
130: /**
131: * Overrides parent implementation to skip join panel if fewer than two source tables are
132: * selected.
133: *
134: * @see org.openide.WizardDescriptor.Iterator#previousPanel
135: */
136: public void previousPanel() {
137: super .previousPanel(); // Otherwise use parent implementation.
138: }
139:
140: protected List createPanels(final WizardDescriptor wiz) {
141: final List srcModel = new ArrayList();
142: final List destModel = new ArrayList();
143:
144: final List dbModels = new ArrayList();
145:
146: final List sourceDBModels = new ArrayList();
147: final List targetDBModels = new ArrayList();
148:
149: Project project = Templates.getProject(wiz);
150: if (project != null) {
151: Sources sources = ProjectUtils.getSources(project);
152: SourceGroup[] groups = sources
153: .getSourceGroups(Sources.TYPE_GENERIC);
154:
155: if (groups == null || groups.length < 1) {
156: groups = sources
157: .getSourceGroups(Sources.TYPE_GENERIC);
158: }
159:
160: this .collaborationNamePanel = new SimpleTargetChooserPanel(
161: project, groups, null, false);
162: }
163:
164: this .dataSelectionPanel = new JDBCWizardSelectionPanel(
165: NbBundle.getMessage(JDBCCollaborationWizard.class,
166: "TITLE_tblwizard_selecttableobjects"));
167: this .dataSelectionPanel.initialize();
168: this .sourceTableSelectionPanel = new JDBCWizardTransferPanel(
169: NbBundle.getMessage(JDBCCollaborationWizard.class,
170: "TITLE_tblwizard_selectsources"));
171:
172: this .jndiNamePanel = new JNDINameFinishPanel(NbBundle
173: .getMessage(JDBCCollaborationWizard.class,
174: "STEP_tblwizard_jndiname"));
175:
176: this .panels = new ArrayList(4);
177: if (this .collaborationNamePanel != null) {
178: this .panels.add(this .collaborationNamePanel);
179: }
180: this .panels.add(this .dataSelectionPanel);
181: this .panels.add(this .sourceTableSelectionPanel);
182: this .panels.add(this .jndiNamePanel);
183: return Collections.unmodifiableList(this .panels);
184: }
185:
186: protected String[] createSteps() {
187: try {
188: return new String[] {
189: // TODO - need make wizard steps text match actual panel being viewed
190: "Choose File Type", // TODO - use bundle property
191: NbBundle.getMessage(
192: JDBCCollaborationWizard.class,
193: "STEP_tblwizard_name"),
194: NbBundle.getMessage(
195: JDBCCollaborationWizard.class,
196: "STEP_tblwizard_select"),
197: NbBundle.getMessage(
198: JDBCCollaborationWizard.class,
199: "STEP_tblwizard_sources"),
200: NbBundle.getMessage(
201: JDBCCollaborationWizard.class,
202: "STEP_tblwizard_jndiname") };
203: } catch (final MissingResourceException e) {
204: return new String[] {};
205: }
206: }
207: }
208:
209: /** Key name used to reference database sources in wizard context. */
210: public static final String DATABASE_SOURCES = "database_sources";
211:
212: /** Key name used to reference JNDI Name. */
213: public static final String JNDI_NAME = "jndi_name";
214:
215: public static final String DBTYPE = "dbtype";
216:
217: /** Key name used to reference collaboration name in wizard context. */
218: public static final String COLLABORATION_NAME = "collaboration_name";
219:
220: /** Key name used to reference Project in wizard context. */
221: public static final String PROJECT = "project";
222:
223: /** Key name used to reference Collection of runtime input args in wizard context. */
224: public static final String RUNTIME_INPUTS = "runtime_inputs";
225:
226: /** Key name used to reference List of source OTDs in wizard context. */
227: public static final String SOURCE_OTDS = "source_otds";
228:
229: public static final int SOURCE_PANEL_INDEX = 2;
230:
231: /** Key name used to reference List of source tables in wizard context. */
232: public static final String SOURCE_TABLES = "source_tables";
233:
234: /* Defines panels to be displayed */
235: private WizardDescriptor descriptor;
236:
237: /* Wizard iterator; handles display and movement among wizard panels */
238: private JDBCWizardIterator iterator;
239:
240: private Project project;
241:
242: public JDBCCollaborationWizard(Project prj) {
243: this .project = prj;
244: }
245:
246: public static WizardDescriptor.Iterator newTemplateIterator() {
247: final JDBCCollaborationWizard wizard = new JDBCCollaborationWizard();
248: wizard.initialize();
249: return wizard.getIterator();
250: }
251:
252: /**
253: * @see JDBCWizard#getDescriptor
254: */
255: public WizardDescriptor getDescriptor() {
256: if (this .descriptor == null) {
257: this .descriptor = new Descriptor(this .iterator);
258: }
259: return this .descriptor;
260: }
261:
262: public void setDescriptor(final WizardDescriptor wd) {
263: this .descriptor = wd;
264: }
265:
266: /**
267: * @see JDBCWizard#getIterator
268: */
269: public WizardDescriptor.Iterator getIterator() {
270: return this .iterator;
271: }
272:
273: // public Project getProject() {
274: // return project;
275: // }
276:
277: /**
278: * Initializes iterator and descriptor for this wizard.
279: */
280: public void initialize() {
281: this .iterator = new WizardIterator(this );
282:
283: }
284:
285: /**
286: * Performs processing to handle cancellation of this wizard.
287: */
288: protected void cancel() {
289: }
290:
291: /**
292: * Performs processing to cleanup any resources used by this wizard.
293: */
294: protected void cleanup() {
295: }
296:
297: protected String getDialogTitle() {
298: return NbBundle.getMessage(JDBCCollaborationWizard.class,
299: "TITLE_dlg_new_collab");
300: }
301:
302: }
|