quantum.name = Quantum DB Utility
-perspective.name = Quantum DB Perspective
+perspective.name = Quantum DB
sqllogview.name = Quantum SQL Log
+driverview.name = JDBC Driver View
tableview.name = Quantum Table View
sqlqueryview.name = Quantum SQL Query Editor
bookmarkview.name = Database Bookmarks
scope.name = Quantum UI Scope
scope.description = Quantum UI Scope
command.execute.name = Execute SQL
-command.execute.description = Execute the SQL statements against a database bookmark
+command.execute.description = Execute the SQL statements against a database bookmark
\ No newline at end of file
<plugin
id="net.sourceforge.phpeclipse.quantum.sql"
name="%quantum.name"
- version="2.3.0"
- provider-name="Tom Schneider"
+ version="2.3.2"
+ provider-name="Tom Schneider, Julen Parra, BC Holmes"
class="com.quantum.QuantumPlugin">
<runtime>
id="com.quantum.properties.SchemaPropertyPage">
</page>
<page
- objectClass="com.quantum.view.bookmark.EntityNode"
- name="Tables, Views and Sequences"
+ objectClass="com.quantum.model.EntityHolder"
+ name="Columns"
nameFilter="*"
- class="com.quantum.properties.EntityPropertyPage"
- id="com.quantum.properties.EntityPropertyPage">
+ class="com.quantum.properties.ColumnPropertyPage"
+ id="com.quantum.properties.ColumnPropertyPage">
+ </page>
+ <page
+ objectClass="com.quantum.model.EntityHolder"
+ name="Indices"
+ nameFilter="*"
+ class="com.quantum.properties.IndexPropertyPage"
+ id="com.quantum.properties.IndexPropertyPage">
+ </page>
+ <page
+ objectClass="com.quantum.model.EntityHolder"
+ name="References"
+ nameFilter="*"
+ class="com.quantum.properties.ReferencesPropertyPage"
+ id="com.quantum.properties.ReferencesPropertyPage">
</page>
</extension>
<extension
public static final String PLUGIN_ID ="com.quantum"; //$NON-NLS-1$
public static final String PREFIX = PLUGIN_ID+"."; //$NON-NLS-1$
- public static final String ADD_SCHEMA_DIALOG_CONTEXT = PREFIX+"add_schema_dialog_context"; //$NON-NLS-1$
-
//Constants for specifying Tables, Views and Sequences to the JDBC driver
public static final String Table = "TABLE";
public static final String View = "VIEW";
import org.xml.sax.SAXException;
/**
- * @author root
* Main class of the quantum plugin, sets defaults, saves and recovers state.
+ * @author root
*/
public class QuantumPlugin extends AbstractUIPlugin {
- public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.quantum.sql";
+ public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.quantum.sql";
private static QuantumPlugin plugin;
private Clipboard sysClip;
-
+ /**
+ *
+ * TODO: BCH - this constructor has changed in Eclipse 3.0. This
+ * old version of the constructor is still necessary for running under
+ * Eclipse 2.x.
+ *
+ * @param descriptor
+ */
public QuantumPlugin(IPluginDescriptor descriptor) {
super(descriptor);
plugin = this;
*/
public void shutdown() throws CoreException {
super.shutdown();
-// sysClip.dispose();
+ sysClip.dispose();
}
/**
getPreferenceStore().setDefault("quantum.numeric.bold", false); //$NON-NLS-1$
PreferenceConverter.setDefault(getPreferenceStore(), "quantum.font", (FontData) null); //$NON-NLS-1$
getPreferenceStore().setDefault("com.quantum.model.Bookmark.queryHistorySize", 20); //$NON-NLS-1$
-
+
+
getPreferenceStore().setDefault(
"phpeclipse.sql.select.template",
"$results = mysql_query(\"SELECT {0} FROM {1} WHERE {2} \");");
filedialog.message.ConfirmOverwriteTitle = Confirm Overwrite
filedialog.message.ConfirmOverwriteMessage = This file already exists :
filedialog.message.ConfirmOverwriteQuestion= \n\nDo you want to overwrite it?
-adapters.generic = Generic JDBC
-adapters.oracle = Oracle
-adapters.postgres = Postgres
-adapters.mysql = MySQL
-adapters.db2 = DB2
-adapters.db2as400 = DB2 for AS400
-adapters.adabasd = Adabas-D
-adapters.informix = Informix
-adapters.redbrick = Red Brick
-adapters.sybase = Sybase
QuantumPlugin.save_2=save
QuantumPlugin.icons_3=icons/
QuantumPlugin.quantum.keyword.color_6=quantum.keyword.color
PreferencesPage.italic=italic
PreferencesPage.boldItalic=bold italic
PreferencesPage.FontPrompt=Font:
-BookmarkLabelProvider.TablePrefix=
-BookmarkLabelProvider.ViewPrefix=
-BookmarkLabelProvider.SequencePrefix=
DeleteColumnAction.DeleteColumns=Delete Columns...
DeleteColumnAction.ConfirmDeleteColumns=Are you sure you want to delete the selected columns?
DeleteObjectAction.DeleteSubset=Delete Subset...
com.quantum.ui.dialog.ExceptionDisplayDialog.java.sql.IOException.message=A problem was encountered while trying to access the file.
com.quantum.ui.dialog.ExceptionDisplayDialog.java.sql.SQLException.title=SQL Exception
com.quantum.ui.dialog.ExceptionDisplayDialog.java.sql.SQLException.message=An SQL Exception was encountered while trying to process your request.
-BookmarkWizard.Error=Error
-BookmarkWizard.bookmarkAlreadyExists=The selected bookmark name already exists.
-com.quantum.wizards.NewBookmarkPage1.driverColumn0=JDBC Driver Name
-com.quantum.wizards.NewBookmarkPage1.driverColumn1=Driver Class Name
-com.quantum.wizards.NewBookmarkPage1.driverColumn2=Version
-com.quantum.wizards.NewBookmarkPage1.driverColumn3=File Path
+com.quantum.wizards.JDBCDriverSelectionWizardPage.addDriver=Add driver...
+com.quantum.wizards.JDBCDriverSelectionWizardPage.title=JDBC Driver
+com.quantum.wizards.JDBCDriverSelectionWizardPage.description=Choose one of the drivers from the list or click the Add driver button
+
+com.quantum.wizards.BookmarkConnectionWizardPage.title=Connection details
+com.quantum.wizards.BookmarkConnectionWizardPage.description=Provide the information needed to connect to the database
+com.quantum.wizards.BookmarkConnectionWizardPage.userid=Userid:
+com.quantum.wizards.BookmarkConnectionWizardPage.password=Password:
+com.quantum.wizards.BookmarkConnectionWizardPage.prompt=Prompt for password
+com.quantum.wizards.BookmarkConnectionWizardPage.url=JDBC URL:
+
+com.quantum.wizards.BookmarkNameWizardPage.title=Bookmark Name
+com.quantum.wizards.BookmarkNameWizardPage.description=What name do you want for your bookmark?
+com.quantum.wizards.BookmarkNameWizardPage.name=Name:
+com.quantum.wizards.BookmarkNameWizardPage.alreadyExists=A bookmark with that name already exists.
+com.quantum.wizards.BookmarkNameWizardPage.mustProvide=Please provide a bookmark name.
+
+com.quantum.wizards.SchemaSelectionWizardPage.title=Schemas
+com.quantum.wizards.SchemaSelectionWizardPage.description=Which schemas should be displayed?
com.quantum.view.JDBCDriverTableViewer.driverColumn0=JDBC Driver Name
com.quantum.view.JDBCDriverTableViewer.driverColumn1=Driver Class Name
-com.quantum.view.JDBCDriverTableViewer.driverColumn2=Version
-com.quantum.view.JDBCDriverTableViewer.driverColumn3=File Path
+com.quantum.view.JDBCDriverTableViewer.driverColumn2=Driver Type
+com.quantum.view.JDBCDriverTableViewer.driverColumn3=Version
+com.quantum.view.JDBCDriverTableViewer.driverColumn4=File Path
+
+com.quantum.wizards.AddDriverWizard.windowTitle=New JDBC Driver
+com.quantum.wizards.AddDriverWizard$PageImpl.title=JDBC Driver
+com.quantum.wizards.AddDriverWizard$PageImpl.description=Provide the following information about the driver.
+com.quantum.wizards.AddDriverWizard$PageImpl.browse=Browse
+com.quantum.wizards.AddDriverWizard$PageImpl.fileName=File name:
+com.quantum.wizards.AddDriverWizard$PageImpl.driverClassName=Class name:
+
+com.quantum.adapters.DatabaseAdapter.GENERIC = Generic JDBC
+com.quantum.adapters.DatabaseAdapter.HSQLDB = HSQL (Hypersonic)
+com.quantum.adapters.DatabaseAdapter.ORACLE = Oracle
+com.quantum.adapters.DatabaseAdapter.POSTGRES = Postgres
+com.quantum.adapters.DatabaseAdapter.MYSQL = MySQL
+com.quantum.adapters.DatabaseAdapter.DB2 = DB2
+com.quantum.adapters.DatabaseAdapter.DB2AS400 = DB2 for AS400
+com.quantum.adapters.DatabaseAdapter.ADABASD = Adabas-D
+com.quantum.adapters.DatabaseAdapter.INFORMIX = Informix Dynamic Server
+com.quantum.adapters.DatabaseAdapter.REDBRICK = Red Brick
+com.quantum.adapters.DatabaseAdapter.SYBASE = Sybase
+com.quantum.adapters.DatabaseAdapter.POINTBASE = Pointbase
+
+com.quantum.view.SchemaSelectionControl.addSchemaDialog = Select a Schema
+com.quantum.view.SchemaSelectionControl.connectTitle = Connect Required
+com.quantum.view.SchemaSelectionControl.connectMessage = We must connect to the database to retrieve schemas.
+com.quantum.view.SchemaSelectionControl.useAllSchemas = Show all schemas
+com.quantum.view.SchemaSelectionControl.useUsernameAsSchema = Show the default schema
+com.quantum.view.SchemaSelectionControl.useSelectedSchemas = Show selected schemas
+
+com.quantum.properties.DatabaseInformationPropertyPage.dataTypes = The following data types are supported by this database:
+com.quantum.properties.DatabaseInformationPropertyPage.column0 = Data Type
+com.quantum.properties.DatabaseInformationPropertyPage.column1 = Java Type
+com.quantum.properties.DatabaseInformationPropertyPage.product = Product:
+com.quantum.properties.DatabaseInformationPropertyPage.unknown = <unknown>
+com.quantum.properties.DatabaseInformationPropertyPage.error = QuantumDB could not retrieve the database information due to an error:
+
+com.quantum.properties.BaseEntityPropertyPage.name = Name:
+com.quantum.properties.BaseEntityPropertyPage.schema = Schema:
+com.quantum.properties.BaseEntityPropertyPage.error = QuantumDB could not retrieve the information due to an error:
+
+com.quantum.properties.ReferencesPropertyPage.column0 = Constraint Name
+com.quantum.properties.ReferencesPropertyPage.column1 = Primary
+com.quantum.properties.ReferencesPropertyPage.column2 = Foreign
+com.quantum.properties.ReferencesPropertyPage.column3 = On Delete
+com.quantum.properties.ReferencesPropertyPage.importedKeyNoAction = NO ACTION
+com.quantum.properties.ReferencesPropertyPage.importedKeyCascade = CASCADE
+com.quantum.properties.ReferencesPropertyPage.importedKeySetNull = SET NULL
+com.quantum.properties.ReferencesPropertyPage.importedKeySetDefault = SET DEFAULT
+com.quantum.properties.ReferencesPropertyPage.importedKeyRestrict = RESTRICT
+
+com.quantum.properties.IndexPropertyPage.column0 = Index Name
+com.quantum.properties.IndexPropertyPage.column1 = Column Name
+com.quantum.properties.IndexPropertyPage.column2 = Order
+com.quantum.properties.IndexPropertyPage.ascending = Ascending
+com.quantum.properties.IndexPropertyPage.descending = Descending
-com.quantum.ui.dialog.AddDriverDialog.title=Add Driver
-com.quantum.ui.dialog.AddDriverDialog.browse=Browse
-com.quantum.ui.dialog.AddDriverDialog.fileName=File name:
-com.quantum.ui.dialog.AddDriverDialog.driverClassName=Class name:
+com.quantum.properties.ColumnPropertyPage.column0 = Name
+com.quantum.properties.ColumnPropertyPage.column1 = Type
+com.quantum.properties.ColumnPropertyPage.column2 = Size
+com.quantum.properties.ColumnPropertyPage.column3 = Digits
+com.quantum.properties.ColumnPropertyPage.column4 = Primary Key
+com.quantum.properties.ColumnPropertyPage.column5 = Nullable
+com.quantum.properties.ColumnPropertyPage.column6 = Remarks
+com.quantum.properties.ColumnPropertyPage.true = Yes
+com.quantum.properties.ColumnPropertyPage.false = No
* @author bcholmes
*/
public class AddToQuickListAction extends SelectionListenerAction {
- private IViewPart view;
private List entities = Collections.synchronizedList(new ArrayList());
public AddToQuickListAction(IViewPart view) {
super(Messages.getString(AddToQuickListAction.class.getName() + ".text"));
- this.view = view;
}
public void run() {
*/
package com.quantum.actions;
+import java.sql.SQLException;
import java.util.Iterator;
import com.quantum.QuantumPlugin;
import com.quantum.model.Column;
import com.quantum.model.EntityHolder;
+import com.quantum.model.NotConnectedException;
import com.quantum.util.NthLevelConverter;
import com.quantum.util.QuantumUtil;
import com.quantum.util.StringUtil;
public class CustomCopyAction extends SelectionListenerAction {
- private final IViewPart view;
private final int ind;
/**
* @param BookmarkView
*/
public CustomCopyAction(IViewPart view, int ind) {
super(null);
- this.view = view;
this.ind = ind;
}
public void run() {
ColumnNode column = (ColumnNode) current;
if (column != null) {
converter.add(column.getColumn().getName(),
- column.getColumn().getParentEntity().getCondQualifiedName(), 0);
+ column.getColumn().getParentEntity().getQualifiedName(), 0);
}
} else if (current instanceof EntityHolder) {
EntityHolder currentSelec = (EntityHolder) current;
- converter.add(currentSelec.getEntity().getCondQualifiedName(), null, 1);
- Column[] columns = currentSelec.getEntity().getColumns();
- for (int i = 0, length = (columns == null) ? 0 : columns.length;
- i < length;
- i++) {
- converter.add(columns[i].getName(),
- currentSelec.getEntity().getCondQualifiedName(), 0);
- }
+ converter.add(currentSelec.getEntity().getQualifiedName(), null, 1);
+ try {
+ Column[] columns = currentSelec.getEntity().getColumns();
+ for (int i = 0, length = (columns == null) ? 0 : columns.length;
+ i < length;
+ i++) {
+ converter.add(columns[i].getName(),
+ currentSelec.getEntity().getQualifiedName(), 0);
+ }
+ } catch (NotConnectedException e) {
+ } catch (SQLException e) {
+ }
}
}
IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
view.getSite().getShell(),
Messages.getString(DeleteAllRowsAction.class.getName() + ".confirmTitle"),
Messages.getString(DeleteAllRowsAction.class.getName() + ".confirmText",
- new Object[] { table.getCondQualifiedName() }));
+ new Object[] { table.getQualifiedName() }));
if (flag) {
table.deleteAllRows();
}
import com.quantum.view.tableview.DefaultSizes;
import com.quantum.view.tableview.TableView;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
/**
- * @author panic
+ * Executes a query from the QueryView
*
- * Executes a query from the QueryView
+ * @author panic
*/
public class ExecuteAction extends BaseSQLAction implements IViewActionDelegate {
SQLQueryView view;
- boolean flag = false;
String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
public ExecuteAction() {
setActionDefinitionId("com.quantum.actions.ExecuteAction");
+ setImageDescriptor(QuantumPlugin.getImageDescriptor("play.gif"));
+ setText(Messages.getString("sqlqueryview.executeQuery"));
+ setToolTipText(Messages.getString("sqlqueryview.executeQuery"));
}
public void init(IViewPart view) {
view.getSite().getShell(),"Sorry","Please select a bookmark to use as connection.");
return;
}
+ getStatusLineManager().setErrorMessage(null);
Connection con = getConnection();
- view.setStatus(execute1);
+ getStatusLineManager().setMessage(execute1);
MultiSQLServer server = MultiSQLServer.getInstance();
- view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
+ getStatusLineManager().setMessage(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
Vector queries = new Vector();
String viewQuery = view.getQuery();
// We parse the executable units to send to the JDBC driver
double startTime = 0.0; // stores the time when query is started
double queryDuration= 0.0; // stores query's execution time
+ IProgressMonitor progressBar = getStatusLineManager().getProgressMonitor();
+ progressBar.beginTask("queries", queries.size());
for (int i = 0; i < queries.size(); i++) {
- if (flag) {
- view.setStatus(execute1);
+ if (i % 2 == 0) {
+ getStatusLineManager().setMessage(execute1);
} else {
- view.setStatus(execute2);
+ getStatusLineManager().setMessage(execute2);
}
String query = (String) queries.elementAt(i);
resultUpdateCount += results.getUpdateCount();
}
}
- }
- flag = !flag;
- view.setProgress(i + 1, queries.size());
+ }
+System.out.println(getStatusLineManager().getProgressMonitor() == null ? "not found" : "found!");
+ progressBar.worked(i);
+// view.setProgress(i + 1, queries.size());
}
- Image statImage = QuantumPlugin.getImage((errorCount > 0) ? "stop.gif" : "success.gif"); //$NON-NLS-1$ //$NON-NLS-2$
- view.setStatus(statImage, Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
+ progressBar.done();
+ String message = Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
resultCount + Messages.getString("ExecuteAction.QueriesExecuted") + //$NON-NLS-1$
resultUpdateCount + Messages.getString("ExecuteAction.RowsUpdated") + //$NON-NLS-1$
resultsDisplayed + Messages.getString("ExecuteAction.ResultsDisplayed") + //$NON-NLS-1$
errorCount + Messages.getString("ExecuteAction.Errors") + //$NON-NLS-1$
- queryDuration + Messages.getString("ExecutAction.TimeExec") + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ queryDuration + Messages.getString("ExecutAction.TimeExec") + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ if (errorCount > 0) {
+ getStatusLineManager().setErrorMessage(
+ QuantumPlugin.getImage("stop.gif"), message);
+ } else {
+ getStatusLineManager().setMessage(
+ QuantumPlugin.getImage("success.gif"), message);
+ }
+ }
- view.setProgress(0, 1);
+ /**
+ * @return
+ */
+ private IStatusLineManager getStatusLineManager() {
+ return this.view.getViewSite().getActionBars().getStatusLineManager();
}
public void selectionChanged(IAction action, ISelection selection) {
import java.util.StringTokenizer;
import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
import com.quantum.util.StringUtil;
import com.quantum.view.LogProxy;
import com.quantum.view.SQLLogView;
public class ExportQueryAction extends Action implements IViewActionDelegate {
SQLQueryView view;
+ public ExportQueryAction() {
+ setImageDescriptor(QuantumPlugin.getImageDescriptor("export.gif"));
+ setText(Messages.getString("sqlqueryview.exportQuery"));
+ setToolTipText(Messages.getString("sqlqueryview.exportQuery"));
+ }
+
/**
* @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
*/
*/
public class ImportQueryAction extends Action implements IViewActionDelegate {
SQLQueryView view;
- FileDialog dialog;
+ FileDialog dialog;
+
+ public ImportQueryAction() {
+ setText(Messages.getString("sqlqueryview.importQuery"));
+ setImageDescriptor(QuantumPlugin.getImageDescriptor("import.gif"));
+ setToolTipText(Messages.getString("sqlqueryview.importQuery"));
+ }
+
/**
* @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
*/
dialog.setFilterExtensions(new String[]{"*.sql", "*.ddl", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dialog.setFilterNames(new String[]{Messages.getString("filedialog.sqlFiles"), //$NON-NLS-1$
Messages.getString("filedialog.ddlFiles"), Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
-
}
/**
package com.quantum.actions;
+import org.eclipse.ui.IViewPart;
+
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
-import com.quantum.adapters.AdapterFactory;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.model.Bookmark;
import com.quantum.sql.SQLResults;
import com.quantum.view.bookmark.EntityNode;
import com.quantum.view.tableview.TableView;
-import org.eclipse.ui.IViewPart;
-
public class NextSequenceAction extends BaseSequenceAction {
/**
}
public void run() {
- EntityNode node = getEntityNode();
+ EntityNode sequence = getEntityNode();
String name = null;
- if (node.isSequence()) {
- EntityNode sequence = (EntityNode) node;
+ if (sequence.isSequence()) {
Bookmark bookmark = sequence.getBookmark();
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+ DatabaseAdapter adapter = bookmark.getAdapter();
if (adapter == null) return;
name = sequence.getName();
String query = adapter.getNextValue(name, sequence.getEntity().getSchema());
*/
package com.quantum.actions;
+import org.eclipse.ui.IViewPart;
+
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
-import com.quantum.adapters.AdapterFactory;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.model.Bookmark;
import com.quantum.sql.SQLResults;
import com.quantum.view.bookmark.EntityNode;
import com.quantum.view.tableview.TableView;
-import org.eclipse.ui.IViewPart;
-
public class PrevSequenceAction extends BaseSequenceAction {
/**
* @param text
}
public void run() {
- EntityNode node = getEntityNode();
- if (((EntityNode) node).isSequence()) {
- EntityNode sequence = (EntityNode) node;
+ EntityNode sequence = getEntityNode();
+ if (sequence.isSequence()) {
Bookmark bookmark = sequence.getBookmark();
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(
- bookmark.getType());
+ DatabaseAdapter adapter = bookmark.getAdapter();
if (adapter == null) return;
String name = sequence.getName();
String query = adapter.getPrevValue(name, sequence.getEntity().getSchema());
package com.quantum.actions;
+import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
-import com.quantum.sql.SQLHelper;
-import com.quantum.view.bookmark.BookmarkView;
+import com.quantum.model.NotConnectedException;
+import com.quantum.ui.dialog.ExceptionDisplayDialog;
import com.quantum.view.bookmark.TreeNode;
import org.eclipse.ui.IViewPart;
* @author root
*/
public class RefreshBookmarkAction extends SelectionListenerAction {
- SQLHelper helper = new SQLHelper();
-
- BookmarkView view;
+ private IViewPart view;
public RefreshBookmarkAction(IViewPart view) {
super(Messages.getString(RefreshBookmarkAction.class.getName() + ".text"));
- this.view = (BookmarkView) view;
+ this.view = view;
setImageDescriptor(QuantumPlugin.getImageDescriptor("refresh.gif"));
}
for (Iterator i = list.iterator(); i.hasNext(); ) {
Object object = i.next();
if (object != null && object instanceof TreeNode) {
- ((TreeNode) object).reload();
+ try {
+ ((TreeNode) object).reload();
+ } catch (NotConnectedException e) {
+ handleException(e);
+ } catch (SQLException e) {
+ handleException(e);
+ }
}
}
}
+
+ /**
+ * @param e
+ */
+ private void handleException(Throwable t) {
+ ExceptionDisplayDialog.openError(
+ this.view.getSite().getShell(), null, null, t);
+ }
}
* @author bcholmes
*/
public class RemoveFromQuickListAction extends SelectionListenerAction {
- private IViewPart view;
private List entities = Collections.synchronizedList(new ArrayList());
public RemoveFromQuickListAction(IViewPart view) {
super(Messages.getString(RemoveFromQuickListAction.class.getName() + ".text"));
- this.view = view;
}
public void run() {
* Implements action for "View Table"
*/
public class ViewTableAction extends SelectionListenerAction {
- private IViewPart view;
private Entity entity;
public ViewTableAction(IViewPart view) {
super(Messages.getString(ViewTableAction.class.getName() + ".text"));
- this.view = view;
setImageDescriptor(
QuantumPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
}
public class AdabasDAdapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
+ /**
+ * @param type
+ */
+ protected AdabasDAdapter() {
+ super(AdapterFactory.ADABASD);
+ }
+ public String getShowTableQuery(String qualifier) {
return "SELECT OWNER, TABLENAME FROM TABLES WHERE OWNER = '" + qualifier.toUpperCase() + "'"; //$NON-NLS-1$
}
- public String getShowViewQuery(String qualifier, boolean isDefault) {
+ public String getShowViewQuery(String qualifier) {
return "SELECT OWNER, VIEWNAME FROM VIEWS WHERE OWNER = '" + qualifier.toUpperCase() + "'"; //$NON-NLS-1$
}
}
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
-
-import com.quantum.Messages;
+import java.util.Map;
/**
- * @author root
* Basically this Factory is a Singleton that is used to return the proper adapter
+ * @author root
*/
public class AdapterFactory {
+
+ static class ComparatorImpl implements Comparator {
+
+ public int compare(Object arg0, Object arg1) {
+ DatabaseAdapter adapter0 = (DatabaseAdapter) arg0;
+ DatabaseAdapter adapter1 = (DatabaseAdapter) arg1;
+
+ if (adapter0 == null && adapter0 != null) {
+ return -1;
+ } else if (adapter0 != null && adapter1 == null) {
+ return 1;
+ } else if (adapter0 == null && adapter1 == null) {
+ return 0;
+ } else {
+ return adapter0.getDisplayName().compareTo(adapter1.getDisplayName());
+ }
+ }
+ }
+
public static final String GENERIC = "GENERIC"; //$NON-NLS-1$
+ public static final String HSQLDB = "HSQLDB"; //$NON-NLS-1$
public static final String ORACLE = "ORACLE"; //$NON-NLS-1$
public static final String POSTGRES = "POSTGRES"; //$NON-NLS-1$
public static final String MYSQL = "MYSQL"; //$NON-NLS-1$
public static final String ADABASD = "ADABASD"; //$NON-NLS-1$
public static final String INFORMIX = "INFORMIX"; //$NON-NLS-1$
public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$
+ public static final String POINTBASE = "POINTBASE"; //$NON-NLS-1$
public static final String SYBASE = "SYBASE"; //$NON-NLS-1$
+ private static final Map DRIVER_MAP = Collections.synchronizedMap(new HashMap());
+
+ static {
+ DRIVER_MAP.put("com.ddtek.jdbc.informix.InformixDriver", AdapterFactory.INFORMIX);
+ DRIVER_MAP.put("com.ddtek.jdbc.db2.DB2Driver", AdapterFactory.DB2);
+ DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", AdapterFactory.ORACLE);
+ DRIVER_MAP.put("com.ddtek.jdbc.sqlserver.SQLServerDriver", AdapterFactory.GENERIC);
+ DRIVER_MAP.put("com.ddtek.jdbc.sybase.SybaseDriver", AdapterFactory.SYBASE);
+ DRIVER_MAP.put("com.ibm.as400.access.AS400JDBCDriver", AdapterFactory.DB2AS400);
+ DRIVER_MAP.put("COM.ibm.db2.jdbc.app.DB2Driver", AdapterFactory.DB2);
+ DRIVER_MAP.put("COM.ibm.db2.jdbc.net.DB2Driver", AdapterFactory.DB2);
+ DRIVER_MAP.put("com.inet.ora.OraDriver", AdapterFactory.ORACLE);
+ DRIVER_MAP.put("com.inet.drda.DRDADriver", AdapterFactory.DB2);
+ DRIVER_MAP.put("com.inet.syb.SybDriver", AdapterFactory.SYBASE);
+ DRIVER_MAP.put("com.inet.tds.TdsDriver", AdapterFactory.GENERIC);
+ DRIVER_MAP.put("com.informix.jdbc.IfxDriver", AdapterFactory.INFORMIX);
+ DRIVER_MAP.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", AdapterFactory.GENERIC);
+ DRIVER_MAP.put("com.mysql.jdbc.Driver", AdapterFactory.MYSQL);
+ DRIVER_MAP.put("com.pointbase.jdbc.jdbcUniversalDriver", AdapterFactory.POINTBASE);
+ DRIVER_MAP.put("com.sybase.jdbcx.SybDriver", AdapterFactory.SYBASE);
+ DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", AdapterFactory.ORACLE);
+ DRIVER_MAP.put("org.gjt.mm.mysql.Driver", AdapterFactory.MYSQL);
+ DRIVER_MAP.put("org.hsqldb.jdbcDriver", AdapterFactory.HSQLDB);
+ DRIVER_MAP.put("org.postgresql.Driver", AdapterFactory.POSTGRES);
+ DRIVER_MAP.put("weblogic.jdbc.informix.InformixDriver", AdapterFactory.INFORMIX);
+ DRIVER_MAP.put("weblogic.jdbc.sqlserver.SybaseDriver", AdapterFactory.SYBASE);
+ }
+
private static AdapterFactory instance;
- private ArrayList drivers;
+ private Map adapters = Collections.synchronizedMap(new HashMap());
private AdapterFactory() {
- loadDrivers();
+ addAdapter(new GenericAdapter(GENERIC));
+ addAdapter(new GenericAdapter(HSQLDB));
+ addAdapter(new OracleAdapter());
+ addAdapter(new DB2Adapter());
+ addAdapter(new DB2AS400Adapter());
+ addAdapter(new PostgresAdapter());
+ addAdapter(new GenericAdapter(MYSQL));
+ addAdapter(new AdabasDAdapter());
+ addAdapter(new GenericAdapter(INFORMIX));
+ addAdapter(new RedBrickAdapter());
+ addAdapter(new GenericAdapter(SYBASE));
+ addAdapter(new GenericAdapter(POINTBASE));
+ }
+ private void addAdapter(DatabaseAdapter adapter) {
+ this.adapters.put(adapter.getType(), adapter);
}
+
public static synchronized AdapterFactory getInstance() {
if (instance == null) {
instance = new AdapterFactory();
return instance;
}
- /**
- * Master list of supported drivers
- */
- private void loadDrivers() {
- drivers = new ArrayList();
-
- DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter()); //$NON-NLS-1$
- DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); //$NON-NLS-1$
- DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); //$NON-NLS-1$
- DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); //$NON-NLS-1$
- DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); //$NON-NLS-1$
- DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new GenericAdapter()); //$NON-NLS-1$
- DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); //$NON-NLS-1$
- DriverInfo informix = new DriverInfo(INFORMIX, Messages.getString("adapters.informix"), new GenericAdapter()); //$NON-NLS-1$
- DriverInfo redbrick = new DriverInfo(REDBRICK, Messages.getString("adapters.redbrick"), new RedBrickAdapter()); //$NON-NLS-1$
- DriverInfo sybase = new DriverInfo(SYBASE, Messages.getString("adapters.sybase"), new GenericAdapter()); //$NON-NLS-1$
-
- drivers.add(generic);
- drivers.add(oracle);
- drivers.add(db2);
- drivers.add(db2as400);
- drivers.add(postgres);
- drivers.add(mysql);
- drivers.add(adabasd);
- drivers.add(informix);
- drivers.add(redbrick);
- drivers.add(sybase);
+ public DatabaseAdapter getAdapter(String type){
+ DatabaseAdapter result = (DatabaseAdapter) this.adapters.get(type);
+ if (result == null) {
+ result = (DatabaseAdapter) this.adapters.get(GENERIC);
+ }
+ return result == null ? null : result;
}
- public synchronized DatabaseAdapter getAdapter(String type){
- if (drivers == null) {
- loadDrivers();
- }
- for (int i = 0; i < drivers.size(); i++) {
- DriverInfo info = (DriverInfo) drivers.get(i);
- if (type.equals(info.getDriverType())) {
- return info.getAdapter();
- }
- }
- // If its not a recognized driver, we return the generic one
- for (int i = 0; i < drivers.size(); i++) {
- DriverInfo info = (DriverInfo) drivers.get(i);
- if (type.equals(GENERIC)) {
- return info.getAdapter();
- }
- }
- return null;
+ public DatabaseAdapter[] getDriverList() {
+ List list = new ArrayList(this.adapters.values());
+ Collections.sort(list, new ComparatorImpl());
+ return (DatabaseAdapter[]) list.toArray(new DatabaseAdapter[list.size()]);
}
- public synchronized DriverInfo[] getDriverList() {
- List list = new ArrayList(this.drivers);
- Collections.sort(list);
- return (DriverInfo[]) list.toArray(new DriverInfo[list.size()]);
+ /**
+ *
+ * @param driverClassName
+ * @return the adapter type, or null if the adapter type is not known
+ */
+ public String getAdapterType(String driverClassName) {
+ return (String) DRIVER_MAP.get(driverClassName);
}
}
\ No newline at end of file
public class DB2AS400Adapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
+ protected DB2AS400Adapter() {
+ super(AdapterFactory.DB2AS400);
+ }
+ public String getShowTableQuery(String qualifier) {
return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" +
qualifier.toUpperCase() +
"' AND TABLE_TYPE IN ('T', 'P') AND SYSTEM_TABLE= 'N'"; //$NON-NLS-1$ //$NON-NLS-2$
}
- public String getShowViewQuery(String qualifier, boolean isDefault) {
+ public String getShowViewQuery(String qualifier) {
return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" +
qualifier.toUpperCase() +
"' AND TABLE_TYPE IN ('V', 'L') AND SYSTEM_TABLE= 'N'"; //$NON-NLS-1$ //$NON-NLS-2$
import com.quantum.sql.SQLHelper;
public class DB2Adapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
+ /**
+ * @param type
+ */
+ protected DB2Adapter() {
+ super(AdapterFactory.DB2);
+ }
+ public String getShowTableQuery(String qualifier) {
return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + qualifier.toUpperCase() + "' AND TYPE='T'"; //$NON-NLS-1$ //$NON-NLS-2$
}
- public String getShowViewQuery(String qualifier, boolean isDefault) {
+ public String getShowViewQuery(String qualifier) {
return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + qualifier.toUpperCase() + "' AND TYPE='V'"; //$NON-NLS-1$ //$NON-NLS-2$
}
- public String getShowSequenceQuery(String qualifier, boolean isDefault) {
+ public String getShowSequenceQuery(String qualifier) {
return "SELECT SEQNAME FROM sysibm.syssequences WHERE seqschema = '" + qualifier.toUpperCase() + "'"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String getNextValue(String sequence, String owner) {
package com.quantum.adapters;
+import com.quantum.Messages;
import com.quantum.sql.SQLHelper;
import com.quantum.util.StringUtil;
*/
public abstract class DatabaseAdapter {
+ private final String type;
+
+ protected DatabaseAdapter(String type) {
+ this.type = type;
+ }
+
+ public String getDisplayName() {
+ return Messages.getString(DatabaseAdapter.class, getType());
+ }
+
/**
* Returns the SQL Query to get a list of the tables for the current user (schema)
* @param info
* @return - A String with the SQL query
*/
- public String getShowTableQuery(String schema, boolean isDefault) {
+ public String getShowTableQuery(String schema) {
return null;
}
/**
* @param info
* @return - A String with the SQL query
*/
- public String getShowViewQuery(String schema, boolean isDefault) {
+ public String getShowViewQuery(String schema) {
return null;
}
/**
* @param info
* @return - A String with the SQL query
*/
- public String getShowSequenceQuery(String schema, boolean isDefault) {
+ public String getShowSequenceQuery(String schema) {
return null;
}
public String getDefaultSchema(String userid) {
return userid;
}
+ /**
+ * @return Returns the type.
+ */
+ public String getType() {
+ return this.type;
+ }
}
\ No newline at end of file
+++ /dev/null
-package com.quantum.adapters;
-
-import java.util.Vector;
-
-public class DriverInfo implements Comparable {
- private String driverType;
- private String displayName;
- private Vector driverNames = new Vector();
- private DatabaseAdapter adapter;
- public DriverInfo(String driverType, String displayName, DatabaseAdapter adapter) {
- this.driverType = driverType;
- this.displayName = displayName;
- this.adapter = adapter;
- }
-
- public String getDriverType() {
- return driverType;
- }
-
- public void setDriverType(String driverType) {
- this.driverType = driverType;
- }
-
- public void addDriverName(String driverName) {
- driverNames.addElement(driverName);
- }
-
- public String[] getDriverNames() {
- String retVal[] = new String[driverNames.size()];
- for (int i = 0; i < driverNames.size(); i++) {
- retVal[i] = (String) driverNames.elementAt(i);
- }
- return retVal;
- }
-
- public DatabaseAdapter getAdapter() {
- return adapter;
- }
-
- public void setAdapter(DatabaseAdapter adapter) {
- this.adapter = adapter;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public int compareTo(Object o) {
- DriverInfo that = (DriverInfo) o;
- return this.getDisplayName().compareTo(that.getDisplayName());
- }
-
-}
+++ /dev/null
-package com.quantum.adapters;
-
-public class FeatureNotSupported extends Error {
- public FeatureNotSupported(String error) {
- super(error);
- }
-}
\ No newline at end of file
public class GenericAdapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
+ /**
+ * @param type
+ */
+ protected GenericAdapter(String type) {
+ super(type);
+ }
+ public String getShowTableQuery(String qualifier) {
return null;
}
- public String getShowViewQuery(String qualifier, boolean isDefault) {
+ public String getShowViewQuery(String qualifier) {
return null;
}
- public String getShowSequenceQuery(String qualifier, boolean isDefault) {
+ public String getShowSequenceQuery(String qualifier) {
return null;
}
-
-
}
public class MySQLAdapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
- return "SHOW TABLES"; //$NON-NLS-1$
- }
+
+ /**
+ * @param type
+ */
+ protected MySQLAdapter() {
+ super(AdapterFactory.MYSQL);
+ }
+// public String getShowTableQuery(String qualifier, boolean isDefault) {
+// return "SHOW TABLES"; //$NON-NLS-1$
+// }
}
\ No newline at end of file
+++ /dev/null
-package com.quantum.adapters;
-
-import com.quantum.Messages;
-
-public class NoSuchAdapterException extends Exception {
- public NoSuchAdapterException(String driverName) {
- super(Messages.getString("Error.NoDatabase") + driverName + Messages.getString("NoSuchAdapterException.<-_2")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-}
\ No newline at end of file
public class OracleAdapter extends DatabaseAdapter {
- public String getShowSequenceQuery(String qualifier, boolean isDefault) {
+ protected OracleAdapter() {
+ super(AdapterFactory.ORACLE);
+ }
+ public String getShowSequenceQuery(String qualifier) {
return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + qualifier + "'"; //$NON-NLS-1$
}
public String getPrevValue(String sequence, String owner) {
public class PostgresAdapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
+ protected PostgresAdapter() {
+ super(AdapterFactory.POSTGRES);
+ }
+ public String getShowTableQuery(String qualifier) {
return "SELECT SCHEMANAME, TABLENAME FROM PG_TABLES WHERE SCHEMANAME = '"
+ qualifier + "'";
}
- public String getShowViewQuery(String qualifier, boolean isDefault) {
+ public String getShowViewQuery(String qualifier) {
return "SELECT SCHEMANAME, VIEWNAME FROM PG_VIEWS WHERE SCHEMANAME = '"
+ qualifier + "'";
}
- public String getShowSequenceQuery(String qualifier, boolean isDefault) {
- return "SELECT SCHEMANAME, relname FROM pg_class WHERE relkind = 'S'" +
- "AND SCHEMANAME = '" + qualifier + "'";
+ public String getShowSequenceQuery(String qualifier) {
+ return "select pg_namespace.nspname, relname " +
+ "from pg_class, pg_namespace where relkind = 'S' " +
+ "and relnamespace = pg_namespace.oid " +
+ "and pg_namespace.nspname = '" + qualifier + "'";
}
public String getNextValue(String sequence, String owner) {
return "SELECT NEXTVAL('" + SQLHelper.getQualifiedName(owner, sequence) + "')";
*/
public class RedBrickAdapter extends DatabaseAdapter {
- public String getShowTableQuery(String qualifier, boolean isDefault) {
+ /**
+ * @param type
+ */
+ protected RedBrickAdapter() {
+ super(AdapterFactory.REDBRICK);
+ }
+
+ public String getShowTableQuery(String qualifier) {
return "select name from rbw_tables where type = 'TABLE'";
}
- public String getShowViewQuery(String qualifier, boolean isDefault) {
+ public String getShowViewQuery(String qualifier) {
return "select name from rbw_tables where type = 'VIEW'";
}
/**
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
* @author root
*/
public class Bookmark {
+
+ public static final int SCHEMA_RULE_USE_ALL = 1;
+ public static final int SCHEMA_RULE_USE_DEFAULT = 2;
+ public static final int SCHEMA_RULE_USE_SELECTED = 3;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
private String name = ""; //$NON-NLS-1$
private String username = ""; //$NON-NLS-1$
private String password = ""; //$NON-NLS-1$
- private String connect = ""; //$NON-NLS-1$
- private String driver = ""; //$NON-NLS-1$
- private String type = ""; //$NON-NLS-1$
- private String driverFile = ""; //$NON-NLS-1$
+ private String connectionUrl = ""; //$NON-NLS-1$
+ private JDBCDriver driver;
+
+ private int schemaRule = SCHEMA_RULE_USE_ALL;
/**
* A quick list is a list of favourite tables that a person might want to view
setUsername(data.getUsername());
setPassword(data.getPassword());
setConnect(data.getConnect());
- setDriver(data.getDriver());
- setType(data.getType());
- setDriverFile(data.getDriverFile());
+ setJDBCDriver(data.getJDBCDriver());
setPromptForPassword(data.getPromptForPassword());
setAutoCommit(data.isAutoCommit());
setAutoCommitPreference(data.getAutoCommitPreference());
* @return String
*/
public String getConnect() {
- return connect;
- }
-
- /**
- * Returns the driver.
- * @return String
- */
- String getDriver() {
- return driver;
- }
-
- /**
- * Returns the driverFile.
- * @return String
- */
- String getDriverFile() {
- return driverFile;
+ return this.connectionUrl;
}
/**
* @return String
*/
public String getPassword() {
- return password;
+ if (this.promptForPassword) {
+ return null;
+ } else {
+ return this.password;
+ }
}
/**
/**
* Sets the connect.
- * @param connect The connect to set
+ * @param connectionUrl The connect to set
*/
- public void setConnect(String connect) {
- if (connect == null) {
- connect = ""; //$NON-NLS-1$
+ public void setConnect(String connectionUrl) {
+ if (connectionUrl == null) {
+ connectionUrl = ""; //$NON-NLS-1$
}
- this.connect = connect;
- }
-
- /**
- * Sets the driver.
- * @param driver The driver to set
- */
- void setDriver(String driver) {
- if (driver == null) {
- driver = ""; //$NON-NLS-1$
- }
- this.driver = driver;
- }
-
- /**
- * Sets the driverFile.
- * @param driverFile The driverFile to set
- */
- void setDriverFile(String driverFile) {
- if (driverFile == null) {
- driverFile = ""; //$NON-NLS-1$
- }
- this.driverFile = driverFile;
+ this.connectionUrl = connectionUrl;
}
/**
if (name.equals("") && //$NON-NLS-1$
username.equals("") && //$NON-NLS-1$
password.equals("") && //$NON-NLS-1$
- connect.equals("") && //$NON-NLS-1$
+ connectionUrl.equals("") && //$NON-NLS-1$
driver.equals("") && //$NON-NLS-1$
- type.equals("") && //$NON-NLS-1$
- driverFile.equals("")) { //$NON-NLS-1$
+ driver == null) {
return true;
}
return false;
buffer.append("password=****"); //$NON-NLS-1$
buffer.append(", "); //$NON-NLS-1$
buffer.append("connect="); //$NON-NLS-1$
- buffer.append(connect);
+ buffer.append(connectionUrl);
buffer.append(", "); //$NON-NLS-1$
buffer.append("driver="); //$NON-NLS-1$
buffer.append(driver);
- buffer.append(", "); //$NON-NLS-1$
- buffer.append("type="); //$NON-NLS-1$
- buffer.append(type);
- buffer.append(", "); //$NON-NLS-1$
- buffer.append("driverFile="); //$NON-NLS-1$
- buffer.append(driverFile);
buffer.append("]"); //$NON-NLS-1$
return buffer.toString();
}
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
public Connection connect(PasswordFinder passwordFinder) throws ConnectionException {
boolean isConnected = isConnected();
if (this.connection == null) {
}
}
- public void setSchemas(Schema[] schemas) {
+ public void setSchemaSelections(Schema[] schemas) {
this.schemas.clear();
for (int i = 0, length = (schemas == null) ? 0 : schemas.length;
i < length;
/**
* @return a list of all the schemas that have been set up.
*/
- public Schema[] getSchemas() {
- Set set = new HashSet();
- set.addAll(this.schemas);
- if (set.isEmpty()) {
- set.add(new Schema(getAdapter().getDefaultSchema(this.username),
- this.username, true));
- }
- List list = new ArrayList(set);
+ public Schema[] getSchemaSelections() {
+ List list = new ArrayList(this.schemas);
Collections.sort(list);
return (Schema[]) list.toArray(new Schema[list.size()]);
}
+
+ public Schema[] getSchemas() throws NotConnectedException, SQLException {
+ Schema[] schemas = null;
+ if (useUsernameAsSchema()) {
+ // do nothing
+ } else if (useAllSchemas()) {
+ schemas = getDatabase().getSchemas();
+ } else {
+ schemas = verifySchemas(getSchemaSelections());
+ }
+ return (schemas == null || schemas.length == 0)
+ ? new Schema[] { getDefaultSchema() }
+ : schemas;
+ }
+
+ /**
+ * @param schemaSelections
+ * @return
+ * @throws SQLException
+ * @throws NotConnectedException
+ */
+ private Schema[] verifySchemas(Schema[] schemaSelections)
+ throws NotConnectedException, SQLException {
+ Schema[] schemasFromDatabase = getDatabase().getSchemas();
+ List list = Arrays.asList(schemasFromDatabase);
+ for (int i = 0, length = schemaSelections == null ? 0 : schemaSelections.length;
+ i < length; i++) {
+ schemaSelections[i].setExists(list.contains(schemaSelections[i]));
+ }
+ return schemaSelections;
+ }
+
+ /**
+ * @return
+ * @throws NotConnectedException
+ * @throws SQLException
+ */
+ private Schema getDefaultSchema() throws NotConnectedException, SQLException {
+ String username = getDatabase().getUsername();
+ String actual = getAdapter().getDefaultSchema(username);
+ return new Schema(actual, username, true);
+ }
/**
* @see java.lang.Object#equals(java.lang.Object)
public void addQuickListEntry(String type, String schemaName, String name) {
Entity entity = EntityFactory.getInstance().create(this, schemaName, name, type);
- this.quickList.put(entity.getCondQualifiedName(), entity);
+ this.quickList.put(entity.getQualifiedName(), entity);
this.propertyChangeSupport.firePropertyChange("quickList", null, null);
this.changed = true;
}
}
public void removeQuickListEntry(Entity entity) {
- if (entity != null && this.quickList.containsKey(entity.getCondQualifiedName())) {
- this.quickList.remove(entity.getCondQualifiedName());
+ if (entity != null && this.quickList.containsKey(entity.getQualifiedName())) {
+ this.quickList.remove(entity.getQualifiedName());
this.propertyChangeSupport.firePropertyChange("quickList", null, null);
this.changed = true;
}
}
public DatabaseAdapter getAdapter() {
- return AdapterFactory.getInstance().getAdapter(getType());
+ return this.driver == null
+ ? null
+ : AdapterFactory.getInstance().getAdapter(this.driver.getType());
}
public Entity[] getEntitiesForSchema(Schema schema, String type) throws SQLException {
}
public boolean isInQuickList(Entity entity) {
- return this.quickList.containsKey(entity.getCondQualifiedName());
+ return this.quickList.containsKey(entity.getQualifiedName());
}
/**
}
public void setJDBCDriver(JDBCDriver jdbcDriver) {
- jdbcDriver = BookmarkCollection.getInstance().findDriver(jdbcDriver);
- setDriver(jdbcDriver.getClassName());
- setDriverFile(jdbcDriver.getJarFileName());
+ this.driver = BookmarkCollection.getInstance().findDriver(jdbcDriver);
+ this.changed = true;
}
public JDBCDriver getJDBCDriver() {
- return BookmarkCollection.getInstance().findDriver(getDriver(), getDriverFile());
+ return this.driver;
+ }
+ public boolean useAllSchemas() {
+ return this.schemaRule == SCHEMA_RULE_USE_ALL;
+ }
+ public boolean useUsernameAsSchema() {
+ return this.schemaRule == SCHEMA_RULE_USE_DEFAULT;
+ }
+ public boolean useSelectedSchemas() {
+ return this.schemaRule == SCHEMA_RULE_USE_SELECTED;
+ }
+ public int getSchemaRule() {
+ return this.schemaRule;
+ }
+ public void setSchemaRule(int schemaRule) {
+ if (this.schemaRule != schemaRule) {
+ this.schemaRule = schemaRule;
+ this.propertyChangeSupport.firePropertyChange("schemas", null, null);
+ }
}
}
bookmark.setUsername(props.getProperty(i + ".username")); //$NON-NLS-1$
bookmark.setPassword(props.getProperty(i + ".password")); //$NON-NLS-1$
bookmark.setConnect(props.getProperty(i + ".connect")); //$NON-NLS-1$
- bookmark.setDriver(props.getProperty(i + ".driver")); //$NON-NLS-1$
String schema = props.getProperty(i + ".schema"); //$NON-NLS-1$
if (schema != null) {
bookmark.addSchema(schema);
}
- String type = props.getProperty(i + ".type"); //$NON-NLS-1$
- if (type != null) {
- bookmark.setType(type);
- } else {
- bookmark.setType(""); //$NON-NLS-1$
- }
- String driverFile = props.getProperty(i + ".driverLocation"); //$NON-NLS-1$
- if (driverFile != null) {
- bookmark.setDriverFile(driverFile);
- } else {
- bookmark.setDriverFile(""); //$NON-NLS-1$
- }
- System.out.println(bookmark.toString());
if (!bookmark.isEmpty()) {
newBookmarks.add(bookmark);
}
i++;
- this.drivers.add(new JDBCDriver(bookmark.getDriver(), driverFile));
+ String driver = props.getProperty(i + ".driver"); //$NON-NLS-1$
+ String driverFile = props.getProperty(i + ".driverLocation"); //$NON-NLS-1$
+ String type = props.getProperty(i + ".type"); //$NON-NLS-1$
+ this.drivers.add(new JDBCDriver(driver, driverFile, type));
}
if (overwrite) {
this.bookmarks = newBookmarks;
NodeList nodes = root.getElementsByTagName("jdbcDriver"); //$NON-NLS-1$
for (int i = 0; i < nodes.getLength(); i++) {
Element driver = (Element) nodes.item(i);
- addDriver(new JDBCDriver(
- driver.getAttribute("className"),
- driver.getAttribute("jarFileName"),
- driver.getAttribute("name"),
- driver.getAttribute("version")));
+
+ if (!"".equals(driver.getAttribute("type"))) {
+ addDriver(new JDBCDriver(
+ driver.getAttribute("className"),
+ driver.getAttribute("jarFileName"),
+ driver.getAttribute("type"),
+ driver.getAttribute("name"),
+ driver.getAttribute("version")));
+ }
+
}
}
bookmark.setAutoCommit(Boolean.TRUE.toString().equalsIgnoreCase(
MetaDataXMLInterface.getElementText(column,"autoCommit", "True"))); //$NON-NLS-1$
bookmark.setAutoCommitPreference(MetaDataXMLInterface.getElementText(column,"autoCommitPreference", IQuantumConstants.autoCommitTrue)); //$NON-NLS-1$
- bookmark.addSchema(MetaDataXMLInterface.getElementText(column,"schema")); //$NON-NLS-1$
- bookmark.setType(MetaDataXMLInterface.getElementText(column,"type")); //$NON-NLS-1$
- NodeList children = column.getElementsByTagName(Messages.getString("ExportXMLAction.OtherSchemas"));
+
+ backwardCompatibility(bookmark, column);
String driverClassName = MetaDataXMLInterface.getElementText(column,"driver"); //$NON-NLS-1$
String driverFile = MetaDataXMLInterface.getElementText(column,"driverLocation"); //$NON-NLS-1$
+ String type = MetaDataXMLInterface.getElementText(column,"type"); //$NON-NLS-1$
- bookmark.setJDBCDriver(new JDBCDriver(driverClassName, driverFile));
+ bookmark.setJDBCDriver(new JDBCDriver(driverClassName, driverFile, type));
+ NodeList children = column.getElementsByTagName("Other_Schemas");
if (children.getLength() > 0) {
importSchemas((Element) children.item(0), bookmark);
}
+
+
System.out.println(bookmark.toString());
if (!bookmark.isEmpty()) {
newBookmarks.addElement(bookmark);
return newBookmarks;
}
+ /**
+ * Earlier versions of the xml file expected one schema element under the
+ * bookmark element. This method sees if it exists.
+ *
+ * @param bookmark
+ * @param element
+ */
+ private void backwardCompatibility(Bookmark bookmark, Element element) {
+ NodeList children = element.getChildNodes();
+ for (int i = 0, length = children.getLength(); i < length; i++) {
+ Node node = children.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE &&
+ "schema".equals(((Element) node).getTagName())) {
+ String schema = MetaDataXMLInterface.extractText(element,"");
+ if (schema != null && schema.trim().length() > 0) {
+ bookmark.addSchema(schema);
+ }
+ }
+ }
+ }
+
private void importSchemas(Element otherSchemas, Bookmark bookmark) {
- Vector vector = MetaDataXMLInterface.getVectorText(otherSchemas, Messages.getString("ExportXMLAction.SchemaName"));
List list = new ArrayList();
- for (Iterator i = vector.iterator(); i.hasNext();) {
- String schemaName = (String) i.next();
- list.add(new Schema(schemaName));
+ NodeList children = otherSchemas.getChildNodes();
+ for (int i = 0, length = children.getLength(); i < length; i++) {
+ Node node = children.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && "schema".equalsIgnoreCase(((Element) node).getTagName())) {
+ list.add(new Schema(
+ MetaDataXMLInterface.extractText((Element) node, "")));
+ }
+ }
+
+ String schemaRule = otherSchemas.getAttribute("schemaRule");
+ if ("useAll".equals(schemaRule)) {
+ bookmark.setSchemaRule(Bookmark.SCHEMA_RULE_USE_ALL);
+ } else if ("useDefault".equals(schemaRule)) {
+ bookmark.setSchemaRule(Bookmark.SCHEMA_RULE_USE_DEFAULT);
+ } else {
+ bookmark.setSchemaRule(Bookmark.SCHEMA_RULE_USE_SELECTED);
}
- bookmark.setSchemas((Schema[]) list.toArray(new Schema[list.size()]));
+ bookmark.setSchemaSelections((Schema[]) list.toArray(new Schema[list.size()]));
}
- private void importQuickList(Bookmark bookmark, Element bookmarkElement) {
+ private void importQuickList(Bookmark bookmark, Element bookmarkElement) {
NodeList quickList = bookmarkElement.getElementsByTagName("quickList");
for (int j = 0,
length = (quickList == null) ? 0 : quickList.getLength();
* @param driver
* @param driverFile
*/
- public JDBCDriver findDriver(String driverClassName, String driverFile) {
- JDBCDriver temp = new JDBCDriver(driverClassName, driverFile);
+ public JDBCDriver findDriver(String driverClassName, String driverFile, String type) {
+ JDBCDriver temp = new JDBCDriver(driverClassName, driverFile, type);
return findDriver(temp);
}
* @see com.quantum.model.Column#getQualifiedTableName()
*/
public String getQualifiedTableName() {
- return this.entity.getCondQualifiedName();
+ return this.entity.getQualifiedName();
}
/**
* @param i
--- /dev/null
+package com.quantum.model;
+
+import com.quantum.util.sql.TypesHelper;
+
+
+/**
+ * This class represents a data type. Columns in databases can be of particular types.
+ *
+ * @author BC
+ */
+public class DataType {
+ private final int javaType;
+ private final String databaseTypeName;
+
+ public DataType(int javaType, String databaseTypeName) {
+ this.javaType = javaType;
+ this.databaseTypeName = databaseTypeName;
+ }
+ public String getDatabaseTypeName() {
+ return this.databaseTypeName;
+ }
+ public int getJavaType() {
+ return this.javaType;
+ }
+ public String getJavaNameType() {
+ return TypesHelper.getTypeName(this.javaType);
+ }
+}
import java.util.List;
import java.util.Set;
-import com.quantum.IQuantumConstants;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.sql.MultiSQLServer;
import com.quantum.sql.SQLResults;
this.databaseAdapter = bookmark.getAdapter();
}
- private static final String[] ALL_TYPES = {
- IQuantumConstants.Table,
- IQuantumConstants.View,
- IQuantumConstants.Sequence };
+ private static final String[] ALL_TABLE_TYPES = {
+ Entity.TABLE_TYPE,
+ Entity.VIEW_TYPE,
+ Entity.SEQUENCE_TYPE };
private static final List STANDARD_TABLE_TYPES =
Collections.synchronizedList(new ArrayList());
static {
- for (int i = 0, length = (ALL_TYPES == null) ? 0 : ALL_TYPES.length;
+ for (int i = 0, length = (ALL_TABLE_TYPES == null) ? 0 : ALL_TABLE_TYPES.length;
i < length;
i++) {
- STANDARD_TABLE_TYPES.add(ALL_TYPES[i]);
+ STANDARD_TABLE_TYPES.add(ALL_TABLE_TYPES[i]);
}
}
public String[] getEntityTypes()
throws NotConnectedException, SQLException {
- return getEntityTypes(this.bookmark.getConnection(), this.bookmark.getSchemas()[0]);
+ return getEntityTypes(this.bookmark.getConnection());
+ }
+
+ public String getUsername() throws NotConnectedException, SQLException {
+ return getMetaData().getUserName();
}
* Tables, Views and Sequences.</p>
*
* @param connection
- * @param schema -
- * This parameter is somewhat bogus. It is used to determine if the
- * adapter defines an SQL statement for finding entities of a
- * particular types.
* @return
* @throws SQLException
*/
- public String[] getEntityTypes(Connection connection, Schema schema)
- throws SQLException {
+ public String[] getEntityTypes(Connection connection) throws SQLException {
Set set = new HashSet();
- if (this.databaseAdapter.getShowTableQuery(schema.getName(), false) != null) {
- set.add(IQuantumConstants.Table);
- } else if (this.databaseAdapter.getShowViewQuery(schema.getName(), false) != null) {
- set.add(IQuantumConstants.View);
- } else if (this.databaseAdapter.getShowSequenceQuery(schema.getName(), false) != null) {
- set.add(IQuantumConstants.Sequence);
+ if (this.databaseAdapter.getShowTableQuery(this.bookmark.getUsername()) != null) {
+ set.add(Entity.TABLE_TYPE);
+ } else if (this.databaseAdapter.getShowViewQuery(this.bookmark.getUsername()) != null) {
+ set.add(Entity.VIEW_TYPE);
+ } else if (this.databaseAdapter.getShowSequenceQuery(this.bookmark.getUsername()) != null) {
+ set.add(Entity.SEQUENCE_TYPE);
}
DatabaseMetaData metaData = connection.getMetaData();
while (resultSet.next()) {
String type = resultSet.getString("TABLE_TYPE");
if (type != null) {
+ // Informix, in particular, pads this with extra spaces
type = type.trim();
}
if (STANDARD_TABLE_TYPES.contains(type)) {
public String getInformation() throws SQLException {
try {
- Connection connection = this.bookmark.getConnection();
- DatabaseMetaData metaData = connection.getMetaData();
+ DatabaseMetaData metaData = getMetaData();
return metaData == null ? null : metaData.getDatabaseProductName() + " "
+ metaData.getDatabaseProductVersion();
throws SQLException {
List list = new ArrayList();
- String[] types = (type == null) ? ALL_TYPES : new String[] { type };
+ String[] types = (type == null) ? ALL_TABLE_TYPES : new String[] { type };
for (int i = 0; i < types.length; i++) {
list.addAll(getEntitiesList(bookmark, connection, types[i], schema));
set.close();
return list;
}
+
+ public DataType[] getTypes() throws NotConnectedException, SQLException {
+ DatabaseMetaData metaData = getMetaData();
+ List list = new ArrayList();
+ ResultSet results = metaData.getTypeInfo();
+ try {
+ while (results.next()) {
+ String name = results.getString("TYPE_NAME");
+ int type = results.getInt("DATA_TYPE");
+ list.add(new DataType(type, name));
+ }
+ } finally {
+ results.close();
+ }
+ return (DataType[]) list.toArray(new DataType[list.size()]);
+ }
- private String getSQL(Bookmark bookmark, String type, Schema schema) {
+ /**
+ * @return
+ * @throws NotConnectedException
+ * @throws SQLException
+ */
+ private DatabaseMetaData getMetaData() throws NotConnectedException, SQLException {
+ Connection connection = this.bookmark.getConnection();
+ DatabaseMetaData metaData = connection.getMetaData();
+ return metaData;
+ }
+
+ private String getSQL(Bookmark bookmark, String type, Schema schema) {
if (Entity.TABLE_TYPE.equals(type)) {
- return this.databaseAdapter.getShowTableQuery(schema.getName(), schema.isDefault());
+ return this.databaseAdapter.getShowTableQuery(schema.getName());
} else if (Entity.VIEW_TYPE.equals(type)) {
- return this.databaseAdapter.getShowViewQuery(schema.getName(), schema.isDefault());
+ return this.databaseAdapter.getShowViewQuery(schema.getName());
} else if (Entity.SEQUENCE_TYPE.equals(type)) {
- return this.databaseAdapter.getShowSequenceQuery(schema.getName(), schema.isDefault());
+ return this.databaseAdapter.getShowSequenceQuery(schema.getName());
} else {
return null;
}
}
-
+
+ public ForeignKey[] getExportedKeys(String schema, String entityName)
+ throws NotConnectedException, SQLException {
+ DatabaseMetaData metaData = getMetaData();
+ List list = new ArrayList();
+ return getForeignKeys(list, metaData.getExportedKeys(null, schema, entityName));
+ }
+
+ public ForeignKey[] getImportedKeys(String schema, String entityName)
+ throws NotConnectedException, SQLException {
+ DatabaseMetaData metaData = getMetaData();
+ List list = new ArrayList();
+ return getForeignKeys(list, metaData.getImportedKeys(null, schema, entityName));
+ }
+
+ /**
+ * @param list
+ * @param resultSet
+ * @return
+ * @throws SQLException
+ */
+ private ForeignKey[] getForeignKeys(List list, ResultSet resultSet) throws SQLException {
+ ForeignKeyImpl foreignKey = null;
+
+ int lowestKeySequence = Integer.MAX_VALUE;
+ try {
+ while (resultSet.next()) {
+ int keySequence = resultSet.getInt("KEY_SEQ");
+ lowestKeySequence = Math.min(lowestKeySequence, keySequence);
+
+ if (keySequence == lowestKeySequence || foreignKey == null) {
+ foreignKey = new ForeignKeyImpl();
+ list.add(foreignKey);
+ foreignKey.setName(resultSet.getString("FK_NAME"));
+ foreignKey.setDeleteRule(resultSet.getShort("DELETE_RULE"));
+ foreignKey.setForeignEntitySchema(resultSet.getString("FKTABLE_SCHEM"));
+ foreignKey.setForeignEntityName(resultSet.getString("FKTABLE_NAME"));
+ foreignKey.setLocalEntitySchema(resultSet.getString("PKTABLE_SCHEM"));
+ foreignKey.setLocalEntityName(resultSet.getString("PKTABLE_NAME"));
+ }
+
+ foreignKey.addColumns(
+ resultSet.getString("PKCOLUMN_NAME"),
+ resultSet.getString("FKCOLUMN_NAME"));
+ }
+ return (ForeignKey[]) list.toArray(new ForeignKey[list.size()]);
+ } finally {
+ resultSet.close();
+ }
+ }
+ /**
+ * @return
+ * @throws SQLException
+ * @throws NotConnectedException
+ */
+ public Schema[] getSchemas() throws NotConnectedException, SQLException {
+ DatabaseMetaData metaData = getMetaData();
+ List list = new ArrayList();
+ ResultSet resultSet = metaData.getSchemas();
+ try {
+ while (resultSet.next()) {
+ String schemaName = resultSet.getString("TABLE_SCHEM");
+ list.add(new Schema(schemaName));
+ }
+ return (Schema[]) list.toArray(new Schema[list.size()]);
+ } finally {
+ resultSet.close();
+ }
+ }
}
package com.quantum.model;
+import java.sql.SQLException;
+
import com.quantum.IQuantumConstants;
/**
* @author BC
*/
-public interface Entity extends BookmarkHolder {
+public interface Entity extends BookmarkHolder, Comparable {
public static final String TABLE_TYPE = IQuantumConstants.Table;
public static final String VIEW_TYPE = IQuantumConstants.View;
public String getName();
public String getSchema();
public String getType();
- public Column[] getColumns();
- public Index[] getIndexes();
- public Column getColumn(String columnName);
+ public Column[] getColumns() throws NotConnectedException, SQLException;
+ public Index[] getIndexes() throws NotConnectedException, SQLException;
+ public Column getColumn(String columnName) throws NotConnectedException, SQLException;
/**
- * Returns a String with the qualified name of the Entity.
- * That is, "schema.name". The difference with getQualifiedName()
- * is that the schema may be absent if it's not defined in the bookmark
+ * Returns a String with the qualified name of the Entity in the
+ * format "schema.name".
*/
- public String getCondQualifiedName();
+ public String getQualifiedName();
/**
* @return - TRUE if the entity exists in the database<br />
* @return
*/
public String getQuotedTableName();
+ public ForeignKey[] getExportedKeys() throws NotConnectedException, SQLException;
+ public ForeignKey[] getImportedKeys() throws NotConnectedException, SQLException;
+ public ForeignKey[] getReferences() throws NotConnectedException, SQLException;
}
import java.util.List;
import java.util.Map;
-import com.quantum.adapters.AdapterFactory;
import com.quantum.adapters.DatabaseAdapter;
/**
public String getType() {
return this.type;
}
- public String getCondQualifiedName() {
+ public String getQualifiedName() {
return (this.schema == null || this.schema.length() == 0) ?
this.name : this.schema + "." + this.name;
}
- public Column getColumn(String columnName) {
+ public Column getColumn(String columnName) throws NotConnectedException, SQLException {
Column column = null;
Column[] columns = getColumns();
for (int i = 0, length = (columns == null) ? 0 : columns.length;
}
return column;
}
- public Column[] getColumns() {
+ public Column[] getColumns() throws NotConnectedException, SQLException {
- Column[] columns = new Column[0];
+ Map temp = new HashMap();
+ Connection connection = this.bookmark.getConnection();
+ DatabaseMetaData metaData = connection.getMetaData();
+ ResultSet resultSet = metaData.getColumns(null, getSchema(), getName(), null);
try {
- // TODO: Some DBs (like DB2) don't support metadata
- Map temp = new HashMap();
- Connection connection = this.bookmark.getConnection();
- DatabaseMetaData metaData = connection.getMetaData();
- ResultSet resultSet = metaData.getColumns(null, getSchema(), getName(), null);
-
- while (resultSet.next()) {
- ColumnImpl column = new ColumnImpl(
- this,
- resultSet.getString("COLUMN_NAME"),
- resultSet.getString("TYPE_NAME"),
- resultSet.getInt("DATA_TYPE"),
- resultSet.getInt("COLUMN_SIZE"),
- resultSet.getInt("DECIMAL_DIGITS"),
- "YES".equalsIgnoreCase(resultSet.getString("IS_NULLABLE")),
- resultSet.getInt("ORDINAL_POSITION"),
- getComments(resultSet.getString("REMARKS"),getCondQualifiedName(), resultSet.getString("COLUMN_NAME"))
- );
- temp.put(column.getName(), column);
- }
- resultSet.close();
+ while (resultSet.next()) {
+ ColumnImpl column = new ColumnImpl(
+ this,
+ resultSet.getString("COLUMN_NAME"),
+ resultSet.getString("TYPE_NAME"),
+ resultSet.getInt("DATA_TYPE"),
+ resultSet.getInt("COLUMN_SIZE"),
+ resultSet.getInt("DECIMAL_DIGITS"),
+ "YES".equalsIgnoreCase(resultSet.getString("IS_NULLABLE")),
+ resultSet.getInt("ORDINAL_POSITION"),
+ getComments(resultSet.getString("REMARKS"),getQualifiedName(), resultSet.getString("COLUMN_NAME"))
+ );
+ temp.put(column.getName(), column);
+ }
+ } finally {
+ resultSet.close();
+ }
- resultSet = metaData.getPrimaryKeys(null, getSchema(), getName());
- while (resultSet.next()) {
- String name = resultSet.getString("COLUMN_NAME");
- short keySequence = resultSet.getShort("KEY_SEQ");
- ColumnImpl column = (ColumnImpl) temp.get(name);
- if (column != null) {
- column.setPrimaryKeyOrder(keySequence);
- }
- }
- resultSet.close();
-
- List columnList = Collections.synchronizedList(
- new ArrayList(temp.values()));
- Collections.sort(columnList);
- columns = (Column[]) columnList.toArray(new Column[columnList.size()]);
-
- } catch (NotConnectedException e) {
- } catch (SQLException e) {
+ resultSet = metaData.getPrimaryKeys(null, getSchema(), getName());
+ try {
+ while (resultSet.next()) {
+ String name = resultSet.getString("COLUMN_NAME");
+ short keySequence = resultSet.getShort("KEY_SEQ");
+ ColumnImpl column = (ColumnImpl) temp.get(name);
+ if (column != null) {
+ column.setPrimaryKeyOrder(keySequence);
+ }
+ }
+ resultSet.close();
+
+ List columnList = Collections.synchronizedList(
+ new ArrayList(temp.values()));
+ Collections.sort(columnList);
+ return (Column[]) columnList.toArray(new Column[columnList.size()]);
+ } finally {
+ resultSet.close();
}
- return columns;
}
/**
try {
Connection con = this.bookmark.getConnection();
Statement stmt = con.createStatement();
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(this.bookmark.getType());
+ DatabaseAdapter adapter = this.bookmark.getAdapter();
if (adapter != null && stmt != null && adapter.getCommentsQuery(tableName, columnName) != null) {
stmt.execute(adapter.getCommentsQuery(tableName, columnName));
* @see com.quantum.model.Entity#getQuotedTableName()
*/
public String getQuotedTableName() {
- return getBookmark().getAdapter().filterTableName(getCondQualifiedName());
+ return getBookmark().getAdapter().filterTableName(getQualifiedName());
}
+ public ForeignKey[] getExportedKeys() throws SQLException, NotConnectedException {
+ return this.bookmark.getDatabase().getExportedKeys(getSchema(), getName());
+ }
+
+ public ForeignKey[] getImportedKeys() throws SQLException, NotConnectedException {
+ return this.bookmark.getDatabase().getImportedKeys(getSchema(), getName());
+ }
+ public ForeignKey[] getReferences() throws SQLException, NotConnectedException {
+ ForeignKey[] importedKeys = getImportedKeys();
+ ForeignKey[] exportedKeys = getExportedKeys();
+
+ List list = new ArrayList(); // if we could guarantee JDK 1.4, we'd use LinkedHashSet
+ for (int i = 0, length = importedKeys == null ? 0 : importedKeys.length; i < length; i++) {
+ list.add(importedKeys[i]);
+ }
+ for (int i = 0, length = exportedKeys == null ? 0 : exportedKeys.length; i < length; i++) {
+ if (!list.contains(exportedKeys[i])) {
+ list.add(exportedKeys[i]);
+ }
+ }
+ return (ForeignKey[]) list.toArray(new ForeignKey[list.size()]);
+ }
+
+ public int compareTo(Object object) {
+ Entity that = (Entity) object;
+ if (that.getQualifiedName() == null && this.getQualifiedName() != null) {
+ return 1;
+ } else if (this.getQualifiedName() == null && that.getQualifiedName() != null) {
+ return -1;
+ } else if (this.getQualifiedName() == null && that.getQualifiedName() == null) {
+ return 0;
+ } else {
+ return this.getQualifiedName().compareTo(that.getQualifiedName());
+ }
+ }
}
\ No newline at end of file
/**
* @author BC
*/
-public interface ForeignKey extends Constraint {
+public interface ForeignKey {
public String getName();
- public Entity getForeignEntity();
+ public String getLocalEntityName();
+ public String getLocalEntitySchema();
+ public String getLocalEntityQualifiedName();
public String getForeignEntityName();
public String getForeignEntitySchema();
+ public String getForeignEntityQualifiedName();
public int getNumberOfColumns();
public String getLocalColumnName(int index);
public String getForeignColumnName(int index);
--- /dev/null
+package com.quantum.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * @author BC
+ */
+public class ForeignKeyImpl implements ForeignKey {
+
+ private String name;
+ private String localEntityName;
+ private String localEntitySchema;
+ private String foreignEntityName;
+ private String foreignEntitySchema;
+ private List foreignColumns = Collections.synchronizedList(new ArrayList());
+ private List localColumns = Collections.synchronizedList(new ArrayList());
+ private int deleteRule;
+
+ void addColumns(String localColumnName, String foreignColumnName) {
+ this.foreignColumns.add(foreignColumnName);
+ this.localColumns.add(localColumnName);
+ }
+
+ public int getDeleteRule() {
+ return this.deleteRule;
+ }
+ public void setDeleteRule(int deleteRule) {
+ this.deleteRule = deleteRule;
+ }
+ public String getForeignEntityName() {
+ return this.foreignEntityName;
+ }
+ public void setForeignEntityName(String foreignEntityName) {
+ this.foreignEntityName = foreignEntityName;
+ }
+ public String getForeignEntitySchema() {
+ return this.foreignEntitySchema;
+ }
+ public void setForeignEntitySchema(String foreignEntitySchema) {
+ this.foreignEntitySchema = foreignEntitySchema;
+ }
+ public String getLocalEntityName() {
+ return this.localEntityName;
+ }
+ public void setLocalEntityName(String localEntityName) {
+ this.localEntityName = localEntityName;
+ }
+ public String getLocalEntitySchema() {
+ return this.localEntitySchema;
+ }
+ public void setLocalEntitySchema(String localEntitySchema) {
+ this.localEntitySchema = localEntitySchema;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getNumberOfColumns() {
+ return this.localColumns.size();
+ }
+
+ public boolean equals(Object object) {
+ if (this.getClass() != object.getClass()) {
+ return false;
+ } else {
+ ForeignKeyImpl that = (ForeignKeyImpl) object;
+ if (this.name == null && that.name != null) {
+ return false;
+ } else if (this.name != null && !this.name.equals(that.name)) {
+ return false;
+ } else if (this.foreignEntitySchema == null && that.foreignEntitySchema != null) {
+ return false;
+ } else if (this.foreignEntitySchema != null && !this.foreignEntitySchema.equals(that.foreignEntitySchema)) {
+ return false;
+ } else if (this.foreignEntityName == null && that.foreignEntityName != null) {
+ return false;
+ } else if (this.foreignEntityName != null && !this.foreignEntityName.equals(that.foreignEntityName)) {
+ return false;
+ } else if (this.localEntitySchema == null && that.localEntitySchema != null) {
+ return false;
+ } else if (this.localEntitySchema != null && !this.localEntitySchema.equals(that.foreignEntitySchema)) {
+ return false;
+ } else if (this.localEntityName == null && that.localEntityName != null) {
+ return false;
+ } else if (this.localEntityName != null && !this.localEntityName.equals(that.localEntityName)) {
+ return false;
+ } else if (this.deleteRule != that.deleteRule) {
+ return false;
+ } else if (this.localColumns.size() != that.localColumns.size()
+ || this.foreignColumns.size() != that.foreignColumns.size()) {
+ return false;
+ } else {
+ boolean result = true;
+ for (int i = 0, length = this.localColumns.size(); i < length; i++) {
+ Object localColumn = this.localColumns.get(i);
+ result &= (localColumn != null && localColumn.equals(that.localColumns.get(i)));
+ Object foreignColumn = this.foreignColumns.get(i);
+ result &= (foreignColumn != null && foreignColumn.equals(that.foreignColumns.get(i)));
+ }
+ return result;
+ }
+
+ }
+ }
+
+ public int hashCode() {
+ int hashCode = 57;
+ if (this.name != null) {
+ hashCode ^= this.name.hashCode();
+ }
+ if (this.foreignEntitySchema != null) {
+ hashCode ^= this.foreignEntitySchema.hashCode();
+ }
+ if (this.foreignEntityName != null) {
+ hashCode ^= this.foreignEntityName.hashCode();
+ }
+ if (this.localEntitySchema != null) {
+ hashCode ^= this.localEntitySchema.hashCode();
+ }
+ if (this.localEntityName != null) {
+ hashCode ^= this.localEntityName.hashCode();
+ }
+ hashCode ^= this.deleteRule;
+ for (int i = 0, length = this.localColumns.size(); i < length; i++) {
+ hashCode ^= this.localColumns.get(i).hashCode();
+ hashCode ^= this.foreignColumns.get(i).hashCode();
+ }
+ return hashCode;
+ }
+ public String getLocalColumnName(int index) {
+ return (String) this.localColumns.get(index);
+ }
+
+ public String getForeignColumnName(int index) {
+ return (String) this.foreignColumns.get(index);
+ }
+ public String getLocalEntityQualifiedName() {
+ return getLocalEntitySchema() == null ? getLocalEntityName() :
+ getLocalEntitySchema() + "." + getLocalEntityName();
+ }
+ public String getForeignEntityQualifiedName() {
+ return getForeignEntitySchema() == null ? getForeignEntityName() :
+ getForeignEntitySchema() + "." + getForeignEntityName();
+ }
+}
private String version;
private String className;
private String jarFileName;
+ private String type;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
/**
* @param className
* @param jarFileName
*/
- public JDBCDriver(String className, String jarFileName) {
- super();
- this.className = className;
- this.jarFileName = jarFileName;
+ public JDBCDriver(String className, String jarFileName, String type) {
+ this(className, jarFileName, type, null, null);
}
/**
*
* @param name
* @param version
*/
- public JDBCDriver(String className, String jarFileName, String name, String version) {
+ public JDBCDriver(String className, String jarFileName, String type, String name, String version) {
this.name = name;
this.version = version;
+ this.type = type;
this.className = className;
this.jarFileName = jarFileName;
}
return false;
} else if (this.jarFileName != null && !this.jarFileName.equals(that.jarFileName)) {
return false;
+ } else if (this.type == null && that.type != null) {
+ return false;
+ } else if (this.type != null && !this.type.equals(that.type)) {
+ return false;
} else {
return true;
}
if (this.jarFileName != null) {
hashCode ^= this.jarFileName.hashCode();
}
+ if (this.type != null) {
+ hashCode ^= this.type.hashCode();
+ }
return hashCode;
}
public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
this.propertyChangeSupport.removePropertyChangeListener(arg0, arg1);
}
+ /**
+ * @return Returns the type.
+ */
+ public String getType() {
+ return this.type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(String type) {
+ if (type != null && !type.equals(this.type)) {
+ String original = this.type;
+ this.type = type;
+ this.propertyChangeSupport.firePropertyChange("type", original, type);
+ }
+ }
}
private String name;
private String displayName;
private boolean isDefault;
-
+ private boolean exists = true;
public Schema() {
}
* @return
*/
public String getName() {
- return name;
+ return this.name;
}
/**
* @param string
*/
- public void setName(String string) {
- name = string;
+ public void setName(String name) {
+ this.name = name;
}
/**
}
}
public int hashCode() {
- int hashCode = super.hashCode();
+ int hashCode = 51;
if (this.name != null) {
hashCode ^= this.name.hashCode();
}
* @return
*/
public boolean isDefault() {
- return isDefault;
+ return this.isDefault;
}
/**
* @return
*/
public String getDisplayName() {
- return displayName;
+ return this.displayName;
}
/**
* @param string
*/
- public void setDisplayName(String string) {
- displayName = string;
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
}
+ public boolean exists() {
+ return this.exists;
+ }
+
+ void setExists(boolean exists) {
+ this.exists = exists;
+ }
+
+ public String toString() {
+ return this.displayName == null ? this.name : this.displayName;
+ }
}
import java.sql.SQLException;
-import com.quantum.adapters.AdapterFactory;
import com.quantum.sql.MultiSQLServer;
import com.quantum.sql.SQLHelper;
Integer size = null;
try {
size = new Integer(SQLHelper.getSize(
- getBookmark().getConnection(), getCondQualifiedName(),
- AdapterFactory.getInstance().getAdapter(getBookmark().getType())));
+ getBookmark().getConnection(), getQualifiedName(),
+ getBookmark().getAdapter()));
} catch (SQLException e) {
} catch (ConnectionException e) {
}
}
public void deleteAllRows() throws SQLException, ConnectionException {
- String sql = "DELETE FROM " + getCondQualifiedName();
+ String sql = "DELETE FROM " + getQualifiedName();
MultiSQLServer.getInstance().execute(getBookmark().getConnection(), sql);
}
}
\ No newline at end of file
import java.sql.SQLException;
-import com.quantum.adapters.AdapterFactory;
import com.quantum.sql.SQLHelper;
Integer size = null;
try {
size = new Integer(SQLHelper.getSize(
- getBookmark().getConnection(), getCondQualifiedName(),
- AdapterFactory.getInstance().getAdapter(getBookmark().getType())));
+ getBookmark().getConnection(), getQualifiedName(),
+ getBookmark().getAdapter()));
} catch (SQLException e) {
} catch (ConnectionException e) {
}
package com.quantum.model.xml;
-import com.quantum.Messages;
+import java.sql.SQLException;
+
import com.quantum.model.Bookmark;
import com.quantum.model.Column;
import com.quantum.model.Entity;
import com.quantum.model.JDBCDriver;
+import com.quantum.model.NotConnectedException;
import com.quantum.model.Schema;
import com.quantum.sql.metadata.MetaDataXMLInterface;
Element driverNode = document.createElement("jdbcDriver");
driverNode.setAttribute("name", jdbcDriver.getName());
driverNode.setAttribute("version", jdbcDriver.getVersion());
+ driverNode.setAttribute("type", jdbcDriver.getType());
driverNode.setAttribute("jarFileName", jdbcDriver.getJarFileName());
driverNode.setAttribute("className", jdbcDriver.getClassName());
bookmarkRoot.appendChild(driverNode);
MetaDataXMLInterface.createElementText(bookmark,"autoCommit", b.isAutoCommit() ? "true" : "false"); //$NON-NLS-1$
MetaDataXMLInterface.createElementText(bookmark,"autoCommitPreference", b.getAutoCommitPreference()); //$NON-NLS-1$
MetaDataXMLInterface.createElementText(bookmark,"driver", b.getJDBCDriver().getClassName()); //$NON-NLS-1$
- MetaDataXMLInterface.createElementText(bookmark,"type", b.getType()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"type", b.getJDBCDriver().getType()); //$NON-NLS-1$
MetaDataXMLInterface.createElementText(bookmark,"driverLocation", b.getJDBCDriver().getJarFileName()); //$NON-NLS-1$
- Element otherSchemas = (Element) bookmark.appendChild(document.createElement(Messages.getString("ExportXMLAction.OtherSchemas"))); //$NON-NLS-1$
- Schema[] schemas = b.getSchemas();
- for (int i = 0, length = (schemas == null) ? 0 : schemas.length;
- i < length;
- i++) {
- if (!schemas[i].isDefault()) {
- MetaDataXMLInterface.createElementText(
- otherSchemas,Messages.getString("ExportXMLAction.SchemaName"), schemas[i].getName()); //$NON-NLS-1$
- }
+ Element otherSchemas = (Element) bookmark.appendChild(document.createElement("Other_Schemas")); //$NON-NLS-1$
+ otherSchemas.setAttribute("schemaRule",
+ b.useAllSchemas()
+ ? "useAll"
+ : b.useUsernameAsSchema() ? "useDefault" : "useSelected");
+
+ Schema[] schemas = b.getSchemaSelections();
+ for (int i = 0, length = (schemas == null) ? 0 : schemas.length; i < length; i++) {
+ MetaDataXMLInterface.createElementText(
+ otherSchemas,"schema", schemas[i].getName()); //$NON-NLS-1$
}
+
Entity[] quickList = b.getQuickListEntries();
Element quickListEntity = document.createElement("quickList");
for (int j = 0, length = (quickList == null) ? 0 : quickList.length;
element.setAttribute("schema", entity.getSchema());
}
if (recurse) {
- convert(element, entity.getColumns());
+ try {
+ convert(element, entity.getColumns());
+ } catch (NotConnectedException e) {
+ } catch (SQLException e) {
+ }
}
parent.appendChild(element);
}
import com.quantum.model.Bookmark;
import com.quantum.model.Column;
import com.quantum.model.Entity;
+import com.quantum.model.NotConnectedException;
import com.quantum.model.Schema;
import org.w3c.dom.Document;
Element table = root.getOwnerDocument().createElement("table");
table.setAttribute("name", entity.getName());
- Column[] columns = entity.getColumns();
- for (int i = 0, length = (columns == null) ? 0 : columns.length;
- i < length;
- i++) {
- convert(table, columns[i]);
- }
+ try {
+ Column[] columns = entity.getColumns();
+ for (int i = 0, length = (columns == null) ? 0 : columns.length;
+ i < length;
+ i++) {
+ convert(table, columns[i]);
+ }
+ } catch (NotConnectedException e) {
+ } catch (SQLException e) {
+ }
root.appendChild(table);
}
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
-import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
getFieldEditorParent());
queryHistorySize.setValidRange(0, Integer.MAX_VALUE);
this.addField(queryHistorySize);
- StringFieldEditor askPasswordString = new StringFieldEditor("askPasswordString", "&Ask for password string:", getFieldEditorParent());
- this.addField(askPasswordString);
}
}
--- /dev/null
+package com.quantum.properties;
+
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.model.Entity;
+import com.quantum.model.EntityHolder;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+/**
+ * @author BC
+ */
+public abstract class BaseEntityPropertyPage extends PropertyPage {
+
+ class BasicContentProvider implements IStructuredContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+ return (inputElement instanceof Object[]) ? (Object[]) inputElement : null;
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+ protected Control createContents(Composite parent) {
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.getString(BaseEntityPropertyPage.class, "name"));
+
+ Entity entity = getEntity();
+
+ Label name = new Label(composite, SWT.NONE);
+ name.setText(entity.getName());
+
+ label = new Label(composite, SWT.NONE);
+ label.setText(Messages.getString(BaseEntityPropertyPage.class, "schema"));
+
+ Label schema = new Label(composite, SWT.NONE);
+ schema.setText(entity.getSchema());
+
+ createInformationArea(composite);
+
+ return composite;
+ }
+ /**
+ * @param composite
+ */
+ protected void createErrorMessage(Composite composite, Exception e) {
+ Label icon = new Label(composite, SWT.NONE);
+ icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
+ icon.setImage(QuantumPlugin.getImage("warning.gif"));
+
+ Label error = new Label(composite, SWT.NONE);
+ error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
+ error.setText(Messages.getString(BaseEntityPropertyPage.class, "error")
+ + (e.getMessage() == null ? "" : "\n" + e.getMessage()));
+ }
+
+
+ /**
+ * @param composite
+ */
+ protected abstract void createInformationArea(Composite composite);
+
+ protected Entity getEntity() {
+ Entity entity =
+ ((EntityHolder) getElement()).getEntity();
+ return entity;
+ }
+ /**
+ * @param table
+ */
+ protected void setColumnWidths(Table table) {
+ for (int i = 0, length = table.getColumnCount(); i < length; i++) {
+ table.getColumn(i).pack();
+ }
+ }
+
+}
+
package com.quantum.properties;
-import com.quantum.IQuantumConstants;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DriverInfo;
-import com.quantum.model.Bookmark;
-import com.quantum.model.BookmarkCollection;
-import com.quantum.model.JDBCDriver;
-import com.quantum.view.bookmark.TreeNode;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PropertyPage;
+import com.quantum.IQuantumConstants;
+import com.quantum.adapters.AdapterFactory;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
+import com.quantum.model.BookmarkCollection;
+import com.quantum.model.BookmarkHolder;
+import com.quantum.model.JDBCDriver;
+
public class BookmarkPropertyPage extends PropertyPage {
private Text password;
private Combo type;
private Combo autoCommit;
- private DriverInfo[] adapters = AdapterFactory.getInstance().getDriverList();
+ private DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList();
protected Control createContents(Composite parent) {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
composite.setLayout(layout);
- GridData data = new GridData(GridData.FILL);
- data.grabExcessHorizontalSpace = true;
- composite.setLayoutData(data);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Label nameLabel = new Label(composite, SWT.NONE);
nameLabel.setText("Name:");
Bookmark bookmark = getBookmark();
String description = bookmark.getName();
name.setText(description);
+ name.setLayoutData(
+ new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
+ | GridData.VERTICAL_ALIGN_BEGINNING));
- TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
+ TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
layout = new GridLayout();
tabFolder.setLayout(layout);
- data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- data.verticalAlignment = GridData.FILL;
+ GridData data = new GridData(GridData.FILL_BOTH);
data.horizontalSpan = 2;
- data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
tabFolder.setLayoutData(data);
createUserTab(tabFolder);
private Bookmark getBookmark() {
Bookmark bookmark =
- ((TreeNode) getElement()).getBookmark();
+ ((BookmarkHolder) getElement()).getBookmark();
return bookmark;
}
composite.setLayoutData(data);
Label label = new Label(composite, SWT.NONE);
- label.setText("Connection URL:");
-
- this.jdbcURL = new Text(composite, SWT.BORDER);
- data = new GridData(GridData.FILL);
- data.horizontalAlignment = GridData.FILL;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessHorizontalSpace = true;
- this.jdbcURL.setLayoutData(data);
-
- label = new Label(composite, SWT.NONE);
label.setText("Driver Name:");
this.driverName = new Text(composite, SWT.BORDER);
private void createUserTab(TabFolder tabFolder) {
TabItem userTab = new TabItem(tabFolder, SWT.NONE);
- userTab.setText("User");
+ userTab.setText("Connection");
Composite composite = new Composite(tabFolder, SWT.NONE);
GridLayout layout = new GridLayout();
}
});
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Connection URL:");
+
+ this.jdbcURL = new Text(composite, SWT.BORDER);
+ data = new GridData(GridData.FILL);
+ data.horizontalAlignment = GridData.FILL;
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessHorizontalSpace = true;
+ this.jdbcURL.setLayoutData(data);
+
userTab.setControl(composite);
}
}
int index = this.type.getSelectionIndex();
- bookmark.setType(this.adapters[index].getDriverType());
bookmark.setConnect(this.jdbcURL.getText());
JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
- this.driverName.getText(), this.driverPath.getText());
+ this.driverName.getText(), this.driverPath.getText(), this.adapters[index].getType());
bookmark.setJDBCDriver(jdbcDriver);
if (this.autoCommit.getSelectionIndex() >= 0)
bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
this.prompt.setSelection(bookmark.getPromptForPassword());
this.password.setEditable(!bookmark.getPromptForPassword());
- this.password.setText(bookmark.getPassword());
+ String password = bookmark.getPassword();
+ this.password.setText(password == null ? "" : password);
this.userid.setText(bookmark.getUsername());
this.type.select(0);
length = (adapters == null) ? 0 : adapters.length;
!done && i < length;
i++) {
- if (bookmark.getType() != null &&
- bookmark.getType().equals(adapters[i].getDriverType())) {
+ if (bookmark.getJDBCDriver().getType() != null &&
+ bookmark.getJDBCDriver().getType().equals(adapters[i].getType())) {
this.type.select(i);
done = true;
}
--- /dev/null
+package com.quantum.properties;
+
+import java.sql.SQLException;
+
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.model.Column;
+import com.quantum.model.Entity;
+import com.quantum.model.NotConnectedException;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class ColumnPropertyPage extends BaseEntityPropertyPage {
+
+ protected void createInformationArea(Composite composite) {
+ if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
+ try {
+ Column[] columns = getEntity().getColumns();
+
+ Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
+ table.setHeaderVisible(true);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 2;
+ table.setLayoutData(gridData);
+ for (int i = 0, length = 7; i < length; i++) {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(Messages.getString(getClass(), "column" + i));
+ }
+
+ TableViewer viewer = new TableViewer(table);
+ setTableContents(viewer, columns);
+ setColumnWidths(table);
+ } catch (NotConnectedException e) {
+ createErrorMessage(composite, e);
+ } catch (SQLException e) {
+ createErrorMessage(composite, e);
+ } catch (RuntimeException e) {
+ createErrorMessage(composite, e);
+ }
+ }
+ }
+
+ private void setTableContents(TableViewer viewer, Column[] columns) {
+ viewer.setContentProvider(new BasicContentProvider());
+
+ viewer.setLabelProvider(new ITableLabelProvider() {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (columnIndex == 0 && element instanceof Column) {
+ return ((Column) element).isPrimaryKey()
+ ? QuantumPlugin.getImage("keycolumn.gif")
+ : QuantumPlugin.getImage("column.gif");
+ } else {
+ return null;
+ }
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ String label = null;
+ if (element instanceof Column) {
+ Column column = (Column) element;
+ switch (columnIndex) {
+ case 0:
+ label = column.getName();
+ break;
+ case 1:
+ label = column.getTypeName();
+ break;
+ case 2:
+ label = String.valueOf(column.getSize());
+ break;
+ case 3:
+ label = String.valueOf(column.getNumberOfFractionalDigits());
+ break;
+ case 4:
+ label = column.isPrimaryKey()
+ ? Messages.getString(ColumnPropertyPage.class, "true")
+ : Messages.getString(ColumnPropertyPage.class, "false");
+ break;
+ case 5:
+ label = column.isNullable()
+ ? Messages.getString(ColumnPropertyPage.class, "true")
+ : Messages.getString(ColumnPropertyPage.class, "false");
+ break;
+ case 6:
+ label = column.getRemarks();
+ break;
+ default:
+ }
+ }
+
+ return label == null ? "" : label;
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ });
+
+ viewer.setInput(columns);
+ }
+}
\ No newline at end of file
import java.sql.SQLException;
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
+import com.quantum.model.DataType;
import com.quantum.model.NotConnectedException;
import com.quantum.view.bookmark.TreeNode;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.dialogs.PropertyPage;
public class DatabaseInformationPropertyPage extends PropertyPage {
GridLayout layout = new GridLayout();
layout.numColumns = 2;
composite.setLayout(layout);
- GridData data = new GridData(GridData.FILL);
- data.grabExcessHorizontalSpace = true;
+ GridData data = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(data);
+ Bookmark bookmark =
+ ((TreeNode) getElement()).getBookmark();
+ createDatabaseNameArea(composite, bookmark);
+ createTypesArea(composite, bookmark);
+
+ return composite;
+ }
+
+ /**
+ * @param composite
+ * @param bookmark
+ */
+ private void createTypesArea(Composite composite, Bookmark bookmark) {
+ if (bookmark.isConnected()) {
+ try {
+ DataType[] dataTypes = bookmark.getDatabase().getTypes();
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.getString(getClass(), "dataTypes"));
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.horizontalSpan = 2;
+ label.setLayoutData(data);
+
+ Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
+ table.setHeaderVisible(true);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 2;
+ gridData.heightHint = 200;
+ table.setLayoutData(gridData);
+ for (int i = 0, length = 2; i < length; i++) {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(Messages.getString(getClass(), "column" + i));
+ }
+ TableViewer viewer = new TableViewer(table);
+ viewer.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof DataType[]) {
+ return (DataType[]) inputElement;
+ } else {
+ return null;
+ }
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ });
+ viewer.setLabelProvider(new ITableLabelProvider() {
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ String result = null;
+ if (element != null && element instanceof DataType) {
+ DataType dataType = (DataType) element;
+ switch (columnIndex) {
+ case 0:
+ result = dataType.getDatabaseTypeName();
+ break;
+ case 1:
+ result = dataType.getJavaNameType();
+ break;
+ default:
+ result = null;
+ }
+ }
+ return result == null ? "" : result;
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ });
+
+ viewer.setInput(dataTypes);
+
+ for (int i = 0, length = table.getColumnCount(); i < length; i++) {
+ table.getColumn(i).pack();
+ }
+
+ } catch (SQLException e) {
+ createErrorMessage(composite, e);
+ } catch (NotConnectedException e) {
+ createErrorMessage(composite, e);
+ } catch (RuntimeException e) {
+ createErrorMessage(composite, e);
+ }
+ }
+ }
+
+ /**
+ * @param composite
+ */
+ private void createErrorMessage(Composite composite, Exception e) {
+ Label icon = new Label(composite, SWT.NONE);
+ icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
+ icon.setImage(QuantumPlugin.getImage("warning.gif"));
+
+ Label error = new Label(composite, SWT.NONE);
+ error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
+ error.setText(Messages.getString(getClass(), "error")
+ + (e.getMessage() == null ? "" : "\n" + e.getMessage()));
+ }
+
+ /**
+ * @param composite
+ * @param bookmark
+ */
+ private void createDatabaseNameArea(Composite composite, Bookmark bookmark) {
Label productLabel = new Label(composite, SWT.NONE);
- productLabel.setText("Product:");
+ productLabel.setText(Messages.getString(getClass(), "product"));
Label productDescriptionLabel = new Label(composite, SWT.NONE);
- Bookmark bookmark =
- ((TreeNode) getElement()).getBookmark();
String description = null;
- try {
- description = bookmark.getDatabase().getInformation();
- } catch (NotConnectedException e) {
- } catch (SQLException e) {
+ if (bookmark.isConnected()) {
+ try {
+ description = bookmark.getDatabase().getInformation();
+ } catch (NotConnectedException e) {
+ createErrorMessage(composite, e);
+ } catch (SQLException e) {
+ createErrorMessage(composite, e);
+ } catch (RuntimeException e) {
+ createErrorMessage(composite, e);
+ }
}
if (description == null) {
- description = "<unknown>";
+ description = Messages.getString(getClass(), "unknown");
}
productDescriptionLabel.setText(description);
- return composite;
}
protected void performDefaults() {
+++ /dev/null
-package com.quantum.properties;
-
-import com.quantum.model.Column;
-import com.quantum.model.Entity;
-import com.quantum.model.Index;
-import com.quantum.view.bookmark.EntityNode;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.swt.widgets.TabItem;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.dialogs.PropertyPage;
-
-public class EntityPropertyPage extends PropertyPage {
-
- protected Control createContents(Composite parent) {
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- composite.setLayout(layout);
- GridData data = new GridData(GridData.FILL);
- data.grabExcessHorizontalSpace = true;
- composite.setLayoutData(data);
-
- Label label = new Label(composite, SWT.NONE);
- label.setText("Name:");
-
- Entity entity = getEntity();
-
- Label name = new Label(composite, SWT.NONE);
- name.setText(entity.getName());
-
- label = new Label(composite, SWT.NONE);
- label.setText("Schema:");
-
- Label schema = new Label(composite, SWT.NONE);
- schema.setText(entity.getSchema());
-
- if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
- TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
- layout = new GridLayout();
- tabFolder.setLayout(layout);
- data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- data.verticalAlignment = GridData.FILL;
- data.horizontalSpan = 2;
- data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
- tabFolder.setLayoutData(data);
-
- createColumnsTab(tabFolder);
- createIndexesTab(tabFolder);
- }
-
- return composite;
- }
-
- private Entity getEntity() {
- Entity entity =
- ((EntityNode) getElement()).getEntity();
- return entity;
- }
-
- private void createColumnsTab(TabFolder tabFolder) {
- TabItem columnsTab = new TabItem(tabFolder, SWT.NONE);
- columnsTab.setText("Columns");
-
- Table table = new Table(tabFolder, SWT.FULL_SELECTION | SWT.MULTI);
- table.setLinesVisible(true);
- table.setHeaderVisible(true);
-
- GridLayout layout = new GridLayout();
- layout.marginWidth = 5;
- layout.marginHeight = 5;
- table.setLayout(layout);
- GridData data = new GridData(GridData.FILL);
- data.horizontalAlignment = GridData.FILL_HORIZONTAL;
- data.verticalAlignment = GridData.FILL_VERTICAL;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- table.setLayoutData(data);
-
- String[] columnNames = { "Name", "Type", "Size", "Digits",
- "Primary Key", "Nullable", "Remarks" };
-
- for (int i = 0, length = columnNames.length; i < length; i++) {
- TableColumn column = new TableColumn(table, SWT.NONE);
- column.setText(columnNames[i]);
- }
- for (int i = 0, length = columnNames.length; i < length; i++) {
- table.getColumn(i).pack();
- }
-
- Column[] columns = getEntity().getColumns();
- for (int i = 0, length = columns.length; i < length; i++) {
- TableItem item = new TableItem(table, SWT.NONE);
- item.setText(new String[] {
- columns[i].getName(),
- columns[i].getTypeName(),
- String.valueOf(columns[i].getSize()),
- columns[i].getNumberOfFractionalDigits() == 0 ? "" :
- String.valueOf(columns[i].getNumberOfFractionalDigits()),
- columns[i].isPrimaryKey() ? "Yes" : "No",
- columns[i].isNullable() ? "Yes" : "No",
- columns[i].getRemarks() });
- }
-
- for (int i = 0, length = columnNames.length; i < length; i++) {
- table.getColumn(i).pack();
- }
-
- data = new GridData(GridData.FILL);
- data.horizontalAlignment = GridData.FILL_HORIZONTAL;
- data.verticalAlignment = GridData.FILL_VERTICAL;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- table.setLayoutData(data);
-
- columnsTab.setControl(table);
- }
-
- private void createIndexesTab(TabFolder tabFolder) {
- TabItem indexesTab = new TabItem(tabFolder, SWT.NONE);
- indexesTab.setText("Indexes");
-
- Table table = new Table(tabFolder, SWT.FULL_SELECTION | SWT.MULTI);
- table.setLinesVisible(true);
- table.setHeaderVisible(true);
-
- GridLayout layout = new GridLayout();
- layout.marginWidth = 5;
- layout.marginHeight = 5;
- table.setLayout(layout);
- GridData data = new GridData(GridData.FILL);
- data.horizontalAlignment = GridData.FILL_HORIZONTAL;
- data.verticalAlignment = GridData.FILL_VERTICAL;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- table.setLayoutData(data);
-
- String[] columnNames = { "Name", "Column", "Ascending" };
-
- for (int i = 0, length = columnNames.length; i < length; i++) {
- TableColumn column = new TableColumn(table, SWT.NONE);
- column.setText(columnNames[i]);
- }
- for (int i = 0, length = columnNames.length; i < length; i++) {
- table.getColumn(i).pack();
- }
-
- Index[] indexes = getEntity().getIndexes();
- for (int i = 0, length = indexes.length; i < length; i++) {
- for (int j = 0, numberOfColumns = indexes[i].getNumberOfColumns();
- j < numberOfColumns; j++) {
-
- TableItem item = new TableItem(table, SWT.NONE);
- item.setText(new String[] {
- j == 0 ? indexes[i].getName() : "",
- indexes[i].getColumnName(j),
- indexes[i].isAscending(j) ? "Yes"
- : (indexes[i].isDescending(j)) ? "No" : "" });
- }
- }
-
- for (int i = 0, length = columnNames.length; i < length; i++) {
- table.getColumn(i).pack();
- }
-
- data = new GridData(GridData.FILL);
- data.horizontalAlignment = GridData.FILL_HORIZONTAL;
- data.verticalAlignment = GridData.FILL_VERTICAL;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- table.setLayoutData(data);
-
- indexesTab.setControl(table);
- }
-
-}
\ No newline at end of file
--- /dev/null
+package com.quantum.properties;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.model.Entity;
+import com.quantum.model.Index;
+import com.quantum.model.NotConnectedException;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class IndexPropertyPage extends BaseEntityPropertyPage {
+
+ class IndexAdaptor {
+ private final Index index;
+ private final int columnNumber;
+ public IndexAdaptor(Index index, int columnNumber) {
+ this.index = index;
+ this.columnNumber = columnNumber;
+ }
+ public Index getIndex() {
+ return this.index;
+ }
+ public int getColumnNumber() {
+ return this.columnNumber;
+ }
+ }
+
+ protected void createInformationArea(Composite composite) {
+ if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
+ try {
+ Index[] indeces = getEntity().getIndexes();
+
+ Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
+ table.setHeaderVisible(true);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 2;
+ table.setLayoutData(gridData);
+ for (int i = 0, length = 3; i < length; i++) {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(Messages.getString(getClass(), "column" + i));
+ }
+
+ TableViewer viewer = new TableViewer(table);
+ setTableContents(viewer, indeces);
+ setColumnWidths(table);
+ } catch (NotConnectedException e) {
+ createErrorMessage(composite, e);
+ } catch (SQLException e) {
+ createErrorMessage(composite, e);
+ } catch (RuntimeException e) {
+ createErrorMessage(composite, e);
+ }
+ }
+ }
+
+ private void setTableContents(TableViewer viewer, Index[] indeces) {
+ viewer.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof Index[]) {
+ Index[] indeces = (Index[]) inputElement;
+ List list = new ArrayList();
+ for (int i = 0, length = indeces == null ? 0 : indeces.length; i < length; i++) {
+ for (int j = 0, columns = indeces[i].getNumberOfColumns(); j < columns; j++) {
+ list.add(new IndexAdaptor(indeces[i], j));
+ }
+ }
+ return list.toArray();
+ } else {
+ return null;
+ }
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ });
+
+ viewer.setLabelProvider(new ITableLabelProvider() {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (columnIndex == 1 && element instanceof IndexAdaptor) {
+ return QuantumPlugin.getImage("column.gif");
+ } else {
+ return null;
+ }
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ String label = null;
+ if (element instanceof IndexAdaptor) {
+ IndexAdaptor index = (IndexAdaptor) element;
+ switch (columnIndex) {
+ case 0:
+ if (index.getColumnNumber() == 0) {
+ label = index.getIndex().getName();
+ }
+ break;
+ case 1:
+ label = index.getIndex().getColumnName(index.getColumnNumber());
+ break;
+ case 2:
+ if (index.getIndex().isAscending(index.getColumnNumber())) {
+ label = Messages.getString(IndexPropertyPage.class, "ascending");
+ } else if (index.getIndex().isDescending(index.getColumnNumber())) {
+ label = Messages.getString(IndexPropertyPage.class, "descending");
+ }
+ break;
+ default:
+ }
+ }
+
+ return label == null ? "" : label;
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ });
+
+
+ viewer.setInput(indeces);
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.quantum.properties;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.model.Entity;
+import com.quantum.model.ForeignKey;
+import com.quantum.model.NotConnectedException;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class ReferencesPropertyPage extends BaseEntityPropertyPage {
+
+ class ColumnDetailsAdaptor {
+ private final int columnNumber;
+ private final ForeignKey foreignKey;
+
+ public ColumnDetailsAdaptor(ForeignKey foreignKey, int columnNumber) {
+ this.foreignKey = foreignKey;
+ this.columnNumber = columnNumber;
+ }
+ public int getColumnNumber() {
+ return this.columnNumber;
+ }
+ public ForeignKey getForeignKey() {
+ return this.foreignKey;
+ }
+ }
+
+ class TableDetailsAdaptor {
+ private final ForeignKey foreignKey;
+
+ public TableDetailsAdaptor(ForeignKey foreignKey) {
+ this.foreignKey = foreignKey;
+ }
+ public ForeignKey getForeignKey() {
+ return this.foreignKey;
+ }
+ }
+
+ protected void createInformationArea(Composite composite) {
+ if (!Entity.SEQUENCE_TYPE.equals(getEntity().getType())) {
+ try {
+ ForeignKey[] references = getEntity().getReferences();
+
+ Table table = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
+ table.setHeaderVisible(true);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 2;
+ table.setLayoutData(gridData);
+ for (int i = 0, length = 4; i < length; i++) {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(Messages.getString(getClass(), "column" + i));
+ }
+
+ TableViewer viewer = new TableViewer(table);
+ setTableContents(viewer, references);
+ setColumnWidths(table);
+ } catch (NotConnectedException e) {
+ createErrorMessage(composite, e);
+ } catch (SQLException e) {
+ createErrorMessage(composite, e);
+ } catch (RuntimeException e) {
+ createErrorMessage(composite, e);
+ }
+ }
+ }
+
+ /**
+ * @param viewer
+ */
+ private void setTableContents(TableViewer viewer, ForeignKey[] references) {
+ viewer.setContentProvider(new IStructuredContentProvider() {
+
+ public Object[] getElements(Object inputElement) {
+ List list = new ArrayList();
+ if (inputElement instanceof ForeignKey[]) {
+ ForeignKey[] keys = (ForeignKey[]) inputElement;
+ for (int i = 0, length = keys == null ? 0
+ : keys.length; i < length; i++) {
+ list.add(new TableDetailsAdaptor(keys[i]));
+ for (int j = 0, columns = keys[i].getNumberOfColumns(); j < columns; j++) {
+ list.add(new ColumnDetailsAdaptor(keys[i], j));
+ }
+ }
+ }
+ return list.toArray();
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ });
+
+ viewer.setLabelProvider(new ITableLabelProvider() {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if ((columnIndex == 1 || columnIndex == 2)
+ && element instanceof ColumnDetailsAdaptor) {
+ return QuantumPlugin.getImage("column.gif");
+ } else if ((columnIndex == 1 || columnIndex == 2)
+ && element instanceof TableDetailsAdaptor) {
+ return QuantumPlugin.getImage("bigtable.gif");
+ } else if ((columnIndex == 0)
+ && element instanceof TableDetailsAdaptor) {
+ return QuantumPlugin.getImage("foreignkey.gif");
+ } else {
+ return null;
+ }
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ String label = null;
+ if (element instanceof TableDetailsAdaptor) {
+ label = getColumnText((TableDetailsAdaptor) element, columnIndex);
+ } else if (element instanceof ColumnDetailsAdaptor) {
+ label = getColumnText((ColumnDetailsAdaptor) element, columnIndex);
+ }
+
+ return label == null ? "" : label;
+ }
+ private String getColumnText(TableDetailsAdaptor adaptor, int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return adaptor.getForeignKey().getName();
+ case 1:
+ return adaptor.getForeignKey().getLocalEntityQualifiedName();
+ case 2:
+ return adaptor.getForeignKey().getForeignEntityQualifiedName();
+ case 3:
+ ForeignKey key = adaptor.getForeignKey();
+ if (key.getDeleteRule() == DatabaseMetaData.importedKeyCascade) {
+ return Messages.getString(
+ ReferencesPropertyPage.class, "importedKeyCascade");
+ } else if (key.getDeleteRule() == DatabaseMetaData.importedKeyNoAction) {
+ return Messages.getString(
+ ReferencesPropertyPage.class, "importedKeyNoAction");
+ } else if (key.getDeleteRule() == DatabaseMetaData.importedKeyRestrict) {
+ return Messages.getString(
+ ReferencesPropertyPage.class, "importedKeyRestrict");
+ } else if (key.getDeleteRule() == DatabaseMetaData.importedKeySetDefault) {
+ return Messages.getString(
+ ReferencesPropertyPage.class, "importedKeySetDefault");
+ } else if (key.getDeleteRule() == DatabaseMetaData.importedKeySetNull) {
+ return Messages.getString(
+ ReferencesPropertyPage.class, "importedKeySetNull");
+ } else {
+ return null;
+ }
+ default:
+ return null;
+ }
+ }
+ private String getColumnText(ColumnDetailsAdaptor adaptor, int columnIndex) {
+ switch (columnIndex) {
+ case 1:
+ return adaptor.getForeignKey().getLocalColumnName(adaptor.getColumnNumber());
+ case 2:
+ return adaptor.getForeignKey().getForeignColumnName(adaptor.getColumnNumber());
+ default:
+ return null;
+ }
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ });
+
+ viewer.setInput(references);
+ }
+}
\ No newline at end of file
package com.quantum.properties;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkHolder;
-import com.quantum.model.ConnectionException;
-import com.quantum.model.Schema;
-import com.quantum.sql.SQLHelper;
-import com.quantum.ui.dialog.ExceptionDisplayDialog;
-import com.quantum.util.connection.ConnectionUtil;
-import com.quantum.view.bookmark.AddSchemaDialog;
+import com.quantum.view.SchemaSelectionControl;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.dialogs.PropertyPage;
public class SchemaPropertyPage extends PropertyPage {
-
- class ContentProviderImpl implements IStructuredContentProvider {
- public Object[] getElements(Object inputElement) {
- List list = new ArrayList((Collection) inputElement);
- Collections.sort(list);
- return list.toArray();
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- }
-
- class LabelProviderImpl implements ITableLabelProvider {
-
- public Image getColumnImage(Object element, int columnIndex) {
- if (columnIndex == 0) {
- return QuantumPlugin.getImage("schema.gif");
- } else {
- return null;
- }
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if (columnIndex == 0) {
- return ((Schema) element).getDisplayName();
- } else {
- return null;
- }
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
-
- public void dispose() {
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return "displayName".equals(property);
- }
-
- public void removeListener(ILabelProviderListener listener) {
- }
- }
-
- private Set schemas = Collections.synchronizedSet(new HashSet());
- private TableViewer schemaTable;
- private Button addButton;
- private Button removeButton;
-
- private ConnectionUtil connectionUtil = new ConnectionUtil();
+
+ private SchemaSelectionControl control;
protected Control createContents(Composite parent) {
-
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- composite.setLayout(layout);
- GridData data = new GridData();
- composite.setLayoutData(data);
-
- this.schemaTable = new TableViewer(composite,
- SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
-
- layout = new GridLayout();
- layout.marginWidth = 5;
- layout.marginHeight = 5;
-
- this.schemaTable.getTable().setLayout(layout);
- data = new GridData();
- data.heightHint = 200;
- data.widthHint = 200;
-// data.verticalSpan = 2;
- this.schemaTable.getTable().setLayoutData(data);
- this.schemaTable.setLabelProvider(new LabelProviderImpl());
- this.schemaTable.setContentProvider(new ContentProviderImpl());
- this.schemaTable.setInput(this.schemas);
-
- createButtonArea(composite);
-
- performDefaults();
- return composite;
- }
-
- private void createButtonArea(Composite composite) {
- GridLayout layout;
- GridData data;
- Composite buttonArea = new Composite(composite, SWT.NONE);
- layout = new GridLayout();
- layout.numColumns = 1;
- buttonArea.setLayout(layout);
- data = new GridData();
- data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
- buttonArea.setLayoutData(data);
-
- this.addButton = new Button(buttonArea, SWT.NULL);
- this.addButton.setText("Add");
- data = new GridData();
- data.horizontalAlignment = GridData.FILL_HORIZONTAL;
- data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
- data.widthHint = 60;
- this.addButton.setLayoutData(data);
- this.addButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- addSchema();
- }
- });
-
- this.removeButton = new Button(buttonArea, SWT.NULL);
- this.removeButton.setText("Remove");
- this.removeButton.setEnabled(false);
- data = new GridData();
- data.horizontalAlignment = GridData.FILL_HORIZONTAL;
- data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
- data.widthHint = 60;
- this.removeButton.setLayoutData(data);
- this.removeButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- removeSchema(SchemaPropertyPage.this.schemaTable.getSelection());
- }
- });
-
- this.schemaTable.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- SchemaPropertyPage.this.removeButton.setEnabled(
- !event.getSelection().isEmpty());
- }
- });
- }
-
- private void addSchema() {
- Bookmark bookmark = getBookmark();
- boolean isAlreadyConnected = bookmark.isConnected();
-
- if (!isAlreadyConnected) {
- boolean confirmed = MessageDialog.openConfirm(getShell(), "Connect Required",
- "We must connect to the database to retrieve schemas.");
- if (confirmed) {
- this.connectionUtil.connect(bookmark, getShell());
- }
- }
-
- try {
- if (bookmark.isConnected()) {
- Vector schemas = SQLHelper.getSchemas(bookmark.getConnection());
- AddSchemaDialog dialog = new AddSchemaDialog(getShell(), schemas);
- dialog.open();
- if (dialog.getSelectedSchemas() != null) {
- Collection temp = dialog.getSelectedSchemas();
- for (Iterator i = temp.iterator(); i.hasNext();) {
- String name = (String) i.next();
- this.schemas.add(new Schema(name));
- }
- refreshTable();
- }
-
- if (!isAlreadyConnected) {
- bookmark.disconnect();
- }
- }
- } catch (ConnectionException e) {
- ExceptionDisplayDialog.openError(getShell(), null, null, e);
- }
- }
-
- private void removeSchema(ISelection selection) {
- IStructuredSelection structuredSelection = (IStructuredSelection) selection;
- for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
- Schema element = (Schema) i.next();
- this.schemas.remove(element);
- }
- refreshTable();
+ return this.control = new SchemaSelectionControl(parent, getBookmark());
}
private Bookmark getBookmark() {
* @see org.eclipse.jface.preference.PreferencePage#performApply()
*/
public boolean performOk() {
- getBookmark().setSchemas((Schema[]) this.schemas.toArray(
- new Schema[this.schemas.size()]));
+ Bookmark bookmark = getBookmark();
+ bookmark.setSchemaSelections(this.control.getSchemas());
+ bookmark.setSchemaRule(this.control.getSchemaRule());
return true;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
- */
+
protected void performDefaults() {
super.performDefaults();
Bookmark bookmark = getBookmark();
-
- this.schemas.clear();
- Schema[] schemas = bookmark.getSchemas();
- for (int i = 0, length = (schemas == null) ? 0 : schemas.length;
- i < length;
- i++) {
- if (!schemas[i].isDefault()) {
- this.schemas.add(schemas[i]);
- }
- }
- refreshTable();
- }
-
- private void refreshTable() {
- this.schemaTable.refresh();
+ this.control.setSchemaRule(bookmark.getSchemaRule());
+ this.control.setSchemas(bookmark.getSchemaSelections());
}
}
\ No newline at end of file
}
}
- public Vector getSchemas(Connection con) {
- ResultSet set;
- Vector schemaList = new Vector();
- try {
- DatabaseMetaData meta = con.getMetaData();
- set = meta.getSchemas();
- while (set.next()) {
- schemaList.add(set.getString("TABLE_SCHEM")); //$NON-NLS-1$
- }
- set.close();
- } catch (SQLException e) {
- LogProxy log = LogProxy.getInstance();
- log.addText(LogProxy.ERROR, e);
- }
- return schemaList;
- }
/**
* Makes a connection to a JDBC driver based on the data from a bookmark
* @param bookmark -
bookmark.setPassword(password);
}
}
- Connection con;
+
if (password != null) {
- con = connect(bookmark, password);
+ Connection connection = connect(bookmark, password);
+ if (connection != null) {
+ // Set the autoCommit state of the bookmark to the default on new connections
+ bookmark.setAutoCommit(bookmark.getDefaultAutoCommit());
+ // Set the autoCommit state of the JDBC connection to the bookmark autoCommit statec
+ setAutoCommit(connection, bookmark.isAutoCommit());
+ }
+ return connection;
} else {
return null;
}
- // Set the autoCommit state of the bookmark to the default on new connections
- bookmark.setAutoCommit(bookmark.getDefaultAutoCommit());
- // Set the autoCommit state of the JDBC connection to the bookmark autoCommit statec
- setAutoCommit(con, bookmark.isAutoCommit());
- return con;
}
private Connection connect(Bookmark bookmark, String password)
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Vector;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.view.LogProxy;
public class SQLHelper {
- public static Vector getSchemas(Connection connection) {
- return MultiSQLServer.getInstance().getSchemas(connection);
- }
public static int getSize(Connection connection, String tableName, DatabaseAdapter adapter) throws SQLException {
SQLResults results = MultiSQLServer.getInstance().execute(
connection, adapter.getCountQuery(tableName));
} catch (Throwable e) {
e.printStackTrace();
}
- System.out.println("Returning"); //$NON-NLS-1$
Vector result = new Vector();
result.addAll(groups);
result.addAll(commands);
return value;
}
- private static String extractText(Element node, String defValue){
+ public static String extractText(Element node, String defValue){
String value = defValue;
if (node != null && node.hasChildNodes()) {
Node valueNode = node.getFirstChild();
Vector result = new Vector();
Vector columnNames = columns.getColumn("COLUMN_NAME"); //$NON-NLS-1$
for (int i = 0; i < columnNames.size(); i++) {
- result.add((String) columnNames.get(i));
+ result.add(columnNames.get(i));
}
return result;
}
p.mark();
// If we have '/*', it's a comment till '*/' found or eof
if (p.peek() == '*') {
- StringBuffer value = new StringBuffer();
- c = p.getNext();
- value.append('/');
- while (!( c == '*' && p.peek() == '/' ) && !p.isDone()) {
- value.append(c);
- c = p.getNext();
- }
- if (!p.isDone()){
- value.append(c);
- c = p.getNext();
- value.append(c);
- }
- tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
+ tokens.addElement(tokenizeComment(p, offset));
} else {
// It's not '/*' , so it's a group token
- tokens.addElement(new Token(Token.GROUP, group, offset, offset + 1));
+ // BCH ??? what's this business about groups?
+ // Shouldn't '/' be a divide operator?
+ tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}) /*group*/, offset, offset + 1));
p.reset();
}
// Adds SYMBOL token;
// }
return tokens;
}
+ /**
+ * @param tokens
+ * @param p
+ * @param offset
+ */
+ private static Token tokenizeComment(StringPointer p, int offset) {
+ char c;
+ StringBuffer value = new StringBuffer();
+ c = p.getNext();
+ value.append('/');
+ while (!( c == '*' && p.peek() == '/' ) && !p.isDone()) {
+ value.append(c);
+ c = p.getNext();
+ }
+ if (!p.isDone()){
+ value.append(c);
+ c = p.getNext();
+ value.append(c);
+ }
+ return new Token(Token.COMMENT, value.toString(), offset, offset + value.length());
+ }
}
+++ /dev/null
-package com.quantum.ui.dialog;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.util.JarUtil;
-
-/**
- * @author BC
- */
-public class AddDriverDialog extends Dialog {
-
- private FileDialog fileDialog;
-
- private Text driverFileName;
- private Text driverClassName;
-
-
- /**
- * @param parentShell
- */
- public AddDriverDialog(Shell parentShell) {
- super(parentShell);
- }
-
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setText(Messages.getString(getClass(), "title"));
- }
-
- /* (non-Javadoc)
- * Method declared on Dialog
- */
- protected Control createDialogArea(Composite parent) {
- parent.setLayout(new GridLayout());
- Composite composite = (Composite) super.createDialogArea(parent);
- GridLayout layout = new GridLayout();
- composite.setLayout(layout);
- layout.numColumns = 3;
- GridData fullHorizontal = new GridData(
- GridData.HORIZONTAL_ALIGN_BEGINNING,
- GridData.VERTICAL_ALIGN_BEGINNING,
- true, false);
- composite.setLayoutData(fullHorizontal);
-
-
- this.fileDialog = new FileDialog(composite.getShell(), SWT.OPEN);
- this.fileDialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
- this.fileDialog.setFilterNames(new String[] {
- Messages.getString("BookmarkWizard.JarFiles"),
- Messages.getString("BookmarkWizard.ZipFiles"),
- Messages.getString("BookmarkWizard.AllFiles") });
-
- Label label = new Label(composite, SWT.NULL);
- label.setText(Messages.getString(getClass(), "fileName"));
- this.driverFileName = new Text(composite, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData(
- GridData.HORIZONTAL_ALIGN_FILL,
- GridData.VERTICAL_ALIGN_BEGINNING,
- true, false);
- fullHorizontal.widthHint = 150;
- this.driverFileName.setLayoutData(fullHorizontal);
-
- Button button = new Button(composite, SWT.PUSH);
- button.setText(Messages.getString(getClass(), "browse"));
-
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- AddDriverDialog.this.fileDialog.setFilterPath(QuantumPlugin.getDefault()
- .getPreferenceStore().getString(
- "quantum.dialogs.bookmarkwizard.path"));
- String filename = AddDriverDialog.this.fileDialog.open();
- if (filename != null) {
- AddDriverDialog.this.driverFileName.setText(filename);
- QuantumPlugin.getDefault().getPreferenceStore().setValue(
- "quantum.dialogs.bookmarkwizard.path", filename);
- }
- }
- });
-
- label = new Label(composite, SWT.NULL);
- label.setText(Messages.getString(getClass(), "driverClassName"));
- this.driverClassName = new Text(composite, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData(
- GridData.HORIZONTAL_ALIGN_FILL,
- GridData.VERTICAL_ALIGN_BEGINNING,
- true, false);
- fullHorizontal.widthHint = 150;
- this.driverClassName.setLayoutData(fullHorizontal);
-
- button = new Button(composite, SWT.PUSH);
- button.setText(Messages.getString(getClass(), "browse"));
-
- button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- SimpleSelectionDialog dialog = new SimpleSelectionDialog(
- getShell(), "Select a Driver", JarUtil.getAllDriverNames(
- getDriverFile()), QuantumPlugin.getImage("class.gif"));
- if (dialog.open() == SimpleSelectionDialog.OK) {
- AddDriverDialog.this.driverClassName.setText(
- dialog.getSelectedElement());
- }
- }
- });
- return composite;
- }
-
- protected String getDriverFile() {
- return this.driverFileName.getText();
- }
-}
\ No newline at end of file
package com.quantum.ui.dialog;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
}
public String getColumnText(Object element, int columnIndex) {
- return (String) element;
+ return element.toString();
}
public void addListener(ILabelProviderListener listener) {
private final String title;
private TableViewer viewer;
private final Image image;
- private final String[] objects;
+ private final Object[] objects;
- private String selectedElement = null;
+ private List selection = Collections.synchronizedList(new ArrayList());
+ private final boolean multipleSelection;
/**
* @param parentShell
*/
- protected SimpleSelectionDialog(Shell parentShell, String title,
- String[] objects, Image image) {
+ public SimpleSelectionDialog(Shell parentShell, String title,
+ Object[] objects, Image image) {
+ this(parentShell, title, objects, image, false);
+ }
+ public SimpleSelectionDialog(Shell parentShell, String title,
+ Object[] objects, Image image, boolean multipleSelection) {
super(parentShell);
this.title = title;
this.objects = objects;
this.image = image;
+ this.multipleSelection = multipleSelection;
}
protected void configureShell(Shell shell) {
layout.numColumns = 1;
layout.verticalSpacing = 1;
- this.viewer = new TableViewer(composite);
+ int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL;
+ if (this.multipleSelection) {
+ style |= SWT.MULTI;
+ }
+ this.viewer = new TableViewer(composite, style);
GridData full = new GridData(GridData.FILL_HORIZONTAL);
full.widthHint = 200;
full.heightHint = 50;
this.viewer.setContentProvider(new ContentProvider());
this.viewer.setInput(this);
+
+ this.viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ Button okButton = getButton(IDialogConstants.OK_ID);
+ okButton.setEnabled(!event.getSelection().isEmpty());
+ }
+
+ });
return composite;
}
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ Button okButton = getButton(IDialogConstants.OK_ID);
+ okButton.setEnabled(false);
+ }
protected void okPressed() {
-
IStructuredSelection selection = (IStructuredSelection) this.viewer.getSelection();
- this.selectedElement = (String) selection.getFirstElement();
+ this.selection.clear();
+ for (Iterator i = selection.iterator(); i.hasNext();) {
+ this.selection.add(i.next());
+ }
super.okPressed();
}
/**
* @return Returns the selectedElement.
*/
- public String getSelectedElement() {
- return this.selectedElement;
- }
- /**
- * @param selectedElement The selectedElement to set.
- */
- public void setSelectedElement(String selectedElement) {
- this.selectedElement = selectedElement;
+ public IStructuredSelection getSelection() {
+ return new StructuredSelection(this.selection);
}
}
public static Driver loadDriver(String driverFile, String className) {
Driver result = null;
try {
- File file = new File(driverFile);
- if (file.exists() && file.isFile()) {
- URLClassLoader loader = getURLClassLoader(file);
- Class driverClass = loader.loadClass(className);
+ Class driverClass = loadDriverClass(driverFile, className);
+ if (driverClass != null) {
try {
result = (Driver) driverClass.newInstance();
} catch (ClassCastException e) {
}
}
- } catch (MalformedURLException e) {
- } catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
return result;
}
+ public static Class loadDriverClass(String driverFile, String className) {
+ Class result = null;
+ if (driverFile != null && className != null) {
+ try {
+ File file = new File(driverFile);
+ if (file.exists() && file.isFile()) {
+ URLClassLoader loader = getURLClassLoader(file);
+ Class driverClass = loader.loadClass(className);
+ result = Driver.class.isAssignableFrom(driverClass) ? driverClass : null;
+ }
+ } catch (MalformedURLException e) {
+ } catch (ClassNotFoundException e) {
+ }
+ }
+ return result;
+ }
+
public static String[] getAllDriverNames(String driverFile) {
List list = new ArrayList();
try {
*/
public void addMatrixHeader(String header[]){
for (int i = 0; i < header.length; i++) {
- String element = (String) header[i];
+ String element = header[i];
this.header.add(element);
}
}
package com.quantum.util.sql;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.sql.Types;
/**
- * @author holmesbc
+ * This class provides some utilities for working with Types, as well as providing some
+ * support around SQL types that exist in certain versions of the JDK.
+ *
+ * @author BC Holmes
+ * @see java.lang.Types
*/
public class TypesHelper {
public static final int BLOB = Types.BLOB;
public static final int CLOB = Types.CLOB;
public static final int REF = Types.REF;
+ /**
+ * <p>The constant in the Java programming language, somtimes referred to
+ * as a type code, that identifies the generic SQL type <code>DATALINK</code>.
+ *
+ * <p>Note: For some reason, some versions of DB2 and/or the DB2 driver use an invalid
+ * type code for DATALINK. The correct value should be 70, but DB2/NT 7.01.00 uses
+ * -400.
+ */
public static final int DATALINK;
public static final int BOOLEAN;
return defaultValue;
}
+ public static String getTypeName(int type) {
+ String name = null;
+ try {
+ Field[] fields = TypesHelper.class.getFields();
+ for (int i = 0, length = fields == null ? 0 : fields.length;
+ name == null && i < length; i++) {
+ if (Modifier.isStatic(fields[i].getModifiers())
+ && Modifier.isPublic(fields[i].getModifiers())
+ && fields[i].getType() == Integer.TYPE
+ && type == fields[i].getInt(null)) {
+ name = fields[i].getName();
+ }
+ }
+ } catch (IllegalAccessException e) {
+ }
+ return name;
+ }
+
}
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.FontDialog;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.part.WorkbenchPart;
/**
* This class provides backward compatibility between versions of Eclipse for
public class VersioningHelper {
public static final int ECLIPSE_VERSION_2_1_1 = 2135;
+ public static final int ECLIPSE_VERSION_3_0_RC1 = 3054;
+ public static final int ECLIPSE_VERSION_3_0_RC3 = 3061;
/**
* Set the font in a FontDialog. In Eclipse 2.1.1, the
// should not happen
}
}
+
+ public static void setPartName(ViewPart viewPart, String partName) {
+ try {
+ if (SWT.getVersion() >= ECLIPSE_VERSION_3_0_RC1) {
+ Method method = WorkbenchPart.class.getDeclaredMethod(
+ "setPartName", new Class[] { String.class });
+ method.invoke(viewPart, new Object[] {partName});
+ } else {
+ Method method = WorkbenchPart.class.getDeclaredMethod(
+ "setTitle", new Class[] { FontData.class });
+ method.invoke(method, new Object[] { partName });
+ }
+ } catch (NoSuchMethodException e) {
+ // should not happen
+ } catch (IllegalArgumentException e) {
+ // should not happen
+ } catch (IllegalAccessException e) {
+ // should not happen
+ } catch (InvocationTargetException e) {
+ // should not happen
+ }
+ }
+
+ public static void main(String[] args) {
+ System.out.println(SWT.getVersion());
+ }
}
public final class CopyAction extends Action {
- private final TableView view;
private final Table table;
public CopyAction(TableView view, Table table) {
super();
- this.view = view;
this.table = table;
}
public void run() {
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.adapters.AdapterFactory;
import com.quantum.model.BookmarkCollection;
import com.quantum.model.JDBCDriver;
/**
* @author BC
*/
-public class JDBCDriverTableViewer implements PropertyChangeListener {
+public class JDBCDriverTableViewer implements PropertyChangeListener, ISelectionProvider {
+ public class LabelProviderImpl implements ITableLabelProvider {
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (columnIndex == 0) {
+ return QuantumPlugin.getImage("driver.gif");
+ } else {
+ return null;
+ }
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ String result = null;
+ switch (columnIndex) {
+ case 0:
+ result = ((JDBCDriver) element).getName();
+ break;
+ case 1:
+ result = ((JDBCDriver) element).getClassName();
+ break;
+ case 2:
+ String type = ((JDBCDriver) element).getType();
+ result = AdapterFactory.getInstance().getAdapter(type).getDisplayName();
+ break;
+ case 3:
+ result = ((JDBCDriver) element).getVersion();
+ break;
+ case 4:
+ result = ((JDBCDriver) element).getJarFileName();
+ break;
+ default:
+ }
+ return result == null ? "" : result;
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ }
+
+ public class ContentProviderImpl implements IStructuredContentProvider {
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ public Object[] getElements(Object inputElement) {
+ if (inputElement == BookmarkCollection.getInstance()) {
+ return BookmarkCollection.getInstance().getJDBCDrivers();
+ } else {
+ return null;
+ }
+ }
+ }
+
private TableViewer tableViewer;
+ private List listeners = Collections.synchronizedList(new ArrayList());
public JDBCDriverTableViewer(Composite container) {
Table table = new Table(container, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
table.setHeaderVisible(true);
- for (int i = 0, length = 4; i < length; i++) {
+ for (int i = 0, length = 5; i < length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(Messages.getString(getClass(), "driverColumn" + i));
}
- for (int i = 0, length = 4; i < length; i++) {
+ for (int i = 0, length = table.getColumnCount(); i < length; i++) {
table.getColumn(i).pack();
}
this.tableViewer = new TableViewer(table);
- this.tableViewer.setContentProvider(new JDBCDriverContentProvider());
- this.tableViewer.setLabelProvider(new JDBCDriverLabelProvider());
- this.tableViewer.setColumnProperties(new String[] { "name", "className", "version", "jarFileName" });
+ this.tableViewer.setContentProvider(new ContentProviderImpl());
+ this.tableViewer.setLabelProvider(new LabelProviderImpl());
+ this.tableViewer.setColumnProperties(new String[] { "name", "className", "driverType", "version", "jarFileName" });
this.tableViewer.setInput(BookmarkCollection.getInstance());
+ this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){
+ public void selectionChanged(SelectionChangedEvent event) {
+ fireSelectionChangedEvent(event.getSelection());
+ }
+ });
+
BookmarkCollection.getInstance().addPropertyChangeListener(this);
registerWithAllDrivers();
}
private void registerWithAllDrivers() {
JDBCDriver[] drivers = BookmarkCollection.getInstance().getJDBCDrivers();
for (int i = 0, length = drivers == null ? 0 : drivers.length; i < length; i++) {
+ drivers[i].removePropertyChangeListener(this);
drivers[i].addPropertyChangeListener(this);
}
}
public Control getControl() {
return this.tableViewer.getControl();
}
- /* (non-Javadoc)
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
public void propertyChange(PropertyChangeEvent event) {
if ("drivers".equals(event.getPropertyName())) {
registerWithAllDrivers();
- this.tableViewer.refresh();
+ if (!this.tableViewer.getControl().isDisposed()) {
+ this.tableViewer.refresh();
+ }
} else if (event.getSource() instanceof JDBCDriver) {
- this.tableViewer.refresh(event.getSource());
+ if (!this.tableViewer.getControl().isDisposed()) {
+ this.tableViewer.refresh(event.getSource());
+ }
}
}
}
BookmarkCollection.getInstance().removePropertyChangeListener(this);
}
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ if (!this.listeners.contains(listener)) {
+ this.listeners.add(listener);
+ }
+ }
+ public ISelection getSelection() {
+ return this.tableViewer == null ? null : this.tableViewer.getSelection();
+ }
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ this.listeners.remove(listener);
+ }
+ public void setSelection(ISelection selection) {
+ }
+ /**
+ * @param selection
+ */
+ protected void fireSelectionChangedEvent(ISelection selection) {
+ for (Iterator i = this.listeners.iterator(); selection != null && i.hasNext();) {
+ ISelectionChangedListener listener = (ISelectionChangedListener) i.next();
+ listener.selectionChanged(new SelectionChangedEvent(this, selection));
+ }
+ }
}
import java.util.Vector;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ExtendedModifyEvent;
import org.eclipse.swt.custom.ExtendedModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IActionBars;
import com.quantum.sql.MultiSQLServer;
import com.quantum.sql.parser.SQLLexx;
import com.quantum.sql.parser.Token;
+import com.quantum.util.versioning.VersioningHelper;
import com.quantum.view.bookmark.BookmarkNode;
import com.quantum.view.bookmark.BookmarkView;
public class SQLQueryView extends ViewPart {
+ private class ClearAction extends Action {
+
+ public ClearAction() {
+ setImageDescriptor(QuantumPlugin.getImageDescriptor("clear.gif"));
+ setToolTipText(Messages.getString("sqlqueryview.clear"));
+ }
+
+ public void run() {
+ setQuery("");
+ }
+ }
+
+ private class AutoCommitPreferenceAction extends Action {
+
+ public AutoCommitPreferenceAction() {
+ super(Messages.getString("SQLQueryView.AutoCommit"), SWT.CHECK);
+ setToolTipText(Messages.getString("SQLQueryView.AutoCommit"));
+ setImageDescriptor(QuantumPlugin.getImageDescriptor("autocommit.gif"));
+ }
+
+ public void run() {
+ Connection connection = null;
+ try {
+ // Get the connection
+ connection = getBookmark().getConnection();
+ // If connected (else will throw exception and jump out) switchs the state of the
+ // autoCommit option of the JDBC driver
+ MultiSQLServer.getInstance().setAutoCommit( connection, isChecked());
+ } catch (NotConnectedException e) {
+ //Doesn't matter
+ }
+ // Update the bookmark and the buttons
+ updateAutoCommitState(getBookmark(), connection);
+ }
+ }
+
+
private ExecuteAction executeAction;
private ImportQueryAction importQueryAction;
private ExportQueryAction exportQueryAction;
- private Label statusImage;
- private Label status;
- private ProgressBar progress;
private StyledText widget;
private ToolItem autoCommitItem;
private ToolItem commitItem;
private Color COMMENT;
private Color NUMERIC;
private Color DEFAULT;
- private long parseTime = 0;
- private long fullTime = 0;
+ private AutoCommitPreferenceAction autoCommitPreferenceAction;
+
public SQLQueryView() {
super();
}
public void setFocus() {
String title = "Quantum SQL Query Editor";
- BookmarkNode bookmarkNode = null;
Bookmark bookmark = null;
Connection con = null;
if (BookmarkView.getInstance() != null ) {
- bookmarkNode = BookmarkView.getInstance().getCurrentBookmark();
+ bookmark = getBookmark();
}
- if (bookmarkNode != null)
- bookmark = bookmarkNode.getBookmark();
if (bookmark != null) {
title = bookmark.getName() + " (" + title + ")";
- setTitle( title );
+ VersioningHelper.setPartName(this, title);
+// setPartName("fred");
try {
con = bookmark.getConnection();
} catch (NotConnectedException e) {
widget.setFocus();
}
+ /**
+ * @return
+ */
+ private Bookmark getBookmark() {
+ if (BookmarkView.getInstance() != null ) {
+ BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
+ return node == null ? null : node.getBookmark();
+ } else {
+ return null;
+ }
+ }
public static SQLQueryView getInstance() {
return (SQLQueryView) QuantumPlugin.getDefault().getView("com.quantum.view.sqlqueryview");
public void createPartControl(org.eclipse.swt.widgets.Composite parent) {
initActions();
+
KEYWORD = new Color(parent.getShell().getDisplay(), 126, 0, 75);
STRING_LITERAL = new Color(parent.getShell().getDisplay(), 0, 0, 255);
COMMENT = new Color(parent.getShell().getDisplay(), 88, 148, 64);
layout.verticalSpacing = 0;
main.setLayout(layout);
ToolBar toolbar = new ToolBar(main, SWT.HORIZONTAL);
- ToolItem item = new ToolItem(toolbar, SWT.PUSH);
- item.setImage(QuantumPlugin.getImage("play.gif")); //$NON-NLS-1$
- item.setToolTipText(Messages.getString("sqlqueryview.executeQuery")); //$NON-NLS-1$
- item.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- executeAction.run();
- }
- });
- item = new ToolItem(toolbar, SWT.SEPARATOR);
- item = new ToolItem(toolbar, SWT.PUSH);
- item.setImage(QuantumPlugin.getImage("import.gif")); //$NON-NLS-1$
- item.setToolTipText(Messages.getString("sqlqueryview.importQuery")); //$NON-NLS-1$
- item.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- importQueryAction.run();
- }
- });
- item = new ToolItem(toolbar, SWT.PUSH);
- item.setImage(QuantumPlugin.getImage("export.gif")); //$NON-NLS-1$
- item.setToolTipText(Messages.getString("sqlqueryview.exportQuery")); //$NON-NLS-1$
- item.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- exportQueryAction.run();
- }
- });
- item = new ToolItem(toolbar, SWT.PUSH);
- item.setImage(QuantumPlugin.getImage("clear.gif")); //$NON-NLS-1$
- item.setToolTipText(Messages.getString("sqlqueryview.clear")); //$NON-NLS-1$
- item.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- setQuery(""); //$NON-NLS-1$
- }
- });
-
- item = new ToolItem(toolbar, SWT.SEPARATOR);
commitItem = new ToolItem(toolbar, SWT.PUSH);
commitItem.setImage(QuantumPlugin.getImage("commit.gif")); //$NON-NLS-1$
}
});
- BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
- if (node == null) autoCommitItem.setSelection(true);
- else autoCommitItem.setSelection(node.getBookmark().isAutoCommit());
+
+ // TODO: BCH -- this is causing some problems during start-up
+ Bookmark bookmark = null;
+ try {
+ bookmark = getBookmark();
+ } catch (NullPointerException e) {
+ }
+
+ if (bookmark == null) {
+ autoCommitItem.setSelection(true);
+ } else {
+ autoCommitItem.setSelection(bookmark.isAutoCommit());
+ }
if (autoCommitItem.getSelection()) {
commitItem.setEnabled(false);
rollbackItem.setEnabled(false);
gridData.grabExcessVerticalSpace = true;
widget.setLayoutData(gridData);
- Composite bottomStatus = new Composite(main, SWT.NONE);
- gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.grabExcessHorizontalSpace = true;
- bottomStatus.setLayoutData(gridData);
-
- GridLayout horizontal = new GridLayout(3, false);
- layout.horizontalSpacing = 0;
- layout.verticalSpacing = 0;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- bottomStatus.setLayout(horizontal);
-
- statusImage = new Label(bottomStatus, SWT.NONE);
- status = new Label(bottomStatus, SWT.NONE);
- gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.grabExcessHorizontalSpace = true;
- status.setLayoutData(gridData);
-
- progress = new ProgressBar(bottomStatus, SWT.HORIZONTAL);
-
- status.setText(Messages.getString("sqlqueryview.done")); //$NON-NLS-1$
- statusImage.setImage(QuantumPlugin.getImage("success.gif")); //$NON-NLS-1$
- progress.setMinimum(0);
-
IKeyBindingService keyBindingService = getSite().getKeyBindingService();
// TODO: check the version numbers for this method
keyBindingService.setScopes(new String[] {
* Sets the state of the "Commit", "Rollback" and "autoCommit" buttons
* to reflect the situation in the connection
*/
- protected void updateAutoCommitState(Bookmark bookmark, Connection con) {
+ protected void updateAutoCommitState(Bookmark bookmark, Connection connection) {
boolean autoCommit = true;
// Calculate the state of the autoCommit option
- if (con != null)
+ if (connection != null)
{
// If we have a connection, the autoCommit state is that of the connection
try {
- autoCommit = con.getAutoCommit();
+ autoCommit = connection.getAutoCommit();
} catch (SQLException e) {
// Doesn't matter, we take default
}
if (bookmark != null) bookmark.setAutoCommit(autoCommit);
// Set the state of the buttons to the correct autoCommit state
autoCommitItem.setSelection(autoCommit);
+ this.autoCommitPreferenceAction.setChecked(autoCommit);
if (autoCommitItem.getSelection()) {
commitItem.setEnabled(false);
rollbackItem.setEnabled(false);
rollbackItem.setEnabled(true);
}
}
- public void setProgress(int increment, int max) {
- progress.setMaximum(max);
- progress.setSelection(increment);
- }
-
private void initActions() {
+
executeAction = new ExecuteAction();
executeAction.init(this);
- importQueryAction = new ImportQueryAction();
- importQueryAction.init(this);
- exportQueryAction = new ExportQueryAction();
- exportQueryAction.init(this);
- }
- public void setStatus(String text) {
- statusImage.setImage(null);
- status.setText(text);
+ IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+ toolBar.add(this.executeAction);
+// toolBar.add(this.importQueryAction);
+// toolBar.add(this.exportQueryAction);
+
+ toolBar.add(new ClearAction());
+
+ IActionBars actionBars = getViewSite().getActionBars();
+ this.importQueryAction = new ImportQueryAction();
+ this.importQueryAction.init(this);
+ actionBars.getMenuManager().add(this.importQueryAction);
+ this.exportQueryAction = new ExportQueryAction();
+ this.exportQueryAction.init(this);
+ actionBars.getMenuManager().add(this.exportQueryAction);
+ actionBars.getMenuManager().add(new Separator());
+ this.autoCommitPreferenceAction = new AutoCommitPreferenceAction();
+ actionBars.getMenuManager().add(this.autoCommitPreferenceAction);
}
- public void setStatus(Image img, String text) {
- statusImage.setImage(img);
- status.setText(text);
- }
-
public String getQuery() {
return widget.getText();
}
//int dirtyStart = request.start;
//int dirtyEnd = request.start + request.length;
StyleRange styleRange;
- long startTime = System.currentTimeMillis();
Vector tokens = SQLLexx.parse(text);
- long subTime = System.currentTimeMillis();
Vector styles = new Vector();
int min = Integer.MAX_VALUE;
int max = 0;
if (max >= 0 && ranges.length > 0) {
setStyles(ranges, min, max - min);
}
- long endTime = System.currentTimeMillis();
- parseTime = subTime - startTime;
- fullTime = endTime - startTime;
} catch (NoSuchElementException e) {
// ignore a missing request
} catch (InterruptedException e) {
--- /dev/null
+package com.quantum.view;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.model.Bookmark;
+import com.quantum.model.ConnectionException;
+import com.quantum.model.NotConnectedException;
+import com.quantum.model.Schema;
+import com.quantum.ui.dialog.ExceptionDisplayDialog;
+import com.quantum.ui.dialog.SimpleSelectionDialog;
+import com.quantum.util.connection.ConnectionUtil;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * @author BC
+ */
+public class SchemaSelectionControl extends Composite {
+
+ class ContentProviderImpl implements IStructuredContentProvider {
+ public Object[] getElements(Object inputElement) {
+ List list = new ArrayList((Collection) inputElement);
+ Collections.sort(list);
+ return list.toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ class LabelProviderImpl implements ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (columnIndex == 0) {
+ return QuantumPlugin.getImage("schema.gif");
+ } else {
+ return null;
+ }
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (columnIndex == 0) {
+ return ((Schema) element).getDisplayName();
+ } else {
+ return null;
+ }
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return "displayName".equals(property);
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ }
+
+
+ private final Bookmark bookmarkForConnection;
+ private ConnectionUtil connectionUtil = new ConnectionUtil();
+ private Set schemas = Collections.synchronizedSet(new HashSet());
+ private TableViewer schemaTable;
+ private Button useAllSchemasButton;
+
+ private int schemaRule;
+
+ private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+ private Button useUsernameAsSchemaButton;
+ private Button useSelectedSchemasButton;
+ private Button removeButton;
+ private Button addButton;
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public SchemaSelectionControl(Composite parent, Bookmark bookmarkForConnection) {
+ super(parent, SWT.NONE);
+ this.bookmarkForConnection = bookmarkForConnection;
+
+ Schema[] schemas = bookmarkForConnection.getSchemaSelections();
+ this.schemas.addAll(Arrays.asList(schemas));
+ this.schemaRule = this.bookmarkForConnection.getSchemaRule();
+ createContents();
+ }
+
+ protected void createContents() {
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ setLayout(layout);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ setLayoutData(data);
+
+ this.useAllSchemasButton = new Button(this, SWT.RADIO);
+ this.useAllSchemasButton.setText(Messages.getString(getClass(), "useAllSchemas")); //$NON-NLS-1$
+ this.useAllSchemasButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ this.useAllSchemasButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setSchemaRule(Bookmark.SCHEMA_RULE_USE_ALL);
+ updateControls();
+ }
+ });
+
+ this.useUsernameAsSchemaButton = new Button(this, SWT.RADIO);
+ this.useUsernameAsSchemaButton.setText(Messages.getString(getClass(), "useUsernameAsSchema")); //$NON-NLS-1$
+ this.useUsernameAsSchemaButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ this.useUsernameAsSchemaButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setSchemaRule(Bookmark.SCHEMA_RULE_USE_DEFAULT);
+ updateControls();
+ }
+ });
+
+ this.useSelectedSchemasButton = new Button(this, SWT.RADIO);
+ this.useSelectedSchemasButton.setText(Messages.getString(getClass(), "useSelectedSchemas")); //$NON-NLS-1$
+ this.useSelectedSchemasButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ this.useSelectedSchemasButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ setSchemaRule(Bookmark.SCHEMA_RULE_USE_SELECTED);
+ updateControls();
+ }
+ });
+
+ Composite composite = new Composite(this, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+ data = new GridData(GridData.FILL_BOTH);
+ composite.setLayoutData(data);
+
+ this.schemaTable = new TableViewer(composite,
+ SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
+ layout = new GridLayout();
+ layout.marginWidth = 5;
+ layout.marginHeight = 5;
+
+ this.schemaTable.getTable().setLayout(layout);
+ data = new GridData(GridData.FILL_BOTH);
+ this.schemaTable.getTable().setLayoutData(data);
+ this.schemaTable.setLabelProvider(new LabelProviderImpl());
+ this.schemaTable.setContentProvider(new ContentProviderImpl());
+ this.schemaTable.setInput(this.schemas);
+
+ createButtonArea(composite);
+
+ updateControls();
+ }
+
+ private void updateControls() {
+ this.useAllSchemasButton.setSelection(this.schemaRule == Bookmark.SCHEMA_RULE_USE_ALL);
+ this.useUsernameAsSchemaButton.setSelection(this.schemaRule == Bookmark.SCHEMA_RULE_USE_DEFAULT);
+
+ boolean enabled = (this.schemaRule != Bookmark.SCHEMA_RULE_USE_ALL
+ && this.schemaRule != Bookmark.SCHEMA_RULE_USE_DEFAULT);
+
+ this.useSelectedSchemasButton.setSelection(enabled);
+ this.schemaTable.getControl().setEnabled(enabled);
+
+ this.addButton.setEnabled(enabled);
+ this.removeButton.setEnabled(
+ enabled && !this.schemaTable.getSelection().isEmpty());
+ }
+
+ private void createButtonArea(Composite composite) {
+ Composite buttonArea = new Composite(composite, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ buttonArea.setLayout(layout);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
+ buttonArea.setLayoutData(data);
+
+ this.addButton = new Button(buttonArea, SWT.NULL);
+ this.addButton.setText("Add");
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+ this.addButton.setLayoutData(data);
+ this.addButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ addSchema();
+ }
+ });
+
+ this.removeButton = new Button(buttonArea, SWT.NULL);
+ this.removeButton.setText("Remove");
+ this.removeButton.setEnabled(false);
+ data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+ this.removeButton.setLayoutData(data);
+ this.removeButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ removeSchema(SchemaSelectionControl.this.schemaTable.getSelection());
+ }
+ });
+
+ schemaTable.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateControls();
+ }
+ });
+ }
+ private void addSchema() {
+ Bookmark bookmark = getBookmark();
+ boolean isAlreadyConnected = bookmark.isConnected();
+
+ if (!isAlreadyConnected) {
+ boolean confirmed = MessageDialog.openConfirm(getShell(),
+ Messages.getString(getClass(), "connectTitle"),
+ Messages.getString(getClass(), "connectMessage"));
+ if (confirmed) {
+ this.connectionUtil.connect(bookmark, getShell());
+ }
+ }
+
+ try {
+ if (bookmark.isConnected()) {
+ List schemaList = getAllUnselectedSchemas(bookmark);
+ SimpleSelectionDialog dialog = new SimpleSelectionDialog(
+ getShell(), Messages.getString(getClass(), "addSchemaDialog"),
+ schemaList.toArray(),
+ QuantumPlugin.getImage("schema.gif"), true);
+ int result = dialog.open();
+ if (result == SimpleSelectionDialog.OK
+ && !dialog.getSelection().isEmpty()) {
+ for (Iterator i = dialog.getSelection().iterator(); i.hasNext();) {
+ this.schemas.add(i.next());
+ }
+
+ refreshTable();
+ this.propertyChangeSupport.firePropertyChange("schemas", null, getSchemas());
+ }
+
+ if (!isAlreadyConnected) {
+ bookmark.disconnect();
+ }
+ }
+ } catch (ConnectionException e) {
+ ExceptionDisplayDialog.openError(getShell(), null, null, e);
+ } catch (SQLException e) {
+ ExceptionDisplayDialog.openError(getShell(), null, null, e);
+ }
+ }
+
+ /**
+ * @param bookmark
+ * @return
+ * @throws NotConnectedException
+ * @throws SQLException
+ */
+ private List getAllUnselectedSchemas(Bookmark bookmark)
+ throws NotConnectedException, SQLException {
+ Schema[] schemas = bookmark.getDatabase().getSchemas();
+ List schemaList = new ArrayList(Arrays.asList(schemas));
+ schemaList.removeAll(this.schemas);
+ Collections.sort(schemaList);
+ return schemaList;
+ }
+
+ private void removeSchema(ISelection selection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
+ Schema element = (Schema) i.next();
+ this.schemas.remove(element);
+ }
+ refreshTable();
+ this.propertyChangeSupport.firePropertyChange("schemas", null, getSchemas());
+ }
+
+ private Bookmark getBookmark() {
+ return this.bookmarkForConnection;
+ }
+
+ private void refreshTable() {
+ this.schemaTable.refresh();
+ }
+
+ public Schema[] getSchemas() {
+ return (Schema[]) this.schemas.toArray(new Schema[this.schemas.size()]);
+ }
+
+ public void setSchemas(Schema[] schemas) {
+ this.schemas.clear();
+ this.schemas.addAll(Arrays.asList(schemas));
+ updateControls();
+ refreshTable();
+ this.propertyChangeSupport.firePropertyChange("schemas", null, getSchemas());
+ }
+ public void addPropertyChangeListener(PropertyChangeListener arg0) {
+ this.propertyChangeSupport.addPropertyChangeListener(arg0);
+ }
+ public void removePropertyChangeListener(PropertyChangeListener arg0) {
+ this.propertyChangeSupport.removePropertyChangeListener(arg0);
+ }
+ public int getSchemaRule() {
+ return this.schemaRule;
+ }
+ public void setSchemaRule(int schemaRule) {
+ if (schemaRule != this.schemaRule) {
+ int original = this.schemaRule;
+ this.schemaRule = schemaRule;
+ updateControls();
+ refreshTable();
+ this.propertyChangeSupport.firePropertyChange(
+ "schemaRule", original, schemaRule);
+ }
+ }
+}
+++ /dev/null
-package com.quantum.view.bookmark;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.model.Bookmark;
-import com.quantum.model.NotConnectedException;
-import com.quantum.sql.SQLHelper;
-
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.actions.SelectionListenerAction;
-
-
-final class AddSchemaAction extends SelectionListenerAction {
- private final IViewPart view;
- /**
- * @param BookmarkView
- */
- public AddSchemaAction(IViewPart view) {
- super(Messages.getString("BookmarkView.SetExtraSchemas")); //$NON-NLS-1$
- setImageDescriptor(
- QuantumPlugin.getImageDescriptor("add_schema.gif")); //$NON-NLS-1$
- this.view = view;
- }
-
- public void run() {
- Bookmark bookmark = getBookmark();
- if (bookmark != null) {
- try {
- Vector schemas = SQLHelper.getSchemas(bookmark.getConnection());
- AddSchemaDialog dialog = new AddSchemaDialog(this.view.getSite().getShell(), schemas);
- dialog.open();
- if (dialog.getSelectedSchemas() != null) {
- for (Iterator i = dialog.getSelectedSchemas().iterator(); i.hasNext();) {
- bookmark.addSchema((String) i.next());
- }
- }
- } catch (NotConnectedException e) {
- }
- }
- }
-
- protected Bookmark getBookmark() {
- List list = getSelectedNonResources();
- return (list.size() > 0) ? ((BookmarkNode) list.get(0)).getBookmark() : null;
- }
-
- protected boolean updateSelection(IStructuredSelection selection) {
- boolean enabled = super.updateSelection(selection) &
- selection.size() == 1 &
- (selection.getFirstElement() instanceof BookmarkNode);
- return enabled & getBookmark().isConnected();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Created on 12-jul-2003
- *
- */
-package com.quantum.view.bookmark;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Vector;
-
-import com.quantum.IQuantumConstants;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.help.WorkbenchHelp;
-
-/**
- * @author panic
- *
- */
-public class AddSchemaDialog extends Dialog {
-
- protected Vector input;
- protected List list;
- private Vector selection;
- /**
- * Creates a new AddSchemaDialog.
- */
- public AddSchemaDialog(Shell parentShell, Vector input) {
- super(parentShell);
- this.input = input;
- this.list = null;
- selection = null;
- }
- /* (non-Javadoc)
- * Method declared on Window.
- */
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText("Set Schemas");
- WorkbenchHelp.setHelp(
- newShell,
- IQuantumConstants.ADD_SCHEMA_DIALOG_CONTEXT);
- }
- /* (non-Javadoc)
- * Method declared on Dialog
- */
- protected Control createDialogArea(Composite parent) {
- Composite composite = (Composite) super.createDialogArea(parent);
-
- list = new List(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
- GridData data = new GridData(GridData.FILL_BOTH);
- list.setLayoutData(data);
- for (Iterator iter = input.iterator(); iter.hasNext();) {
- String element = (String) iter.next();
- list.add(element);
- }
- return composite;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
- */
- protected void okPressed() {
- // If it's OK, then the selection is not null. Null is used to signal a canceled dialog.
- selection = new Vector();
- if (list != null) {
- String selecStr[] = list.getSelection();
- for (int i = 0; i < selecStr.length; i++) {
- String string = selecStr[i];
- selection.add(string);
- }
- }
- super.okPressed();
- }
-
- public Collection getSelectedSchemas() {
- return this.selection == null ? null : new ArrayList(this.selection);
- }
-
-}
package com.quantum.view.bookmark;
+import java.sql.SQLException;
+
+import com.quantum.model.NotConnectedException;
+import com.quantum.ui.dialog.ExceptionDisplayDialog;
+
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IViewPart;
public class BookmarkContentProvider implements ITreeContentProvider {
+
+ private final IViewPart view;
+
+ public BookmarkContentProvider(IViewPart view) {
+ this.view = view;
+ }
+
public Object[] getChildren(Object element) {
if (element instanceof TreeNode) {
TreeNode node = (TreeNode) element;
- return node.getChildren();
+ try {
+ return node.getChildren();
+ } catch (NotConnectedException e) {
+ ExceptionDisplayDialog.openError(getShell(), null, null, e);
+ } catch (SQLException e) {
+ ExceptionDisplayDialog.openError(getShell(), null, null, e);
+ }
}
return BookmarkListNode.EMPTY_ARRAY;
}
+ /**
+ * @return
+ */
+ private Shell getShell() {
+ return this.view.getSite().getShell();
+ }
+
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
this.bookmark.addPropertyChangeListener(this);
}
- public Object[] getChildren() {
+ public Object[] getChildren() throws NotConnectedException, SQLException {
if (bookmark.isConnected() && this.children.isEmpty()) {
initializeChildren();
}
}
}
- protected void initializeChildren() {
+ protected void initializeChildren() throws NotConnectedException, SQLException {
boolean changed = false;
Map temp = new HashMap();
for (Iterator i = this.children.iterator(); i.hasNext(); ) {
}
firePropertyChange("connected", event.getOldValue(), event.getNewValue());
} else if ("schemas".equals(event.getPropertyName())) {
- initializeChildren();
+ try {
+ initializeChildren();
+ } catch (NotConnectedException e) {
+ this.children.clear();
+ } catch (SQLException e) {
+ this.children.clear();
+ }
firePropertyChange("children", event.getOldValue(), event.getNewValue());
} else if ("name".equals(event.getPropertyName())) {
firePropertyChange("name", event.getOldValue(), event.getNewValue());
private static BookmarkNode getRoot(TreeNode node){
if (node == null) return null;
- if (! (node instanceof TreeNode)) return null;
while (!( node instanceof BookmarkNode))
{
- node = (TreeNode) node.getParent();
+ node = node.getParent();
}
if (node instanceof BookmarkNode) return (BookmarkNode) node;
else return null;
treeViewer = new TreeViewer(
parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- treeViewer.setContentProvider(new BookmarkContentProvider());
+ treeViewer.setContentProvider(new BookmarkContentProvider(this));
treeViewer.setLabelProvider(this.labelProvider);
BookmarkListNode input = BookmarkListNode.getInstance();
treeViewer.setInput(input);
this.actionGroup = new BookmarkViewActionGroup(this, this.treeViewer);
-// openDataEditorAction = new OpenDataEditorAction();
-// openDataEditorAction.setText("Edit Data");
-// openDataEditorAction.setImageDescriptor(
-// QuantumPlugin.getImageDescriptor("greentable.gif")); //$NON-NLS-1$
-// openDataEditorAction.init(this);
-
- IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
- this.customCopyAction1 = new CustomCopyAction(this,1); // 1 is unused, just in case more custom copies are defined
- this.customCopyAction1.setText(store.getString("customCopyName1")); //$NON-NLS-1$
- this.customCopyAction1.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
- this.customCopyAction2 = new CustomCopyAction(this,2); // 1 is unused, just in case more custom copies are defined
- this.customCopyAction2.setText(store.getString("customCopyName2")); //$NON-NLS-1$
- this.customCopyAction2.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
- this.customCopyAction3 = new CustomCopyAction(this,3); // 1 is unused, just in case more custom copies are defined
- this.customCopyAction3.setText(store.getString("customCopyName3")); //$NON-NLS-1$
- this.customCopyAction3.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
extensionVector = new Vector();
try {
e.printStackTrace();
}
- }
+ }
+ /**
+ *
+ */
+ private void initCustomCopyActions() {
+ IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
+ String text1 = store.getString("customCopyName1");
+ if (text1 != null && text1.trim().length() > 0) {
+ this.customCopyAction1 = new CustomCopyAction(this,1); // 1 is unused, just in case more custom copies are defined
+ this.customCopyAction1.setText(text1); //$NON-NLS-1$
+ this.customCopyAction1.setImageDescriptor(
+ QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ }
+ String text2 = store.getString("customCopyName2");
+ if (text2 != null && text1.trim().length() > 0) {
+ this.customCopyAction2 = new CustomCopyAction(this,2); // 1 is unused, just in case more custom copies are defined
+ this.customCopyAction2.setText(text2); //$NON-NLS-1$
+ this.customCopyAction2.setImageDescriptor(
+ QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ }
+ String text3 = store.getString("customCopyName3");
+ if (text3 != null && text1.trim().length() > 0) {
+ this.customCopyAction3 = new CustomCopyAction(this,3); // 1 is unused, just in case more custom copies are defined
+ this.customCopyAction3.setText(text3); //$NON-NLS-1$
+ this.customCopyAction3.setImageDescriptor(
+ QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ }
+ }
public void dispose(){
super.dispose();
BookmarkListNode.getInstance().removePropertyChangeListener(this);
private void fillContextMenu(IMenuManager mgr) {
// TODO: this method is pretty barfy... make it cleaner
+ initCustomCopyActions();
IStructuredSelection selection = getSelection();
ActionContext context = new ActionContext(selection);
this.actionGroup.setContext(context);
if (sel instanceof EntityNode) {
EntityNode entityNode = (EntityNode) sel;
if (!entityNode.isSequence()) {
- mgr.add(new Separator());
- MenuManager subMenu = new MenuManager(Messages.getString("bookmarkview.customCopyAction"));
- subMenu.add(customCopyAction1);
- subMenu.add(customCopyAction2);
- subMenu.add(customCopyAction3);
- mgr.add(subMenu);
+ if (this.customCopyAction1 != null
+ || this.customCopyAction2 != null
+ || this.customCopyAction3 != null) {
+ mgr.add(new Separator());
+ MenuManager subMenu = new MenuManager(Messages.getString("bookmarkview.customCopyAction"));
+ if (this.customCopyAction1 != null) {
+ subMenu.add(customCopyAction1);
+ }
+ if (this.customCopyAction2 != null) {
+ subMenu.add(customCopyAction2);
+ }
+ if (this.customCopyAction3 != null) {
+ subMenu.add(customCopyAction3);
+ }
+ mgr.add(subMenu);
+ }
MenuManager subMenuExtension = new MenuManager("Extensions");
for (int i = 0; i < extensionVector.size(); i++) {
}
if (extensionVector.size() > 0) mgr.add(subMenuExtension);
}
- } else if (sel instanceof ColumnNode) {
+ } else if ((sel instanceof ColumnNode) && (this.customCopyAction1 != null
+ || this.customCopyAction2 != null
+ || this.customCopyAction3 != null)) {
MenuManager subMenu = new MenuManager(Messages.getString("bookmarkview.customCopyAction"));
+ if (this.customCopyAction1 != null) {
subMenu.add(customCopyAction1);
- subMenu.add(customCopyAction2);
- subMenu.add(customCopyAction3);
+ }
+ if (this.customCopyAction2 != null) {
+ subMenu.add(customCopyAction2);
+ }
+ if (this.customCopyAction3 != null) {
+ subMenu.add(customCopyAction3);
+ }
mgr.add(subMenu);
-
}
}
/**
private SelectionListenerAction addToQuickListAction;
private SelectionListenerAction removeFromQuickListAction;
private SelectionListenerAction viewTableAction;
- private SelectionListenerAction addSchemaAction;
private SelectionListenerAction viewTableDetailsAction;
private SelectionListenerAction nextSequenceAction;
this.openQueryAction = new OpenQueryAction(this.viewPart);
this.viewTableAction = new ViewTableAction(this.viewPart);
- this.addSchemaAction = new AddSchemaAction(this.viewPart);
this.refreshAction = new RefreshBookmarkAction(this.viewPart);
this.renameAction = new RenameAction(this.viewPart);
this.copyAction = new CopyAction(this.viewPart, this, selectionProvider);
if (getStructuredSelection().size() == 1 &&
isEverySelectionInstanceof(BookmarkNode.class)) {
-
- menu.add(new Separator());
- addToMenu(menu, this.addSchemaAction);
}
if (isEverySelectionInstanceof(QueryNode.class)) {
final class CopyAction extends SelectionListenerAction {
- private IViewPart view;
private BookmarkClipboard bookmarkClipboard;
/**
ISelectionProvider selectionProvider) {
super(Messages.getString(CopyAction.class.getName() + ".text"));
setImageDescriptor(QuantumPlugin.getImageDescriptor("copy.gif"));
- this.view = view;
this.bookmarkClipboard = bookmarkClipboard;
selectionProvider.addSelectionChangedListener(this);
}
package com.quantum.view.bookmark;
+import java.sql.SQLException;
+
import com.quantum.model.Column;
import com.quantum.model.Entity;
import com.quantum.model.EntityHolder;
+import com.quantum.model.NotConnectedException;
import com.quantum.model.SchemaHolder;
import com.quantum.model.Table;
import com.quantum.model.View;
}
}
- public Object[] getChildren() {
+ public Object[] getChildren() throws NotConnectedException, SQLException {
initializeChildren();
if (this.children.size() > 0) {
return (ColumnNode[]) this.children.toArray(new ColumnNode[this.children.size()]);
}
}
- protected synchronized void initializeChildren() {
+ protected synchronized void initializeChildren() throws NotConnectedException, SQLException {
this.children.clear();
Column[] columns = this.entity.getColumns();
for (int i = 0, length = (columns == null) ? 0 : columns.length;
}
public String getLabelName() {
- return (this.longFormName) ? this.entity.getCondQualifiedName() : this.entity.getName();
+ return (this.longFormName) ? this.entity.getQualifiedName() : this.entity.getName();
}
public boolean isTable() {
public int compareTo(Object o) {
if (o instanceof EntityNode) {
EntityNode that = (EntityNode) o;
- return this.entity.getCondQualifiedName().compareTo(
- that.entity.getCondQualifiedName());
+ return this.entity.getQualifiedName().compareTo(
+ that.entity.getQualifiedName());
} else {
return super.compareTo(o);
}
package com.quantum.view.bookmark;
import java.sql.SQLException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
this.children.add(entityNode);
}
}
+ Collections.sort(this.children);
if ((temp.size() > 0 || changed ) && !firstTimeInitialization) {
firePropertyChange("children", null, null);
}
package com.quantum.view.bookmark;
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.model.Bookmark;
-import com.quantum.model.BookmarkCollection;
-
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.SelectionListenerAction;
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.model.Bookmark;
+import com.quantum.model.BookmarkCollection;
+
final class PasteAction extends SelectionListenerAction {
- private IViewPart view;
private BookmarkClipboard bookmarkClipboard;
/**
* @param BookmarkView
ISelectionProvider selectionProvider) {
super(Messages.getString(PasteAction.class.getName() + ".text"));
setImageDescriptor(QuantumPlugin.getImageDescriptor("paste.gif"));
- this.view = view;
selectionProvider.addSelectionChangedListener(this);
this.bookmarkClipboard = bookmarkClipboard;
}
i < length;
i++) {
- this.children.put(entities[i].getCondQualifiedName(),
+ this.children.put(entities[i].getQualifiedName(),
new EntityNode(this, entities[i], true));
}
}
package com.quantum.view.bookmark;
-import com.quantum.Messages;
-import com.quantum.model.Bookmark;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
-import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.SelectionListenerAction;
+import com.quantum.Messages;
+import com.quantum.model.Bookmark;
+import com.quantum.wizards.BookmarkNameWizardPage;
+
/**
* @author BC
*/
public class RenameAction extends SelectionListenerAction {
+
+ public class RenameWizard extends Wizard implements PropertyChangeListener {
+
+ private BookmarkNameWizardPage page;
+ private String name;
+
+ public RenameWizard(String name) {
+ this.name = name;
+ }
+
+ public void addPages() {
+ super.addPages();
+ this.page = new BookmarkNameWizardPage("pageName", this.name);
+ this.page.addPropertyChangeListener(this);
+ addPage(this.page);
+ }
+
+ public void dispose() {
+ this.page.removePropertyChangeListener(this);
+ super.dispose();
+ }
+ public boolean performFinish() {
+ return true;
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if ("name".equals(event.getPropertyName())) {
+ setName((String) event.getNewValue());
+ }
+ }
+
+ public String getName() {
+ return this.name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+
private IViewPart viewPart;
super(Messages.getString(RenameAction.class.getName() + ".text"));
this.viewPart = viewPart;
}
-
-
/**
* @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
- InputDialog dialog = new InputDialog(this.viewPart.getSite().getShell(), "Select a new name",
- "Name: ", getBookmark().getName(), null);
+ RenameWizard wizard = new RenameWizard(getBookmark().getName());
+ WizardDialog dialog = new WizardDialog(this.viewPart.getSite().getShell(), wizard);
int result = dialog.open();
- if (result == InputDialog.OK) {
- getBookmark().setName(dialog.getValue());
+ if (result == WizardDialog.OK) {
+ getBookmark().setName(wizard.getName());
}
}
}
* @see com.quantum.view.bookmark.TreeNode#getImageName()
*/
protected String getImageName() {
- return this.schema.isDefault() ? "user.gif" : "schema.gif";
+ return this.schema.isDefault()
+ ? "user.gif"
+ : this.schema.exists()
+ ? "schema.gif"
+ : "missingschema.gif";
}
/**
package com.quantum.view.bookmark;
import java.beans.PropertyChangeEvent;
+import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkHolder;
+import com.quantum.model.NotConnectedException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.graphics.Image;
this.parent = parent;
}
- public abstract Object[] getChildren();
+ public abstract Object[] getChildren() throws NotConnectedException, SQLException;
public TreeNode getParent() {
return this.parent;
}
public Object getAdapter(Class adapter) {
return null;
}
- protected abstract void initializeChildren();
- public void reload() {
+ protected abstract void initializeChildren() throws SQLException, NotConnectedException;
+ public void reload() throws NotConnectedException, SQLException {
if (isInitialized()) {
initializeChildren();
for (Iterator i = this.children.iterator(); i.hasNext(); ) {
import com.quantum.model.BookmarkCollection;
import com.quantum.model.Column;
import com.quantum.model.Entity;
+import com.quantum.model.ForeignKey;
import com.quantum.model.Index;
+import com.quantum.model.NotConnectedException;
import com.quantum.model.Schema;
/**
// TODO: limit the columns
Entity relatedEntity = getEntityFromBookmark();
if (relatedEntity != null) {
- Column[] columns = relatedEntity.getColumns();
- return columns;
+ try {
+ Column[] columns = relatedEntity.getColumns();
+ return columns;
+ } catch (NotConnectedException e) {
+ return new Column[0];
+ } catch (SQLException e) {
+ return new Column[0];
+ }
} else {
return null;
}
return new Index[0];
}
- public Column getColumn(String columnName) {
+ public Column getColumn(String columnName) throws NotConnectedException, SQLException {
Entity relatedEntity = getEntityFromBookmark();
return relatedEntity == null
? null : relatedEntity.getColumn(columnName);
}
- public String getCondQualifiedName() {
+ public String getQualifiedName() {
return this.schema + "." + this.name;
}
* @see com.quantum.model.Entity#getQuotedTableName()
*/
public String getQuotedTableName() {
- return getBookmark().getAdapter().filterTableName(getCondQualifiedName());
+ return getBookmark().getAdapter().filterTableName(getQualifiedName());
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object arg0) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see com.quantum.model.Entity#getExportedKeys()
+ */
+ public ForeignKey[] getExportedKeys() throws NotConnectedException, SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.quantum.model.Entity#getImportedKeys()
+ */
+ public ForeignKey[] getImportedKeys() throws NotConnectedException, SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.quantum.model.Entity#getReferences()
+ */
+ public ForeignKey[] getReferences() throws NotConnectedException, SQLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
if (node.getOrder() > getOrder()) return -1;
if (node.getOrder() < getOrder()) return 1;
// If the order is the same, we use alphabetical order
- return getEntity().getCondQualifiedName().compareTo(
- node.getEntity().getCondQualifiedName());
+ return getEntity().getQualifiedName().compareTo(
+ node.getEntity().getQualifiedName());
} else throw new ClassCastException();
}
*/
public boolean equals(Object obj) {
if (!(obj instanceof ObjectNode)) return false;
- return (getEntity().getCondQualifiedName().equals(
- ((ObjectNode) obj).getEntity().getCondQualifiedName()));
+ return (getEntity().getQualifiedName().equals(
+ ((ObjectNode) obj).getEntity().getQualifiedName()));
}
/**
*/
public String getQuery() {
String result = new String(""); //$NON-NLS-1$
- result = "SELECT " + metadata.getColumnsString() + " FROM " + getEntity().getCondQualifiedName(); //$NON-NLS-1$ //$NON-NLS-2$
+ result = "SELECT " + metadata.getColumnsString() + " FROM " + getEntity().getQualifiedName(); //$NON-NLS-1$ //$NON-NLS-2$
return result;
}
package com.quantum.view.subset;
+import java.sql.SQLException;
import java.util.Vector;
import com.quantum.Messages;
+import com.quantum.model.NotConnectedException;
import com.quantum.sql.metadata.MetaDataXMLInterface;
import com.quantum.view.bookmark.ColumnNode;
import com.quantum.view.bookmark.TreeNode;
return subsets.toArray();
} else if (parentElement instanceof TreeNode) {
TreeNode node = (TreeNode) parentElement;
- return node.getChildren();
+ try {
+ return node.getChildren();
+ } catch (NotConnectedException e) {
+ } catch (SQLException e) {
+ }
}
return SubsetRoot.EMPTY_ARRAY;
}
import java.sql.SQLException;
import java.util.Vector;
-import com.quantum.Messages;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-import com.quantum.model.NotConnectedException;
-import com.quantum.sql.FilterSort;
-import com.quantum.sql.SQLHelper;
-import com.quantum.sql.SQLResults;
-
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
+import com.quantum.Messages;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
+import com.quantum.model.Entity;
+import com.quantum.model.NotConnectedException;
+import com.quantum.sql.FilterSort;
+import com.quantum.sql.SQLHelper;
+import com.quantum.sql.SQLResults;
+
public class TableAdapter {
- private Table table = null;
-
public static final String DEFAULT = ""; //$NON-NLS-1$
public static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
public static final String UTF_16 = "UTF-16"; //$NON-NLS-1$
try {
if (entity != null) {
totalSize = SQLHelper.getSize(
- bookmark.getConnection(), entity.getCondQualifiedName(),
- AdapterFactory.getInstance().getAdapter(bookmark.getType()));
+ bookmark.getConnection(), entity.getQualifiedName(),
+ bookmark.getAdapter());
}
} catch (SQLException e) {
e.printStackTrace();
public String getQuery() {
if (entity != null) {
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+ DatabaseAdapter adapter = bookmark.getAdapter();
if (adapter == null) throw new RuntimeException();
- else return adapter.getTableQuery((entity).getCondQualifiedName()) + extra.toString();
+ else return adapter.getTableQuery((entity).getQualifiedName()) + extra.toString();
}
return query;
}
}
}
public void loadTable(Table table) {
- this.table = table;
table.setHeaderVisible(true);
for (int i = 0; i < columnNames.size(); i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
this.extra = extra;
}
public String getTable() {
- return (entity != null) ? entity.getCondQualifiedName() : null;
+ return (entity != null) ? entity.getQualifiedName() : null;
}
public void setQuery(String query) {
ta.setEncoding(TableAdapter.DEFAULT);
}
}
- private static TableView instance = null;
private TabFolder tabs = null;
private Composite parent;
private Vector extensionVector;
if (tableName != null) {
tabItem.setText(bookmark.getName() + ":" + tableName);
} else {
- tabItem.setText(bookmark.getName() + ":" + adapter.getQuery());
+ tabItem.setText(bookmark.getName() + ": SQL");
+ tabItem.setToolTipText(bookmark.getName() + ":\n" + adapter.getQuery());
}
toolBar.getPrevious().setEnabled(adapter.hasPreviousPage());
}
public void createPartControl(Composite parent) {
- instance = this;
this.parent = parent;
initActions();
tabs = new TabFolder(parent, SWT.NONE);
--- /dev/null
+package com.quantum.view.widget;
+
+import org.eclipse.jface.viewers.ContentViewer;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * <p>A Combo viewer.
+ *
+ * <p>In Eclipse version 3.0, a standard JFace ComboViewer class exists.
+ *
+ * @author BC Holmes
+ */
+public class ComboViewer extends ContentViewer {
+
+ private Combo combo;
+
+ private Object[] objects = new Object[0];
+
+ public ComboViewer(Composite parent) {
+ this.combo = new Combo(parent, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
+ this.combo.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ ComboViewer.this.fireSelectionChanged(new SelectionChangedEvent(
+ ComboViewer.this, getSelection()) );
+ }
+ });
+ }
+
+ public Control getControl() {
+ return this.combo;
+ }
+
+ public ISelection getSelection() {
+ int index = this.combo.getSelectionIndex();
+
+ return (this.objects == null || index >= this.objects.length || index < 0)
+ ? new StructuredSelection()
+ : new StructuredSelection(this.objects[index]);
+ }
+
+ protected void inputChanged(Object input, Object oldInput) {
+ super.inputChanged(input, oldInput);
+
+ if (input == null) {
+ this.objects = new Object[0];
+ } else {
+ this.objects = ((IStructuredContentProvider) getContentProvider()).getElements(input);
+ for (int i = 0, length = this.objects == null ? 0 : this.objects.length; i < length; i++) {
+ String label = ((ILabelProvider) getLabelProvider()).getText(this.objects[i]);
+ this.combo.add(label);
+ }
+ }
+ }
+ public void refresh() {
+ }
+
+ public void setSelection(ISelection selection, boolean reveal) {
+ if (selection != null && selection instanceof IStructuredSelection) {
+ Object object = ((IStructuredSelection) selection).getFirstElement();
+ for (int i = 0, length = this.objects == null ? 0 : this.objects.length;
+ object != null && i < length; i++) {
+ if (this.objects[i] == object) {
+ this.combo.select(i);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.quantum.wizards;
+
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.adapters.AdapterFactory;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.BookmarkCollection;
+import com.quantum.model.JDBCDriver;
+import com.quantum.ui.dialog.SimpleSelectionDialog;
+import com.quantum.util.JarUtil;
+import com.quantum.view.widget.ComboViewer;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author BC Holmes
+ */
+public class AddDriverWizard extends Wizard {
+
+ public class PageImpl extends WizardPage {
+
+ private FileDialog fileDialog;
+
+ private Text driverFileName;
+ private Text driverClassName;
+ private ComboViewer type;
+ private DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList();
+
+ public PageImpl() {
+ super("");
+ }
+ public void createControl(Composite parent) {
+ setPageComplete(false);
+
+ setTitle(Messages.getString(getClass(), "title"));
+ setDescription(Messages.getString(getClass(), "description"));
+
+
+ parent.setLayout(new GridLayout());
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+ layout.numColumns = 3;
+ GridData fullHorizontal = new GridData(
+ GridData.FILL_HORIZONTAL |
+ GridData.VERTICAL_ALIGN_BEGINNING);
+ composite.setLayoutData(fullHorizontal);
+
+
+ this.fileDialog = new FileDialog(composite.getShell(), SWT.OPEN);
+ this.fileDialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
+ this.fileDialog.setFilterNames(new String[] {
+ Messages.getString("BookmarkWizard.JarFiles"),
+ Messages.getString("BookmarkWizard.ZipFiles"),
+ Messages.getString("BookmarkWizard.AllFiles") });
+
+ Label label = new Label(composite, SWT.NULL);
+ label.setText(Messages.getString(getClass(), "fileName"));
+ this.driverFileName = new Text(composite, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+ this.driverFileName.setLayoutData(fullHorizontal);
+
+ this.driverFileName.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent event) {
+ updateButtons();
+ }
+
+ });
+
+ Button button = new Button(composite, SWT.PUSH);
+ button.setText(Messages.getString(getClass(), "browse"));
+
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ PageImpl.this.fileDialog.setFilterPath(QuantumPlugin.getDefault()
+ .getPreferenceStore().getString(
+ "quantum.dialogs.bookmarkwizard.path"));
+ String filename = PageImpl.this.fileDialog.open();
+ if (filename != null) {
+ PageImpl.this.driverFileName.setText(filename);
+ QuantumPlugin.getDefault().getPreferenceStore().setValue(
+ "quantum.dialogs.bookmarkwizard.path", filename);
+ AddDriverWizard.this.setDriverFileName(filename);
+ updateButtons();
+ }
+ }
+ });
+
+ label = new Label(composite, SWT.NULL);
+ label.setText(Messages.getString(getClass(), "driverClassName"));
+ this.driverClassName = new Text(composite, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+ this.driverClassName.setLayoutData(fullHorizontal);
+
+ this.driverClassName.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent event) {
+ AddDriverWizard.this.setDriverClassName(((Text) event.getSource()).getText());
+ updateButtons();
+ }
+
+ });
+ button = new Button(composite, SWT.PUSH);
+ button.setText(Messages.getString(getClass(), "browse"));
+
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ SimpleSelectionDialog dialog = new SimpleSelectionDialog(
+ getShell(), "Select a Driver", JarUtil.getAllDriverNames(
+ getDriverFile()), QuantumPlugin.getImage("class.gif"));
+ if (dialog.open() == SimpleSelectionDialog.OK) {
+ IStructuredSelection selection = dialog.getSelection();
+ if (!selection.isEmpty()) {
+ String className = (String) selection.getFirstElement();
+ PageImpl.this.driverClassName.setText(
+ className);
+ AddDriverWizard.this.setDriverClassName(className);
+ updateButtons();
+ }
+
+
+ }
+ }
+ });
+ label = new Label(composite, SWT.NULL);
+ label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
+ this.type = new ComboViewer(composite);
+ this.type.setContentProvider(new IStructuredContentProvider() {
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ public Object[] getElements(Object inputElement) {
+ return PageImpl.this.adapters;
+ }
+ });
+
+ this.type.setLabelProvider(new ILabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+ public String getText(Object element) {
+ if (element != null && element instanceof DatabaseAdapter) {
+ return ((DatabaseAdapter) element).getDisplayName();
+ } else {
+ return "";
+ }
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ });
+
+ type.setInput(this);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ type.getControl().setLayoutData(fullHorizontal);
+
+ type.setSelection(new StructuredSelection(
+ AdapterFactory.getInstance().getAdapter(AdapterFactory.GENERIC)));
+
+ setControl(composite);
+ }
+ protected void updateButtons() {
+ Class driver = JarUtil.loadDriverClass(getDriverFile(), getDriverClassName());
+ setPageComplete(driver != null);
+
+ String adapterType = AdapterFactory.getInstance().getAdapterType(getDriverClassName());
+ if (adapterType != null) {
+ this.type.setSelection(new StructuredSelection(
+ AdapterFactory.getInstance().getAdapter(adapterType)));
+ }
+ }
+ protected String getDriverClassName() {
+ return this.driverClassName == null ? null : this.driverClassName.getText();
+ }
+ protected String getDriverFile() {
+ return this.driverFileName == null ? null : this.driverFileName.getText();
+ }
+
+ protected String getDriverType() {
+ DatabaseAdapter driverInfo = (DatabaseAdapter)
+ ((IStructuredSelection) this.type.getSelection()).getFirstElement();
+ return (driverInfo == null) ? null : driverInfo.getType();
+ }
+ }
+ private PageImpl page;
+
+ private String driverClassName;
+ private String driverFileName;
+ private String driverType;
+
+
+ public void addPages() {
+ this.page = new PageImpl();
+ addPage(page);
+ }
+
+ public AddDriverWizard() {
+ super();
+ setWindowTitle(Messages.getString(getClass(), "windowTitle"));
+ }
+
+ public boolean performFinish() {
+ JDBCDriver driver = new JDBCDriver(
+ getDriverClassName(),
+ getDriverFileName(),
+ this.page.getDriverType());
+ BookmarkCollection.getInstance().addDriver(driver);
+ return true;
+ }
+
+
+ /**
+ * @return Returns the driverClassName.
+ */
+ public String getDriverClassName() {
+ return this.driverClassName;
+ }
+ /**
+ * @param driverClassName The driverClassName to set.
+ */
+ public void setDriverClassName(String driverClassName) {
+ this.driverClassName = driverClassName;
+ }
+ /**
+ * @return Returns the driverType.
+ */
+ public String getDriverType() {
+ return this.driverType;
+ }
+ /**
+ * @param driverType The driverType to set.
+ */
+ public void setDriverType(String driverType) {
+ this.driverType = driverType;
+ }
+ /**
+ * @return Returns the driverFileName.
+ */
+ public String getDriverFileName() {
+ return this.driverFileName;
+ }
+ /**
+ * @param driverFileName The driverFileName to set.
+ */
+ public void setDriverFileName(String driverFileName) {
+ this.driverFileName = driverFileName;
+ }
+}
\ No newline at end of file
package com.quantum.wizards;
+import java.sql.SQLException;
+
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.model.Bookmark;
import com.quantum.model.Column;
import com.quantum.model.ConnectionException;
import com.quantum.model.Entity;
+import com.quantum.model.NotConnectedException;
import com.quantum.sql.TableRow;
import com.quantum.view.ViewHelper;
import com.quantum.view.tableview.TableAdapter;
}
protected abstract String getQueryText();
protected void appendColumn(StringBuffer whereClause, Entity entity, String columnName, DatabaseAdapter adapter, String value) {
-
- if (adapter != null && entity != null && entity.getColumn(columnName) != null) {
- Column column = entity.getColumn(columnName);
+
+ if (adapter != null && entity != null && getColumn(entity, columnName) != null) {
+ Column column = getColumn(entity, columnName);
whereClause.append(adapter.quote(value, column.getType(), column.getTypeName()));
} else {
whereClause.append(value);
}
}
- public void init(TableRow row, TableAdapter adapter) {
+ /**
+ * @param entity
+ * @param columnName
+ * @return
+ * @throws NotConnectedException
+ * @throws SQLException
+ */
+ protected Column getColumn(Entity entity, String columnName) {
+ try {
+ return entity == null ? null : entity.getColumn(columnName);
+ } catch (NotConnectedException e) {
+ return null;
+ } catch (SQLException e) {
+ return null;
+ }
+ }
+ public void init(TableRow row, TableAdapter adapter) {
this.row = row;
this.adapter = adapter;
}
--- /dev/null
+package com.quantum.wizards;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import com.quantum.Messages;
+import com.quantum.model.JDBCDriver;
+
+
+class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
+
+ /* use this to paint a more helpful UI for the JDBC URL */
+ private JDBCDriver driver;
+ private String userid;
+ private String password;
+ private String connectionURL;
+ private boolean prompt;
+
+ /**
+ * Constructor for BookmarkPage.
+ * @param pageName
+ */
+ public BookmarkConnectionWizardPage(String pageName) {
+ super(pageName);
+ setTitle(Messages.getString(getClass(), "title"));
+ setDescription(Messages.getString(getClass(), "description"));
+ }
+ public void createControl(Composite parent) {
+ setPageComplete(false);
+
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 3;
+ layout.verticalSpacing = 9;
+
+ Label label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString(getClass(), "userid")); //$NON-NLS-1$
+ Text username = new Text(container, SWT.BORDER | SWT.SINGLE);
+
+
+ GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
+ fullHorizontal.horizontalSpan = 2;
+ username.setLayoutData(fullHorizontal);
+ username.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent event) {
+ String userid = ((Text) event.getSource()).getText();
+ setUserid(userid);
+ updateButtonState();
+ }
+ });
+
+ label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString(getClass(), "password")); //$NON-NLS-1$
+ final Text password = new Text(container, SWT.BORDER | SWT.SINGLE);
+ password.setEchoChar('*');
+ fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
+ fullHorizontal.horizontalSpan = 2;
+ password.setLayoutData(fullHorizontal);
+ password.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent event) {
+ String password = ((Text) event.getSource()).getText();
+ setPassword(password);
+ updateButtonState();
+ }
+ });
+
+ Button prompt = new Button(container, SWT.CHECK);
+ prompt.setText(Messages.getString(getClass(), "prompt")); //$NON-NLS-1$
+ fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
+ fullHorizontal.horizontalSpan = 3;
+ prompt.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$
+
+ Text connect = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
+ fullHorizontal.horizontalSpan = 2;
+ connect.setLayoutData(fullHorizontal);
+ connect.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent event) {
+ String connectionURL = ((Text) event.getSource()).getText();
+ setConnectionURL(connectionURL);
+ updateButtonState();
+ }
+ });
+ prompt.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ Button prompt = ((Button) event.getSource());
+ password.setEditable(!prompt.getSelection());
+ setPrompt(prompt.getSelection());
+ updateButtonState();
+ }
+ });
+
+ setControl(container);
+ }
+
+ /**
+ * @return Returns the driver.
+ */
+ public JDBCDriver getDriver() {
+ return this.driver;
+ }
+ /**
+ * @param driver The driver to set.
+ */
+ public void setDriver(JDBCDriver driver) {
+ this.driver = driver;
+ }
+ /**
+ *
+ */
+ private void updateButtonState() {
+ boolean complete = true;
+ complete &= (this.connectionURL != null
+ && this.connectionURL.trim().length() > 0);
+ complete &= (this.userid != null
+ && this.userid.trim().length() > 0);
+ setPageComplete(complete);
+ }
+ /**
+ * @return Returns the userid.
+ */
+ public String getUserid() {
+ return this.userid;
+ }
+ /**
+ * @param userid The userid to set.
+ */
+ public void setUserid(String userid) {
+ if (userid != null && !userid.equals(this.userid)) {
+ String original = this.userid;
+ this.userid = userid;
+ firePropertyChange("userid", original, userid);
+ }
+ }
+ /**
+ * @return Returns the prompt.
+ */
+ public boolean isPrompt() {
+ return this.prompt;
+ }
+ /**
+ * @param prompt The prompt to set.
+ */
+ public void setPrompt(boolean prompt) {
+ if (this.prompt != prompt) {
+ boolean original = this.prompt;
+ this.prompt = prompt;
+ firePropertyChange("prompt", original, prompt);
+ }
+ }
+ /**
+ * @return Returns the connectionURL.
+ */
+ public String getConnectionURL() {
+ return this.connectionURL;
+ }
+ /**
+ * @param connectionURL The connectionURL to set.
+ */
+ public void setConnectionURL(String connectionURL) {
+ if (connectionURL != null && !connectionURL.equals(this.connectionURL)) {
+ String original = this.connectionURL;
+ this.connectionURL = connectionURL;
+ firePropertyChange("connectionURL", original, connectionURL);
+ }
+ }
+ /**
+ * @return Returns the password.
+ */
+ public String getPassword() {
+ return this.password;
+ }
+ /**
+ * @param password The password to set.
+ */
+ public void setPassword(String password) {
+ if (password != null && !password.equals(this.password)) {
+ String original = this.password;
+ this.password = password;
+ firePropertyChange("password", original, password);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.quantum.wizards;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import com.quantum.Messages;
+import com.quantum.model.BookmarkCollection;
+
+
+/**
+ * @author BC
+ */
+public class BookmarkNameWizardPage extends PropertyChangeWizardPage {
+
+ private String name;
+ private final String originalName;
+
+ public BookmarkNameWizardPage(String pageName) {
+ this(pageName, null);
+ }
+
+ /**
+ * @param pageName
+ */
+ public BookmarkNameWizardPage(String pageName, String originalName) {
+ super(pageName);
+ this.originalName = originalName;
+ setTitle(Messages.getString(getClass(), "title"));
+ setDescription(Messages.getString(getClass(), "description"));
+ }
+
+ public void createControl(Composite parent) {
+ setPageComplete(false);
+
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.getString(getClass(), "name"));
+
+ Text name = new Text(composite, SWT.BORDER | SWT.SINGLE);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ name.setLayoutData(data);
+ if (this.originalName != null) {
+ name.setText(this.originalName);
+ }
+ name.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent event) {
+ String name = ((Text) event.getSource()).getText();
+ setName(name);
+ }
+ });
+ setControl(composite);
+ }
+
+ /**
+ *
+ */
+ private void setName(String bookmarkName) {
+ String errorMessage = null;
+ boolean done = true;
+ if (bookmarkName == null || bookmarkName.trim().length() == 0) {
+ errorMessage = Messages.getString(getClass(), "mustProvide");
+ done = false;
+ } else if (this.originalName != null && this.originalName.equals(bookmarkName)) {
+ done = false;
+ } else if (BookmarkCollection.getInstance().find(bookmarkName) != null) {
+ errorMessage = Messages.getString(getClass(), "alreadyExists");
+ done = false;
+ }
+
+ setErrorMessage(errorMessage);
+ setPageComplete(done);
+
+ if (errorMessage == null && !bookmarkName.equals(this.name)) {
+ String original = this.name;
+ this.name = bookmarkName;
+ firePropertyChange("name", original, bookmarkName);
+ }
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return this.name;
+ }
+}
package com.quantum.wizards;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DriverInfo;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkCollection;
import com.quantum.model.JDBCDriver;
+import com.quantum.model.Schema;
-public class BookmarkWizard extends Wizard {
- BookmarkPage mainPage;
+public class BookmarkWizard extends Wizard implements PropertyChangeListener {
+ private JDBCDriverSelectionWizardPage page1;
+ private BookmarkConnectionWizardPage page2;
+ private BookmarkNameWizardPage page3;
+ private SchemaSelectionWizardPage page4;
+ private Bookmark bookmark;
+
public void init() {
- System.out.println("Initing workbench"); //$NON-NLS-1$
setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
+ this.bookmark = new Bookmark();
}
public boolean performFinish() {
- System.out.println("perform finish workbench"); //$NON-NLS-1$
- String bookmarkName = mainPage.name.getText();
- if ( BookmarkCollection.getInstance().find(bookmarkName) != null){
- MessageDialog.openInformation(
- this.getShell(),Messages.getString("BookmarkWizard.Error"),Messages.getString("BookmarkWizard.bookmarkAlreadyExists")); //$NON-NLS-1$ //$NON-NLS-2$
- return false;
- }
-
- mainPage.performFinish();
+ BookmarkCollection.getInstance().addBookmark(this.bookmark);
+
return true;
}
public void addPages() {
- System.out.println("adding pages"); //$NON-NLS-1$
-// WizardPage page = new NewBookmarkPage1(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
-// addPage(page);
- mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
- addPage(mainPage);
- System.out.println("adding pages"); //$NON-NLS-1$
- }
-}
-
-class BookmarkPage extends WizardPage {
- public static final String ADD = "ADD"; //$NON-NLS-1$
- String action = ADD;
- Text name;
- Text username;
- Text password;
- Text schema;
- Text connect;
- Text driver;
- //List driverList;
- Combo type;
- Text driverFile;
- Button prompt;
-
- FileDialog dialog;
-
- DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
- /**
- * Constructor for BookmarkPage.
- * @param pageName
- */
- public BookmarkPage(String pageName) {
- super(pageName);
+ this.page1 = new JDBCDriverSelectionWizardPage("page1"); //$NON-NLS-1$
+ this.page1.addPropertyChangeListener(this);
+ addPage(this.page1);
+ this.page2 = new BookmarkConnectionWizardPage("page2"); //$NON-NLS-1$
+ this.page2.addPropertyChangeListener(this);
+ addPage(this.page2);
+ this.page3 = new BookmarkNameWizardPage("page3"); //$NON-NLS-1$
+ this.page3.addPropertyChangeListener(this);
+ addPage(this.page3);
+ this.page4 = new SchemaSelectionWizardPage("page4", this.bookmark); //$NON-NLS-1$
+ this.page4.addPropertyChangeListener(this);
+ addPage(this.page4);
}
- public void createControl(Composite parent) {
- System.out.println("page create control"); //$NON-NLS-1$
- dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
- dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- dialog.setFilterNames(new String[]{Messages.getString("BookmarkWizard.JarFiles"),Messages.getString("BookmarkWizard.ZipFiles"), Messages.getString("BookmarkWizard.AllFiles")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 2;
- layout.verticalSpacing = 9;
-
-
- Label label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.BookmarkNameAst")); //$NON-NLS-1$
- name = new Text(container, SWT.BORDER | SWT.SINGLE);
- GridData fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- name.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.UsernameAst")); //$NON-NLS-1$
- username = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- username.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.PasswordAst")); //$NON-NLS-1$
- password = new Text(container, SWT.BORDER | SWT.SINGLE);
- password.setEchoChar('*');
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- password.setLayoutData(fullHorizontal);
-
- this.prompt = new Button(container, SWT.CHECK);
- this.prompt.setText(Messages.getString("BookmarkWizard.Prompt")); //$NON-NLS-1$
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- fullHorizontal.horizontalSpan = 2;
- this.prompt.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.Schema")); //$NON-NLS-1$
- schema = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- schema.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.ConnectAst")); //$NON-NLS-1$
- connect = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- connect.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
- driver = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- driver.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
- type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
- String driverNames[] = new String[drivers.length];
- for (int i = 0; i < drivers.length; i++) {
- driverNames[i] = drivers[i].getDisplayName();
- }
- type.setItems(driverNames);
- type.select(0);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- type.setLayoutData(fullHorizontal);
-
- label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.DriverFilenameAst")); //$NON-NLS-1$
- driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- driverFile.setLayoutData(fullHorizontal);
-
- Button button = new Button(container, SWT.PUSH);
- button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
-
- button.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- // We retrieve the last saved path
- dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.bookmarkwizard.path")); //$NON-NLS-1$
- String filename = dialog.open();
- if (filename != null) {
- driverFile.setText(filename);
- // We save the used path
- QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.bookmarkwizard.path", filename); //$NON-NLS-1$
+ public void propertyChange(PropertyChangeEvent event) {
- }
- }
- });
-
- prompt.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- BookmarkPage.this.password.setEditable(!prompt.getSelection());
- }
- });
- //jsurfer start typical MySQL settings !?
- IPreferenceStore fStore = QuantumPlugin.getDefault().getPreferenceStore();
-
- username.setText(fStore.getString("phpeclipse.sql.username.connect"));
- connect.setText(fStore.getString("phpeclipse.sql.connect.connect"));
- driver.setText(fStore.getString("phpeclipse.sql.driver.connect"));
- String typeData = fStore.getString("phpeclipse.sql.type.connect");
- int selectedIndex = 0;
- for (int i = 0; i < drivers.length; i++) {
- if (typeData.equals(drivers[i].getDisplayName())) {
- selectedIndex = i;
- }
+ if ("driver".equals(event.getPropertyName())) {
+ JDBCDriver driver = (JDBCDriver) event.getNewValue();
+ this.bookmark.setJDBCDriver(driver);
+ this.page2.setDriver(driver);
+ } else if ("name".equals(event.getPropertyName())) {
+ this.bookmark.setName((String) event.getNewValue());
+ } else if ("userid".equals(event.getPropertyName())) {
+ this.bookmark.setUsername((String) event.getNewValue());
+ } else if ("password".equals(event.getPropertyName())) {
+ this.bookmark.setPassword((String) event.getNewValue());
+ } else if ("connectionURL".equals(event.getPropertyName())) {
+ this.bookmark.setConnect((String) event.getNewValue());
+ } else if ("prompt".equals(event.getPropertyName())) {
+ this.bookmark.setPromptForPassword(Boolean.TRUE.equals(event.getNewValue()));
+ } else if ("schemaRule".equals(event.getPropertyName())) {
+ this.bookmark.setSchemaRule(((Integer) event.getNewValue()).intValue());
+ } else if ("schemas".equals(event.getPropertyName())) {
+ this.bookmark.setSchemaSelections((Schema[]) event.getNewValue());
}
- type.select(selectedIndex);
- driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
-// jsurfer end
- setControl(container);
-
- setPageComplete(true);
- }
- public void updateDriverList() {
- /*try {
- JarFile file = new JarFile(driverFile.getText());
- Enumeration enum = file.entries();
- while (enum.hasMoreElements()) {
- JarEntry entry = (JarEntry) enum.nextElement();
- String className = entry.getName().replace('/', '.');
- if (className.endsWith("Driver.class")) {
- className = className.substring(0, className.lastIndexOf('.'));
- //driverList.add(className);
- }
- }
- } catch (IOException ex) {
- //driverList.removeAll();
- }*/
}
- public void performFinish() {
- Bookmark initialData = new Bookmark();
- initialData.setName(name.getText());
- initialData.setUsername(username.getText());
- initialData.setPromptForPassword(this.prompt.getSelection());
- if (initialData.getPromptForPassword()) {
- initialData.setPassword(""); //$NON-NLS-1$
- } else {
- initialData.setPassword(password.getText());
- }
- initialData.addSchema(schema.getText());
- initialData.setConnect(connect.getText());
- JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
- driver.getText(), driverFile.getText());
- initialData.setJDBCDriver(jdbcDriver);
- int selection = type.getSelectionIndex();
- if (selection >= 0) {
- initialData.setType(drivers[selection].getDriverType());
- }
- BookmarkCollection.getInstance().addBookmark(initialData);
+ public void dispose() {
+ this.page1.removePropertyChangeListener(this);
+ this.page2.removePropertyChangeListener(this);
+ this.page3.removePropertyChangeListener(this);
+ this.page4.removePropertyChangeListener(this);
+ super.dispose();
}
-}
\ No newline at end of file
+}
+
package com.quantum.wizards;
-import com.quantum.Messages;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import com.quantum.Messages;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
+import com.quantum.model.Column;
+import com.quantum.model.Entity;
+
public class DeleteRowPage extends BaseSQLPage implements SQLPage {
String[] columnNames;
Text[] values;
whereValues[i] = new Button(container, SWT.CHECK);
whereValues[i].setText(Messages.getString("DeleteRowPage.WhereClause")); //$NON-NLS-1$
// we check if it's a primary key to select it in the WHERE clause
- if (entity != null && entity.getColumn(columnNames[i]).isPrimaryKey()) {
- whereValues[i].setSelection(true);
- } else {
- whereValues[i].setSelection(false);
- }
+ Column column = getColumn(entity, columnNames[i]);
+ whereValues[i].setSelection(column == null ? false : column.isPrimaryKey());
whereValues[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
StringBuffer whereClause = new StringBuffer();
Bookmark bookmark = row.getBookmark();
Entity entity = row.getEntity();
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+ DatabaseAdapter adapter = bookmark.getAdapter();
int numSelected = 0;
for (int i = 0; i < columnNames.length; i++) {
package com.quantum.wizards;
-import com.quantum.Messages;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import com.quantum.Messages;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
+import com.quantum.model.Entity;
+
public class InsertRowPage extends BaseSQLPage implements SQLPage {
String[] columnNames;
Text[] values;
StringBuffer namesClause = new StringBuffer();
Bookmark bookmark = row.getBookmark();
Entity entity = row.getEntity();
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+ DatabaseAdapter adapter = bookmark.getAdapter();
numColumns = 0;
for (int i = 0; i < columnNames.length; i++) {
--- /dev/null
+package com.quantum.wizards;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+import com.quantum.Messages;
+import com.quantum.model.JDBCDriver;
+import com.quantum.view.JDBCDriverTableViewer;
+
+/**
+ * @author BC
+ */
+public class JDBCDriverSelectionWizardPage extends PropertyChangeWizardPage implements ISelectionChangedListener {
+
+ private JDBCDriverTableViewer tableViewer;
+
+ private JDBCDriver driver;
+
+ /**
+ * @param pageName
+ */
+ protected JDBCDriverSelectionWizardPage(String pageName) {
+ super(pageName);
+
+ setTitle(Messages.getString(getClass(), "title"));
+ setDescription(Messages.getString(getClass(), "description"));
+ }
+
+ public void createControl(Composite parent) {
+ setPageComplete(false);
+ Composite container = createBasicContainer(parent, 1);
+ GridLayout layout = new GridLayout(1, false);
+ container.setLayout(layout);
+
+ this.tableViewer = new JDBCDriverTableViewer(container);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ this.tableViewer.getControl().setLayoutData(data);
+ this.tableViewer.addSelectionChangedListener(this);
+
+ Button newDriver = new Button(container, SWT.PUSH);
+ newDriver.setText(Messages.getString(getClass(), "addDriver"));
+ newDriver.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ AddDriverWizard wizard = new AddDriverWizard();
+ WizardDialog dialog =
+ new WizardDialog(getShell(), wizard);
+ dialog.open();
+ }
+ });
+ data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
+ newDriver.setLayoutData(data);
+
+ setControl(container);
+ }
+ /**
+ * @param parent
+ */
+ private Composite createBasicContainer(Composite parent, int numberOfColumns) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = numberOfColumns;
+ layout.verticalSpacing = 9;
+ GridData fullHorizontal = new GridData(GridData.FILL_BOTH);
+ container.setLayoutData(fullHorizontal);
+ return container;
+ }
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ setPageComplete(!selection.isEmpty());
+ if (!selection.isEmpty()) {
+ setDriver((JDBCDriver) selection.getFirstElement());
+ }
+
+ }
+ /**
+ * @return Returns the driver.
+ */
+ public JDBCDriver getDriver() {
+ return this.driver;
+ }
+ /**
+ * @param driver The driver to set.
+ */
+ public void setDriver(JDBCDriver driver) {
+ if (this.driver != driver) {
+ JDBCDriver original = this.driver;
+ this.driver = driver;
+ firePropertyChange("driver", original, driver);
+ }
+ }
+ public void dispose() {
+ this.tableViewer.dispose();
+ super.dispose();
+ }
+}
\ No newline at end of file
+++ /dev/null
-package com.quantum.wizards;
-
-import java.io.File;
-
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.Text;
-
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.model.BookmarkCollection;
-import com.quantum.ui.dialog.AddDriverDialog;
-import com.quantum.view.JDBCDriverContentProvider;
-import com.quantum.view.JDBCDriverLabelProvider;
-
-/**
- * @author BC
- */
-public class NewBookmarkPage1 extends WizardPage {
-
- private FileDialog fileDialog;
-
- private Text driverFileName;
-
- private TableViewer tableViewer;
-
- /**
- * @param pageName
- */
- protected NewBookmarkPage1(String pageName) {
- super(pageName);
- }
-
- public void createControl(Composite parent) {
- Composite container = createBasicContainer(parent, 1);
- GridLayout layout = new GridLayout(2, false);
- container.setLayout(layout);
-
- Label label = new Label(container, SWT.NONE);
- label.setText("Select a driver");
- GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
- data.horizontalSpan = 2;
- label.setLayoutData(data);
-
- Table table = new Table(container, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
- table.setHeaderVisible(true);
- for (int i = 0, length = 4; i < length; i++) {
- TableColumn column = new TableColumn(table, SWT.NONE);
- column.setText(Messages.getString(getClass(), "driverColumn" + i));
- }
-
- for (int i = 0, length = 4; i < length; i++) {
- table.getColumn(i).pack();
- }
-
- this.tableViewer = new TableViewer(table);
- data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
- this.tableViewer.getControl().setLayoutData(data);
- this.tableViewer.setContentProvider(new JDBCDriverContentProvider());
- this.tableViewer.setLabelProvider(new JDBCDriverLabelProvider());
- this.tableViewer.setColumnProperties(new String[] { "name", "className", "version", "jarFileName" });
-// Table table = ((Table) this.tableViewer.getControl());
- this.tableViewer.setInput(BookmarkCollection.getInstance());
-
-
- Button newDriver = new Button(container, SWT.PUSH);
- newDriver.setText("Add driver...");
- newDriver.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- AddDriverDialog dialog = new AddDriverDialog(getShell());
- dialog.open();
- }
- });
- data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
- newDriver.setLayoutData(data);
-
- setControl(container);
- }
-
- /**
- * @param parent
- */
- private Composite createBasicContainer(Composite parent, int numberOfColumns) {
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = numberOfColumns;
- layout.verticalSpacing = 9;
- GridData fullHorizontal = new GridData(
- GridData.HORIZONTAL_ALIGN_BEGINNING,
- GridData.VERTICAL_ALIGN_BEGINNING,
- true, false);
- container.setLayoutData(fullHorizontal);
- return container;
- }
-
- /**
- * @param parent
- * @return
- */
- private Composite createNewDriverSelection(Composite parent) {
- this.fileDialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
- this.fileDialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
- this.fileDialog.setFilterNames(new String[] {
- Messages.getString("BookmarkWizard.JarFiles"),
- Messages.getString("BookmarkWizard.ZipFiles"),
- Messages.getString("BookmarkWizard.AllFiles") });
-
- Composite container = createBasicContainer(parent, 3);
-
- Label label = new Label(container, SWT.NULL);
- label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
- this.driverFileName = new Text(container, SWT.BORDER | SWT.SINGLE);
- GridData fullHorizontal = new GridData(
- GridData.HORIZONTAL_ALIGN_BEGINNING,
- GridData.VERTICAL_ALIGN_BEGINNING,
- false, false);
- this.driverFileName.setLayoutData(fullHorizontal);
-
- Button button = new Button(container, SWT.PUSH);
- button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
-
- button.addSelectionListener(new SelectionListener() {
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- public void widgetSelected(SelectionEvent e) {
- NewBookmarkPage1.this.fileDialog.setFilterPath(QuantumPlugin.getDefault()
- .getPreferenceStore().getString(
- "quantum.dialogs.bookmarkwizard.path"));
- String filename = NewBookmarkPage1.this.fileDialog.open();
- if (filename != null) {
- NewBookmarkPage1.this.driverFileName.setText(filename);
- QuantumPlugin.getDefault().getPreferenceStore().setValue(
- "quantum.dialogs.bookmarkwizard.path", filename);
- }
- }
- });
- return container;
- }
-
- // public boolean isPageComplete() {
- // File file = getDriverFile();
- // if (file == null) {
- // return false;
- // } else if (!file.exists() || !file.isFile()) {
- // return false;
- // } else {
- // return true;
- // }
- // }
- //
- private File getDriverFile() {
- return (this.driverFileName == null || this.driverFileName.getText() == null) ? null
- : new File(this.driverFileName.getText());
- }
-}
\ No newline at end of file
--- /dev/null
+package com.quantum.wizards;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+import org.eclipse.jface.wizard.WizardPage;
+
+
+/**
+ * @author BC
+ */
+public abstract class PropertyChangeWizardPage extends WizardPage {
+
+ protected PropertyChangeWizardPage(String pageName) {
+ super(pageName);
+ }
+
+ private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
+
+ /**
+ * @param listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ this.propertyChangeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * @param listener
+ */
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ this.propertyChangeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * @param propertyName
+ * @param oldValue
+ * @param newValue
+ */
+ protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
+ this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
+ }
+ /**
+ * @param propertyName
+ * @param oldValue
+ * @param newValue
+ */
+ protected void firePropertyChange(String propertyName, int oldValue, int newValue) {
+ this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
+ }
+ /**
+ * @param propertyName
+ * @param oldValue
+ * @param newValue
+ */
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
+ }
+}
--- /dev/null
+package com.quantum.wizards;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import com.quantum.Messages;
+import com.quantum.model.Bookmark;
+import com.quantum.view.SchemaSelectionControl;
+
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * @author BC
+ */
+public class SchemaSelectionWizardPage extends PropertyChangeWizardPage {
+
+ private final Bookmark bookmark;
+ private SchemaSelectionControl control;
+ private PropertyChangeListener listener;
+
+ /**
+ * @param pageName
+ */
+ protected SchemaSelectionWizardPage(String pageName, Bookmark bookmark) {
+ super(pageName);
+ this.bookmark = bookmark;
+ setTitle(Messages.getString(getClass(), "title"));
+ setDescription(Messages.getString(getClass(), "description"));
+ }
+
+ public void createControl(Composite parent) {
+ control = new SchemaSelectionControl(parent, this.bookmark);
+ control.addPropertyChangeListener(this.listener = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ firePropertyChange(event.getPropertyName(), event.getOldValue(), event.getNewValue());
+ }
+ });
+ setControl(control);
+ }
+ public void dispose() {
+ if (this.listener != null) {
+ this.control.removePropertyChangeListener(this.listener);
+ }
+ super.dispose();
+ }
+}
package com.quantum.wizards;
-import com.quantum.Messages;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.adapters.DatabaseAdapter;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import com.quantum.Messages;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
+import com.quantum.model.Entity;
+
public class UpdateRowPage extends BaseSQLPage implements SQLPage {
String[] columnNames;
Text[] oldValues;
});
primaryKeys[i] = new Button(container, SWT.CHECK);
primaryKeys[i].setText("Where"); //$NON-NLS-1$
- if (entity != null && entity.getColumn(columnNames[i]).isPrimaryKey())
+ if (entity != null && getColumn(entity, columnNames[i]).isPrimaryKey())
primaryKeys[i].setSelection(true);
primaryKeys[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
StringBuffer whereClause = new StringBuffer();
Bookmark bookmark = row.getBookmark();
Entity entity = row.getEntity();
- DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+ DatabaseAdapter adapter = bookmark.getAdapter();
int numValuesSet = 0;
int numValuesWhere = 0;