--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.core.boot_2.1.0/boot.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.boot_2.1.0/bootsrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.core.runtime_2.1.0/runtime.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.runtime_2.1.0/runtimesrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.core.resources_2.1.0/resources.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.resources_2.1.0/resourcessrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.swt.win32_2.1.0/ws/win32/swt.jar" sourcepath="ORG_ECLIPSE_PLATFORM_WIN32_SOURCE_SRC/org.eclipse.swt.win32_2.1.0/ws/win32/swtsrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui_2.1.0/ui.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui_2.1.0/uisrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.text_2.1.0/text.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.text_2.1.0/textsrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.jface_2.1.0/jface.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.jface_2.1.0/jfacesrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.jface.text_2.1.0/jfacetext.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.jface.text_2.1.0/jfacetextsrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui.views_2.1.0/views.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui.views_2.1.0/viewssrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui.workbench_2.1.0/workbench.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui.workbench_2.1.0/workbenchsrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui.win32_2.1.0/workbenchwin32.jar" sourcepath="ORG_ECLIPSE_PLATFORM_WIN32_SOURCE_SRC/org.eclipse.ui.win32_2.1.0/workbenchwin32src.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui.workbench.texteditor_2.1.0/texteditor.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui.workbench.texteditor_2.1.0/texteditorsrc.zip"/>
+ <classpathentry kind="var"
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui.editors_2.1.0/editors.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui.editors_2.1.0/editorssrc.zip"/>
+ <classpathentry kind="var" path="JRE_LIB" sourcepath="JRE_SRC"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>net.sourceforge.phpeclipse.sql</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+P7 332
+#IMGINFO:16x16 Greyscale (883 bytes)
+#END_OF_COMMENTS
+16 16 255
+I$IIÛ¶¶¶IH%IÛ¶¶ÚI$IIÛ¶¶¶IH%IÛ¶¶ÚI$IImIIIIHJl%Û¶¶I$II¶’’¶‘’¶’$Û¶ÛÛ¶¶H“H%H%IH“HI$IÛ¶¶H“µ’’¶’’‘II$IÛ¶¶H“H%H%IH“HI$IÛ¶¶H“µ’’¶’’‘II$II$II¶%H%H%I¶$Û¶ÛI$II¶’’¶‘’¶’$Û¶ÛI$II¶%H%H%I¶$Û¶ÛI$II¶’’¶‘’¶’$Û¶ÛÛ¶¶H“H%H%IH“HI$IÛ¶¶H“µ’’¶’’‘II$IÛ¶¶HI%IHÛ¶·¶H%IHÛ¶¶¶I$IIÛ¶¶Ú%H%I
\ No newline at end of file
--- /dev/null
+Quick and Dirty Install Instructions:
+1. Download and unpack eclipse 2.0 into a directory [e.g. C:\eclipse]
+2. Download Quantum
+3. Unzip quantum into the plugins directory of eclipse [e.g. C:\eclipse\plugins]
+4. Launch eclipse
+5. Open the Quantum DB Perspective [Go to Windows -> Open Perspective -> Other and select Quantum DB Perspective]
+6. Right click any where on the Bookmark view and select "New Bookmark..."
\ No newline at end of file
--- /dev/null
+phpsql.name = PHPEclipse SQL Utility
+perspective.name = PHPEclipse SQL Perspective
+sqllogview.name = PHPEclipse SQL Log
+queryhistoryview.name = Query History
+tableview.name = PHPEclipse Table View
+sqlqueryview.name PHPEclipse SQL Query Editor
+bookmarkview.name = Database Bookmarks
+bookmarkview.importboomarks = Import Bookmarks
+bookmarkview.exportbookmarks = Export Bookmarks
+phpsourceconsoleview.name = PHP Source Generator Console
+category.name = PHPEclipseSQL
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin
+ id="net.sourceforge.phpeclipse.sql"
+ name="%phpsql.name"
+ version="2.0.1"
+ provider-name="eclipseproject.de"
+ class="net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin">
+
+ <runtime>
+ <library name="phpeclipsesql.jar"/>
+ </runtime>
+ <requires>
+ <import plugin="org.eclipse.core.boot"/>
+ <import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.resources"/>
+ <import plugin="org.eclipse.swt"/>
+ <import plugin="org.eclipse.ui"/>
+ </requires>
+
+
+<!-- Perspective -->
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ name="%perspective.name"
+ icon="icons/quantum-ng.gif"
+ class="net.sourceforge.phpdt.sql.perspective.DBPerspective"
+ id="net.sourceforge.phpdt.sql.dbperspective">
+ </perspective>
+ </extension>
+<!-- Views -->
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ name="%category.name"
+ id="net.sourceforge.phpdt.sql.views">
+ </category>
+ <view
+ name="%sqllogview.name"
+ icon="icons/log.gif"
+ category="net.sourceforge.phpdt.sql.views"
+ class="net.sourceforge.phpdt.sql.view.SQLLogView"
+ id="net.sourceforge.phpdt.sql.view.logview">
+ </view>
+ <view
+ name="%queryhistoryview.name"
+ icon="icons/script.gif"
+ category="net.sourceforge.phpdt.sql.views"
+ class="net.sourceforge.phpdt.sql.view.QueryHistoryView"
+ id="net.sourceforge.phpdt.sql.view.queryhistoryview">
+ </view>
+ <view
+ name="%tableview.name"
+ icon="icons/table.gif"
+ category="net.sourceforge.phpdt.sql.views"
+ class="net.sourceforge.phpdt.sql.view.TableView"
+ id="net.sourceforge.phpdt.sql.view.tableview">
+ </view>
+ <view
+ name="%bookmarkview.name"
+ icon="icons/bookmarks.gif"
+ category="net.sourceforge.phpdt.sql.views"
+ class="net.sourceforge.phpdt.sql.view.BookmarkView"
+ id="net.sourceforge.phpdt.sql.view.bookmarkview">
+ </view>
+ <view
+ name="%sqlqueryview.name"
+ icon="icons/script.gif"
+ category="net.sourceforge.phpdt.sql.views"
+ class="net.sourceforge.phpdt.sql.view.SQLQueryView"
+ id="net.sourceforge.phpdt.sql.view.sqlqueryview">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views">
+ <view
+ name="%phpsourceconsoleview.name"
+ icon="icons/script.gif"
+ class="net.sourceforge.phpdt.sql.view.PHPSourceConsole"
+ id="net.sourceforge.phpdt.sql.view.phpsourceconsoleview">
+ </view>
+ </extension>
+<!-- Editors -->
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="Quantum SQL Editor"
+ icon="icons/script.gif"
+ extensions="sql,ddl"
+ contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
+ class="net.sourceforge.phpdt.sql.editors.SQLEditor"
+ id="net.sourceforge.phpdt.sql.editors.SQLEditor">
+ </editor>
+ </extension>
+<!-- Preferences -->
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ name="Quantum SQL Editor"
+ category="QuantumDB"
+ class="net.sourceforge.phpdt.sql.preferences.PreferencesPage"
+ id="net.sourceforge.phpdt.sql.preferences">
+ </page>
+ </extension>
+<!-- Menu for Bookmark View -->
+ <extension
+ point="org.eclipse.ui.viewActions">
+ <viewContribution
+ targetID="net.sourceforge.phpdt.sql.view.bookmarkview"
+ id="net.sourceforge.phpdt.sql.view.bookmarkview.menu">
+<!-- Export Bookmarks -->
+ <action
+ label="%bookmarkview.exportbookmarks"
+ icon="icons/export.gif"
+ tooltip="Exports bookmarks to a file"
+ class="net.sourceforge.phpdt.sql.actions.ExportBookmarksAction"
+ menubarPath="additions"
+ id="net.sourceforge.phpdt.sql.action.importbookmarks">
+ </action>
+<!-- Import Bookmarks -->
+ <action
+ label="%bookmarkview.importboomarks "
+ icon="icons/import.gif"
+ tooltip="Imports bookmarks from a file"
+ class="net.sourceforge.phpdt.sql.actions.ImportBookmarksAction"
+ menubarPath="additions"
+ id="net.sourceforge.phpdt.sql.action.importbookmarks">
+ </action>
+ </viewContribution>
+ </extension>
+
+</plugin>
--- /dev/null
+package net.sourceforge.phpdt.sql;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.resources.ISaveContext;
+import org.eclipse.core.resources.ISaveParticipant;
+import org.eclipse.core.resources.ISavedState;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+
+/**
+ * @author
+ */
+public class PHPEclipseSQLPlugin extends AbstractUIPlugin {
+ private static final String BUNDLE_NAME =
+ "net.sourceforge.phpdt.sql.PHPEclipseSQLResources";
+ private static final ResourceBundle RESOURCE_BUNDLE =
+ ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private static PHPEclipseSQLPlugin plugin;
+ public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.sql";
+
+ public PHPEclipseSQLPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ plugin = this;
+ }
+
+ public static PHPEclipseSQLPlugin getDefault() {
+ return plugin;
+ }
+ protected void readStateFrom(File target) {
+ BookmarkContentProvider.getInstance().load(target);
+ }
+
+ public void startup() throws CoreException {
+ super.startup();
+ ISaveParticipant saveParticipant = new QuantumSaveParticipant();
+ ISavedState lastState =
+ ResourcesPlugin.getWorkspace().addSaveParticipant(this, saveParticipant);
+ if (lastState == null)
+ return;
+ IPath location = lastState.lookup(new Path("save"));
+ if (location == null)
+ return;
+ // the plugin instance should read any important state from the file.
+ File f = getStateLocation().append(location).toFile();
+ readStateFrom(f);
+ }
+ protected void writeImportantState(File target) {
+ BookmarkContentProvider.getInstance().save(target);
+ }
+ public static ImageDescriptor getImageDescriptor(String name) {
+ ImageDescriptor descriptor = null;
+ try {
+ URL installURL =
+ PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
+ URL url = new URL(installURL, "icons/" + name);
+ descriptor = ImageDescriptor.createFromURL(url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return descriptor;
+ }
+ public static Image getImage(String name) {
+ return getImageDescriptor(name).createImage();
+ }
+
+ public void dispose() throws CoreException {
+ MultiSQLServer.getInstance().shutdown();
+ }
+
+ protected void initializeDefaultPluginPreferences() {
+ RGB BACKGROUND = new RGB(255, 255, 255);
+ RGB COMMENT = new RGB(88, 148, 64);
+ RGB IDENTIFIER = new RGB(0, 0, 0);
+ RGB KEYWORD = new RGB(126, 0, 75);
+ RGB STRING = new RGB(0, 0, 255);
+ RGB NUMERIC = new RGB(255, 0, 0);
+ RGB DEFAULT = new RGB(0, 0, 0);
+ IPreferenceStore store = getPreferenceStore();
+ PreferenceConverter.setDefault(
+ store,
+ "quantum.background.color",
+ BACKGROUND);
+ PreferenceConverter.setDefault(store, "quantum.text.color", DEFAULT);
+ PreferenceConverter.setDefault(store, "quantum.keyword.color", KEYWORD);
+ PreferenceConverter.setDefault(store, "quantum.comment.color", COMMENT);
+ PreferenceConverter.setDefault(store, "quantum.string.color", STRING);
+ PreferenceConverter.setDefault(store, "quantum.numeric.color", NUMERIC);
+ getPreferenceStore().setDefault("quantum.text.bold", false);
+ getPreferenceStore().setDefault("quantum.keyword.bold", true);
+ getPreferenceStore().setDefault("quantum.string.bold", false);
+ getPreferenceStore().setDefault("quantum.comment.bold", false);
+ getPreferenceStore().setDefault("quantum.numeric.bold", false);
+ PreferenceConverter.setDefault(
+ getPreferenceStore(),
+ "quantum.font",
+ (FontData) null);
+ }
+
+}
+class QuantumSaveParticipant implements ISaveParticipant {
+ /**
+ * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext)
+ */
+ public void doneSaving(ISaveContext context) {
+ }
+
+ /**
+ * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(ISaveContext)
+ */
+ public void prepareToSave(ISaveContext context) throws CoreException {
+ }
+
+ /**
+ * @see org.eclipse.core.resources.ISaveParticipant#rollback(ISaveContext)
+ */
+ public void rollback(ISaveContext context) {
+ }
+
+ /**
+ * @see org.eclipse.core.resources.ISaveParticipant#saving(ISaveContext)
+ */
+ public void saving(ISaveContext context) throws CoreException {
+ switch (context.getKind()) {
+ case ISaveContext.FULL_SAVE :
+ PHPEclipseSQLPlugin quantumPluginInstance = PHPEclipseSQLPlugin.getDefault();
+ // save the plug in state
+ if (BookmarkContentProvider.getInstance().hasChanged()) {
+ int saveNumber = context.getSaveNumber();
+ String saveFileName = "save " + Integer.toString(saveNumber);
+ File f =
+ quantumPluginInstance
+ .getStateLocation()
+ .append(saveFileName)
+ .toFile();
+ // if we fail to write, an exception is thrown and we do not update the path
+ quantumPluginInstance.writeImportantState(f);
+ context.map(new Path("save"), new Path(saveFileName));
+ context.needSaveNumber();
+ } else {
+ System.out.println("Not saving unchanged bookmarks");
+ }
+ break;
+ case ISaveContext.PROJECT_SAVE :
+ // get the project related to this save operation
+ //IProject project = context.getProject();
+ // save its information, if necessary
+ break;
+ case ISaveContext.SNAPSHOT :
+ // This operation needs to be really fast because
+ // snapshots can be requested frequently by the
+ // workspace.
+ break;
+ }
+ }
+}
--- /dev/null
+bookmarkview.done = Done
+bookmarkview.connect = Connect
+bookmarkview.disconnect = Disconnect
+bookmarkview.newBookmark = New Bookmark...
+bookmarkview.editBookmark = Edit Bookmark...
+bookmarkview.deleteBookmark = Delete Bookmark...
+bookmarkview.refresh = Refresh
+bookmarkview.viewTable = View Table
+bookmarkview.viewTableDetails = View Table Details
+bookmarkview.nextSequence = Next Sequence Value
+bookmarkview.noSequence = Database type does not support sequences
+bookmarkview.noViews = Database type does not support views
+bookmarkview.noTables = Database type does not support tables
+sqlqueryview.executeQuery = Execute Query
+sqlqueryview.importQuery = Import Query
+sqlqueryview.exportQuery = Export Query
+sqlqueryview.clear = Clear
+sqlqueryview.copy = Copy
+sqlqueryview.paste = Paste
+sqlqueryview.done = Done
+tableview.refresh = Refresh Table
+tableview.copy = Copy Table Selection To Clipboard
+tableview.selectAll = Select All Table Rows
+tableview.close = Close Table
+tableview.update = Update...
+tableview.insert = Insert...
+tableview.delete = Delete...
+tableview.phpselect = PHP Select...
+tableview.filterSort = Sort or Filter Table...
+tableview.showAll = Toggle Show All Table Rows
+tableview.defaultEncoding = Set Default Encoding
+tableview.UTF8Encoding = Set UTF-8
+tableview.UTF16Encoding = Set UTF-16
+bookmarkview.retrieveTableData = Retrieving table data...
+bookmarkview.retrieveViewData = Retrieving view data...
+bookmarkview.retrieveSeqData = Retrieving sequence data...
+bookmarkview.done = Done
+bookmarkview.metaDataError = Error while retrieving metadata
+bookmarkview.deleteBookmark = Delete Bookmark
+bookmarkview.confirm = Are you sure you want to delete bookmark
+bookmarkview.disconnect = Disconnecting from
+filedialog.preferences = Preferences (*.ini)
+filedialog.allfiles = All Files (*.*)
+filedialog.sqlFiles = SQL query (*.sql)
+filedialog.ddlFiles = SQL query (*.ddl)
+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
+
+sqlconsole.viewopeningproblem = Problems while opening the PHP source console
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.TableView;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class CloseTableAction extends Action implements IViewActionDelegate {
+ TableView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (TableView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+ public void run() {
+ view.closeCurrent();
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
+public class ConnectAction extends Action implements IViewActionDelegate {
+ private SQLHelper helper = new SQLHelper();
+ private BookmarkView view;
+ /**
+ * Constructor for Action1.
+ */
+ public ConnectAction() {
+ super();
+ }
+
+ /**
+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ /**
+ * @see IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ /**
+ * @see org.eclipse.jface.action.IAction#run()
+ */
+ public void run() {
+ view.disconnect();
+ BookmarkNode current = view.getCurrentBookmark();
+ view.setStatus("Connecting to " + current.getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
+ boolean status = MultiSQLServer.getInstance().connect(current);
+ if (status) {
+ view.refreshBookmarkData();
+ view.expandCurrent(current);
+ } else {
+ view.setStatus("Error while connecting to " + current.getName()); //$NON-NLS-1$
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class DeleteBookmarkAction extends Action implements IViewActionDelegate {
+ BookmarkView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ Object selection = view.getCurrent();
+ if (selection instanceof BookmarkNode) {
+ BookmarkNode node = (BookmarkNode) selection;
+ if (node != null) {
+ String name = node.getName();
+ boolean flag = MessageDialog.openConfirm(view.getSite().getShell(), Messages.getString("bookmarkview.deleteBookmark"), Messages.getString("bookmarkview.confirm") + name); //$NON-NLS-1$ //$NON-NLS-2$
+ if (flag) {
+ view.deleteCurrent();
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class DisconnectAction extends Action implements IViewActionDelegate {
+ BookmarkView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ view.disconnect();
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.wizards.BookmarkWizard;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class EditBookmarkAction extends Action implements IViewActionDelegate {
+ IViewPart view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = view;
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+ public void run() {
+ System.out.println("Wizard..");
+ BookmarkWizard wizard = new BookmarkWizard();
+
+ BookmarkNode b = BookmarkView.getInstance().getCurrentBookmark();
+ wizard.init(b);
+ WizardDialog dialog = new WizardDialog (view.getSite().getShell(),wizard);
+ dialog.open();
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLParser;
+import net.sourceforge.phpdt.sql.sql.SQLResults;
+import net.sourceforge.phpdt.sql.view.QueryHistoryView;
+import net.sourceforge.phpdt.sql.view.SQLQueryView;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
+
+public class ExecuteAction extends Action implements IViewActionDelegate {
+ SQLQueryView view;
+ boolean flag = false;
+ String execute1 = "Executing Query...";
+ String execute2 = "Executing Query..";
+ public void init(IViewPart view) {
+ this.view = (SQLQueryView) view;
+ }
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ view.setStatus(execute1);
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ view.setStatus("Parsing sql script...");
+ Vector queries = new Vector();
+ String viewQuery = view.getQuery();
+ queries = SQLParser.parse(viewQuery);
+ for (int i = 0; i < queries.size(); i++) {
+ String query = (String) queries.elementAt(i);
+ System.out.println(query);
+ }
+ int resultCount = 0;
+ int resultUpdateCount = 0;
+ int errorCount = 0;
+ int resultsDisplayed = 0;
+ for (int i = 0; i < queries.size(); i++) {
+ if (flag) {
+ view.setStatus(execute1);
+ } else {
+ view.setStatus(execute2);
+ }
+ String query = (String) queries.elementAt(i);
+ System.out.println(">" + query + "<");
+ if (!query.equals("")) {
+ SQLResults results = server.execute(query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
+ resultCount++;
+ if (results.isResultSet()) {
+ TableView.getInstance().loadQuery(results);
+ resultsDisplayed++;
+ } else {
+ int count = results.getUpdateCount();
+ if (count > 0) {
+ resultUpdateCount += results.getUpdateCount();
+ }
+ }
+ if (results.isError()) {
+ errorCount++;
+ }
+ }
+ flag = !flag;
+ view.setProgress(i + 1, queries.size());
+ }
+ if (errorCount > 0) {
+ Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
+ view.setStatus(error, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
+ } else {
+ Image success = PHPEclipseSQLPlugin.getImage("success.gif");
+ view.setStatus(success, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
+ }
+ view.setProgress(0, 1);
+ QueryHistoryView history = QueryHistoryView.getInstance();
+ history.addQuery(viewQuery);
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.io.File;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class ExportBookmarksAction
+ implements IViewActionDelegate {
+
+ BookmarkView view;
+ FileDialog dialog;
+
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
+ dialog.setFilterExtensions(new String[]{"*.ini","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[]{Messages.getString("filedialog.preferences"),Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ String filename = dialog.open();
+ if (filename != null) {
+ File exportFile = new File(filename);
+ BookmarkContentProvider.getInstance().save(exportFile);
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.StringTokenizer;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.LogProxy;
+import net.sourceforge.phpdt.sql.view.SQLLogView;
+import net.sourceforge.phpdt.sql.view.SQLQueryView;
+
+public class ExportQueryAction extends Action implements IViewActionDelegate {
+ SQLQueryView view;
+ FileDialog dialog;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (SQLQueryView) view;
+ dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
+ 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$
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ String filename = dialog.open();
+ if (filename != null) {
+ try {
+ File exportFile = new File(filename);
+ FileWriter fileWriter = new FileWriter(exportFile);
+ PrintWriter writer = new PrintWriter(fileWriter);
+ String output = view.getQuery();
+ StringTokenizer tokenizer = new StringTokenizer(output, "\n");
+ while (tokenizer.hasMoreElements()) {
+ String line = (String) tokenizer.nextElement();
+ writer.println(line);
+ }
+ writer.close();
+ } catch (IOException e) {
+ LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.io.File;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class ImportBookmarksAction implements IViewActionDelegate {
+ BookmarkView view;
+ FileDialog dialog;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[]{"*.ini","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[]{Messages.getString("filedialog.preferences"),Messages.getString("filedialog.allfiles")}); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ String filename = dialog.open();
+ if (filename != null) {
+ File importFile = new File(filename);
+ BookmarkContentProvider.getInstance().importBookmarks(importFile);
+ view.refresh();
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.LogProxy;
+import net.sourceforge.phpdt.sql.view.SQLLogView;
+import net.sourceforge.phpdt.sql.view.SQLQueryView;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class ImportQueryAction extends Action implements IViewActionDelegate {
+ SQLQueryView view;
+ FileDialog dialog;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (SQLQueryView) view;
+ dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
+ 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$
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ String filename = dialog.open();
+ if (filename != null) {
+ try {
+ File importFile = new File(filename);
+ FileReader fileReader = new FileReader(importFile);
+ BufferedReader reader = new BufferedReader(fileReader);
+ String line;
+ StringBuffer buffer = new StringBuffer();
+ while ((line = reader.readLine()) != null) {
+ buffer.append(line);
+ buffer.append('\n');
+ }
+ view.setQuery(buffer.toString());
+ reader.close();
+ } catch (IOException e) {
+ LogProxy.getInstance().addText(SQLLogView.ERROR, e.toString());
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+
+ private static final String BUNDLE_NAME = "net.sourceforge.phpdt.sql.PHPEclipseSQLResources"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.wizards.BookmarkWizard;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class NewBookmarkAction extends Action implements IViewActionDelegate {
+ IViewPart view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = view;
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+ public void run() {
+ System.out.println("Wizard..");
+ BookmarkWizard wizard = new BookmarkWizard();
+
+ wizard.init();
+
+ WizardDialog dialog = new WizardDialog (view.getSite().getShell(),wizard);
+ dialog.open();
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
+import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLResults;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
+
+public class NextSequenceAction extends Action implements IViewActionDelegate {
+ BookmarkView view;
+
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ TreeNode node = (TreeNode) view.getCurrent();
+ String name = null;
+ try {
+ if (node instanceof SequenceNode) {
+ SequenceNode sequence = (SequenceNode) node;
+ BookmarkNode parent = (BookmarkNode) sequence.getParent();
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(parent.getType());
+ name = sequence.getName();
+ String query = adapter.getNextValue(name);
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ SQLResults results = server.execute(query);
+ TableView.getInstance().loadQuery(results);
+ }
+ } catch (NoSuchAdapterException e) {
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class RefreshBookmarkAction extends Action implements IViewActionDelegate {
+ SQLHelper helper = new SQLHelper();
+
+ BookmarkView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+ public void run() {
+ view.refreshBookmarkData();
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.view.TableView;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class RefreshTableAction extends Action implements IViewActionDelegate {
+ TableView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (TableView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+ public void run() {
+ view.refreshCurrent();
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+
+public class SetSchemaAction extends Action implements IViewActionDelegate {
+ BookmarkView view;
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ Bookmark bookmark = view.getCurrentBookmark();
+ InputDialog dialog = new InputDialog(view.getSite().getShell(),
+ "Set Schema", "Please enter the name of new schema:",
+ bookmark.getSchema(), null);
+ dialog.open();
+ String value = dialog.getValue();
+ if (value != null) {
+ bookmark.setSchema(value);
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class ViewTableAction extends Action implements IViewActionDelegate {
+ BookmarkView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ TreeNode node = (TreeNode) view.getCurrent();
+ String name = null;
+ if (node instanceof TableNode) {
+ name = ((TableNode) node).getName();
+ } else if (node instanceof ViewNode) {
+ name = ((ViewNode) node).getName();
+ }
+
+ try {
+ IWorkbenchPage page =
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ page.showView(TableView.TABLEVIEW_ID);
+ } catch (PartInitException e) {
+ }
+ TableView.getInstance().loadTable(name);
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
+
+public class ViewTableDetailsAction extends Action implements IViewActionDelegate {
+ BookmarkView view;
+
+ public void init(IViewPart view) {
+ this.view = (BookmarkView) view;
+ }
+
+ public void run(IAction action) {
+ run();
+ }
+ public void run() {
+ TreeNode node = (TreeNode) view.getCurrent();
+ StringBuffer query = new StringBuffer();
+ query.append("METADATA:");
+ if (node instanceof TableNode) {
+ query.append(((TableNode) node).getName());
+ } else if (node instanceof ViewNode) {
+ query.append(((ViewNode) node).getName());
+ }
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ TableView.getInstance().loadQuery(server.execute(query.toString()));
+ }
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public class AdabasDAdapter extends DatabaseAdapter {
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABLENAME FROM TABLES";
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT VIEWNAME FROM VIEWS";
+ }
+ public DatabaseAdapter getInstance() {
+ return new AdabasDAdapter();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+import java.util.ArrayList;
+
+public class AdapterFactory {
+ public static final String GENERIC = "GENERIC";
+ public static final String ORACLE = "ORACLE";
+ public static final String POSTGRES = "POSTGRES";
+ public static final String MYSQL = "MYSQL";
+ public static final String DB2 = "DB2";
+ public static final String DB2AS400 = "DB2AS400";
+ public static final String ADABASD = "ADABASD";
+
+ private static AdapterFactory instance;
+
+ private ArrayList drivers;
+
+ private AdapterFactory() {
+ loadDrivers();
+ }
+ 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());
+ DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter());
+ DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter());
+ DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter());
+ DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter());
+ DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new MySQLAdapter());
+ DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter());
+
+ drivers.add(generic);
+ drivers.add(oracle);
+ drivers.add(db2);
+ drivers.add(db2as400);
+ drivers.add(postgres);
+ drivers.add(mysql);
+ drivers.add(adabasd);
+ }
+
+ public synchronized DatabaseAdapter getAdapter(String type) throws NoSuchAdapterException {
+ 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().getInstance();
+ }
+ }
+ throw new NoSuchAdapterException(type);
+ }
+
+ public synchronized DriverInfo[] getDriverList() {
+ DriverInfo[] driverList = new DriverInfo[drivers.size()];
+ for (int i = 0; i < drivers.size(); i++) {
+ DriverInfo info = (DriverInfo) drivers.get(i);
+ driverList[i] = info;
+ }
+ return driverList;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public class DB2AS400Adapter extends DatabaseAdapter {
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + info.getSchema().toUpperCase() + "' AND TABLE_TYPE = 'P'";
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + info.getSchema().toUpperCase() + "' AND TABLE_TYPE = 'L'";
+ }
+ public DatabaseAdapter getInstance() {
+ return new DB2AS400Adapter();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public class DB2Adapter extends DatabaseAdapter {
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + info.getSchema().toUpperCase() + "' AND TYPE='T'";
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + info.getSchema().toUpperCase() + "' AND TYPE='V'";
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return "SELECT SEQNAME FROM sysibm.syssequences WHERE seqschema = '" + info.getSchema().toUpperCase() + "'";
+ }
+ public String getNextValue(String sequence) {
+ return "VALUES NEXTVAL FOR " + sequence;
+ }
+ public DatabaseAdapter getInstance() {
+ return new DB2Adapter();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public abstract class DatabaseAdapter {
+ public abstract DatabaseAdapter getInstance();
+ public abstract String getShowTableQuery(DatabaseInfo info);
+ public String getShowViewQuery(DatabaseInfo info) {
+ throw new FeatureNotSupported("Views");
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ throw new FeatureNotSupported("Sequences");
+ }
+ public final String getShowTableQuery(DatabaseInfo info, String table) {
+ String schema = info.getSchema();
+ if (schema.equals("")) {
+ return "SELECT * FROM " + table;
+ } else {
+ return "SELECT * FROM " + info.getSchema() + "." + table;
+ }
+ }
+ public final String getTableCountQuery(DatabaseInfo info, String table) {
+ String schema = info.getSchema();
+ if (schema.equals("")) {
+ return "SELECT COUNT(*) FROM " + table;
+ } else {
+ return "SELECT COUNT(*) FROM " + info.getSchema() + "." + table;
+ }
+ }
+ public String getNextValue(String sequence) {
+ throw new FeatureNotSupported("Sequences");
+ }
+ public String getTableListFilter() {
+ return null;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+
+public class DatabaseInfo {
+ private String schema;
+
+ private DatabaseInfo(String schema) {
+ this.schema = schema;
+ }
+
+ public static DatabaseInfo create(Bookmark bookmark) {
+ return new DatabaseInfo(bookmark.getSchema());
+ }
+
+ public String getSchema() {
+ return schema;
+ }
+
+ public void setSchema(String schema) {
+ this.schema = schema;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+import java.util.Vector;
+
+public class DriverInfo {
+ 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;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public class FeatureNotSupported extends Error {
+ public FeatureNotSupported(String error) {
+ super(error);
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public class GenericAdapter extends DatabaseAdapter {
+
+ public DatabaseAdapter getInstance() {
+ return new GenericAdapter();
+ }
+
+ public String getShowTableQuery(DatabaseInfo info) {
+ return null;
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return null;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+
+ private static final String BUNDLE_NAME = "net.sourceforge.phpdt.sql.PHPEclipseSQLResources"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+
+public class MySQLAdapter extends DatabaseAdapter {
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SHOW TABLES";
+ }
+ public DatabaseAdapter getInstance() {
+ return new MySQLAdapter();
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+public class NoSuchAdapterException extends Exception {
+ public NoSuchAdapterException(String driverName) {
+ super("Database not supported: ->" + driverName + "<-");
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+
+public class OracleAdapter extends DatabaseAdapter {
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABLE_NAME FROM USER_TABLES";
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT VIEW_NAME FROM USER_VIEWS";
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return "SELECT SEQUENCE_NAME FROM USER_SEQUENCES";
+ }
+ public String getNextValue(String sequence) {
+ return "SELECT LAST_NUMBER FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '" + sequence + "'";
+ }
+ public DatabaseAdapter getInstance() {
+ return new OracleAdapter();
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+
+public class PostgresAdapter extends DatabaseAdapter {
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABLENAME FROM PG_TABLES";
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT VIEWNAME FROM PG_VIEWS";
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return "SELECT relname FROM pg_class WHERE relkind = 'S'";
+ }
+ public String getNextValue(String sequence) {
+ return "select nextval('" + sequence + "')";
+ }
+ public String getTableListFilter() {
+ return "pg_";
+ }
+ public DatabaseAdapter getInstance() {
+ return new PostgresAdapter();
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.bookmarks;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class Bookmark {
+ String name = "";
+ String username = "";
+ String password = "";
+ String connect = "";
+ String driver = "";
+ String type = "";
+ String driverFile = "";
+ String schema = "";
+
+ public Bookmark() {
+ }
+
+ public Bookmark(Bookmark data) {
+ setName(data.getName());
+ setUsername(data.getUsername());
+ setPassword(data.getPassword());
+ setConnect(data.getConnect());
+ setDriver(data.getDriver());
+ setType(data.getType());
+ setDriverFile(data.getDriverFile());
+ }
+
+ public Bookmark(
+ String name,
+ String username,
+ String password,
+ String connect,
+ String driver,
+ String type,
+ String driverFile) {
+ this.name = username;
+ this.username = username;
+ this.password = password;
+ this.connect = connect;
+ this.driver = driver;
+ this.type = type;
+ this.driverFile = driverFile;
+ }
+
+ /**
+ * Returns the connect.
+ * @return String
+ */
+ public String getConnect() {
+ return connect;
+ }
+
+ /**
+ * Returns the driver.
+ * @return String
+ */
+ public String getDriver() {
+ return driver;
+ }
+
+ /**
+ * Returns the driverFile.
+ * @return String
+ */
+ public String getDriverFile() {
+ return driverFile;
+ }
+
+ /**
+ * Returns the password.
+ * @return String
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Returns the username.
+ * @return String
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * Sets the connect.
+ * @param connect The connect to set
+ */
+ public void setConnect(String connect) {
+ if (connect == null) {
+ connect = "";
+ }
+ this.connect = connect;
+ }
+
+ /**
+ * Sets the driver.
+ * @param driver The driver to set
+ */
+ public void setDriver(String driver) {
+ if (driver == null) {
+ driver = "";
+ }
+ this.driver = driver;
+ }
+
+ /**
+ * Sets the driverFile.
+ * @param driverFile The driverFile to set
+ */
+ public void setDriverFile(String driverFile) {
+ if (driverFile == null) {
+ driverFile = "";
+ }
+ this.driverFile = driverFile;
+ }
+
+ /**
+ * Sets the password.
+ * @param password The password to set
+ */
+ public void setPassword(String password) {
+ if (password == null) {
+ password = "";
+ }
+ this.password = password;
+ }
+
+ /**
+ * Sets the username.
+ * @param username The username to set
+ */
+ public void setUsername(String username) {
+ if (username == null) {
+ username = "";
+ }
+ this.username = username;
+ }
+
+ /**
+ * Returns the name.
+ * @return String
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ * @param name The name to set
+ */
+ public void setName(String name) {
+ if (name == null) {
+ name = "";
+ }
+ this.name = name;
+ }
+
+ public boolean isEmpty() {
+ if (name.equals("") &&
+ username.equals("") &&
+ password.equals("") &&
+ connect.equals("") &&
+ driver.equals("") &&
+ type.equals("") &&
+ driverFile.equals("")) {
+ return true;
+ }
+ return false;
+ }
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("[");
+ buffer.append("name=");
+ buffer.append(name);
+ buffer.append(", ");
+ buffer.append("username=");
+ buffer.append(username);
+ buffer.append(", ");
+ buffer.append("password=****");
+ buffer.append(", ");
+ buffer.append("connect=");
+ buffer.append(connect);
+ buffer.append(", ");
+ buffer.append("driver=");
+ buffer.append(driver);
+ buffer.append(", ");
+ buffer.append("type=");
+ buffer.append(type);
+ buffer.append(", ");
+ buffer.append("driverFile=");
+ buffer.append(driverFile);
+ buffer.append("]");
+ return buffer.toString();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getSchema() {
+ return schema;
+ }
+
+ public void setSchema(String schema) {
+ this.schema = schema;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+public class ColorManager {
+
+ protected Map fColorTable = new HashMap(10);
+
+ public void dispose() {
+ Iterator e= fColorTable.values().iterator();
+ while (e.hasNext())
+ ((Color) e.next()).dispose();
+ }
+ public Color getColor(RGB rgb) {
+ Color color= (Color) fColorTable.get(rgb);
+ if (color == null) {
+ color= new Color(Display.getCurrent(), rgb);
+ fColorTable.put(rgb, color);
+ }
+ return color;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.TextPresentation;
+import org.eclipse.jface.text.presentation.IPresentationDamager;
+import org.eclipse.jface.text.presentation.IPresentationRepairer;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.swt.custom.StyleRange;
+
+public class NonRuleBasedDamagerRepairer
+ implements IPresentationDamager, IPresentationRepairer {
+
+ /** The document this object works on */
+ protected IDocument fDocument;
+ /** The default text attribute if non is returned as data by the current token */
+ protected TextAttribute fDefaultTextAttribute;
+
+ /**
+ * Constructor for NonRuleBasedDamagerRepairer.
+ */
+ public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) {
+ Assert.isNotNull(defaultTextAttribute);
+
+ fDefaultTextAttribute = defaultTextAttribute;
+ }
+
+ /**
+ * @see IPresentationRepairer#setDocument(IDocument)
+ */
+ public void setDocument(IDocument document) {
+ fDocument = document;
+ }
+
+ public void setTextAttribute(TextAttribute attr) {
+ fDefaultTextAttribute = attr;
+ }
+
+ /**
+ * Returns the end offset of the line that contains the specified offset or
+ * if the offset is inside a line delimiter, the end offset of the next line.
+ *
+ * @param offset the offset whose line end offset must be computed
+ * @return the line end offset for the given offset
+ * @exception BadLocationException if offset is invalid in the current document
+ */
+ protected int endOfLineOf(int offset) throws BadLocationException {
+
+ IRegion info = fDocument.getLineInformationOfOffset(offset);
+ if (offset <= info.getOffset() + info.getLength())
+ return info.getOffset() + info.getLength();
+
+ int line = fDocument.getLineOfOffset(offset);
+ try {
+ info = fDocument.getLineInformation(line + 1);
+ return info.getOffset() + info.getLength();
+ } catch (BadLocationException x) {
+ return fDocument.getLength();
+ }
+ }
+
+ /**
+ * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
+ */
+ public IRegion getDamageRegion(
+ ITypedRegion partition,
+ DocumentEvent event,
+ boolean documentPartitioningChanged) {
+ if (!documentPartitioningChanged) {
+ try {
+
+ IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
+ int start = Math.max(partition.getOffset(), info.getOffset());
+
+ int end =
+ event.getOffset()
+ + (event.getText() == null ? event.getLength() : event.getText().length());
+
+ if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
+ // optimize the case of the same line
+ end = info.getOffset() + info.getLength();
+ } else
+ end = endOfLineOf(end);
+
+ end = Math.min(partition.getOffset() + partition.getLength(), end);
+ return new Region(start, end - start);
+
+ } catch (BadLocationException x) {
+ }
+ }
+
+ return partition;
+ }
+
+ /**
+ * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
+ */
+ public void createPresentation(
+ TextPresentation presentation,
+ ITypedRegion region) {
+ addRange(
+ presentation,
+ region.getOffset(),
+ region.getLength(),
+ fDefaultTextAttribute);
+ }
+
+ /**
+ * Adds style information to the given text presentation.
+ *
+ * @param presentation the text presentation to be extended
+ * @param offset the offset of the range to be styled
+ * @param length the length of the range to be styled
+ * @param attr the attribute describing the style of the range to be styled
+ */
+ protected void addRange(
+ TextPresentation presentation,
+ int offset,
+ int length,
+ TextAttribute attr) {
+ if (attr != null)
+ presentation.addStyleRange(
+ new StyleRange(
+ offset,
+ length,
+ attr.getForeground(),
+ attr.getBackground(),
+ attr.getStyle()));
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import org.eclipse.swt.graphics.RGB;
+
+public class SQLColorConstants {
+ public static RGB BACKGROUND = new RGB(255, 0, 255);
+ public static RGB COMMENT = new RGB(88, 148, 64);
+ public static RGB IDENTIFIER = new RGB(0, 0, 0);
+ public static RGB KEYWORD = new RGB(126, 0, 75);
+ public static RGB STRING = new RGB(0, 0, 255);
+ public static RGB NUMERIC = new RGB(255, 0, 0);
+ public static RGB DEFAULT = new RGB(0, 0, 0);
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import java.util.HashMap;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+public class SQLConfiguration extends SourceViewerConfiguration {
+ private PresentationReconciler reconciler = new PresentationReconciler();
+ private ColorManager colorManager;
+ private HashMap cache = new HashMap();
+ private boolean textBold = false;
+ private boolean keywordBold = true;
+ private boolean stringBold = false;
+ private boolean commentBold = false;
+ private boolean numericBold = false;
+ public SQLConfiguration(ColorManager colorManager) {
+ this.colorManager = colorManager;
+ }
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return new String[] {
+ IDocument.DEFAULT_CONTENT_TYPE,
+ SQLPartitionScanner.SQL_COMMENT,
+ SQLPartitionScanner.SQL_KEYWORD,
+ SQLPartitionScanner.SQL_IDENTIFIER};
+ }
+
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+ initializeColors();
+ return reconciler;
+ }
+ public void loadPrefs() {
+ IPreferenceStore store = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+ textBold = store.getBoolean("quantum.text.bold");
+ keywordBold = store.getBoolean("quantum.keyword.bold");
+ stringBold = store.getBoolean("quantum.string.bold");
+ commentBold = store.getBoolean("quantum.comment.bold");
+ numericBold = store.getBoolean("quantum.numeric.bold");
+ SQLColorConstants.BACKGROUND = PreferenceConverter.getColor(store, "quantum.background.color");
+ SQLColorConstants.DEFAULT = PreferenceConverter.getColor(store, "quantum.text.color");
+ SQLColorConstants.IDENTIFIER = PreferenceConverter.getColor(store, "quantum.text.color");
+ SQLColorConstants.KEYWORD = PreferenceConverter.getColor(store, "quantum.keyword.color");
+ SQLColorConstants.STRING = PreferenceConverter.getColor(store, "quantum.string.color");
+ SQLColorConstants.COMMENT = PreferenceConverter.getColor(store, "quantum.comment.color");
+ SQLColorConstants.NUMERIC = PreferenceConverter.getColor(store, "quantum.numeric.color");
+ }
+ public void initializeColors() {
+ setDamageRepairer(getAttr(SQLColorConstants.KEYWORD, keywordBold), SQLPartitionScanner.SQL_KEYWORD);
+ setDamageRepairer(getAttr(SQLColorConstants.COMMENT, commentBold), SQLPartitionScanner.SQL_COMMENT);
+ setDamageRepairer(getAttr(SQLColorConstants.STRING, stringBold), SQLPartitionScanner.SQL_STRING);
+ setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), IDocument.DEFAULT_CONTENT_TYPE);
+ setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SYMBOL);
+ setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_IDENTIFIER);
+ setDamageRepairer(getAttr(SQLColorConstants.DEFAULT, textBold), SQLPartitionScanner.SQL_SEPARATOR);
+ setDamageRepairer(getAttr(SQLColorConstants.NUMERIC, numericBold), SQLPartitionScanner.SQL_NUMERIC);
+ }
+ public TextAttribute getAttr(RGB color, boolean bold) {
+ Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
+ Color foreground = colorManager.getColor(color);
+ TextAttribute attr = new TextAttribute(foreground);
+ if (bold) {
+ return new TextAttribute(foreground, attr.getBackground(), SWT.BOLD);
+ }
+ return attr;
+ }
+ public void setDamageRepairer(TextAttribute attr, String token) {
+ NonRuleBasedDamagerRepairer ndr = (NonRuleBasedDamagerRepairer) cache.get(token);
+ if (ndr == null) {
+ ndr =
+ new NonRuleBasedDamagerRepairer(attr);
+ reconciler.setDamager(ndr, token);
+ reconciler.setRepairer(ndr, token);
+ cache.put(token, ndr);
+ } else {
+ ndr.setTextAttribute(attr);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.DefaultPartitioner;
+import org.eclipse.ui.editors.text.FileDocumentProvider;
+
+public class SQLDocumentProvider extends FileDocumentProvider {
+
+ public SQLDocumentProvider() {
+ super();
+ }
+
+ protected IDocument createDocument(Object element) throws CoreException {
+ IDocument document = super.createDocument(element);
+ if (document != null) {
+ IDocumentPartitioner partitioner =
+ new DefaultPartitioner(
+ new SQLPartitionScanner(),
+ new String[] {
+ IDocument.DEFAULT_CONTENT_TYPE,
+ SQLPartitionScanner.SQL_KEYWORD,
+ SQLPartitionScanner.SQL_COMMENT,
+ SQLPartitionScanner.SQL_IDENTIFIER,
+ SQLPartitionScanner.SQL_STRING,
+ SQLPartitionScanner.SQL_SEPARATOR,
+ SQLPartitionScanner.SQL_SYMBOL,
+ SQLPartitionScanner.SQL_NUMERIC });
+ partitioner.connect(document);
+ document.setDocumentPartitioner(partitioner);
+ }
+ return document;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.editors.text.TextEditor;
+
+public class SQLEditor extends TextEditor {
+ SQLConfiguration config;
+ private ColorManager colorManager;
+ /**
+ * An editor capable of editing SQL scripts
+ */
+ public SQLEditor() {
+ super();
+ colorManager = new ColorManager();
+ config = new SQLConfiguration(colorManager);
+ config.loadPrefs();
+
+ setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
+ IPropertyChangeListener preferenceListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ config.loadPrefs();
+ config.initializeColors();
+ getSourceViewer().invalidateTextPresentation();
+ StyledText widget = getSourceViewer().getTextWidget();
+ FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
+ widget.setFont(new Font(Display.getCurrent(), font));
+ Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
+ widget.setBackground(background);
+ }
+ };
+ getPreferenceStore().
+ addPropertyChangeListener(preferenceListener);
+
+ setSourceViewerConfiguration(config);
+ setDocumentProvider(new SQLDocumentProvider());
+ }
+ public void dispose() {
+ colorManager.dispose();
+ super.dispose();
+ }
+ public void createPartControl(Composite arg0) {
+ super.createPartControl(arg0);
+ StyledText widget = getSourceViewer().getTextWidget();
+ FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
+ widget.setFont(new Font(Display.getCurrent(), font));
+ Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
+ widget.setBackground(background);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.editors;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IPredicateRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+import org.eclipse.jface.text.rules.MultiLineRule;
+import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+
+public class SQLPartitionScanner extends RuleBasedPartitionScanner {
+ public final static String SQL_COMMENT = "__sql_comment";
+ public final static String SQL_IDENTIFIER = "__sql_word";
+ public final static String SQL_STRING = "__sql_string";
+ public final static String SQL_KEYWORD = "__sql_keyword";
+ public final static String SQL_SYMBOL = "__sql_symbol";
+ public final static String SQL_SEPARATOR = "__sql_separator";
+ public final static String SQL_NUMERIC = "__sql_numeric";
+
+ private final static String[] KEYWORDS = {
+ "ALTER",
+ "AND",
+ "BY",
+ "COLUMN",
+ "CREATE",
+ "DELETE",
+ "DROP",
+ "FROM",
+ "GROUP",
+ "INSERT",
+ "INTO",
+ "NOT",
+ "NULL",
+ "OR",
+ "ORDER",
+ "SELECT",
+ "SEQUENCE",
+ "SET",
+ "TABLE",
+ "UNION",
+ "UNIQUE",
+ "UPDATE",
+ "USING",
+ "VALUES",
+ "VIEW",
+ "WHEN",
+ "WHERE"
+ };
+
+ public SQLPartitionScanner() {
+
+ List rules = new ArrayList();
+
+ IToken comment = new Token(SQL_COMMENT);
+ IToken string = new Token(SQL_STRING);
+ IToken identifier = new Token(SQL_IDENTIFIER);
+ IToken keyword = new Token(SQL_KEYWORD);
+ IToken separator = new Token(SQL_SEPARATOR);
+ IToken symbol = new Token(SQL_SYMBOL);
+ IToken whitespace = new Token(IDocument.DEFAULT_CONTENT_TYPE);
+ IToken numeric = new Token(SQL_NUMERIC);
+
+ rules.add(new PredicateRuleAdapter(new WhitespaceRule(new WhitespaceDetector()), whitespace));
+ rules.add(new MultiLineRule("/*", "*/", comment));
+ rules.add(new EndOfLineRule("--", comment));
+ rules.add(new SingleLineRule("'", "'", string));
+ rules.add(new PredicateRuleAdapter(new SQLNumberRule(numeric), numeric));
+ SQLWordRule wordRule = new SQLWordRule(identifier);
+ for (int i = 0; i < KEYWORDS.length; i++) {
+ wordRule.addKeyword(KEYWORDS[i], keyword);
+ }
+ rules.add(new PredicateRuleAdapter(wordRule, keyword));
+ rules.add(new PredicateRuleAdapter(wordRule, identifier));
+ rules.add(new PredicateRuleAdapter(new SQLSeparatorRule(separator), separator));
+ rules.add(new PredicateRuleAdapter(new SymbolRule(symbol), symbol));
+
+ IPredicateRule[] result= new IPredicateRule[rules.size()];
+ rules.toArray(result);
+ setPredicateRules(result);
+ }
+}
+
+class PredicateRuleAdapter implements IPredicateRule {
+ IRule rule;
+ IToken token;
+ public PredicateRuleAdapter(IRule rule, IToken token) {
+ this.rule = rule;
+ this.token = token;
+ }
+
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+ return rule.evaluate(scanner);
+ }
+
+ public IToken getSuccessToken() {
+ return token;
+ }
+
+ public IToken evaluate(ICharacterScanner scanner) {
+ return rule.evaluate(scanner);
+ }
+
+}
+
+class SQLSeparatorRule implements IRule {
+ IToken token;
+ public SQLSeparatorRule(IToken token) {
+ this.token = token;
+ }
+ public IToken evaluate(ICharacterScanner scanner) {
+ char c = (char) scanner.read();
+ if (c == ';') {
+ return token;
+ }
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+
+}
+
+class SymbolRule implements IRule {
+ IToken token;
+ public SymbolRule(IToken token) {
+ this.token = token;
+ }
+ public IToken evaluate(ICharacterScanner scanner) {
+ int val = scanner.read();
+ if (val != scanner.EOF) {
+ char c = (char) val;
+ if (!Character.isWhitespace(c) && !Character.isLetterOrDigit(c) && c != '_') {
+ return token;
+ }
+ }
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+
+}
+
+class WhitespaceDetector implements IWhitespaceDetector {
+
+ public boolean isWhitespace(char c) {
+ return Character.isWhitespace(c);
+ }
+}
+
+class SQLNumberRule implements IRule {
+ private IToken token;
+
+ public SQLNumberRule(IToken token) {
+ this.token = token;
+ }
+
+ public IToken evaluate(ICharacterScanner scanner) {
+ char c = (char) scanner.read();
+ if (Character.isDigit(c)) {
+ // postive numbers and zero
+ do {
+ c= (char) scanner.read();
+ } while (Character.isDigit(c) || c == '.');
+ scanner.unread();
+ return token;
+ } else if (c == '-') {
+ // negative numbers
+ c = (char) scanner.read();
+ if (Character.isDigit(c)) {
+ do {
+ c= (char) scanner.read();
+ } while (Character.isDigit(c) || c == '.');
+ scanner.unread();
+ return token;
+ } else {
+ scanner.unread();
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+ } else {
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+ }
+}
+
+class SQLWordRule implements IRule {
+ private IToken token;
+ private HashMap keywords = new HashMap();
+
+ public SQLWordRule(IToken token) {
+ this.token = token;
+ }
+
+ public void addKeyword(String word, IToken token) {
+ keywords.put(word.toUpperCase(), token);
+ }
+
+ public IToken evaluate(ICharacterScanner scanner) {
+ char c = (char) scanner.read();
+ if (Character.isLetter(c) || c == '_') {
+ StringBuffer value = new StringBuffer();
+ do {
+ value.append(c);
+ c= (char) scanner.read();
+ } while (Character.isLetterOrDigit(c) || c == '_');
+ scanner.unread();
+ IToken retVal = (IToken) keywords.get(value.toString().toUpperCase());
+ if (retVal != null) {
+ return retVal;
+ } else {
+ return token;
+ }
+ } else {
+ scanner.unread();
+ return Token.UNDEFINED;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.parser;
+
+import java.util.Vector;
+
+public class SQLLexx {
+ private static String endline = ";";
+ private static String dash = "-";
+ public static Vector parse(String text) {
+ Vector tokens = new Vector();
+ StringPointer p = new StringPointer(text);
+ try {
+ while (!p.isDone()) {
+ int offset = p.getOffset();
+ char c = p.getNext();
+ //System.out.print(c);
+ if (Character.isWhitespace(c)) {
+ StringBuffer value = new StringBuffer();
+ while (Character.isWhitespace(c) && !p.isDone()) {
+ value.append(c);
+ p.mark();
+ c = p.getNext();
+ }
+ // done because of is done
+ if (Character.isWhitespace(c)) {
+ value.append(c);
+ } else {
+ p.reset();
+ }
+ tokens.addElement(new Token(Token.WHITESPACE, value.toString(), offset, offset + value.length()));
+ } else if (Character.isLetter(c) || c == '_') {
+ StringBuffer value = new StringBuffer();
+ while ((Character.isLetterOrDigit(c) || c == '_') && !p.isDone()) {
+ value.append(c);
+ p.mark();
+ c = p.getNext();
+ }
+ if ((Character.isLetterOrDigit(c) || c == '_')) {
+ value.append(c);
+ } else {
+ p.reset();
+ }
+ tokens.addElement(new Token(Token.IDENTIFIER, value.toString(), offset, offset + value.length()));
+ } else if (c == '\'') {
+ StringBuffer value = new StringBuffer();
+ value.append(c);
+ if (!p.isDone()) {
+ c = p.getNext();
+ while (c != '\'' && c != '\n' && !p.isDone()) {
+ value.append(c);
+ c = p.getNext();
+ }
+ if (c == '\'' || p.isDone()) {
+ value.append(c);
+ }
+ }
+ tokens.addElement(new Token(Token.LITERAL, value.toString(), offset, offset + value.length()));
+ } else if (c == '-') {
+ p.mark();
+ if (p.isDone()) {
+ tokens.addElement(new Token(Token.SYMBOL, dash, offset, offset + 1));
+ } else {
+ char next = p.getNext();
+ if (next == '-') {
+ StringBuffer value = new StringBuffer("--");
+ if (!p.isDone()) {
+ c = p.getNext();
+ while (c != '\n' && !p.isDone()) {
+ value.append(c);
+ c = p.getNext();
+ }
+ if (p.isDone()) {
+ value.append(c);
+ }
+ }
+ tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
+ } else {
+ tokens.addElement(new Token(Token.SYMBOL, dash, offset, offset + 1));
+ p.reset();
+ }
+ }
+ } else if (c == ';') {
+ tokens.addElement(new Token(Token.SEPARATOR, endline, offset, offset + 1));
+ StringBuffer value = new StringBuffer();
+ if (!p.isDone()) {
+ c = p.getNext();
+ while (c != '\n' && !p.isDone()) {
+ value.append(c);
+ c = p.getNext();
+ }
+ if (p.isDone()) {
+ value.append(c);
+ }
+ offset++;
+ tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
+ }
+ } else if (Character.isDigit(c)) {
+ StringBuffer value = new StringBuffer();
+ while ((Character.isDigit(c) || c == '.') && !p.isDone()) {
+ value.append(c);
+ p.mark();
+ c = p.getNext();
+ }
+ if ((Character.isDigit(c) || c == '.')) {
+ value.append(c);
+ } else {
+ p.reset();
+ }
+ tokens.addElement(new Token(Token.NUMERIC, value.toString(), offset, offset + value.length()));
+ } else {
+ tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}), offset, offset + 1));
+ }
+ }
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ }
+
+ //System.out.println("-------------------");
+ //for (int i = 0; i < tokens.size(); i++) {
+ // System.out.println((Token) tokens.elementAt(i));
+ //}
+ return tokens;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.parser;
+
+public class StringPointer {
+ char[] value;
+ int offset = 0;
+ int mark = 0;
+ public StringPointer(String s) {
+ value = s.toCharArray();
+ }
+ public char getNext() {
+ char retVal = value[offset];
+ offset++;
+ return retVal;
+ }
+ public void mark() {
+ mark = offset;
+ }
+ public void reset() {
+ offset = mark;
+ }
+ public int getOffset() {
+ return offset;
+ }
+ public boolean isDone() {
+ return offset == value.length;
+ }
+ public int getLength() {
+ return value.length;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.parser;
+
+public class Token {
+ public static final char SEPARATOR = 'S';
+ public static final char SYMBOL = 'Y';
+ public static final char LITERAL = 'L';
+ public static final char IDENTIFIER = 'I';
+ public static final char COMMENT = 'C';
+ public static final char WHITESPACE = 'W';
+ public static final char NUMERIC = 'N';
+ private char type;
+ private int start;
+ private int end;
+ private String value;
+ public Token(char type, String value, int start, int end) {
+ this.type = type;
+ this.value = value;
+ this.start = start;
+ this.end = end;
+ }
+ public int getEnd() {
+ return end;
+ }
+
+ public int getStart() {
+ return start;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setEnd(int end) {
+ this.end = end;
+ }
+
+ public void setStart(int start) {
+ this.start = start;
+ }
+
+ public void setType(char type) {
+ this.type = type;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ public String toString() {
+ return type + " ->" + value + "<- [" + start + ", " + end + "]";
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.perspective;
+
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class DBPerspective implements IPerspectiveFactory {
+ public void createInitialLayout(IPageLayout layout) {
+ layout.setEditorAreaVisible(false);
+ IFolderLayout side =
+ layout.createFolder(
+ "side",
+ IPageLayout.LEFT,
+ 0.33F,
+ layout.getEditorArea());
+ side.addView("net.sourceforge.phpdt.sql.view.bookmarkview");
+ side.addView("net.sourceforge.phpdt.sql.view.queryhistoryview");
+ layout.addView("net.sourceforge.phpdt.sql.view.sqlqueryview", IPageLayout.TOP, 0.33F, layout.getEditorArea());
+ IFolderLayout bottomRight =
+ layout.createFolder(
+ "bottomRight",
+ IPageLayout.LEFT,
+ 0.33F,
+ layout.getEditorArea());
+ bottomRight.addView("net.sourceforge.phpdt.sql.view.tableview");
+ bottomRight.addView("net.sourceforge.phpdt.sql.view.logview");
+ // bottomRight.addView(PHPSourceConsole.CONSOLE_ID);
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.preferences;
+
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.preference.ColorFieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+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.FontDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+import net.sourceforge.phpdt.sql.editors.ColorManager;
+import net.sourceforge.phpdt.sql.editors.SQLColorConstants;
+
+public class PreferencesPage extends PreferencePage
+ implements IWorkbenchPreferencePage {
+ FontDialog fontDialog;
+ ColorFieldEditor backgroundColorEditor;
+
+ ColorFieldEditor textColorEditor;
+ boolean textFlag;
+ ColorFieldEditor keywordColorEditor;
+ boolean keywordFlag;
+ ColorFieldEditor stringColorEditor;
+ boolean stringFlag;
+ ColorFieldEditor numericColorEditor;
+ boolean numericFlag;
+ ColorFieldEditor commentColorEditor;
+ boolean commentFlag;
+
+ Button boldText;
+ Button boldKeyword;
+ Button boldString;
+ Button boldNumeric;
+ Button boldComment;
+
+ IWorkbench workbench;
+ FontData fontData;
+ Label fontDisplay;
+ public void init(IWorkbench workbench) {
+ //Initialize the preference store
+ this.workbench = workbench;
+ setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
+ initializeColorDefaults(getPreferenceStore());
+ }
+
+ private void initializeColorDefaults(IPreferenceStore store) {
+ RGB BACKGROUND = new RGB(255, 255, 255);
+ RGB COMMENT = new RGB(88, 148, 64);
+ RGB IDENTIFIER = new RGB(0, 0, 0);
+ RGB KEYWORD = new RGB(126, 0, 75);
+ RGB STRING = new RGB(0, 0, 255);
+ RGB NUMERIC = new RGB(255, 0, 0);
+ RGB DEFAULT = new RGB(0, 0, 0);
+ PreferenceConverter.setDefault(store,
+ "quantum.background.color", BACKGROUND);
+ PreferenceConverter.setDefault(store,
+ "quantum.text.color", DEFAULT);
+ PreferenceConverter.setDefault(store,
+ "quantum.keyword.color", KEYWORD);
+ PreferenceConverter.setDefault(store,
+ "quantum.comment.color", COMMENT);
+ PreferenceConverter.setDefault(store,
+ "quantum.string.color", STRING);
+ PreferenceConverter.setDefault(store,
+ "quantum.numeric.color", NUMERIC);
+ }
+
+ protected void performDefaults() {
+ fontData = null;
+ updateFontDisplay();
+ textFlag = false;
+ keywordFlag = true;
+ stringFlag = false;
+ numericFlag = false;
+ commentFlag = false;
+ updateFlags();
+ backgroundColorEditor.loadDefault();
+ textColorEditor.loadDefault();
+ keywordColorEditor.loadDefault();
+ stringColorEditor.loadDefault();
+ commentColorEditor.loadDefault();
+ numericColorEditor.loadDefault();
+ }
+ /**
+ * Save the preferences to the preference store.
+ */
+ public boolean performOk() {
+ PreferenceConverter.setValue(getPreferenceStore(), "quantum.font", fontData);
+ getPreferenceStore().setValue("quantum.text.bold", textFlag);
+ getPreferenceStore().setValue("quantum.keyword.bold", keywordFlag);
+ getPreferenceStore().setValue("quantum.string.bold", stringFlag);
+ getPreferenceStore().setValue("quantum.comment.bold", commentFlag);
+ getPreferenceStore().setValue("quantum.numeric.bold", numericFlag);
+ backgroundColorEditor.store();
+ textColorEditor.store();
+ keywordColorEditor.store();
+ stringColorEditor.store();
+ commentColorEditor.store();
+ numericColorEditor.store();
+ return super.performOk();
+ }
+ protected Control createContents(Composite parent) {
+ Composite main = new Composite(parent, SWT.NULL);
+
+ GridLayout innerLayout = new GridLayout();
+ innerLayout.numColumns = 4;
+ main.setLayout(innerLayout);
+
+ fontData = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
+ textFlag = getPreferenceStore().getBoolean("quantum.text.bold");
+ keywordFlag = getPreferenceStore().getBoolean("quantum.keyword.bold");
+ stringFlag = getPreferenceStore().getBoolean("quantum.string.bold");
+ commentFlag = getPreferenceStore().getBoolean("quantum.comment.bold");
+ numericFlag = getPreferenceStore().getBoolean("quantum.numeric.bold");
+
+ fontDialog = new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
+ Button fontButton = new Button(main, SWT.PUSH);
+ fontButton.setText("Pick Font");
+ fontButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if (fontData != null) {
+ fontDialog.setFontData(fontData);
+ }
+ FontData data = fontDialog.open();
+ if (data != null) {
+ fontData = data;
+ updateFontDisplay();
+ }
+ }
+ });
+ Button defaultButton = new Button(main, SWT.PUSH);
+ defaultButton.setText("Default Font");
+ defaultButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ fontData = null;
+ updateFontDisplay();
+ }
+ });
+
+ fontDisplay = new Label(main, SWT.NULL);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.grabExcessHorizontalSpace = true;
+ fontDisplay.setLayoutData(data);
+ updateFontDisplay();
+
+ ColorManager manager = new ColorManager();
+
+ Composite comp = new Composite(main, SWT.NULL);
+ GridData layoutData = new GridData();
+ layoutData.horizontalSpan = 2;
+ comp.setLayoutData(layoutData);
+
+ Color defaultColor = manager.getColor(SQLColorConstants.DEFAULT);
+ backgroundColorEditor =
+ new ColorFieldEditor(
+ "quantum.background.color",
+ "Background Color",
+ comp);
+
+ Composite temp = new Composite(main, SWT.NULL);
+ temp.setSize(0, 0);
+
+ comp = new Composite(main, SWT.NULL);
+ layoutData = new GridData();
+ layoutData.horizontalSpan = 2;
+ comp.setLayoutData(layoutData);
+
+ textColorEditor =
+ new ColorFieldEditor(
+ "quantum.text.color",
+ "Default Text Color",
+ comp);
+
+ boldText = new Button(main, SWT.CHECK);
+ boldText.setSelection(textFlag);
+ boldText.setText("Bold");
+ boldText.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ textFlag = boldText.getSelection();
+ }
+ });
+
+ comp = new Composite(main, SWT.NULL);
+ layoutData = new GridData();
+ layoutData.horizontalSpan = 2;
+ comp.setLayoutData(layoutData);
+
+ keywordColorEditor =
+ new ColorFieldEditor(
+ "quantum.keyword.color",
+ "Keyword Text Color",
+ comp);
+
+ boldKeyword = new Button(main, SWT.CHECK);
+ boldKeyword.setSelection(keywordFlag);
+ boldKeyword.setText("Bold");
+ boldKeyword.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ keywordFlag = boldKeyword.getSelection();
+ }
+ });
+
+ comp = new Composite(main, SWT.NULL);
+ layoutData = new GridData();
+ layoutData.horizontalSpan = 2;
+ comp.setLayoutData(layoutData);
+
+ commentColorEditor =
+ new ColorFieldEditor(
+ "quantum.comment.color",
+ "Comment Text Color",
+ comp);
+
+ boldComment = new Button(main, SWT.CHECK);
+ boldComment.setSelection(commentFlag);
+ boldComment.setText("Bold");
+ boldComment.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ commentFlag = boldComment.getSelection();
+ }
+ });
+
+ comp = new Composite(main, SWT.NULL);
+ layoutData = new GridData();
+ layoutData.horizontalSpan = 2;
+ comp.setLayoutData(layoutData);
+
+ stringColorEditor =
+ new ColorFieldEditor(
+ "quantum.string.color",
+ "String Text Color",
+ comp);
+
+ boldString = new Button(main, SWT.CHECK);
+ boldString.setSelection(stringFlag);
+ boldString.setText("Bold");
+ boldString.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ stringFlag = boldString.getSelection();
+ }
+ });
+
+ comp = new Composite(main, SWT.NULL);
+ layoutData = new GridData();
+ layoutData.horizontalSpan = 2;
+ comp.setLayoutData(layoutData);
+
+ numericColorEditor =
+ new ColorFieldEditor(
+ "quantum.numeric.color",
+ "Numeric Text Color",
+ comp);
+
+ boldNumeric = new Button(main, SWT.CHECK);
+ boldNumeric.setSelection(numericFlag);
+ boldNumeric.setText("Bold");
+ boldNumeric.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ numericFlag = boldNumeric.getSelection();
+ }
+ });
+
+ backgroundColorEditor.setPreferencePage(this);
+ backgroundColorEditor.setPreferenceStore(getPreferenceStore());
+ backgroundColorEditor.load();
+
+ textColorEditor.setPreferencePage(this);
+ textColorEditor.setPreferenceStore(getPreferenceStore());
+ textColorEditor.load();
+
+ keywordColorEditor.setPreferencePage(this);
+ keywordColorEditor.setPreferenceStore(getPreferenceStore());
+ keywordColorEditor.load();
+
+ commentColorEditor.setPreferencePage(this);
+ commentColorEditor.setPreferenceStore(getPreferenceStore());
+ commentColorEditor.load();
+
+ stringColorEditor.setPreferencePage(this);
+ stringColorEditor.setPreferenceStore(getPreferenceStore());
+ stringColorEditor.load();
+
+ numericColorEditor.setPreferencePage(this);
+ numericColorEditor.setPreferenceStore(getPreferenceStore());
+ numericColorEditor.load();
+
+ return main;
+ }
+ public void updateFontDisplay() {
+ if (fontData == null) {
+ fontDisplay.setText("Font: default");
+ } else {
+ String style = "regular";
+ if (fontData.getStyle() == SWT.BOLD) {
+ style = "bold";
+ } else if (fontData.getStyle() == SWT.ITALIC) {
+ style = "italic";
+ } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
+ style = "bold italic";
+ }
+ fontDisplay.setText("Font: " + fontData.getName() + '-' + style + '-' + fontData.getHeight());
+ }
+ }
+ public void updateFlags() {
+ boldText.setSelection(textFlag);
+ boldKeyword.setSelection(keywordFlag);
+ boldString.setSelection(stringFlag);
+ boldNumeric.setSelection(numericFlag);
+ boldComment.setSelection(commentFlag);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+import java.util.ArrayList;
+
+public class FilterSort {
+ private ArrayList filterList = new ArrayList();
+ private ArrayList sortList = new ArrayList();
+ public void addFilter(String column, String operator, String value, boolean isString) {
+ FilterRow row = new FilterRow();
+ row.column = column;
+ row.operator = operator;
+ row.value = value;
+ row.isString = isString;
+ filterList.add(row);
+ }
+ public void clearFilters() {
+ filterList.clear();
+ }
+ public void addSort(String column) {
+ sortList.add(column);
+ }
+ public void removeSort(String column) {
+ sortList.remove(column);
+ }
+ public String toString() {
+ StringBuffer text = new StringBuffer();
+ if (filterList.size() > 0) {
+ text.append(" WHERE ");
+ for (int i = 0; i < filterList.size(); i++) {
+ FilterRow row = (FilterRow) filterList.get(i);
+ text.append(row.column);
+ text.append(" ");
+ text.append(row.operator);
+ text.append(" ");
+ if (row.isString) {
+ text.append(escape(row.value));
+ } else {
+ text.append(row.value);
+ }
+ text.append(" ");
+ if (i < filterList.size() - 1) {
+ text.append("AND ");
+ }
+ }
+ }
+ if (sortList.size() > 0) {
+ text.append(" ORDER BY ");
+ for (int i = 0; i < sortList.size(); i++) {
+ String value = (String) sortList.get(i);
+ text.append(value);
+ if (i < sortList.size() - 1) {
+ text.append(",");
+ }
+ }
+ }
+ return text.toString();
+ }
+ public static String escape(String original) {
+ return '\'' + original + '\'';
+ }
+}
+
+class FilterRow {
+ public String column;
+ public String operator;
+ public String value;
+ public boolean isString;
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.Driver;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
+import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.view.LogProxy;
+
+public class MultiSQLServer extends Thread {
+ private static final int STREAM = 1024 * 2;
+ public static final String USERNAME = "user";
+ public static final String PASSWORD = "password";
+ private static MultiSQLServer instance = null;
+ private Hashtable classLoaderCache = new Hashtable();
+ private Connection con = null;
+ boolean running = true;
+ private Bookmark current = null;
+ private MultiSQLServer() {
+ //start();
+ }
+ public synchronized static MultiSQLServer getInstance() {
+ if (instance == null) {
+ instance = new MultiSQLServer();
+ }
+ return instance;
+ }
+ public Bookmark getConnected() {
+ return current;
+ }
+
+ public void commit() {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ con.commit();
+ } catch (SQLException e) {
+ log.addText(log.ERROR, "Error commiting: " + e);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ }
+
+ public void rollback() {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ con.rollback();
+ } catch (SQLException e) {
+ log.addText(log.ERROR, "Error rolling back: " + e);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ }
+
+ public void setAutoCommit(boolean enabled) {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ if (con != null) {
+ con.setAutoCommit(enabled);
+ } else {
+ log.addText(log.ERROR, "Please connect before setting autocommit");
+ }
+ } catch (SQLException e) {
+ log.addText(log.ERROR, "Error setting autocommit: " + e);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ }
+
+ public DatabaseAdapter getCurrentAdapter() {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ AdapterFactory factory = AdapterFactory.getInstance();
+ return factory.getAdapter(current.getType());
+ } catch (NoSuchAdapterException e) {
+ log.addText(log.ERROR, "Invalid database type: ->" + current.getType() + "<-");
+ }
+ return null;
+ }
+ public void disconnect(Bookmark b) {
+ current = null;
+ LogProxy log = LogProxy.getInstance();
+
+ try {
+ con.close();
+ con = null;
+ log.addText(log.RESULTS, "Disconnected from: " + b.getName());
+ } catch (Exception e) {
+ log.addText(
+ log.ERROR,
+ "Error Disonnecting to: " + b.getName() + ":" + e.toString());
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+
+ }
+ }
+ public void shutdown() {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ if (con != null) {
+ con.close();
+ }
+ con = null;
+ } catch (SQLException e) {
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ }
+
+ public void dumpDatabaseData() {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ DatabaseMetaData metadata = con.getMetaData();
+ log.addText(log.WARNING, "[METADATA] Database type: " + metadata.getDatabaseProductName());
+ if (metadata.supportsCatalogsInDataManipulation()) {
+ log.addText(log.WARNING, "[METADATA] Database does support catalog in data manipulation");
+ } else {
+ log.addText(log.WARNING, "[METADATA] Database does not support catalog in data manipulation");
+ }
+ if (metadata.supportsSchemasInDataManipulation()) {
+ log.addText(log.WARNING, "[METADATA] Database does support schema in data manipulation");
+ } else {
+ log.addText(log.WARNING, "[METADATA] Database does not support schema in data manipulation");
+ }
+ if (metadata.supportsCatalogsInTableDefinitions()) {
+ log.addText(log.WARNING, "[METADATA] Database does support catalogs in table definitions");
+ } else {
+ log.addText(log.WARNING, "[METADATA] Database does not support catalogs in table definitions");
+ }
+ log.addText(log.WARNING, "[METADATA] Catalog Separator: " + metadata.getCatalogSeparator());
+ log.addText(log.WARNING, "[METADATA] Catalog Term: " + metadata.getCatalogTerm());
+ ResultSet set = metadata.getCatalogs();
+ ArrayList catalogList = new ArrayList();
+ catalogList.add(null);
+ while (set.next()) {
+ catalogList.add(set.getString(1));
+ }
+ set.close();
+ StringBuffer catalogOutput = new StringBuffer();
+ catalogOutput.append("[CATALOG LIST] [");
+ for (int i = 0; i < catalogList.size(); i++) {
+ String name = (String) catalogList.get(i);
+ catalogOutput.append(name + ", ");
+ }
+ catalogOutput.append("]");
+ log.addText(log.WARNING, catalogOutput.toString());
+
+ set = metadata.getSchemas();
+ ArrayList schemaList = new ArrayList();
+ schemaList.add("");
+ while (set.next()) {
+ schemaList.add(set.getString(1));
+ }
+ set.close();
+ StringBuffer schemaOutput = new StringBuffer();
+ schemaOutput.append("[SCHEMA LIST] [");
+ for (int i = 0; i < schemaList.size(); i++) {
+ String name = (String) schemaList.get(i);
+ schemaOutput.append(name + ", ");
+ }
+ schemaOutput.append("]");
+ log.addText(log.WARNING, schemaOutput.toString());
+
+ ArrayList tableTypes = new ArrayList();
+ set = metadata.getTableTypes();
+ while (set.next()) {
+ tableTypes.add(set.getString(1));
+ }
+ set.close();
+
+ StringBuffer tableListOutput = new StringBuffer();
+ tableListOutput.append("[TABLE LIST] [");
+ for (int i = 0; i < tableTypes.size(); i++) {
+ String name = (String) tableTypes.get(i);
+ tableListOutput.append(name + ", ");
+ }
+ tableListOutput.append("]");
+ log.addText(log.WARNING, tableListOutput.toString());
+
+
+ } catch (Exception e) {
+ log.addText(log.ERROR, "Error occured: " + e);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ }
+ /**
+ * type = "TABLE" "VIEW" "SEQUENCE"
+ */
+ public Vector listTables(String schema, String type) {
+ LogProxy log = LogProxy.getInstance();
+ Vector retVal = new Vector();
+ log.addText(log.QUERY, "Retrieving list [" + type + "]");
+ try {
+ DatabaseMetaData meta = con.getMetaData();
+ ResultSet set = meta.getTableTypes();
+ int columnCount = set.getMetaData().getColumnCount();
+ for (int i = 1; i <= columnCount; i++) {
+ System.out.print(set.getMetaData().getColumnName(i) + "\t");
+ }
+ System.out.println();
+ while (set.next()) {
+ for (int i = 1; i <= columnCount; i++) {
+ System.out.print(set.getString(i) + "\t");
+ }
+ System.out.println();
+ }
+ Vector types = new Vector();
+ set = meta.getTableTypes();
+ while (set.next()) {
+ types.add(set.getString(1));
+ }
+ set.close();
+ if (types.contains(type)) {
+ set = meta.getTables(null, schema, "%", new String[] {type});
+ while (set.next()) {
+ String name = set.getString("TABLE_NAME");
+ String tableType = set.getString("TABLE_TYPE");
+ //System.out.println(name + ":" + tableType);
+ retVal.addElement(name);
+ }
+ set.close();
+ }
+ log.addText(log.RESULTS, "Success");
+ } catch (SQLException e) {
+ log.addText(log.ERROR, "Error occured: " + e);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ return retVal;
+ }
+ public boolean connect(Bookmark b) {
+ LogProxy log = LogProxy.getInstance();
+ log.addText(log.QUERY, "Connecting to: " + b.getName());
+ URL urls[] = new URL[1];
+ try {
+ String driverFile = b.getDriverFile();
+ URLClassLoader loader = (URLClassLoader) classLoaderCache.get(driverFile);
+ if (loader == null) {
+ urls[0] = new File(driverFile).toURL();
+ loader = new URLClassLoader(urls);
+ classLoaderCache.put(driverFile, loader);
+ System.out.println("Creating new classloader");
+ } else {
+ System.out.println("Using classloader in cache");
+ }
+ Class driverClass = loader.loadClass(b.getDriver());
+ Driver driver = (Driver) driverClass.newInstance();
+ Properties props = new Properties();
+ props.put(USERNAME, b.getUsername());
+ props.put(PASSWORD, b.getPassword());
+ con = driver.connect(b.getConnect(), props);
+ if (con == null) {
+ throw new Exception("Error: Driver returned a null connection: " + b.toString());
+ }
+ current = b;
+ log.addText(log.RESULTS, "Connected to: " + b.getName());
+ System.out.println("Connected");
+ return true;
+ } catch (Exception e) {
+ log.addText(
+ log.ERROR,
+ "Error Connecting to: " + b.getName() + ":" + e.toString());
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ return false;
+ }
+ public SQLResults execute(String s) {
+ return execute(s, -1, -1);
+ }
+ public SQLResults execute(String s, int startRow, int endRow) {
+ return execute(s, -1, -1, Integer.MAX_VALUE);
+ }
+ public SQLResults execute(String s, int startRow, int endRow, int maxLength) {
+ return execute(s, startRow, endRow, maxLength, "");
+ }
+ public SQLResults execute(String s, int startRow, int endRow, int maxLength, String encoding) {
+ SQLResults results = new SQLResults();
+
+ System.out.println("Executing");
+ LogProxy log = LogProxy.getInstance();
+ log.addText(log.QUERY, "Executing Request [" + s + "]");
+ boolean metadata = false;
+ if (s.startsWith("METADATA")) {
+ metadata = true;
+ }
+ if (metadata) {
+ results.setQuery(s);
+ String table = s.substring(s.indexOf(':') + 1);
+ String schema = current.getSchema();
+ String query = "SELECT * FROM " + schema + "." + table;
+ if (schema.equals("")) {
+ query = "SELECT * FROM " + table;
+ }
+ s = query;
+ log.addText(log.QUERY, "Metadata Request [" + s + "]");
+ } else {
+ results.setQuery(s);
+ }
+ try {
+ Statement stmt = con.createStatement();
+ boolean flag = stmt.execute(s);
+ results.setResultSet(flag);
+ if (!flag) {
+ int updates = stmt.getUpdateCount();
+ results.setUpdateCount(updates);
+ log.addText(
+ log.RESULTS,
+ "Success: " + updates + " records updated");
+
+ } else {
+ if (metadata) {
+ ResultSet set = stmt.getResultSet();
+ ResultSetMetaData metaData = set.getMetaData();
+ int columnCount = metaData.getColumnCount();
+ Vector columnNames = new Vector();
+ columnNames.addElement("ColumnName");
+ columnNames.addElement("Type");
+ columnNames.addElement("Size");
+ columnNames.addElement("Nullable");
+ columnNames.addElement("AutoIncrement");
+ results.setColumnNames(columnNames);
+ for (int i = 1; i <= columnCount; i++) {
+ Vector row = new Vector();
+ row.addElement(metaData.getColumnName(i));
+ row.addElement(metaData.getColumnTypeName(i));
+ int textSize = metaData.getColumnDisplaySize(i);
+ int precision = metaData.getPrecision(i);
+ int scale = metaData.getScale(i);
+ if (scale == 0 && precision == 0) {
+ row.addElement(Integer.toString(precision));
+ } else {
+ row.addElement(textSize + ", " + precision + ", " + scale);
+ }
+ int nullable = metaData.isNullable(i);
+ if (nullable == metaData.columnNoNulls) {
+ row.addElement("Not Null");
+ } else if (nullable == metaData.columnNullable) {
+ row.addElement("Nullable");
+ } else if (nullable == metaData.columnNullableUnknown) {
+ row.addElement("Nullable");
+ } else {
+ row.addElement("<Error>");
+ }
+ row.addElement(new Boolean(metaData.isAutoIncrement(i)).toString());
+ results.addRow(row);
+ }
+ results.setHasMore(false);
+ } else {
+ ResultSet set = stmt.getResultSet();
+ ResultSetMetaData metaData = set.getMetaData();
+ int columnCount = metaData.getColumnCount();
+ Vector columnNames = new Vector();
+ for (int i = 1; i <= columnCount; i++) {
+ columnNames.addElement(metaData.getColumnName(i));
+ }
+ results.setColumnNames(columnNames);
+ Vector columnTypes = new Vector();
+ for (int i = 1; i <= columnCount; i++) {
+ columnTypes.addElement(metaData.getColumnTypeName(i));
+ }
+ results.setColumnsTypes(columnTypes);
+ int columnSizes[] = new int[columnCount];
+ for (int i = 1; i <= columnCount; i++) {
+ columnSizes[i - 1] = metaData.getColumnDisplaySize(i);
+ }
+ int rowCount = 1;
+ boolean exitEarly = false;
+ while (set.next()) {
+ boolean disable = startRow < 1 || endRow < 1;
+ boolean start = rowCount >= startRow;
+ boolean end = rowCount <= endRow;
+ if (disable || (start && end)) {
+ Vector row = new Vector();
+ for (int i = 1; i <= columnCount; i++) {
+ String value;
+ if (columnSizes[i - 1] < STREAM && columnSizes[i - 1] < maxLength) {
+ if (encoding.equals("")) {
+ value = set.getString(i);
+ } else {
+ value = new String(set.getBytes(i), encoding);
+ }
+ } else {
+ try {
+ if (encoding.equals("")) {
+ Reader reader = set.getCharacterStream(i);
+ StringBuffer buffer = new StringBuffer();
+ if (reader != null) {
+ int retVal = reader.read();
+ int count = 0;
+ while (retVal >= 0) {
+ buffer.append((char) retVal);
+ retVal = reader.read();
+ count++;
+ if (count > maxLength) {
+ buffer.append("...>>>");
+ break;
+ }
+ }
+ reader.close();
+ }
+ value = buffer.toString();
+ } else {
+ InputStream binaryStream = set.getBinaryStream(i);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ if (binaryStream != null) {
+ int retVal = binaryStream.read();
+ int count = 0;
+ while (retVal >= 0) {
+ baos.write(retVal);
+ retVal = binaryStream.read();
+ count++;
+ if (count > maxLength) {
+ break;
+ }
+ }
+ binaryStream.close();
+ }
+ value = new String(baos.toByteArray(), encoding);
+ }
+ } catch (Throwable e) {
+ // hack for mysql which doesn't implement
+ // character streams
+ value = set.getString(i);
+ }
+ }
+ if (set.wasNull()) {
+ row.addElement("<NULL>");
+ } else {
+ row.addElement(value);
+ }
+ }
+ results.addRow(row);
+ }
+ rowCount++;
+ if (!disable && (rowCount > endRow)) {
+ exitEarly = true;
+ break;
+ }
+ }
+ if (exitEarly) {
+ results.setHasMore(set.next());
+ } else {
+ results.setMaxSize(rowCount);
+ results.setHasMore(false);
+ }
+ }
+ log.addText(log.RESULTS, "Success: result set displayed");
+ }
+ stmt.close();
+ System.out.println("Executed");
+ System.out.println();
+ } catch (Exception e) {
+ results.setIsError(true);
+ log.addText(log.ERROR, "Error occured: " + e);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ log.addText(
+ log.ERROR,
+ writer.toString());
+ }
+ return results;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
+import net.sourceforge.phpdt.sql.adapters.DatabaseInfo;
+import net.sourceforge.phpdt.sql.adapters.FeatureNotSupported;
+import net.sourceforge.phpdt.sql.adapters.GenericAdapter;
+import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.MetaDataNode;
+import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
+
+public class SQLHelper {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ public Vector getTableList(BookmarkNode current) throws NoSuchAdapterException, FeatureNotSupported {
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(current.getType());
+ Vector children = new Vector();
+ DatabaseInfo info = DatabaseInfo.create(current);
+ if (adapter instanceof GenericAdapter) {
+ Vector tables = server.listTables(info.getSchema(), "TABLE");
+ for (int i = 0; i < tables.size(); i++) {
+ String tableName = (String) tables.elementAt(i);
+ TableNode node = new TableNode(current, tableName);
+ children.addElement(node);
+ }
+ } else {
+ SQLResults results = server.execute(adapter.getShowTableQuery(info));
+ String filter = adapter.getTableListFilter();
+ int size = results.getRowCount();
+ System.out.println("Found " + size + " tables");
+ for (int i = 1; i <= size; i++) {
+ String tableName = results.getElement(1, i).toString();
+ if (filter == null || filter.equals("") || tableName.indexOf(filter) < 0) {
+ TableNode node = new TableNode(current, tableName);
+ children.addElement(node);
+ }
+ }
+ }
+ return children;
+ }
+ public int getSize(String query) {
+ SQLResults results = server.execute("SELECT COUNT(*) FROM " + query);
+ return Integer.parseInt(results.getElement(1, 1).toString());
+ }
+ public Vector getViewList(BookmarkNode current)
+ throws NoSuchAdapterException, FeatureNotSupported {
+ DatabaseAdapter adapter =
+ AdapterFactory.getInstance().getAdapter(current.getType());
+ Vector children = new Vector();
+ DatabaseInfo info = DatabaseInfo.create(current);
+ if (adapter instanceof GenericAdapter) {
+ Vector views = server.listTables(info.getSchema(), "VIEW");
+ for (int i = 0; i < views.size(); i++) {
+ String viewName = (String) views.elementAt(i);
+ ViewNode node = new ViewNode(current, viewName);
+ children.addElement(node);
+ }
+ } else {
+ SQLResults results =
+ server.execute(
+ adapter.getShowViewQuery(info));
+ String filter = adapter.getTableListFilter();
+ int size = results.getRowCount();
+ for (int i = 1; i <= size; i++) {
+ String viewName = results.getElement(1, i).toString();
+ if (filter == null
+ || filter.equals("")
+ || viewName.indexOf(filter) < 0) {
+ ViewNode node = new ViewNode(current, viewName);
+ children.addElement(node);
+ }
+ }
+ }
+ return children;
+ }
+ public Vector getSequenceList(BookmarkNode current) throws NoSuchAdapterException, FeatureNotSupported {
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(current.getType());
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ Vector children = new Vector();
+ if (!(adapter instanceof GenericAdapter)) {
+ SQLResults results = server.execute(adapter.getShowSequenceQuery(DatabaseInfo.create(current)));
+ String filter = adapter.getTableListFilter();
+ int size = results.getRowCount();
+ for (int i = 1; i <= size; i++) {
+ String seqName = results.getElement(1, i).toString();
+ if (filter == null || filter.equals("") || seqName.indexOf(filter) < 0) {
+ SequenceNode node = new SequenceNode(current, seqName);
+ children.addElement(node);
+ }
+ }
+ }
+ return children;
+ }
+ public Vector getMetaData(TableNode parent, String entity) {
+ Vector columns = new Vector();
+ String query = "SELECT * FROM " + entity;
+ SQLResults results = server.execute(query);
+ for (int i = 1; i <= results.getColumnCount(); i++) {
+ String name = results.getColumnName(i);
+ String type = results.getColumnType(i);
+ MetaDataNode node = new MetaDataNode(parent, name, type);
+ columns.addElement(node);
+ }
+ return columns;
+ }
+ public Vector getMetaData(ViewNode parent, String entity) {
+ Vector columns = new Vector();
+ String query = "SELECT * FROM " + entity;
+ SQLResults results = server.execute(query);
+ for (int i = 1; i <= results.getColumnCount(); i++) {
+ String name = results.getColumnName(i);
+ String type = results.getColumnType(i);
+ MetaDataNode node = new MetaDataNode(parent, name, type);
+ columns.addElement(node);
+ }
+ return columns;
+ }
+ public SQLResults getResults(String query, int start, int end) {
+ return server.execute(query, start, end);
+ }
+ public SQLResults getResults(String query, int start, int end, int maxLength, String encoding) {
+ return server.execute(query, start, end, maxLength, encoding);
+ }
+ public static String getFullTableName(Bookmark current, String table) {
+ String schema = current.getSchema();
+ if (schema == null || schema.equals("")) {
+ return table;
+ }
+ return schema + "." + table;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+import java.util.Vector;
+
+public class SQLMetaData {
+ private String tableName;
+ private Vector columnNames;
+ private Vector columTypes;
+ private Vector columnClassnames;
+ private Vector columnSizes;
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public void setTableName(String tableName) {
+ this.tableName = tableName;
+ }
+ public Vector getColumnClassnames() {
+ return columnClassnames;
+ }
+
+ public Vector getColumnNames() {
+ return columnNames;
+ }
+
+ public Vector getColumnSizes() {
+ return columnSizes;
+ }
+
+ public Vector getColumTypes() {
+ return columTypes;
+ }
+
+ public void setColumnClassnames(Vector columnClassnames) {
+ this.columnClassnames = columnClassnames;
+ }
+
+ public void setColumnNames(Vector columnNames) {
+ this.columnNames = columnNames;
+ }
+
+ public void setColumnSizes(Vector columnSizes) {
+ this.columnSizes = columnSizes;
+ }
+
+ public void setColumTypes(Vector columTypes) {
+ this.columTypes = columTypes;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.parser.SQLLexx;
+import net.sourceforge.phpdt.sql.parser.Token;
+
+public class SQLParser {
+ public static final String COMMENT = "--";
+ public static final String ENDLINE = ";";
+ public static Vector parse(String query) {
+ Vector commands = new Vector();
+ try {
+ //System.out.println("-------------------1");
+ Vector tokens = SQLLexx.parse(query);
+ //System.out.println("-------------------2");
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < tokens.size(); i++) {
+ //System.out.println("-------------------3");
+ Token t = (Token) tokens.elementAt(i);
+ if (t.getType() == t.COMMENT) {
+ // ignore comments
+ } else if (t.getType() == t.SEPARATOR) {
+ String newCommand = buffer.toString().trim();
+ if (!newCommand.equals("")) {
+ commands.addElement(newCommand);
+ }
+ buffer = new StringBuffer();
+ } else {
+ buffer.append(t.getValue());
+ }
+ }
+ String newCommand = buffer.toString().trim();
+ if (!newCommand.equals("")) {
+ commands.addElement(newCommand);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ System.out.println("Returning");
+ return commands;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+import java.util.ArrayList;
+import java.util.Vector;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class SQLResults {
+ private String query;
+ private String table;
+ private ArrayList rows = new ArrayList();
+ private Vector columns;
+ private Vector columnTypes;
+ private int updateCount = 0;
+ private boolean resultSet = false;
+ private boolean hasMore = false;
+ private boolean isError = false;
+ private int maxSize = -1;
+ public void setColumnNames(Vector columns) {
+ this.columns = columns;
+ }
+ public String getColumnName(int column) {
+ return columns.elementAt(column - 1).toString();
+ }
+ public String getColumnType(int column) {
+ return columnTypes.elementAt(column - 1).toString();
+ }
+ public void addRow(Vector row) {
+ rows.add(row);
+ }
+ public Object getElement(int column, int row) {
+ return ((Vector) rows.get(row - 1)).elementAt(column - 1);
+ }
+ public int getColumnCount() {
+ if (columns.size() > 0) {
+ return columns.size();
+ }
+ return 0;
+ }
+ public int getRowCount() {
+ return rows.size();
+ }
+ /**
+ * Returns the query.
+ * @return String
+ */
+ public String getQuery() {
+ return query;
+ }
+
+ /**
+ * Sets the query.
+ * @param query The query to set
+ */
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ /**
+ * Returns the resultSet.
+ * @return boolean
+ */
+ public boolean isResultSet() {
+ return resultSet;
+ }
+
+ /**
+ * Sets the resultSet.
+ * @param resultSet The resultSet to set
+ */
+ public void setResultSet(boolean resultSet) {
+ this.resultSet = resultSet;
+ }
+
+ public int getUpdateCount() {
+ return updateCount;
+ }
+
+ public void setUpdateCount(int updateCount) {
+ this.updateCount = updateCount;
+ }
+
+ public String getTable() {
+ return table;
+ }
+
+ public void setTable(String table) {
+ this.table = table;
+ }
+
+ public void setColumnsTypes(Vector columnsTypes) {
+ this.columnTypes = columnsTypes;
+ }
+
+ public boolean hasMore() {
+ return hasMore;
+ }
+
+ public void setHasMore(boolean hasMore) {
+ this.hasMore = hasMore;
+ }
+
+ public int getMaxSize() {
+ return maxSize;
+ }
+
+ public void setMaxSize(int maxSize) {
+ this.maxSize = maxSize;
+ }
+
+ public boolean isError() {
+ return isError;
+ }
+
+ public void setIsError(boolean isError) {
+ this.isError = isError;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.sql;
+
+public class TableRow {
+ private String[] columnNames;
+ private String[] tableData;
+ private String table;
+
+ public TableRow(String tableName, String[] columnNames, String[] tableData) {
+ this.table = tableName;
+ this.tableData = tableData;
+ this.columnNames = columnNames;
+ }
+
+ public int getColumnCount() {
+ return columnNames.length;
+ }
+
+ public String[] getColumnNames() {
+ return columnNames;
+ }
+
+ public String getTable() {
+ return table;
+ }
+
+ public void setColumnNames(String[] columnNames) {
+ this.columnNames = columnNames;
+ }
+
+ public void setTable(String table) {
+ this.table = table;
+ }
+
+ public String[] getTableData() {
+ return tableData;
+ }
+
+ public void setTableData(String[] tableData) {
+ this.tableData = tableData;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import java.net.URL;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class BookmarkLabelProvider implements ILabelProvider {
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
+ */
+ public Image getImage(Object element) {
+ ImageDescriptor descriptor = null;
+ if (element instanceof BookmarkNode) {
+ try {
+ URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ URL url = new URL(installURL, "icons/bookmarks.gif");
+ if (server.getConnected() != null && element.equals(server.getConnected())){
+ url = new URL(installURL, "icons/connected.gif");
+ }
+ descriptor = ImageDescriptor.createFromURL(url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ return null;
+ }
+ return descriptor.createImage();
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
+ */
+ public String getText(Object element) {
+ if (element instanceof BookmarkNode) {
+ Bookmark bookmark = (Bookmark) element;
+ return bookmark.getName();
+ } else if (element.equals(Root.ROOT)) {
+ return "ROOT";
+ } else if (element instanceof TableNode) {
+ TableNode node = (TableNode) element;
+ if (node.getSize() > -1) {
+ return "T " + element.toString() + " (" + node.getSize() + ")";
+ } else {
+ return "T " + element.toString();
+ }
+ } else if (element instanceof ViewNode) {
+ ViewNode node = (ViewNode) element;
+ if (node.getSize() > -1) {
+ return "V " + element.toString() + " (" + node.getSize() + ")";
+ } else {
+ return "V " + element.toString();
+ }
+ } else if (element instanceof SequenceNode) {
+ return "S " + element.toString();
+ }
+ return element.toString();
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
+ */
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+ */
+ public void dispose() {
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String)
+ */
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
+ */
+ public void removeListener(ILabelProviderListener listener) {
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+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.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.part.ViewPart;
+
+import net.sourceforge.phpdt.sql.actions.ConnectAction;
+import net.sourceforge.phpdt.sql.actions.DeleteBookmarkAction;
+import net.sourceforge.phpdt.sql.actions.DisconnectAction;
+import net.sourceforge.phpdt.sql.actions.EditBookmarkAction;
+import net.sourceforge.phpdt.sql.actions.NewBookmarkAction;
+import net.sourceforge.phpdt.sql.actions.NextSequenceAction;
+import net.sourceforge.phpdt.sql.actions.RefreshBookmarkAction;
+import net.sourceforge.phpdt.sql.actions.ViewTableAction;
+import net.sourceforge.phpdt.sql.actions.ViewTableDetailsAction;
+import net.sourceforge.phpdt.sql.adapters.FeatureNotSupported;
+import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
+
+public class BookmarkView extends ViewPart {
+ private ConnectAction connectAction;
+ private DisconnectAction disconnectAction;
+ private NewBookmarkAction newBookmarkAction;
+ private EditBookmarkAction editBookmarkAction;
+ private DeleteBookmarkAction deleteBookmarkAction;
+ private ViewTableAction viewTableAction;
+ private RefreshBookmarkAction refreshBookmarkAction;
+ private ViewTableDetailsAction viewTableDetailsAction;
+ private NextSequenceAction nextSequenceAction;
+ private Action enableTableSizes;
+ private Action enableTableColumns;
+ private static BookmarkView instance = null;
+ private TreeViewer treeViewer;
+ private BookmarkContentProvider provider =
+ BookmarkContentProvider.getInstance();
+ private Label status;
+ private SQLHelper helper = new SQLHelper();
+ private boolean showTableSizes = false;
+ private boolean showTableColumns = false;
+ private BookmarkNode clipboard;
+ public synchronized static BookmarkView getInstance() {
+ return instance;
+ }
+ public Object getCurrent() {
+ return ((StructuredSelection) treeViewer.getSelection()).getFirstElement();
+ }
+ public BookmarkNode getCurrentBookmark() {
+ return (BookmarkNode) getCurrent();
+ }
+ public TableNode getCurrentTable() {
+ return (TableNode) getCurrent();
+ }
+ public void deleteCurrent() {
+ provider.removeBookmark(getCurrentBookmark());
+ treeViewer.refresh();
+ }
+ public void refreshBookmarkData() {
+ BookmarkNode current =
+ (BookmarkNode) MultiSQLServer.getInstance().getConnected();
+ BookmarkContentProvider provider = BookmarkContentProvider.getInstance();
+ LogProxy log = LogProxy.getInstance();
+ if (current != null) {
+ try {
+ Vector children = new Vector();
+ setStatus(Messages.getString("bookmarkview.retrieveTableData")); //$NON-NLS-1$
+ Vector tables = new Vector();
+ try {
+ tables = helper.getTableList(current);
+ if (showTableSizes || showTableColumns) {
+ for (int i = 0; i < tables.size(); i++) {
+ TableNode table = (TableNode) tables.elementAt(i);
+ String name =
+ SQLHelper.getFullTableName(current, table.getName());
+ if (showTableSizes) {
+ int size = helper.getSize(name);
+ table.setSize(size);
+ }
+ if (showTableColumns) {
+ Vector metaData = helper.getMetaData(table, name);
+ table.setMetadata(metaData);
+ }
+ }
+ }
+ } catch (FeatureNotSupported e) {
+ setStatus(Messages.getString("bookmarkview.noTables")); //$NON-NLS-1$
+ }
+ setStatus(Messages.getString("bookmarkview.retrieveViewData")); //$NON-NLS-1$
+ Vector views = new Vector();
+ try {
+ views = helper.getViewList(current);
+ if (showTableSizes || showTableColumns) {
+ for (int i = 0; i < views.size(); i++) {
+ ViewNode view = (ViewNode) views.elementAt(i);
+ String name = SQLHelper.getFullTableName(current, view.getName());
+ if (showTableSizes) {
+ int size = helper.getSize(name);
+ view.setSize(size);
+ }
+ if (showTableColumns) {
+ Vector metaData = helper.getMetaData(view, name);
+ view.setMetadata(metaData);
+ }
+ }
+ }
+ } catch (FeatureNotSupported e) {
+ setStatus(Messages.getString("bookmarkview.noViews")); //$NON-NLS-1$
+ }
+ children.addAll(tables);
+ children.addAll(views);
+ setStatus(Messages.getString("bookmarkview.retrieveSeqData")); //$NON-NLS-1$
+ try {
+ children.addAll(helper.getSequenceList(current));
+ } catch (FeatureNotSupported e) {
+ setStatus(Messages.getString("bookmarkview.noSequences")); //$NON-NLS-1$
+ }
+ provider.setChildren(current, children);
+ BookmarkView.getInstance().refresh();
+ setStatus(Messages.getString("bookmarkview.done")); //$NON-NLS-1$
+ } catch (NoSuchAdapterException e) {
+ setStatus(Messages.getString("bookmarkview.metaDataError")); //$NON-NLS-1$
+ log.addText(SQLLogView.ERROR, "Error occurred: " + e.toString()); //$NON-NLS-1$
+ e.printStackTrace();
+ }
+ }
+ }
+ public void expandCurrent(BookmarkNode node) {
+ treeViewer.setExpandedState(node, true);
+ treeViewer.refresh(node, false);
+ }
+ public void refresh() {
+ treeViewer.refresh();
+ }
+ public void disconnect() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ BookmarkNode current = (BookmarkNode) server.getConnected();
+ if (current != null) {
+ setStatus(Messages.getString("bookmarkview.disconnect") + current.getName()); //$NON-NLS-1$
+ MultiSQLServer.getInstance().disconnect(current);
+ BookmarkContentProvider provider = BookmarkContentProvider.getInstance();
+ provider.setChildren(current, new Vector());
+ BookmarkView.getInstance().refresh();
+ setStatus(Messages.getString("bookmarkview.done")); //$NON-NLS-1$
+ }
+ }
+ public void createPartControl(org.eclipse.swt.widgets.Composite parent) {
+ instance = this;
+ initActions();
+ Composite main = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 0;
+ main.setLayout(layout);
+
+ enableTableSizes = new Action() {
+ public void run() {
+ showTableSizes = enableTableSizes.isChecked();
+ refreshBookmarkData();
+ }
+ };
+ enableTableSizes.setText("Show Table Sizes");
+ enableTableSizes.setChecked(false);
+
+ enableTableColumns = new Action() {
+ public void run() {
+ showTableColumns = enableTableColumns.isChecked();
+ refreshBookmarkData();
+ }
+ };
+ enableTableColumns.setText("Show Table Column Data");
+ enableTableColumns.setChecked(false);
+
+ IActionBars actionBars = getViewSite().getActionBars();
+ actionBars.getMenuManager().add(enableTableSizes);
+ actionBars.getMenuManager().add(enableTableColumns);
+
+ treeViewer = new TreeViewer(main);
+ treeViewer.setContentProvider(provider);
+ treeViewer.setLabelProvider(new BookmarkLabelProvider());
+ treeViewer.setInput(Root.ROOT);
+ MenuManager manager = new MenuManager();
+ manager.setRemoveAllWhenShown(true);
+ Menu fTextContextMenu = manager.createContextMenu(treeViewer.getControl());
+ treeViewer.getControl().setMenu(fTextContextMenu);
+ treeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ Object sel = getCurrent();
+ if (sel instanceof BookmarkNode) {
+ BookmarkNode node = (BookmarkNode) sel;
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ if (server.getConnected() == null
+ || !node.equals(server.getConnected())) {
+ connectAction.run();
+ }
+ } else if (sel instanceof TableNode) {
+ viewTableAction.run();
+ } else if (sel instanceof ViewNode) {
+ viewTableAction.run();
+ }
+ }
+ });
+ manager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager mgr) {
+ Object sel = getCurrent();
+ if (sel instanceof BookmarkNode) {
+ BookmarkNode node = (BookmarkNode) sel;
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ boolean connected = false;
+ if (server.getConnected() != null
+ && node.equals(server.getConnected())) {
+ connected = true;
+ } else {
+ connected = false;
+ }
+ if (connected) {
+ mgr.add(disconnectAction);
+ } else {
+ mgr.add(connectAction);
+ }
+ mgr.add(new Separator());
+ mgr.add(newBookmarkAction);
+ mgr.add(editBookmarkAction);
+ mgr.add(deleteBookmarkAction);
+ mgr.add(new Separator());
+ mgr.add(copyAction);
+ copyAction.setText("Copy");
+ copyAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ mgr.add(pasteAction);
+ pasteAction.setText("Paste");
+ pasteAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("paste.gif")); //$NON-NLS-1$
+ if (connected) {
+ mgr.add(new Separator());
+ mgr.add(refreshBookmarkAction);
+ }
+ } else if (sel instanceof TableNode || sel instanceof ViewNode) {
+ mgr.add(viewTableAction);
+ mgr.add(viewTableDetailsAction);
+ mgr.add(new Separator());
+ mgr.add(newBookmarkAction);
+ } else if (sel instanceof SequenceNode) {
+ mgr.add(nextSequenceAction);
+ mgr.add(new Separator());
+ mgr.add(newBookmarkAction);
+ } else {
+ mgr.add(newBookmarkAction);
+ }
+ }
+ });
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ treeViewer.getControl().setLayoutData(gridData);
+ status = new Label(main, SWT.NONE);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ status.setLayoutData(gridData);
+
+ IActionBars bars = getViewSite().getActionBars();
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
+ bars.setGlobalActionHandler(
+ IWorkbenchActionConstants.DELETE,
+ deleteBookmarkAction);
+
+ IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+ toolBar.add(newBookmarkAction);
+
+ status.setText(Messages.getString("bookmarkview.done")); //$NON-NLS-1$
+ }
+ public void initActions() {
+ connectAction = new ConnectAction();
+ connectAction.setText(Messages.getString("bookmarkview.connect")); //$NON-NLS-1$
+ connectAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("refresh.gif")); //$NON-NLS-1$
+ connectAction.init(this);
+ disconnectAction = new DisconnectAction();
+ disconnectAction.setText(Messages.getString("bookmarkview.disconnect")); //$NON-NLS-1$
+ disconnectAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("stop.gif")); //$NON-NLS-1$
+ disconnectAction.init(this);
+ newBookmarkAction = new NewBookmarkAction();
+ newBookmarkAction.setText(Messages.getString("bookmarkview.newBookmark")); //$NON-NLS-1$
+ newBookmarkAction.setToolTipText(
+ Messages.getString("bookmarkview.newBookmark"));
+ newBookmarkAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("bookmarks.gif")); //$NON-NLS-1$
+ newBookmarkAction.init(this);
+ editBookmarkAction = new EditBookmarkAction();
+ editBookmarkAction.setText(Messages.getString("bookmarkview.editBookmark")); //$NON-NLS-1$
+ editBookmarkAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("edit.gif")); //$NON-NLS-1$
+ editBookmarkAction.init(this);
+ deleteBookmarkAction = new DeleteBookmarkAction();
+ deleteBookmarkAction.setText(Messages.getString("bookmarkview.deleteBookmark")); //$NON-NLS-1$
+ deleteBookmarkAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ deleteBookmarkAction.init(this);
+ refreshBookmarkAction = new RefreshBookmarkAction();
+ refreshBookmarkAction.setText(Messages.getString("bookmarkview.refresh")); //$NON-NLS-1$
+ refreshBookmarkAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("refresh.gif")); //$NON-NLS-1$
+ refreshBookmarkAction.init(this);
+ viewTableAction = new ViewTableAction();
+ viewTableAction.setText(Messages.getString("bookmarkview.viewTable")); //$NON-NLS-1$
+ viewTableAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ viewTableAction.init(this);
+ viewTableDetailsAction = new ViewTableDetailsAction();
+ viewTableDetailsAction.setText(Messages.getString("bookmarkview.viewTableDetails")); //$NON-NLS-1$
+ viewTableDetailsAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ viewTableDetailsAction.init(this);
+ nextSequenceAction = new NextSequenceAction();
+ nextSequenceAction.setText(Messages.getString("bookmarkview.nextSequence"));
+ nextSequenceAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("table.gif"));
+ nextSequenceAction.init(this);
+ }
+ public void setFocus() {
+ }
+ private Action copyAction = new Action() {
+ public void run() {
+ Object sel = getCurrent();
+ if (sel instanceof BookmarkNode) {
+ clipboard = (BookmarkNode) sel;
+ }
+ }
+ };
+ private Action pasteAction = new Action() {
+ public void run() {
+ if (clipboard != null) {
+ BookmarkNode node = new BookmarkNode(clipboard);
+ node.setName("Copy of " + node.getName());
+ provider.addBookmark(node);
+ refresh();
+ }
+ }
+ };
+ public void addNewBookmark(BookmarkNode bookmark) {
+ provider.addBookmark(bookmark);
+ treeViewer.refresh();
+ }
+ public void setStatus(String text) {
+ status.setText(text);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+public interface LogConstants {
+ public int QUERY = 1;
+ public int ERROR = 2;
+ public int RESULTS = 3;
+ public int WARNING = 4;
+ public int DEFAULT = 5;
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+public class LogProxy implements LogConstants {
+ private static LogProxy instance = null;
+ private SQLLogView log = null;
+ private LogProxy() {
+ }
+ public synchronized static LogProxy getInstance() {
+ if (instance == null) {
+ instance = new LogProxy();
+ }
+ return instance;
+ }
+ public void addText(int type, String text) {
+ log = SQLLogView.getInstance();
+ if (log != null) {
+ log.addText(type, text);
+ }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+
+ private static final String BUNDLE_NAME = "net.sourceforge.phpdt.sql.PHPEclipseSQLResources"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+ IBM Corporation - Initial implementation
+ Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * The PHPSourceConsole is used to display the output from the PHP SQL wizards
+ * @see ViewPart
+ */
+public class PHPSourceConsole extends ViewPart {
+
+ public static final String CONSOLE_ID =
+ "net.sourceforge.phpdt.sql.view.phpsourceconsoleview";
+
+ private TextViewer viewer = null;
+ private Document document = null;
+
+ /**
+ * The constructor.
+ */
+ public PHPSourceConsole() {
+ }
+
+ /**
+ * Insert the method's description here.
+ * @see ViewPart#createPartControl
+ */
+ public void createPartControl(Composite parent) {
+ viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
+ GridData viewerData = new GridData(GridData.FILL_BOTH);
+ viewer.getControl().setLayoutData(viewerData);
+ viewer.setEditable(false);
+
+ StyledText widget = viewer.getTextWidget();
+ widget.setFont(
+ JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT));
+ Action cutAction = new Action() {
+ public void run() {
+ viewer.getTextWidget().cut();
+ }
+ };
+ Action copyAction = new Action() {
+ public void run() {
+ viewer.getTextWidget().copy();
+ }
+ };
+ Action pasteAction = new Action() {
+ public void run() {
+ viewer.getTextWidget().paste();
+ }
+ };
+
+ IActionBars bars = this.getViewSite().getActionBars();
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
+ }
+
+ /**
+ * Insert the method's description here.
+ * @see ViewPart#setFocus
+ */
+ public void setFocus() {
+ }
+
+ /**
+ * Set the text for the viewer
+ */
+ private void setOutputText(String text) {
+ document = new Document(text);
+ viewer.setDocument(document);
+ }
+
+ private void appendOutputText(String text) {
+ try {
+ if (document == null) {
+ document = new Document(text);
+ viewer.setDocument(document);
+ }
+ document.replace(document.getLength(), 0, text);
+ } catch (BadLocationException e) {
+ }
+ // viewer.setDocument(document);
+ }
+
+ public static PHPSourceConsole getInstance() {
+ IWorkbenchPage page =
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ PHPSourceConsole console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID);
+ // if (PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
+
+ try {
+ page.showView(PHPSourceConsole.CONSOLE_ID);
+ if (console == null) {
+ console = (PHPSourceConsole) page.findView(PHPSourceConsole.CONSOLE_ID);
+ }
+ } catch (PartInitException e) {
+ PHPEclipseSQLPlugin.getDefault().getLog().log(
+ new Status(
+ IStatus.ERROR,
+ PHPEclipseSQLPlugin.PLUGIN_ID,
+ 0,
+ Messages.getString("sqlconsole.viewopeningproblem"),
+ e));
+ }
+
+ // }
+ return console;
+ }
+
+ /**
+ * Prints out the string represented by the string buffer
+ */
+ public synchronized void print(String output) {
+ appendOutputText(output);
+ }
+
+ /**
+ * Prints out the string represented by the string buffer
+ */
+ public synchronized void println(String output) {
+ appendOutputText(output+'\n');
+ }
+
+ public synchronized void clear() {
+ setOutputText("");
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+import net.sourceforge.phpdt.sql.view.query.QueryContentProvider;
+import net.sourceforge.phpdt.sql.view.query.QueryNode;
+
+public class QueryHistoryView extends ViewPart {
+ private static QueryHistoryView instance;
+ private QueryContentProvider provider = new QueryContentProvider();
+ private TreeViewer treeViewer;
+
+ public static QueryHistoryView getInstance() {
+ return instance;
+ }
+ public Object getCurrent() {
+ StructuredSelection selection = (StructuredSelection) treeViewer.getSelection();
+ if (selection != null) {
+ return selection.getFirstElement();
+ }
+ return null;
+ }
+ public void createPartControl(Composite parent) {
+ instance = this;
+ treeViewer = new TreeViewer(parent);
+ treeViewer.setContentProvider(provider);
+ treeViewer.setLabelProvider(new BookmarkLabelProvider());
+ treeViewer.setInput(Root.ROOT);
+ treeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ Object sel = getCurrent();
+ if (sel instanceof QueryNode) {
+ QueryNode node = (QueryNode) sel;
+ SQLQueryView.getInstance().setQuery(node.getQuery());
+ }
+ }
+ });
+ treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object sel = getCurrent();
+ if (sel != null) {
+ // preview goes here
+ }
+ }
+ }
+ );
+ }
+
+ public void addQuery(String query) {
+ provider.addQuery(query);
+ treeViewer.refresh();
+ }
+
+ public void setFocus() {
+ }
+}
+
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.custom.StyledTextContent;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.part.ViewPart;
+
+public class SQLLogView extends ViewPart implements LogConstants {
+ private Color QUERY_COLOR;
+ private Color WARNING_COLOR;
+ private Color DEFAULT_COLOR;
+ private Color ERROR_COLOR;
+ private Color RESULTS_COLOR;
+ private StyledText widget;
+ private static SQLLogView instance = null;
+ private static final String newLine = "\n";
+ public static SQLLogView getInstance() {
+ return instance;
+ }
+
+ public void createPartControl(Composite parent) {
+ instance = this;
+ QUERY_COLOR = new Color(parent.getShell().getDisplay(), 0, 255, 0);
+ ERROR_COLOR = new Color(parent.getShell().getDisplay(), 255, 0, 0);
+ RESULTS_COLOR = new Color(parent.getShell().getDisplay(), 0, 0, 255);
+ DEFAULT_COLOR = new Color(parent.getShell().getDisplay(), 0, 0, 0);
+ WARNING_COLOR = new Color(parent.getShell().getDisplay(), 255, 127, 0);
+ widget = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
+ IActionBars bars = this.getViewSite().getActionBars();
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
+
+ IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+ clearAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("clear.gif"));
+ clearAction.setToolTipText("Clear Log");
+ toolBar.add(clearAction);
+
+ widget.setEditable(false);
+
+ widget.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ instance = null;
+ }
+ });
+ }
+
+ public void addText(int style, String text) {
+ text = text + newLine;
+ int start = widget.getText().length();
+ StyleRange styleRange = new StyleRange();
+ styleRange.start = start;
+ styleRange.length = text.length();
+ if (style == QUERY) {
+ styleRange.foreground = QUERY_COLOR;
+ } else if (style == ERROR) {
+ styleRange.foreground = ERROR_COLOR;
+ } else if (style == RESULTS) {
+ styleRange.foreground = RESULTS_COLOR;
+ } else if (style == WARNING) {
+ styleRange.foreground = WARNING_COLOR;
+ } else {
+ styleRange.foreground = DEFAULT_COLOR;
+ }
+ widget.append(text);
+ widget.setStyleRange(styleRange);
+ revealEndOfDocument();
+ }
+
+ protected void revealEndOfDocument() {
+ StyledTextContent doc= widget.getContent();
+ int docLength= doc.getCharCount();
+ if (docLength > 0) {
+ widget.setCaretOffset(docLength);
+ widget.showSelection();
+ }
+ }
+
+ public void setFocus() {
+ widget.setFocus();
+ }
+
+ private Action copyAction = new Action() {
+ public void run() {
+ widget.copy();
+ }
+ };
+ private Action selectAllAction = new Action() {
+ public void run() {
+ widget.selectAll();
+ }
+ };
+ private Action clearAction = new Action() {
+ public void run() {
+ widget.setText("");
+ }
+ };
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ExtendedModifyEvent;
+import org.eclipse.swt.custom.ExtendedModifyListener;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.dnd.Clipboard;
+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 org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.part.ViewPart;
+
+import net.sourceforge.phpdt.sql.actions.ExecuteAction;
+import net.sourceforge.phpdt.sql.actions.ExportQueryAction;
+import net.sourceforge.phpdt.sql.actions.ImportQueryAction;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.parser.SQLLexx;
+import net.sourceforge.phpdt.sql.parser.Token;
+
+public class SQLQueryView extends ViewPart {
+ private ExecuteAction executeAction;
+ private ImportQueryAction importQueryAction;
+ private ExportQueryAction exportQueryAction;
+ private Clipboard clip;
+ private Label statusImage;
+ private Label status;
+ private ProgressBar progress;
+ private static SQLQueryView instance = null;
+ private StyledText widget;
+ private Color STRING_LITERAL;
+ private Color KEYWORD;
+ private Color COMMENT;
+ private Color NUMERIC;
+ private Color DEFAULT;
+ private long parseTime = 0;
+ private long fullTime = 0;
+ public SQLQueryView() {
+ super();
+ }
+ public void setFocus() {
+ widget.setFocus();
+ }
+ public static SQLQueryView getInstance() {
+ return instance;
+ }
+
+ public void createPartControl(org.eclipse.swt.widgets.Composite parent) {
+ instance = this;
+ 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);
+ NUMERIC = new Color(parent.getShell().getDisplay(), 255, 0, 0);
+ DEFAULT = new Color(parent.getShell().getDisplay(), 0, 0, 0);
+ clip = new Clipboard(getSite().getShell().getDisplay());
+ Composite main = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 0;
+ main.setLayout(layout);
+ ToolBar toolbar = new ToolBar(main, SWT.HORIZONTAL);
+ ToolItem item = new ToolItem(toolbar, SWT.PUSH);
+ item.setImage(PHPEclipseSQLPlugin.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(PHPEclipseSQLPlugin.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(PHPEclipseSQLPlugin.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(PHPEclipseSQLPlugin.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("");
+ }
+ });
+
+ item = new ToolItem(toolbar, SWT.SEPARATOR);
+
+ item = new ToolItem(toolbar, SWT.PUSH);
+ final ToolItem commit = item;
+ item.setImage(PHPEclipseSQLPlugin.getImage("commit.gif")); //$NON-NLS-1$
+ item.setToolTipText("Commit");
+ item.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ MultiSQLServer.getInstance().commit();
+ }
+ });
+ item.setEnabled(false);
+
+ item = new ToolItem(toolbar, SWT.PUSH);
+ final ToolItem rollback = item;
+ item.setImage(PHPEclipseSQLPlugin.getImage("rollback.gif")); //$NON-NLS-1$
+ item.setToolTipText("RollBack");
+ item.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ MultiSQLServer.getInstance().rollback();
+ }
+ });
+ item.setEnabled(false);
+
+ item = new ToolItem(toolbar, SWT.CHECK);
+ final ToolItem autocommit = item;
+ item.setImage(PHPEclipseSQLPlugin.getImage("autocommit.gif")); //$NON-NLS-1$
+ item.setToolTipText("AutoCommit");
+ item.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ MultiSQLServer.getInstance().setAutoCommit(autocommit.getSelection());
+ if (autocommit.getSelection()) {
+ commit.setEnabled(false);
+ rollback.setEnabled(false);
+ } else {
+ commit.setEnabled(true);
+ rollback.setEnabled(true);
+ }
+ }
+ });
+ item.setSelection(true);
+
+ widget = new StyledText(main, SWT.H_SCROLL | SWT.V_SCROLL);
+
+ IActionBars bars = this.getViewSite().getActionBars();
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
+
+ widget.setEditable(true);
+ widget.addExtendedModifyListener(modifyListener);
+
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ 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"));
+ statusImage.setImage(PHPEclipseSQLPlugin.getImage("success.gif"));
+ progress.setMinimum(0);
+ }
+
+ 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);
+ }
+
+ public void setStatus(Image img, String text) {
+ statusImage.setImage(img);
+ status.setText(text);
+ }
+
+ public String getQuery() {
+ return widget.getText();
+ }
+
+ public void setQuery(String text) {
+ widget.setText(text);
+ }
+
+ private String[] keywords = {"SELECT", "DROP", "FROM",
+ "INSERT", "INTO", "VALUES",
+ "CREATE", "TABLE", "VIEW", "SEQUENCE",
+ "UPDATE", "SET", "WHERE"};
+
+ SyntaxHighlighter textUpdater = new SyntaxHighlighter();
+
+ private class UpdateRequest {
+ public UpdateRequest(String text, int start, int length) {
+ this.text = text;
+ this.start = start;
+ this.length = length;
+ }
+ public String text;
+ public int start;
+ public int length;
+ }
+
+ private class SyntaxHighlighter extends Thread {
+ private boolean running = true;
+ private LinkedList requests = new LinkedList();
+ public SyntaxHighlighter() {
+ super();
+ setPriority(Thread.MIN_PRIORITY);
+ start();
+ }
+ public synchronized void updateText(String text, int start, int length) {
+ requests.add(new UpdateRequest(text, start, length));
+ notify();
+ }
+ public synchronized void shutdown() {
+ running = false;
+ interrupt();
+ }
+ public void run() {
+ while (running) {
+ try {
+ synchronized (this) {
+ if (requests.size() <= 0) {
+ wait();
+ } else {
+ Thread.sleep(10);
+ }
+ }
+ UpdateRequest request = (UpdateRequest) requests.removeFirst();
+ String text = request.text.toUpperCase();
+ 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;
+ for (int i = 0; i < tokens.size(); i++) {
+ Token t = (Token) tokens.elementAt(i);
+ String value = t.getValue();
+ int start = t.getStart();
+ int length = t.getEnd() - t.getStart();
+ styleRange = new StyleRange();
+ styleRange.start = start;
+ styleRange.length = value.length();
+ styleRange.fontStyle = SWT.NULL;
+ styleRange.foreground = DEFAULT;
+ boolean upper = start <= dirtyEnd && start >= dirtyStart;
+ boolean lower = ((start + length) >= dirtyStart && (start + length) <= dirtyEnd);
+ boolean both = (start <= dirtyStart && (start + length) >= dirtyEnd);
+ if (upper || lower || both) {
+ min = Math.min(start, min);
+ max = Math.max(max, start + length);
+ if (t.getType() == t.IDENTIFIER) {
+ boolean keyword = false;
+ for (int index = 0; index < keywords.length; index++) {
+ if (value.equals(keywords[index])) {
+ keyword = true;
+ }
+ }
+ if (keyword) {
+ styleRange.fontStyle = SWT.BOLD;
+ styleRange.foreground = KEYWORD;
+ } else {
+ styleRange.foreground = DEFAULT;
+ }
+ styles.addElement(styleRange);
+ } else if (t.getType() == t.COMMENT) {
+ styleRange.foreground = COMMENT;
+ styles.addElement(styleRange);
+ } else if (t.getType() == t.LITERAL) {
+ styleRange.foreground = STRING_LITERAL;
+ styles.addElement(styleRange);
+ } else if (t.getType() == t.NUMERIC) {
+ styleRange.foreground = NUMERIC;
+ styles.addElement(styleRange);
+ } else {
+ styles.addElement(styleRange);
+ }
+ }
+ }
+ StyleRange[] ranges = new StyleRange[styles.size()];
+ for (int k = 0; k < ranges.length; k++) {
+ ranges[k] = (StyleRange) styles.elementAt(k);
+ }
+ 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) {
+ // ignore any interruptions
+ }
+ }
+ }
+ }
+ public void setStyles(final StyleRange[] styles, final int start, final int length) {
+ getViewSite().getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ try {
+ for (int i = 0; i < styles.length; i++) {
+ widget.setStyleRange(styles[i]);
+ }
+ } catch (Throwable t) {
+ System.out.println("Error with styles: " + t.getClass().toString());
+ // ignore any errors
+ }
+ }
+ });
+ }
+
+ ExtendedModifyListener modifyListener = new ExtendedModifyListener() {
+ public void modifyText(ExtendedModifyEvent event) {
+ textUpdater.updateText(getQuery(), event.start, event.length);
+ }
+ };
+
+ private Action cutAction = new Action() {
+ public void run() {
+ widget.cut();
+ }
+ };
+ private Action copyAction = new Action() {
+ public void run() {
+ widget.copy();
+ }
+ };
+ private Action pasteAction = new Action() {
+ public void run() {
+ widget.paste();
+ }
+ };
+ private Action selectAllAction = new Action() {
+ public void run() {
+ widget.selectAll();
+ }
+ };
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+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.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+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.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.ViewPart;
+
+import net.sourceforge.phpdt.sql.actions.CloseTableAction;
+import net.sourceforge.phpdt.sql.actions.RefreshTableAction;
+import net.sourceforge.phpdt.sql.sql.SQLResults;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+import net.sourceforge.phpdt.sql.wizards.DeleteRowPage;
+import net.sourceforge.phpdt.sql.wizards.InsertRowPage;
+import net.sourceforge.phpdt.sql.wizards.PHPSelectRowPage;
+import net.sourceforge.phpdt.sql.wizards.SQLRowWizard;
+import net.sourceforge.phpdt.sql.wizards.SortFilterPage;
+import net.sourceforge.phpdt.sql.wizards.UpdateRowPage;
+import net.sourceforge.phpdt.sql.wizards.PHPSelectRowPage;
+
+public class TableView extends ViewPart implements ISelectionListener {
+ public static String TABLEVIEW_ID = "net.sourceforge.phpdt.sql.view.tableview";
+ private Clipboard clip;
+ private RefreshTableAction refreshTableAction;
+ private CloseTableAction closeTableAction;
+ private static TableView instance = null;
+ private TabFolder tabs;
+ private Composite parent;
+ public TableView() {
+ super();
+ }
+ public void setFocus() {
+ }
+ public static TableView getInstance() {
+ return instance;
+ }
+ public void closeCurrent() {
+ TabItem item = tabs.getItem(tabs.getSelectionIndex());
+ item.dispose();
+ }
+ public void refreshCurrent() {
+ TabItem item = tabs.getItem(tabs.getSelectionIndex());
+ TableAdapter adapter = (TableAdapter) item.getData();
+ String table = adapter.getTable();
+ if (table == null) {
+ loadTable(item, null, null, true, true);
+ } else {
+ loadTable(item, null, null, true, true);
+ }
+ }
+ public void loadQuery(SQLResults results) {
+ loadTable(null, null, results, true, false);
+ }
+ public void loadTable(String table) {
+ loadTable(null, table, null, false, true);
+ }
+ public void loadTable(
+ TabItem tabItem,
+ String entity,
+ SQLResults results,
+ boolean query,
+ boolean reload) {
+ TableAdapter adapter;
+ if (tabItem == null) {
+ tabItem = new TabItem(tabs, SWT.NONE);
+ if (query) {
+ adapter = TableAdapter.createFromQuery(results);
+ } else {
+ adapter = TableAdapter.createFromTable(entity);
+ }
+ tabItem.setData(adapter);
+ } else {
+ adapter = (TableAdapter) tabItem.getData();
+ }
+
+ final TableAdapter ta = adapter;
+
+ Composite main = new Composite(tabs, SWT.NONE);
+ GridLayout layout = new GridLayout(1, false);
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 0;
+ main.setLayout(layout);
+
+ // load up main
+ ToolBar toolbar = new ToolBar(main, SWT.HORIZONTAL);
+ final Table table = new Table(main, SWT.FULL_SELECTION | SWT.MULTI);
+ final Label label = new Label(main, SWT.NULL);
+
+ final Action copyAction = new Action() {
+ public void run() {
+ TableItem items[] = table.getSelection();
+ StringBuffer text = new StringBuffer();
+ for (int i = 0; i < items.length; i++) {
+ int columns = table.getColumnCount();
+ for (int col = 0; col < columns; col++) {
+ text.append(items[i].getText(col));
+ text.append('\t');
+ }
+ text.append('\n');
+ }
+ clip.setContents(
+ new Object[] { text.toString()},
+ new Transfer[] { TextTransfer.getInstance()});
+ }
+ };
+ final Action selectAllAction = new Action() {
+ public void run() {
+ table.selectAll();
+ }
+ };
+
+ // load toobar
+ ToolItem toolItem = new ToolItem(toolbar, SWT.PUSH);
+ toolItem.setImage(PHPEclipseSQLPlugin.getImage("refresh.gif")); //$NON-NLS-1$
+ toolItem.setToolTipText(Messages.getString("tableview.refresh")); //$NON-NLS-1$
+ toolItem.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ refreshTableAction.run();
+ }
+ });
+ toolItem = new ToolItem(toolbar, SWT.PUSH);
+ toolItem.setImage(PHPEclipseSQLPlugin.getImage("copy.gif")); //$NON-NLS-1$
+ toolItem.setToolTipText(Messages.getString("tableview.copy")); //$NON-NLS-1$
+ toolItem.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ copyAction.run();
+ }
+ });
+ toolItem = new ToolItem(toolbar, SWT.PUSH);
+ toolItem.setImage(PHPEclipseSQLPlugin.getImage("table.gif")); //$NON-NLS-1$
+ toolItem.setToolTipText(Messages.getString("tableview.selectAll")); //$NON-NLS-1$
+ toolItem.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ selectAllAction.run();
+ }
+ });
+
+ ToolItem filter = new ToolItem(toolbar, SWT.PUSH);
+ filter.setImage(PHPEclipseSQLPlugin.getImage("filter.gif")); //$NON-NLS-1$
+ filter.setToolTipText(Messages.getString("tableview.filterSort")); //$NON-NLS-1$
+
+ toolItem = new ToolItem(toolbar, SWT.SEPARATOR);
+
+ final ToolItem fullMode = new ToolItem(toolbar, SWT.PUSH | SWT.CHECK);
+
+ final ToolItem previous = new ToolItem(toolbar, SWT.PUSH);
+ final ToolItem next = new ToolItem(toolbar, SWT.PUSH);
+
+ fullMode.setImage(PHPEclipseSQLPlugin.getImage("fulldata.gif"));
+ fullMode.setToolTipText(Messages.getString("tableview.showAll")); //$NON-NLS-1$
+ fullMode.setSelection(false);
+ fullMode.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if (ta.getPageSize() == Integer.MAX_VALUE) {
+ ta.resetMode();
+ } else {
+ ta.fullMode();
+ }
+ ta.loadData();
+ table.removeAll();
+ for (int i = table.getColumnCount() - 1; i >= 0; i--) {
+ table.getColumn(i).dispose();
+ }
+ ta.loadTable(table);
+ label.setText(ta.getStatusString());
+ previous.setEnabled(ta.hasPreviousPage());
+ next.setEnabled(ta.hasNextPage());
+ }
+ });
+ previous.setImage(PHPEclipseSQLPlugin.getImage("previous.gif"));
+ previous.setToolTipText("Previous");
+ previous.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ ta.previousPage();
+ ta.loadData();
+ table.removeAll();
+ for (int i = table.getColumnCount() - 1; i >= 0; i--) {
+ table.getColumn(i).dispose();
+ }
+ ta.loadTable(table);
+ label.setText(ta.getStatusString());
+ previous.setEnabled(ta.hasPreviousPage());
+ next.setEnabled(ta.hasNextPage());
+ }
+ });
+ next.setImage(PHPEclipseSQLPlugin.getImage("next.gif"));
+ next.setToolTipText("Next");
+ next.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ ta.nextPage();
+ ta.loadData();
+ table.removeAll();
+ for (int i = table.getColumnCount() - 1; i >= 0; i--) {
+ table.getColumn(i).dispose();
+ }
+ ta.loadTable(table);
+ label.setText(ta.getStatusString());
+ previous.setEnabled(ta.hasPreviousPage());
+ next.setEnabled(ta.hasNextPage());
+ }
+ });
+
+ toolItem = new ToolItem(toolbar, SWT.SEPARATOR);
+
+ toolItem = new ToolItem(toolbar, SWT.PUSH);
+ toolItem.setImage(PHPEclipseSQLPlugin.getImage("close.gif")); //$NON-NLS-1$
+ toolItem.setToolTipText(Messages.getString("tableview.close")); //$NON-NLS-1$
+ toolItem.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ closeTableAction.run();
+ }
+ });
+
+ // load table
+ if (reload) {
+ adapter.resetOffset();
+ adapter.loadData();
+ }
+ adapter.loadTable(table);
+ String tableName = adapter.getTable();
+ if (tableName != null) {
+ tabItem.setText(tableName);
+ } else {
+ tabItem.setText(adapter.getQuery());
+ }
+
+ previous.setEnabled(adapter.hasPreviousPage());
+ next.setEnabled(adapter.hasNextPage());
+ label.setText(ta.getStatusString());
+
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ table.setLayoutData(gridData);
+
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ label.setLayoutData(gridData);
+
+ // create empty table row
+ TableColumn[] columns = table.getColumns();
+ String columnNames[] = new String[columns.length];
+ for (int i = 0; i < columns.length; i++) {
+ columnNames[i] = columns[i].getText();
+ }
+ String data[] = new String[columnNames.length];
+ for (int i = 0; i < columns.length; i++) {
+ data[i] = "";
+ }
+ final TableRow emptyRow = new TableRow(ta.getTable(), columnNames, data);
+
+ filter.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ SortFilterPage page = new SortFilterPage("");
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init("Filter and Sort", page, emptyRow, ta);
+ WizardDialog dialog = new WizardDialog(getSite().getShell(), wizard);
+ dialog.open();
+ }
+ });
+
+ final Action defaultEncodingAction = new Action() {
+ public void run() {
+ ta.setEncoding(TableAdapter.DEFAULT);
+ }
+ };
+ defaultEncodingAction.setText(Messages.getString("tableview.defaultEncoding")); //$NON-NLS-1$
+ final Action UTF8EncodingAction = new Action() {
+ public void run() {
+ ta.setEncoding(TableAdapter.UTF_8);
+ }
+ };
+ UTF8EncodingAction.setText(Messages.getString("tableview.UTF8Encoding")); //$NON-NLS-1$
+ final Action UTF16EncodingAction = new Action() {
+ public void run() {
+ ta.setEncoding(TableAdapter.UTF_16);
+ }
+ };
+ UTF16EncodingAction.setText(Messages.getString("tableview.UTF16Encoding")); //$NON-NLS-1$
+
+ IMenuListener menuListener = new IMenuListener() {
+ public void menuAboutToShow(IMenuManager mgr) {
+ if (ta.getTable() != null) {
+ TableItem[] selection = table.getSelection();
+ TableColumn[] columns = table.getColumns();
+ String columnNames[] = new String[columns.length];
+ for (int i = 0; i < columns.length; i++) {
+ columnNames[i] = columns[i].getText();
+ }
+ String data[] = new String[columnNames.length];
+ if (selection != null && selection.length > 0) {
+ TableItem sel = selection[0];
+ for (int i = 0; i < columns.length; i++) {
+ data[i] = sel.getText(i);
+ }
+ } else {
+ for (int i = 0; i < columns.length; i++) {
+ data[i] = "";
+ }
+ }
+ final TableRow row = new TableRow(ta.getTable(), columnNames, data);
+ Action updateAction = new Action() {
+ public void run() {
+ UpdateRowPage page = new UpdateRowPage("");
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init("Update Row", page, row, ta);
+ WizardDialog dialog =
+ new WizardDialog(getSite().getShell(), wizard);
+ dialog.open();
+ }
+ };
+ updateAction.setText(Messages.getString("tableview.update")); //$NON-NLS-1$
+ Action insertAction = new Action() {
+ public void run() {
+ InsertRowPage page = new InsertRowPage("");
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init("Insert Row", page, row, ta);
+ WizardDialog dialog =
+ new WizardDialog(getSite().getShell(), wizard);
+ dialog.open();
+ }
+ };
+ insertAction.setText(Messages.getString("tableview.insert")); //$NON-NLS-1$
+ Action deleteAction = new Action() {
+ public void run() {
+ DeleteRowPage page = new DeleteRowPage("");
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init("Delete Row", page, row, ta);
+ WizardDialog dialog =
+ new WizardDialog(getSite().getShell(), wizard);
+ dialog.open();
+ }
+ };
+ deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$
+
+ Action phpSelectAction = new Action() {
+ public void run() {
+ PHPSelectRowPage page = new PHPSelectRowPage("");
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init("PHP Select Generation", page, row, ta);
+ WizardDialog dialog =
+ new WizardDialog(getSite().getShell(), wizard);
+ dialog.open();
+ }
+ };
+ phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$
+
+ mgr.add(phpSelectAction);
+
+ mgr.add(insertAction);
+ mgr.add(updateAction);
+ mgr.add(deleteAction);
+
+
+ }
+ mgr.add(defaultEncodingAction);
+ mgr.add(UTF8EncodingAction);
+ mgr.add(UTF16EncodingAction);
+ }
+ };
+
+ // final setup
+ MenuManager manager = new MenuManager();
+ manager.setRemoveAllWhenShown(true);
+ Menu fTextContextMenu = manager.createContextMenu(table);
+ table.setMenu(fTextContextMenu);
+ table.setLinesVisible(true);
+ manager.addMenuListener(menuListener);
+
+ tabItem.setControl(main);
+ tabs.setSelection(tabs.indexOf(tabItem));
+ }
+
+ public void createPartControl(Composite parent) {
+ instance = this;
+ this.parent = parent;
+ initActions();
+ clip = new Clipboard(getSite().getShell().getDisplay());
+ tabs = new TabFolder(parent, SWT.NONE);
+ }
+ public void initActions() {
+ refreshTableAction = new RefreshTableAction();
+ refreshTableAction.setText(Messages.getString("tableview.refresh"));
+ refreshTableAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("refresh.gif"));
+ refreshTableAction.init(this);
+ closeTableAction = new CloseTableAction();
+ closeTableAction.setText(Messages.getString("tableview.close"));
+ closeTableAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("close.gif"));
+ closeTableAction.init(this);
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+
+public class BookmarkContentProvider implements ITreeContentProvider {
+ private Vector bookmarks = new Vector();
+ private static BookmarkContentProvider instance = null;
+ private boolean hasChanged = false;
+
+ /**
+ * Singleton accessor
+ */
+ public static synchronized BookmarkContentProvider getInstance() {
+ if (instance == null) {
+ instance = new BookmarkContentProvider();
+ }
+ return instance;
+ }
+
+ private BookmarkContentProvider() {
+ }
+
+ public void importBookmarks(File file) {
+ hasChanged = true;
+ System.out.println("Importing Bookmarks: Loading from file: " + file);
+ try {
+ Properties props = new Properties();
+ FileInputStream in = new FileInputStream(file);
+ props.load(in);
+ in.close();
+ fromProperties(false, props);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ public void load(File file) {
+ System.out.println("Bookmarks: Loading from file: " + file);
+ try {
+ Properties props = new Properties();
+ FileInputStream in = new FileInputStream(file);
+ props.load(in);
+ in.close();
+ fromProperties(true, props);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ public void save(File file) {
+ System.out.println("Bookmarks: Saving to file: " + file);
+ try {
+ Properties props = getProperties();
+ FileOutputStream out = new FileOutputStream(file);
+ props.store(out, "");
+ out.close();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement.equals(Root.ROOT)) {
+ return bookmarks.toArray();
+ } else if (parentElement instanceof TreeNode) {
+ TreeNode node = (TreeNode) parentElement;
+ return node.getChildren();
+ }
+ return Root.EMPTY_ARRAY;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public Object getParent(Object element) {
+ if (element.equals(Root.ROOT)) {
+ return null;
+ } else if (element instanceof TreeNode) {
+ TreeNode node = (TreeNode) element;
+ return node.getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element.equals(Root.ROOT)) {
+ return true;
+ } else if (element instanceof TreeNode) {
+ TreeNode node = (TreeNode) element;
+ return node.hasChildren();
+ }
+ return false;
+ }
+
+ public void setChildren(BookmarkNode b, Vector tables) {
+ b.setChildren(tables);
+ }
+
+ public void addBookmark(BookmarkNode b) {
+ hasChanged = true;
+ if (!bookmarks.contains(b)) {
+ bookmarks.addElement(b);
+ }
+ }
+ public void removeBookmark(BookmarkNode b) {
+ hasChanged = true;
+ if (bookmarks.contains(b)) {
+ bookmarks.removeElement(b);
+ }
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean hasChanged() {
+ return hasChanged;
+ }
+
+ public int getSize() {
+ return bookmarks.size();
+ }
+
+ public void fromProperties(boolean overwrite, Properties props) {
+ Vector newBookmarks = new Vector();
+ int i = 0;
+ while (true) {
+ Bookmark bookmark = new BookmarkNode();
+ String name = props.getProperty(i + ".name");
+ if (name == null) {
+ break;
+ }
+ bookmark.setName(name);
+ bookmark.setUsername(props.getProperty(i + ".username"));
+ bookmark.setPassword(props.getProperty(i + ".password"));
+ bookmark.setConnect(props.getProperty(i + ".connect"));
+ bookmark.setDriver(props.getProperty(i + ".driver"));
+ String schema = props.getProperty(i + ".schema");
+ if (schema != null) {
+ bookmark.setSchema(schema);
+ } else {
+ bookmark.setSchema("");
+ }
+ String type = props.getProperty(i + ".type");
+ if (type != null) {
+ bookmark.setType(type);
+ } else {
+ bookmark.setType("");
+ }
+ String driverFile = props.getProperty(i + ".driverLocation");
+ if (driverFile != null) {
+ bookmark.setDriverFile(driverFile);
+ } else {
+ bookmark.setDriverFile("");
+ }
+ System.out.println(bookmark.toString());
+ if (!bookmark.isEmpty()) {
+ newBookmarks.addElement(bookmark);
+ }
+ i++;
+ }
+ if (overwrite) {
+ bookmarks = newBookmarks;
+ } else {
+ bookmarks.addAll(newBookmarks);
+ }
+ }
+ public Properties getProperties() {
+ Properties props = new Properties();
+ for (int i = 0; i < bookmarks.size(); i++) {
+ Bookmark b = (Bookmark) bookmarks.elementAt(i);
+ props.put(i + ".name", b.getName());
+ props.put(i + ".username", b.getUsername());
+ props.put(i + ".password", b.getPassword());
+ props.put(i + ".schema", b.getSchema());
+ props.put(i + ".connect", b.getConnect());
+ props.put(i + ".driver", b.getDriver());
+ props.put(i + ".type", b.getType());
+ props.put(i + ".driverLocation", b.getDriverFile());
+ }
+ return props;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.util.Collections;
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+
+public class BookmarkNode extends Bookmark implements TreeNode {
+ private Vector children = new Vector();
+
+ public BookmarkNode() {
+ }
+
+ public BookmarkNode(Bookmark bookmark) {
+ super(bookmark);
+ }
+
+ public Object[] getChildren() {
+ return children.toArray();
+ }
+
+ public Object getParent() {
+ return Root.ROOT;
+ }
+
+ public boolean hasChildren() {
+ if (children != null && children.size() > 0) {
+ return true;
+ }
+ return false;
+ }
+
+ public void setChildren(Vector children) {
+ for (int i = 0; i < children.size(); i++) {
+ Object obj = children.elementAt(i);
+ isValid(obj);
+ }
+ Collections.sort(children);
+ this.children = children;
+ }
+
+ public void isValid(Object child) {
+ boolean valid = false;
+ if (child instanceof TableNode ||
+ child instanceof ViewNode ||
+ child instanceof SequenceNode) {
+ valid = true;
+ }
+ if (!valid) {
+ throw new RuntimeException("Invalid BookmarkNode child: " + child.getClass().getName());
+ }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+public class MetaDataNode implements TreeNode {
+ TreeNode parent;
+ String name;
+ String type;
+
+ public MetaDataNode(TableNode node, String name, String type) {
+ this.parent = node;
+ this.name = name;
+ this.type = type;
+ }
+ public MetaDataNode(ViewNode node, String name, String type) {
+ this.parent = node;
+ this.name = name;
+ this.type = type;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Object[] getChildren() {
+ return Root.EMPTY_ARRAY;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ return false;
+ }
+
+ public String toString() {
+ return name + " " + type;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public final class Root implements TreeNode {
+ public final static Root ROOT = new Root();
+ public final static Object[] EMPTY_ARRAY = new Object[0];
+
+ private Root() {
+ }
+ /**
+ * @see net.sourceforge.phpdt.sql.view.bookmark.TreeNode#getChildren()
+ */
+ public Object[] getChildren() {
+ return EMPTY_ARRAY;
+ }
+
+ /**
+ * @see net.sourceforge.phpdt.sql.view.bookmark.TreeNode#getParent()
+ */
+ public Object getParent() {
+ return null;
+ }
+
+ /**
+ * @see net.sourceforge.phpdt.sql.view.bookmark.TreeNode#hasChildren()
+ */
+ public boolean hasChildren() {
+ return false;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+public class SequenceNode implements TreeNode, Comparable {
+ private BookmarkNode parent;
+ private String name;
+
+ public SequenceNode(BookmarkNode parent, String seqName) {
+ this.parent = parent;
+ this.name = seqName;
+ }
+
+ public Object[] getChildren() {
+ return Root.EMPTY_ARRAY;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ return false;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public int compareTo(Object o) {
+ if (o instanceof SequenceNode) {
+ SequenceNode node = (SequenceNode) o;
+ return name.compareTo(node.getName());
+ } else if (o instanceof TreeNode || o instanceof ViewNode) {
+ return 1;
+ }
+ return 0;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.util.Vector;
+
+public class TableNode implements TreeNode, Comparable {
+ private Vector metadata;
+ private BookmarkNode parent;
+ private String name;
+ private int size = -1;
+
+ public TableNode(BookmarkNode parent, String tableName) {
+ this.parent = parent;
+ this.name = tableName;
+ }
+
+ public Object[] getChildren() {
+ if (metadata != null) {
+ return metadata.toArray();
+ } else {
+ return Root.EMPTY_ARRAY;
+ }
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ return (metadata != null) && (metadata.size() > 0);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public int compareTo(Object o) {
+ if (o instanceof TableNode) {
+ TableNode node = (TableNode) o;
+ return name.compareTo(node.getName());
+ } else if (o instanceof ViewNode ||
+ o instanceof SequenceNode) {
+ return -1;
+ }
+ return 0;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public void setMetadata(Vector metadata) {
+ this.metadata = metadata;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+/**
+ * @author root
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public interface TreeNode {
+ public Object[] getChildren();
+ public Object getParent();
+ public boolean hasChildren();
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.util.Vector;
+
+public class ViewNode implements TreeNode, Comparable {
+ private BookmarkNode parent;
+ private Vector metadata;
+ private String name;
+ private int size = -1;
+ public ViewNode(BookmarkNode parent, String tableName) {
+ this.parent = parent;
+ this.name = tableName;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public int compareTo(Object o) {
+ if (o instanceof ViewNode) {
+ ViewNode node = (ViewNode) o;
+ return name.compareTo(node.getName());
+ } else if (o instanceof SequenceNode) {
+ return -1;
+ } else if (o instanceof TreeNode) {
+ return 1;
+ }
+ return 0;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public boolean hasChildren() {
+ return (metadata != null) && (metadata.size() > 0);
+ }
+
+ public Object[] getChildren() {
+ if (metadata != null) {
+ return metadata.toArray();
+ } else {
+ return Root.EMPTY_ARRAY;
+ }
+ }
+
+ public void setMetadata(Vector metadata) {
+ this.metadata = metadata;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.query;
+
+import java.util.LinkedList;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+
+public class QueryContentProvider implements ITreeContentProvider {
+ private LinkedList queryList = new LinkedList();
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement.equals(Root.ROOT)) {
+ return queryList.toArray();
+ }
+ return Root.EMPTY_ARRAY;
+ }
+
+ public void addQuery(String query) {
+ queryList.add(new QueryNode(query));
+ }
+ public Object getParent(Object element) {
+ return Root.ROOT;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element.equals(Root.ROOT)) {
+ if (queryList.size() > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.query;
+
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
+
+public class QueryNode implements TreeNode {
+ TreeNode parent = Root.ROOT;
+ String name;
+ String query;
+
+ public QueryNode(String query) {
+ this.query = query;
+ query = query.trim();
+ boolean trimmed = false;
+ query = query.replace('\n', ' ');
+ int maxSize = 30;
+ if (query.length() > maxSize) {
+ query = query.substring(0, maxSize);
+ trimmed = true;
+ }
+ if (trimmed) {
+ query += "...->";
+ }
+ name = query;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public Object[] getChildren() {
+ return Root.EMPTY_ARRAY;
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ return false;
+ }
+
+ public String toString() {
+ return name;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.tableview;
+
+public class DefaultSizes {
+ public static int PAGE_SIZE = 200;
+ public static int MAX_COLUMN_SIZE = 1024 * 2;
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.tableview;
+
+import java.util.Vector;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
+import net.sourceforge.phpdt.sql.adapters.DatabaseInfo;
+import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.sql.FilterSort;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.sql.SQLResults;
+
+public class TableAdapter {
+ public static final String DEFAULT = "";
+ public static final String UTF_8 = "UTF-8";
+ public static final String UTF_16 = "UTF-16";
+
+ private int pageSize = DefaultSizes.PAGE_SIZE;
+ private int maxColumnSize = DefaultSizes.MAX_COLUMN_SIZE;
+ private SQLHelper helper = new SQLHelper();
+ private FilterSort extra = new FilterSort();
+ private int offset = 1;
+ private int totalSize = -1;
+ private Vector rows = new Vector();
+ private Vector columnNames = new Vector();
+ private boolean hasMore = false;
+
+ private String table;
+ private String query;
+
+ private String encoding = "";
+
+ private TableAdapter() {
+ }
+ public void fullMode() {
+ offset = 1;
+ pageSize = Integer.MAX_VALUE;
+ }
+ public void resetMode() {
+ offset = 1;
+ pageSize = DefaultSizes.PAGE_SIZE;
+ }
+ public static TableAdapter createFromQuery(SQLResults results) {
+ TableAdapter retVal = new TableAdapter();
+ retVal.setQuery(results.getQuery());
+ retVal.setData(results);
+ return retVal;
+ }
+ public static TableAdapter createFromTable(String table) {
+ TableAdapter retVal = new TableAdapter();
+ retVal.setTable(table);
+ return retVal;
+ }
+ private void loadSize() {
+ if (table != null) {
+ totalSize = helper.getSize(getTableCountQuery());
+ }
+ }
+ public int getStartIndex() {
+ if (totalSize == 0) {
+ return 0;
+ }
+ return offset;
+ }
+ public int getEndIndex() {
+ return offset + rows.size() - 1;
+ }
+ public int getTotalSize() {
+ return totalSize;
+ }
+ public void nextPage() {
+ loadSize();
+ offset = offset + pageSize;
+ if (totalSize >= 0 && offset > totalSize) {
+ offset = offset - pageSize;
+ }
+ }
+ public void previousPage() {
+ offset = offset - pageSize;
+ if (offset < 1) {
+ offset = 1;
+ }
+ }
+ public boolean hasNextPage() {
+ if (table != null) {
+ if (offset + pageSize <= totalSize) {
+ return true;
+ }
+ return false;
+ }
+ return hasMore;
+ }
+ public boolean hasPreviousPage() {
+ if (offset > 1) {
+ return true;
+ }
+ return false;
+ }
+ public String getTableCountQuery() {
+ if (table != null) {
+ Bookmark current = MultiSQLServer.getInstance().getConnected();
+ return SQLHelper.getFullTableName(current, table);
+ }
+ return query;
+ }
+ public String getQuery() {
+ if (table != null) {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ Bookmark current = server.getConnected();
+ try {
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(current.getType());
+ return adapter.getShowTableQuery(DatabaseInfo.create(current), table) + extra.toString();
+ } catch (NoSuchAdapterException e) {
+ throw new RuntimeException(e.toString());
+ }
+ }
+ return query;
+ }
+ public void loadData() {
+ loadSize();
+ if (table != null) {
+ if (offset > totalSize) {
+ offset = 1;
+ }
+ }
+ String query = getQuery();
+ System.out.println(offset + " to " + (offset + pageSize - 1));
+ SQLResults results = helper.getResults(query, offset, offset + pageSize - 1, maxColumnSize, encoding);
+ setData(results);
+ }
+ public void resetOffset() {
+ offset = 1;
+ }
+ public void setData(SQLResults results) {
+ int rowCount = results.getRowCount();
+ int columnCount = results.getColumnCount();
+ rows = new Vector();
+ columnNames = new Vector();
+ for (int col = 1; col <= columnCount; col++) {
+ columnNames.addElement(results.getColumnName(col));
+ }
+ for (int row = 1; row <= rowCount; row++) {
+ String rowData[] = new String[columnCount];
+ for (int col = 1; col <= columnCount; col++) {
+ rowData[col - 1] = results.getElement(col, row).toString();
+ }
+ rows.addElement(rowData);
+ }
+ hasMore = results.hasMore();
+ if (table == null && results.getMaxSize() >= 0) {
+ if (offset > results.getMaxSize()) {
+ offset = 1;
+ loadData();
+ }
+ }
+ }
+ public void loadTable(Table table) {
+ table.setHeaderVisible(true);
+ for (int i = 0; i < columnNames.size(); i++) {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(columnNames.elementAt(i).toString());
+ }
+ for (int i = 0; i < columnNames.size(); i++) {
+ table.getColumn(i).pack();
+ }
+ for (int row = 0; row < rows.size(); row++) {
+ TableItem item = new TableItem(table, SWT.NONE);
+ String itemData[] = (String[]) rows.elementAt(row);
+ item.setText(itemData);
+ }
+ for (int i = 0; i < columnNames.size(); i++) {
+ table.getColumn(i).pack();
+ }
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setFilterSort(FilterSort extra) {
+ this.extra = extra;
+ }
+ public String getTable() {
+ return table;
+ }
+
+ public void setTable(String table) {
+ this.table = table;
+ }
+ public void setQuery(String query) {
+ this.query = query;
+ }
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+ public String getStatusString() {
+ String status = getStartIndex() + " to " + getEndIndex() + " of " +
+ getTotalSize();
+ if (!encoding.equals(DEFAULT)) {
+ status += " (" + encoding + ")";
+ }
+ String filterText = extra.toString();
+ if (!filterText.equals("")) {
+ status += " (" + filterText + ")";
+ }
+ if (pageSize == Integer.MAX_VALUE) {
+ status += " (FULL)";
+ }
+ return status;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+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 net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DriverInfo;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
+public class BookmarkWizard extends Wizard {
+ BookmarkPage mainPage;
+
+ private BookmarkNode current;
+
+ public void init(BookmarkNode selection) {
+ System.out.println("Initing workbench");
+ this.current = selection;
+ setWindowTitle("New Bookmark");
+ }
+ public void init() {
+ System.out.println("Initing workbench");
+ current = null;
+ setWindowTitle("New Bookmark");
+ }
+ public boolean performFinish() {
+ System.out.println("perform finish workbench");
+ mainPage.performFinish();
+ return true;
+ }
+ public void addPages() {
+ System.out.println("adding pages");
+ if (current != null) {
+ mainPage = new BookmarkPage("Testing...", current);
+ } else {
+ mainPage = new BookmarkPage("Testing...");
+ }
+ addPage(mainPage);
+ System.out.println("adding pages");
+ }
+}
+
+class BookmarkPage extends WizardPage {
+ public static final String ADD = "ADD";
+ String action = ADD;
+ Text name;
+ Text username;
+ Text password;
+ Text schema;
+ Text connect;
+ Text driver;
+ //List driverList;
+ Combo type;
+ Text driverFile;
+
+ BookmarkNode initialData = null;
+
+ FileDialog dialog;
+
+ DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
+ /**
+ * Constructor for BookmarkPage.
+ * @param pageName
+ */
+ public BookmarkPage(String pageName) {
+ super(pageName);
+ initialData = null;
+ }
+ /**
+ * Constructor for BookmarkPage.
+ * @param pageName
+ */
+ public BookmarkPage(String pageName, BookmarkNode bookmark) {
+ super(pageName);
+ this.initialData = bookmark;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"});
+ dialog.setFilterNames(new String[]{"Jar Files (*.jar)","Zip Files (*.zip)", "All Files (*.*)"});
+ 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("*Bookmark Name");
+ 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("*Username");
+ 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("*Password");
+ password = new Text(container, SWT.BORDER | SWT.SINGLE);
+ password.setEchoChar('*');
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ password.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText("Schema (optional)");
+ 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("*Connect");
+ 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("*Driver");
+ driver = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ driver.setLayoutData(fullHorizontal);
+
+ //label = new Label(container, SWT.NULL);
+ //fullHorizontal = new GridData();
+ //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
+ //fullHorizontal.verticalSpan = 3;
+ //label.setLayoutData(fullHorizontal);
+ //label.setText("(Drivers Found in File)");
+ /*driverList = new List(container, SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ fullHorizontal.verticalAlignment = GridData.FILL;
+ fullHorizontal.verticalSpan = 3;
+ driverList.setLayoutData(fullHorizontal);
+ driverList.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ String[] selection = driverList.getSelection();
+ if (selection != null && selection.length > 0) {
+ driver.setText(selection[0]);
+ }
+ }
+ });*/
+
+ label = new Label(container, SWT.NULL);
+ label.setText("*Type");
+ 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("*Driver Filename");
+ 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("Browse...");
+
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ String filename = dialog.open();
+ if (filename != null) {
+ driverFile.setText(filename);
+ }
+ }
+ });
+ if (initialData != null) {
+ name.setText(initialData.getName());
+ username.setText(initialData.getUsername());
+ password.setText(initialData.getPassword());
+ schema.setText(initialData.getSchema());
+ connect.setText(initialData.getConnect());
+ driver.setText(initialData.getDriver());
+ String typeData = initialData.getType();
+ int selectedIndex = 0;
+ for (int i = 0; i < drivers.length; i++) {
+ if (typeData.equals(drivers[i].getDriverType())) {
+ selectedIndex = i;
+ }
+ }
+ type.select(selectedIndex);
+ driverFile.setText(initialData.getDriverFile());
+ updateDriverList();
+ }
+ 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() {
+ if (initialData == null) {
+ initialData = new BookmarkNode();
+ }
+ initialData.setName(name.getText());
+ initialData.setUsername(username.getText());
+ initialData.setPassword(password.getText());
+ initialData.setSchema(schema.getText());
+ initialData.setConnect(connect.getText());
+ initialData.setDriver(driver.getText());
+ int selection = type.getSelectionIndex();
+ if (selection >= 0) {
+ initialData.setType(drivers[selection].getDriverType());
+ }
+ initialData.setDriverFile(driverFile.getText());
+ BookmarkView.getInstance().addNewBookmark(initialData);
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+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.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.Label;
+import org.eclipse.swt.widgets.Text;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+public class DeleteRowPage extends WizardPage implements SQLPage {
+ TableRow row;
+ String[] columnNames;
+ Text[] values;
+ Button[] whereValues;
+ Label query;
+
+ public DeleteRowPage(String pageName) {
+ super(pageName);
+ }
+
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 3;
+ layout.numColumns = layoutColumns;
+
+ if (row == null) {
+ System.out.println("Row is null");
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null");
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null");
+ }
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]);
+ System.out.println("column = " + i + "=" + columnNames[i]);
+ }
+ values = new Text[row.getColumnCount()];
+ whereValues = new Button[row.getColumnCount()];
+ Label temp = new Label(container, SWT.NULL);
+ temp.setText("Column Name");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Include in?");
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ Label label = new Label(container, SWT.NULL);
+ label.setText(columnNames[i]);
+ values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ values[i].setLayoutData(fullHorizontal);
+ values[i].setText(data[i]);
+
+ values[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+
+ whereValues[i] = new Button(container, SWT.CHECK);
+ whereValues[i].setText("Where clause");
+ whereValues[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+ }
+ query = new Label(container, SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layoutColumns;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
+
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating query");
+ StringBuffer whereClause = new StringBuffer();
+ int numSelected = 0;
+ for (int i = 0; i < columnNames.length; i++) {
+ if (whereValues[i].getSelection()) {
+ numSelected++;
+ whereClause.append(columnNames[i]);
+ whereClause.append(" = ");
+ whereClause.append(values[i].getText());
+ whereClause.append(", ");
+ }
+ }
+ if (whereClause.length() > 1) {
+ whereClause.deleteCharAt(whereClause.length() - 1);
+ whereClause.deleteCharAt(whereClause.length() - 1);
+ }
+ String query = "DELETE FROM " + row.getTable();
+ if (numSelected > 0) {
+ query += " WHERE " + whereClause.toString();
+ }
+ if (numSelected > 0) {
+ setMessage("");
+ } else {
+ setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted");
+ }
+ this.getControl().pack();
+ this.query.setText(query);
+ }
+ public boolean performFinish() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ server.execute(query.getText());
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+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.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 net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+public class InsertRowPage extends WizardPage implements SQLPage {
+ TableRow row;
+ String[] columnNames;
+ Text[] values;
+ Label query;
+ public InsertRowPage(String pageName) {
+ super(pageName);
+ }
+
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 2;
+ layout.numColumns = layoutColumns;
+
+ if (row == null) {
+ System.out.println("Row is null");
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null");
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null");
+ }
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]);
+ System.out.println("column = " + i + "=" + columnNames[i]);
+ }
+ values = new Text[row.getColumnCount()];
+ Label temp = new Label(container, SWT.NULL);
+ temp.setText("Column Name");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Value");
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ Label label = new Label(container, SWT.NULL);
+ label.setText(columnNames[i]);
+ values[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ values[i].setLayoutData(fullHorizontal);
+
+ //values[i].setText(data[i]);
+ values[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+ }
+ query = new Label(container, SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layoutColumns;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
+
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating query");
+ StringBuffer valuesClause = new StringBuffer();
+ for (int i = 0; i < columnNames.length; i++) {
+ valuesClause.append(values[i].getText());
+ valuesClause.append(", ");
+ }
+ if (valuesClause.length() > 1) {
+ valuesClause.deleteCharAt(valuesClause.length() - 1);
+ valuesClause.deleteCharAt(valuesClause.length() - 1);
+ }
+ String query = "INSERT INTO " + row.getTable();
+ query += " VALUES (" + valuesClause.toString();
+ query += " )";
+ this.query.setText(query);
+ }
+ public boolean performFinish() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ server.execute(query.getText());
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+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.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.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class PHPSelectRowPage extends WizardPage implements SQLPage {
+ TableRow row;
+ String[] columnNames;
+ Text[] oldValues;
+ // Text[] newValues;
+ Button[] primaryKeys;
+ Button[] setValues;
+ Label query;
+
+ public PHPSelectRowPage(String pageName) {
+ super(pageName);
+ }
+
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 4;
+ layout.numColumns = layoutColumns;
+
+ if (row == null) {
+ System.out.println("Row is null");
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null");
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null");
+ }
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]);
+ System.out.println("column = " + i + "=" + columnNames[i]);
+ }
+ oldValues = new Text[row.getColumnCount()];
+ // newValues = new Text[row.getColumnCount()];
+ primaryKeys = new Button[row.getColumnCount()];
+ setValues = new Button[row.getColumnCount()];
+ Label temp = new Label(container, SWT.NULL);
+ temp.setText("Column Name");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Old Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("");
+ // temp = new Label(container, SWT.NULL);
+ // temp.setText("New Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("");
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ Label label = new Label(container, SWT.NULL);
+ label.setText(columnNames[i]);
+ oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ if (data[i] == null || data[i].equals("")) {
+ oldValues[i].setText('$' + columnNames[i]);
+ } else {
+ oldValues[i].setText(data[i]);
+ }
+ oldValues[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+
+ primaryKeys[i] = new Button(container, SWT.CHECK);
+ primaryKeys[i].setText("Where Clause");
+ primaryKeys[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+ // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ // newValues[i].setText(data[i]);
+ // newValues[i].addModifyListener(new ModifyListener() {
+ // public void modifyText(ModifyEvent e) {
+ // updateQuery();
+ // }
+ // });
+ setValues[i] = new Button(container, SWT.CHECK);
+ setValues[i].setText("Select Value");
+ setValues[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+ }
+ query = new Label(container, SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layoutColumns;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
+
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+
+ public void updateQuery() {
+ System.out.println("PHP SELECT");
+ StringBuffer setClause = new StringBuffer();
+ StringBuffer whereClause = new StringBuffer();
+ String temp;
+ boolean firstClause = false;
+ for (int i = 0; i < columnNames.length; i++) {
+ if (primaryKeys[i].getSelection()) {
+ if (firstClause) {
+ whereClause.append(" AND ");
+ }
+ firstClause = true;
+ whereClause.append(columnNames[i]);
+ whereClause.append(" = ");
+ temp = oldValues[i].getText();
+// if (temp.charAt(0) == '$') {
+// whereClause.append(temp);
+// } else {
+ whereClause.append("'"+temp+"'");
+// }
+
+
+ }
+ if (setValues[i].getSelection()) {
+ setClause.append(columnNames[i]);
+ // setClause.append(" = ");
+ // setClause.append(newValues[i].getText());
+ setClause.append(", ");
+ }
+ }
+ // if (whereClause.length() > 1) {
+ // whereClause.deleteCharAt(whereClause.length() - 1);
+ // whereClause.deleteCharAt(whereClause.length() - 1);
+ // }
+ if (setClause.length() > 1) {
+ setClause.deleteCharAt(setClause.length() - 1);
+ setClause.deleteCharAt(setClause.length() - 1);
+ }
+ String query = "$results = mysql_query(\"SELECT " + setClause.toString();
+ query += " FROM " + row.getTable();
+ query += " WHERE " + whereClause.toString() + "\");";
+ this.query.setText(query);
+ }
+
+ public boolean performFinish() {
+ PHPSourceConsole console = PHPSourceConsole.getInstance();
+ console.clear();
+ console.print(query.getText());
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+import org.eclipse.jface.wizard.IWizardPage;
+
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+public interface SQLPage extends IWizardPage {
+ public void init(TableRow row, TableAdapter adapter);
+ public boolean performFinish();
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+import org.eclipse.jface.wizard.Wizard;
+
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+public class SQLRowWizard extends Wizard {
+ SQLPage page;
+ TableRow row;
+ TableAdapter adapter;
+ public void init(String title, SQLPage page, TableRow row, TableAdapter adapter) {
+ System.out.println("Init SQL row wizard");
+ this.row = row;
+ this.adapter = adapter;
+ this.page = page;
+ setWindowTitle(title);
+ }
+ public boolean performFinish() {
+ System.out.println("Perform SQL row wizard finish");
+ return page.performFinish();
+ }
+ public void addPages() {
+ System.out.println("QL row wizard adding pages");
+ page.init(row, adapter);
+ addPage(page);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+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.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.Label;
+import org.eclipse.swt.widgets.Text;
+
+import net.sourceforge.phpdt.sql.sql.FilterSort;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+public class SortFilterPage extends WizardPage implements SQLPage {
+ TableRow row;
+ TableAdapter adapter;
+ Button[] filter;
+ Combo[] operator;
+ Text[] filterValues;
+ Button[] stringFlags;
+ Button[] sort;
+
+ String columnNames[];
+ Label query;
+ FilterSort filterSort = new FilterSort();
+ public SortFilterPage(String pageName) {
+ super(pageName);
+ }
+
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ this.adapter = adapter;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 5;
+ layout.numColumns = layoutColumns;
+
+ if (row == null) {
+ System.out.println("Row is null");
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null");
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null");
+ }
+
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]);
+ System.out.println("column = " + i + "=" + columnNames[i]);
+ }
+ int size = row.getColumnCount();
+ filter = new Button[size];
+ operator = new Combo[size];
+ filterValues = new Text[size];
+ stringFlags = new Button[size];
+ sort = new Button[size];
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ filter[i] = new Button(container, SWT.CHECK);
+ filter[i].setText(columnNames[i]);
+ filter[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+
+ operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY);
+ operator[i].add("=");
+ operator[i].add("<>");
+ operator[i].add("<");
+ operator[i].add(">");
+ operator[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+
+ filterValues[i] = new Text(container, SWT.BORDER);
+ filterValues[i].setText(data[i]);
+ filterValues[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+
+ stringFlags[i] = new Button(container, SWT.CHECK);
+ stringFlags[i].setText("String");
+ stringFlags[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+
+ final int index = i;
+ sort[i] = new Button(container, SWT.CHECK);
+ sort[i].setText(columnNames[i]);
+ sort[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ if (sort[index].getSelection()) {
+ filterSort.addSort(columnNames[index]);
+ } else {
+ filterSort.removeSort(columnNames[index]);
+ }
+ updateQuery();
+ }
+ });
+ }
+ query = new Label(container, SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layoutColumns;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
+
+ setControl(container);
+
+ setPageComplete(true);
+ }
+
+ public void updateQuery() {
+ filterSort.clearFilters();
+ for (int i = 0; i < filter.length; i++) {
+ if (filter[i].getSelection()) {
+ filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection());
+ }
+ }
+ query.setText(filterSort.toString());
+ }
+
+ public boolean performFinish() {
+ adapter.setFilterSort(filterSort);
+ TableView.getInstance().refreshCurrent();
+ return true;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.wizards;
+
+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.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.Label;
+import org.eclipse.swt.widgets.Text;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
+public class UpdateRowPage extends WizardPage implements SQLPage {
+ TableRow row;
+ String[] columnNames;
+ Text[] oldValues;
+ Text[] newValues;
+ Button[] primaryKeys;
+ Button[] setValues;
+ Label query;
+ public UpdateRowPage(String pageName) {
+ super(pageName);
+ }
+
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 5;
+ layout.numColumns = layoutColumns;
+
+ if (row == null) {
+ System.out.println("Row is null");
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null");
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null");
+ }
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]);
+ System.out.println("column = " + i + "=" + columnNames[i]);
+ }
+ oldValues = new Text[row.getColumnCount()];
+ newValues = new Text[row.getColumnCount()];
+ primaryKeys = new Button[row.getColumnCount()];
+ setValues = new Button[row.getColumnCount()];
+ Label temp = new Label(container, SWT.NULL);
+ temp.setText("Column Name");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Old Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("New Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("");
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ Label label = new Label(container, SWT.NULL);
+ label.setText(columnNames[i]);
+ oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ oldValues[i].setText(data[i]);
+ oldValues[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+ primaryKeys[i] = new Button(container, SWT.CHECK);
+ primaryKeys[i].setText("Primary Key");
+ primaryKeys[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+ newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ newValues[i].setText(data[i]);
+ newValues[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+ setValues[i] = new Button(container, SWT.CHECK);
+ setValues[i].setText("Set Value");
+ setValues[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+ }
+ query = new Label(container, SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layoutColumns;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
+
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating query");
+ StringBuffer setClause = new StringBuffer();
+ StringBuffer whereClause = new StringBuffer();
+ for (int i = 0; i < columnNames.length; i++) {
+ if (primaryKeys[i].getSelection()) {
+ whereClause.append(columnNames[i]);
+ whereClause.append(" = ");
+ whereClause.append(oldValues[i].getText());
+ whereClause.append(", ");
+ }
+ if (setValues[i].getSelection()) {
+ setClause.append(columnNames[i]);
+ setClause.append(" = ");
+ setClause.append(newValues[i].getText());
+ setClause.append(", ");
+ }
+ }
+ if (whereClause.length() > 1) {
+ whereClause.deleteCharAt(whereClause.length() - 1);
+ whereClause.deleteCharAt(whereClause.length() - 1);
+ }
+ if (setClause.length() > 1) {
+ setClause.deleteCharAt(setClause.length() - 1);
+ setClause.deleteCharAt(setClause.length() - 1);
+ }
+ String query = "UPDATE " + row.getTable();
+ query += " SET " + setClause.toString();
+ query += " WHERE " + whereClause.toString();
+ this.query.setText(query);
+ }
+ public boolean performFinish() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ server.execute(query.getText());
+ return true;
+ }
+}
\ No newline at end of file