001: package com.quantum.dbunit.wizard;
002:
003: import java.beans.PropertyChangeEvent;
004: import java.beans.PropertyChangeListener;
005: import java.io.File;
006:
007: import org.eclipse.jface.dialogs.MessageDialog;
008: import org.eclipse.jface.viewers.IStructuredSelection;
009: import org.eclipse.jface.wizard.Wizard;
010: import org.eclipse.ui.IExportWizard;
011: import org.eclipse.ui.IWorkbench;
012:
013: import com.quantum.ImageStore;
014: import com.quantum.dbunit.ImageStoreKeys;
015: import com.quantum.dbunit.MessageUtil;
016: import com.quantum.dbunit.QuantumDbUnitPlugin;
017: import com.quantum.model.Entity;
018: import com.quantum.ui.dialog.ExceptionDisplayDialog;
019: import com.quantum.view.bookmark.BookmarkView;
020: import com.quantum.view.bookmark.GroupNode;
021:
022: /**
023: * Main Wizard for Import of DbUnit files
024: * @author BC Holmes
025: * @author Julen
026: */
027: public class ImportDbUnitWizard extends Wizard implements
028: IExportWizard, PropertyChangeListener {
029:
030: private ImportDbUnitDetailsPage page1;
031:
032: public ImportDbUnitWizard() {
033: setWindowTitle(MessageUtil.getString(getClass(), "windowTitle"));
034: setDefaultPageImageDescriptor(ImageStore.getImageDescriptor(
035: ImageStoreKeys.EXPORT_DBUNIT, QuantumDbUnitPlugin
036: .getDefault()));
037: }
038:
039: public boolean performFinish() {
040:
041: boolean successful = false;
042: File file = new File(this .page1.getFileName());
043:
044: // Check if the given file exists
045: if (file.exists()) {
046: ConverterDBUnit converter = new ConverterDBUnit();
047: try {
048: // convert() will do all the work
049: converter.convert(this .page1.getFileName(), this .page1
050: .getBookmark(), this .page1.getSchema(),
051: this .page1.isDeletePreviousContent(),
052: this .page1.isNamesAreQualified());
053: } catch (Exception e) {
054: e.printStackTrace();
055: ExceptionDisplayDialog.openError(getShell(),
056: "Error Importing", "Import caused an error. ",
057: e);
058: }
059: successful = true;
060:
061: }
062: return successful;
063: }
064:
065: public void init(IWorkbench workbench,
066: IStructuredSelection selection) {
067: Object[] nodes = BookmarkView.getInstance().getSelection()
068: .toArray();
069: if (nodes.length == 0) {
070: MessageDialog
071: .openInformation(
072: getShell(),
073: "Invalid selection",
074: "Please select a Tables FOLDER (the one grouping all tables) in the Quantum Bookmark View");
075: return;
076: }
077: if (nodes.length > 1) {
078: MessageDialog
079: .openInformation(getShell(), "Invalid selection",
080: "Please select only one Tables Folder in the Quantum Bookmark View");
081: return;
082: }
083:
084: Object node = nodes[0];
085: if (!(node instanceof GroupNode)
086: || !(((GroupNode) node).getType()
087: .equals(Entity.TABLE_TYPE))) {
088: MessageDialog
089: .openInformation(
090: getShell(),
091: "Invalid selection",
092: "Please select a Tables FOLDER (the one grouping all tables) in the Quantum Bookmark View");
093: return;
094: }
095: this .page1 = new ImportDbUnitDetailsPage("page1");
096: }
097:
098: public void dispose() {
099: super .dispose();
100: }
101:
102: /**
103: * @see org.eclipse.jface.wizard.IWizard#addPages()
104: */
105: public void addPages() {
106: if (this .page1 != null)
107: addPage(this .page1);
108: }
109:
110: /* (non-Javadoc)
111: * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
112: */
113: public void propertyChange(PropertyChangeEvent arg0) {
114: }
115: }
|