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.Dialog;
044: import java.awt.Dimension;
045:
046: import javax.swing.SwingUtilities;
047: import net.java.hulp.i18n.Logger;
048: import org.netbeans.modules.etl.logger.Localizer;
049: import org.netbeans.modules.etl.logger.LogUtil;
050: import org.openide.DialogDisplayer;
051: import org.openide.ErrorManager;
052: import org.openide.WizardDescriptor;
053:
054: /**
055: * Abstract base class for ETL Wizards. Interested classes should instantiate the correct
056: * concrete implementation and call show() to display the wizard.
057: *
058: * @author Jonathan Giron
059: * @version $Revision$
060: */
061: public abstract class ETLWizard {
062: /* Log4J category string */
063:
064: private static final String LOG_CATEGORY = ETLWizard.class
065: .getName();
066: private static transient final Logger mLogger = LogUtil
067: .getLogger(ETLWizard.class.getName());
068: private static transient final Localizer mLoc = Localizer.get();
069: /** Common context for panels to exchange and store data. */
070: protected ETLWizardContext context;
071:
072: /** Creates a new instance of ETLWizard */
073: protected ETLWizard() {
074: context = new ETLWizardContext();
075: }
076:
077: /**
078: * Gets context associated with this wizard.
079: *
080: * @return ETLWizardContext instance associated with this wizard.
081: */
082: public ETLWizardContext getContext() {
083: return context;
084: }
085:
086: /**
087: * Gets descriptor containing information on available panels. Concrete subclasses
088: * should instantiate and define this descriptor.
089: *
090: * @return WizardDescriptor associated with this object
091: */
092: public abstract WizardDescriptor getDescriptor();
093:
094: /**
095: * Gets iterator used to cycle through available panels for this wizard. Concrete
096: * subclasses should instantiate and define this iterator.
097: *
098: * @return WizardDescriptor.Iterator associated with this object
099: */
100: public abstract WizardDescriptor.Iterator getIterator();
101:
102: /**
103: * Displays the wizard and its associated panels.
104: *
105: * @return true if user completed the wizard normally; false otherwise.
106: */
107: public boolean show() {
108: // Set default return value.
109: boolean response = false;
110:
111: try {
112: initialize();
113:
114: final WizardDescriptor desc = getDescriptor();
115: final Dialog dlg = DialogDisplayer.getDefault()
116: .createDialog(desc);
117: dlg.setTitle(getDialogTitle());
118: dlg.getAccessibleContext().setAccessibleDescription(
119: "This is the ETL Collaboration Definition Wizard");
120: dlg.setPreferredSize(new Dimension(575, 425));
121:
122: if (context != null && desc != null) {
123: context.setWizardDescriptor(desc);
124: }
125:
126: if (!SwingUtilities.isEventDispatchThread()) {
127: SwingUtilities.invokeAndWait(new Runnable() {
128:
129: public synchronized void run() {
130: dlg.setVisible(true);
131: }
132: });
133: } else {
134: dlg.setVisible(true);
135: }
136:
137: if (desc != null) {
138: if (desc.getValue() == WizardDescriptor.FINISH_OPTION) {
139: mLogger.infoNoloc(mLoc.t(
140: "PRSR037: User finished the wizard.{0}",
141: LOG_CATEGORY));
142: // Call method in concrete implementation to handle committal.
143: commit();
144: response = true;
145: } else {
146: mLogger
147: .infoNoloc(mLoc
148: .t(
149: "PRSR038: User closed or cancelled the wizard.{0}",
150: LOG_CATEGORY));
151: // Call method in concrete implementation to handle cancellation.
152: cancel();
153: }
154: }
155: } catch (Exception e) {
156: mLogger
157: .errorNoloc(
158: mLoc
159: .t(
160: "PRSR039: Exception caught while performing wizard processing.{0}",
161: LOG_CATEGORY), e);
162: ErrorManager.getDefault().notify(e);
163: } finally {
164: // Call method in concrete implementation to do any necessary cleanup.
165: cleanup();
166: }
167:
168: return response;
169: }
170:
171: /**
172: * Performs processing to handle cancellation of this wizard.
173: */
174: protected abstract void cancel();
175:
176: /**
177: * Performs processing to cleanup any resources used by this wizard.
178: */
179: protected abstract void cleanup();
180:
181: /**
182: * Performs processing to handle committal of data gathered by this wizard.
183: */
184: protected abstract void commit();
185:
186: /**
187: * Gets string label to display as title of dialog window.
188: *
189: * @return String representing dialog title
190: */
191: protected String getDialogTitle() {
192: return "ETL Wizard";
193: }
194:
195: /**
196: * Initializes the wizard.
197: */
198: protected abstract void initialize();
199: }
|