001: package com.quantum.flatfiles.wizard;
002:
003: import java.beans.PropertyChangeEvent;
004: import java.beans.PropertyChangeListener;
005: import java.io.File;
006: import java.io.FileWriter;
007: import java.io.IOException;
008: import java.sql.SQLException;
009:
010: import com.quantum.ImageStore;
011: import com.quantum.QuantumPlugin;
012: import com.quantum.flatfiles.ImageStoreKeys;
013: import com.quantum.flatfiles.MessageUtil;
014: import com.quantum.flatfiles.QuantumFlatFilesPlugin;
015: import com.quantum.model.Bookmark;
016: import com.quantum.ui.dialog.ExceptionDisplayDialog;
017: import com.quantum.ui.dialog.SQLExceptionDialog;
018: import com.quantum.util.connection.NotConnectedException;
019:
020: import org.eclipse.jface.dialogs.MessageDialog;
021: import org.eclipse.jface.preference.IPreferenceStore;
022: import org.eclipse.jface.viewers.IStructuredSelection;
023: import org.eclipse.jface.wizard.Wizard;
024: import org.eclipse.ui.IExportWizard;
025: import org.eclipse.ui.IWorkbench;
026:
027: /**
028: * @author BC Holmes
029: */
030: public class ExportTorqueWizard extends Wizard implements
031: IExportWizard, PropertyChangeListener {
032:
033: private SelectBookmarkWizardPage page1;
034: private ExportDetailsPage page2;
035:
036: public ExportTorqueWizard() {
037: setWindowTitle(MessageUtil.getString(getClass(), "windowTitle"));
038: setDefaultPageImageDescriptor(ImageStore.getImageDescriptor(
039: ImageStoreKeys.EXPORT_TORQUE, QuantumFlatFilesPlugin
040: .getDefault()));
041: }
042:
043: public boolean performFinish() {
044:
045: boolean successful = false;
046: File file = new File(this .page2.getFileName());
047:
048: // Check if the given file exists, and if it does, if it should be overwritten
049: // Quantum has a preference that we should check about this
050: IPreferenceStore store = QuantumPlugin.getDefault()
051: .getPreferenceStore();
052: boolean confirmOverwrite = store
053: .getBoolean(com.quantum.PluginPreferences.EXPORT_CONFIRM_OVERWRITE);
054:
055: if (!file.exists()
056: || !confirmOverwrite
057: || (file.exists() && MessageDialog.openConfirm(
058: getShell(), MessageUtil.getString(getClass(),
059: "overwriteTitle"), MessageUtil
060: .getString(getClass(),
061: "confirmOverwrite",
062: new Object[] { file
063: .getAbsoluteFile() })))) {
064:
065: try {
066: FileWriter writer = new FileWriter(file);
067: try {
068: TorqueConverter converter = new TorqueConverter();
069: converter.convert(writer, this .page2.getBookmark(),
070: this .page2.getSchema(), this .page2
071: .getDatabaseName(), this .page2
072: .getIdMethod());
073: successful = true;
074: } finally {
075: writer.close();
076: }
077: } catch (IOException e) {
078: ExceptionDisplayDialog.openError(getShell(), null,
079: null, e);
080: } catch (NotConnectedException e) {
081: ExceptionDisplayDialog.openError(getShell(), null,
082: null, e);
083: } catch (SQLException e) {
084: SQLExceptionDialog.openException(getShell(), this .page2
085: .getBookmark(), e);
086: }
087: }
088: return successful;
089: }
090:
091: public void init(IWorkbench workbench,
092: IStructuredSelection selection) {
093: this .page1 = new SelectBookmarkWizardPage("page1");
094: this .page1.addPropertyChangeListener(this );
095: this .page2 = new ExportDetailsPage("page2");
096: }
097:
098: public void dispose() {
099: this .page1.removePropertyChangeListener(this );
100: super .dispose();
101: }
102:
103: /**
104: * @see org.eclipse.jface.wizard.IWizard#addPages()
105: */
106: public void addPages() {
107: addPage(this .page1);
108: addPage(this .page2);
109: }
110:
111: /* (non-Javadoc)
112: * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
113: */
114: public void propertyChange(PropertyChangeEvent event) {
115: if ("bookmark".equals(event.getPropertyName())) {
116: this .page2.setBookmark((Bookmark) event.getNewValue());
117: }
118: }
119: }
|