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 java.awt.Font;
026: import java.awt.GridBagConstraints;
027: import java.awt.GridBagLayout;
028: import java.awt.event.ActionEvent;
029: import java.io.File;
030: import java.sql.SQLException;
031:
032: import javax.swing.Box;
033: import javax.swing.JComponent;
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036: import javax.swing.JSeparator;
037: import javax.swing.JTextField;
038: import javax.swing.SwingConstants;
039: import javax.swing.text.Document;
040:
041: import org.isqlviewer.ServiceReference;
042: import org.isqlviewer.sql.embedded.EmbeddedDatabase;
043: import org.isqlviewer.swing.SwingUtilities;
044: import org.isqlviewer.swing.action.SharedActions;
045: import org.isqlviewer.swing.action.SwingEventManager;
046: import org.isqlviewer.ui.wizards.AbstractWizardStep;
047: import org.isqlviewer.ui.wizards.WizardContext;
048: import org.isqlviewer.util.BasicUtilities;
049: import org.isqlviewer.util.IsqlToolkit;
050: import org.isqlviewer.util.LocalMessages;
051:
052: public class ConfirmDeleteService extends AbstractWizardStep {
053:
054: private LocalMessages messages = new LocalMessages(
055: ServiceWizard.BUNDLE_NAME);
056: private Document nameDocument = null;
057: private Document urlDocument = null;
058: private Document classDocument = null;
059:
060: public boolean isFirst() {
061:
062: return false;
063: }
064:
065: public boolean isLast() {
066:
067: return true;
068: }
069:
070: public boolean isValid(WizardContext context) {
071:
072: ServiceReference reference = (ServiceReference) context
073: .getAttribute(ServiceWizard.ATTRIBUTE_SERVICE_REFERENCE);
074:
075: SwingEventManager eventManager = context.getEventManager();
076: EmbeddedDatabase database = EmbeddedDatabase
077: .getSharedInstance();
078: try {
079: database.removeService(reference);
080: String safeName = BasicUtilities
081: .createSafeFilename(reference.getName());
082: File file = new File(IsqlToolkit.getBaseDirectory(),
083: safeName + ".service");
084: if (file.exists() && file.canWrite()) {
085: file.delete();
086: }
087: eventManager
088: .actionPerformed(new ActionEvent(this ,
089: SharedActions.SERVICE_REMOVED, reference
090: .getName()));
091: } catch (SQLException error) {
092: String message = messages.format(
093: "ConfirmDeleteService.internal_sql_error",
094: reference.getName());
095: context.showErrorDialog(error, message);
096: return false;
097: }
098: return true;
099: }
100:
101: @Override
102: public void activate(WizardContext context) {
103:
104: ServiceReference service = (ServiceReference) context
105: .getAttribute(ServiceWizard.ATTRIBUTE_SERVICE_REFERENCE);
106: if (service != null) {
107: SwingUtilities.replaceDocumentContent(nameDocument, service
108: .getName());
109: SwingUtilities.replaceDocumentContent(urlDocument, service
110: .getCreatedOn().toString());
111: SwingUtilities.replaceDocumentContent(classDocument,
112: service.getResourceURL().toExternalForm());
113: }
114: }
115:
116: @Override
117: public void init(WizardContext context) {
118:
119: setTitle(messages.getMessage("ConfirmDeleteService.title"));
120: setComment(messages.getMessage("ConfirmDeleteService.comment"));
121: setImage(SwingUtilities.loadIconResource(ServiceWizard.class,
122: "ok", 22));
123:
124: JPanel panel = new JPanel(new GridBagLayout());
125: setView(panel);
126:
127: Object constraint = null;
128: JComponent component = null;
129: JLabel label = null;
130: String title = null;
131: String tip = null;
132:
133: title = messages.format("newservicewizard.servicename.title");
134: tip = messages.format("newservicewizard.servicename.tip");
135: component = new JTextField(32);
136: component.setToolTipText(tip);
137: component.setFont(component.getFont().deriveFont(Font.BOLD));
138: ((JTextField) component).setEditable(false);
139: nameDocument = ((JTextField) component).getDocument();
140: constraint = ServiceWizard.constrain(0, 0, 1, 1, 0.0, 0.0,
141: GridBagConstraints.WEST, GridBagConstraints.NONE);
142: label = new JLabel(title);
143: label.setLabelFor(component);
144: panel.add(label, constraint);
145: constraint = ServiceWizard.constrain(1, 0, 1, 1, 1.0, 0.0,
146: GridBagConstraints.CENTER,
147: GridBagConstraints.HORIZONTAL);
148: panel.add(component, constraint);
149:
150: title = messages.format("newservicewizard.jdbcdriver.title");
151: tip = messages.format("newservicewizard.jdbcdriver.tip");
152: component = new JTextField(32);
153: component.setToolTipText(tip);
154: component.setFont(component.getFont().deriveFont(Font.BOLD));
155: ((JTextField) component).setEditable(false);
156: classDocument = ((JTextField) component).getDocument();
157: constraint = ServiceWizard.constrain(0, 1, 1, 1, 0.0, 0.0,
158: GridBagConstraints.WEST, GridBagConstraints.NONE);
159: label = new JLabel(title);
160: label.setLabelFor(component);
161: panel.add(label, constraint);
162: constraint = ServiceWizard.constrain(1, 1, 1, 1, 1.0, 0.0,
163: GridBagConstraints.CENTER,
164: GridBagConstraints.HORIZONTAL);
165: panel.add(component, constraint);
166:
167: title = messages.format("newservicewizard.jdbcurl.title");
168: tip = messages.format("newservicewizard.jdbcurl.tip");
169: component = new JTextField(32);
170: component.setToolTipText(tip);
171: component.setFont(component.getFont().deriveFont(Font.BOLD));
172: ((JTextField) component).setEditable(false);
173: urlDocument = ((JTextField) component).getDocument();
174: constraint = ServiceWizard.constrain(0, 2, 1, 1, 0.0, 0.0,
175: GridBagConstraints.WEST, GridBagConstraints.NONE);
176: label = new JLabel(title);
177: label.setLabelFor(component);
178: panel.add(label, constraint);
179: constraint = ServiceWizard.constrain(1, 2, 1, 1, 1.0, 0.0,
180: GridBagConstraints.CENTER,
181: GridBagConstraints.HORIZONTAL);
182: panel.add(component, constraint);
183:
184: constraint = ServiceWizard.constrain(0, 3, 2, 1, 1.0d, 0.0d,
185: GridBagConstraints.CENTER,
186: GridBagConstraints.HORIZONTAL);
187: panel
188: .add(new JSeparator(SwingConstants.HORIZONTAL),
189: constraint);
190: panel.add(Box.createVerticalStrut(32), constraint);
191:
192: title = messages.format("newservicewizard.compatability_info");
193: component = new JLabel(title);
194: constraint = ServiceWizard.constrain(0, 4, 2, 1, 0.0, 0.0,
195: GridBagConstraints.WEST, GridBagConstraints.NONE);
196: panel.add(component, constraint);
197:
198: component = (JComponent) Box.createVerticalGlue();
199: constraint = ServiceWizard.constrain(0, 7, 2, 1, 0.0, 1.0,
200: GridBagConstraints.CENTER, GridBagConstraints.VERTICAL);
201: panel.add(component, constraint);
202: }
203: }
|