001: /*
002: * The contents of this file are subject to the Mozilla Public License
003: * Version 1.1 (the "License"); you may not use this file except in
004: * compliance with the License. You may obtain a copy of the License at
005: * http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009: * License for the specific language governing rights and limitations
010: * under the License.
011: *
012: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013: *
014: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016: *
017: * Contributor(s):
018: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019: *
020: * If you didn't download this code from the following link, you should check
021: * if you aren't using an obsolete version: http://www.isqlviewer.com
022: */
023: package org.isqlviewer.ui.wizards.service;
024:
025: import static java.awt.GridBagConstraints.CENTER;
026: import static java.awt.GridBagConstraints.HORIZONTAL;
027: import static java.awt.GridBagConstraints.NONE;
028: import static java.awt.GridBagConstraints.VERTICAL;
029: import static java.awt.GridBagConstraints.WEST;
030:
031: import java.awt.GridBagConstraints;
032: import java.awt.GridBagLayout;
033: import java.sql.SQLException;
034: import java.util.ArrayList;
035: import java.util.Collections;
036: import java.util.List;
037:
038: import javax.swing.Box;
039: import javax.swing.ButtonGroup;
040: import javax.swing.JComponent;
041: import javax.swing.JPanel;
042: import javax.swing.JRadioButton;
043:
044: import org.isqlviewer.sql.ConnectionProfile;
045: import org.isqlviewer.sql.JdbcService;
046: import org.isqlviewer.sql.embedded.EmbeddedDatabase;
047: import org.isqlviewer.swing.SwingUtilities;
048: import org.isqlviewer.ui.wizards.AbstractWizardStep;
049: import org.isqlviewer.ui.wizards.Step;
050: import org.isqlviewer.ui.wizards.WizardContext;
051: import org.isqlviewer.util.LocalMessages;
052:
053: public class SelectServiceFunctionStep extends AbstractWizardStep {
054:
055: private LocalMessages messages = new LocalMessages(
056: ServiceWizard.BUNDLE_NAME);
057: private ButtonGroup typeSelection = new ButtonGroup();
058:
059: private static final List<Class<? extends AbstractWizardStep>> newServiceWizard;
060: private static final List<Class<? extends AbstractWizardStep>> modifyServiceWizard;
061: private static final List<Class<? extends AbstractWizardStep>> deleteServiceWizard;
062: private static final List<Class<? extends AbstractWizardStep>> importServiceWizard;
063:
064: static {
065: ArrayList<Class<? extends AbstractWizardStep>> wizardList = new ArrayList<Class<? extends AbstractWizardStep>>();
066: wizardList.add(ConfigureBasicServiceOptions.class);
067: wizardList.add(ConfigureServiceResources.class);
068: wizardList.add(ServiceProfileOptions.class);
069: wizardList.add(DriverPropertyOptions.class);
070: wizardList.add(ConfirmNewService.class);
071: newServiceWizard = Collections.unmodifiableList(wizardList);
072:
073: wizardList = new ArrayList<Class<? extends AbstractWizardStep>>();
074: wizardList.add(SelectServiceStep.class);
075: wizardList.add(ConfigureBasicServiceOptions.class);
076: wizardList.add(ConfigureServiceResources.class);
077: wizardList.add(ServiceProfileOptions.class);
078: wizardList.add(DriverPropertyOptions.class);
079: wizardList.add(ConfirmUpdateService.class);
080: modifyServiceWizard = Collections.unmodifiableList(wizardList);
081:
082: wizardList = new ArrayList<Class<? extends AbstractWizardStep>>();
083: wizardList.add(SelectServiceStep.class);
084: wizardList.add(ConfirmDeleteService.class);
085: deleteServiceWizard = Collections.unmodifiableList(wizardList);
086:
087: wizardList = new ArrayList<Class<? extends AbstractWizardStep>>();
088: importServiceWizard = Collections.unmodifiableList(wizardList);
089: }
090:
091: public boolean isFirst() {
092:
093: return true;
094: }
095:
096: public boolean isLast() {
097:
098: return false;
099: }
100:
101: public boolean isValid(WizardContext context) {
102:
103: if (typeSelection.getSelection() == null) {
104: return false;
105: }
106:
107: String serviceFunction = typeSelection.getSelection()
108: .getActionCommand();
109: setNextStep(null);
110: List<Step> wizardSteps = null;
111: if (ServiceWizard.FUNCTION_CREATE.equals(serviceFunction)) {
112: wizardSteps = initializeSteps(newServiceWizard, context);
113: JdbcService service = new JdbcService();
114: service.setProfile(new ConnectionProfile());
115: context.setAttribute(ServiceWizard.ATTRIBUTE_SERVICE,
116: service);
117: } else if (ServiceWizard.FUNCTION_DELETE
118: .equals(serviceFunction)) {
119: wizardSteps = initializeSteps(deleteServiceWizard, context);
120: } else if (ServiceWizard.FUNCTION_MODIFY
121: .equals(serviceFunction)) {
122: wizardSteps = initializeSteps(modifyServiceWizard, context);
123: } else if (ServiceWizard.FUNCTION_IMPORT
124: .equals(serviceFunction)) {
125: wizardSteps = initializeSteps(importServiceWizard, context);
126: } else {
127: return false;
128: }
129:
130: context.setAttribute(ServiceWizard.ATTRIBUTE_FUNCTION,
131: serviceFunction);
132: context.updateSteps(wizardSteps);
133:
134: AbstractWizardStep nextStep = (AbstractWizardStep) wizardSteps
135: .get(0);
136: nextStep.setPrevious(this );
137: setNextStep(nextStep);
138: return true;
139: }
140:
141: @Override
142: public void init(WizardContext context) {
143:
144: super .init(context);
145: setTitle(messages.getMessage("SelectServiceFunctionStep.title"));
146: setComment(messages
147: .getMessage("SelectServiceFunctionStep.comment"));
148: setImage(SwingUtilities.loadIconResource("question", 22));
149:
150: JPanel panel = new JPanel(new GridBagLayout());
151: setView(panel);
152:
153: GridBagConstraints constraint = null;
154: String title = null;
155: String tip = null;
156: JComponent component = null;
157: int serviceCount = 0;
158:
159: EmbeddedDatabase edb = EmbeddedDatabase.getSharedInstance();
160: try {
161: serviceCount = edb.getRegisteredServices().size();
162: } catch (SQLException e) {
163: }
164: title = messages
165: .format("SelectServiceFunction.create-new-service");
166: tip = messages
167: .format("SelectServiceFunction.create-new-service.tip");
168: component = new JRadioButton();
169: typeSelection.add((JRadioButton) component);
170: ((JRadioButton) component).setText(title);
171: ((JRadioButton) component).setSelected(true);
172: ((JRadioButton) component)
173: .setActionCommand(ServiceWizard.FUNCTION_CREATE);
174: component.setToolTipText(tip);
175: constraint = ServiceWizard.constrain(0, 0, 1, 1, 0.0, 0.0,
176: WEST, NONE);
177: panel.add(component, constraint);
178:
179: title = messages.format("SelectServiceFunction.import-service");
180: tip = messages.format("SelectServiceFunction.import.tip");
181: component = new JRadioButton();
182: typeSelection.add((JRadioButton) component);
183: ((JRadioButton) component).setText(title);
184: ((JRadioButton) component).setEnabled(false);
185: ((JRadioButton) component)
186: .setActionCommand(ServiceWizard.FUNCTION_IMPORT);
187: component.setToolTipText(tip);
188: constraint = ServiceWizard.constrain(0, 1, 1, 1, 0.0, 0.0,
189: WEST, NONE);
190: panel.add(component, constraint);
191:
192: title = messages
193: .format("SelectServiceFunction.delete-existing-service");
194: tip = messages
195: .format("SelectServiceFunction.delete-existing-service.tip");
196: component = new JRadioButton();
197: typeSelection.add((JRadioButton) component);
198: ((JRadioButton) component).setText(title);
199: ((JRadioButton) component)
200: .setActionCommand(ServiceWizard.FUNCTION_DELETE);
201: ((JRadioButton) component).setEnabled(serviceCount > 0);
202:
203: component.setToolTipText(tip);
204: constraint = ServiceWizard.constrain(0, 2, 1, 1, 0.0, 0.0,
205: WEST, NONE);
206: panel.add(component, constraint);
207:
208: title = messages.format("SelectServiceFunction.modify-service");
209: tip = messages
210: .format("SelectServiceFunction.modify-service.tip");
211: component = new JRadioButton();
212: typeSelection.add((JRadioButton) component);
213: ((JRadioButton) component).setText(title);
214: ((JRadioButton) component)
215: .setActionCommand(ServiceWizard.FUNCTION_MODIFY);
216: ((JRadioButton) component).setEnabled(serviceCount > 0);
217:
218: component.setToolTipText(tip);
219: constraint = ServiceWizard.constrain(0, 3, 1, 1, 0.0, 0.0,
220: WEST, NONE);
221: panel.add(component, constraint);
222:
223: constraint = ServiceWizard.constrain(0, 4, 1, 1, 0.0, 1.0,
224: CENTER, VERTICAL);
225: panel.add(Box.createVerticalGlue(), constraint);
226:
227: constraint = ServiceWizard.constrain(1, 0, 1, 1, 1.0, 0.0,
228: CENTER, HORIZONTAL);
229: panel.add(Box.createHorizontalGlue(), constraint);
230: }
231: }
|