<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
+ <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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.core.boot_2.1.1/boot.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.boot_2.1.1/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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.core.runtime_2.1.1/runtime.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.runtime_2.1.1/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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.core.resources_2.1.1/resources.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.core.resources_2.1.1/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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.swt.win32_2.1.1/ws/win32/swt.jar" sourcepath="ORG_ECLIPSE_PLATFORM_WIN32_SOURCE_SRC/org.eclipse.swt.win32_2.1.1/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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui_2.1.1/ui.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui_2.1.1/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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.jface_2.1.1/jface.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.jface_2.1.1/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"/>
+ path="ECLIPSE_HOME/plugins/org.eclipse.ui.workbench_2.1.1/workbench.jar" sourcepath="ORG_ECLIPSE_PLATFORM_SOURCE_SRC/org.eclipse.ui.workbench_2.1.1/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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="D:/bin/eclipse/Plugins/org.eclipse.jdt.junit_2.1.1/junitsupport.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
bookmarkview.importboomarks = Import Bookmarks
bookmarkview.exportbookmarks = Export Bookmarks
phpsourceconsoleview.name = PHP Source Generator Console
+category.name = PHPEclipseSQL
+subsetview.name = Subsets
category.name = PHPEclipseSQL
\ No newline at end of file
id="net.sourceforge.phpeclipse.sql"
name="%phpsql.name"
version="1.0.2"
- provider-name="eclipseproject.de"
+ provider-name="PHPEclipse Project"
class="net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin">
<runtime>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.swt"/>
<import plugin="org.eclipse.ui"/>
+ <import plugin="org.apache.xerces"/>
</requires>
name="Connecting"
category="net.sourceforge.phpdt.sql.preferences.PreferencesPage"
class="net.sourceforge.phpdt.sql.preferences.PHPSQLConnectionPreferencePage"
- id="net.sourceforge.phpdt.sql.preferences.PHPSQLConnectionPreferencePage">
+ id="net.sourceforge.phpdt.sql.preferences.PHPSQLConnectionPreferencePage">
</page>
<page
name="Templates"
category="net.sourceforge.phpdt.sql.preferences.PreferencesPage"
class="net.sourceforge.phpdt.sql.preferences.PHPSQLTemplatesPreferencePage"
- id="net.sourceforge.phpdt.sql.preferences.PHPSQLTemplatesPreferencePage">
+ id="net.sourceforge.phpdt.sql.preferences.PHPSQLTemplatesPreferencePage">
</page>
</extension>
<!-- Menu for Bookmark View -->
*/
public interface IConstants {
public boolean DEBUG = false;
+ public final String PHPFILEHEADER = "<?php%%NL%%echo '<html>';%%NL%%echo '<head>';%%NL%%echo '<meta name=\"PHPEclipse-generated\" content=\"PHPEclipse\">';%%NL%%echo '<title>Database access</title>';%%NL%%echo '</head><body>';%%NL%%?>%%NL%%";
+ public final String PHPDBCONNHEADER = "%%NL%%$dbconn = mysql_connect(%%CONNLIST%%) or die(\"Could not connect to database\");%%NL%%$db = mysql_select_db(%%DBNAME%%, $dbconn) or die(\"Database not found\");%%NL%%";
+ public final String PHPDBRESULTHEADER = "$result = mysql_query(%%QUERY%%);%%NL%%";
+ public final String PHPDBCLOSEHEADER = "mysql_close($dbconn);%%NL%%exit;%%NL%%?>%%NL%%";
}
-package net.sourceforge.phpdt.sql.actions;
+package net.sourceforge.phpdt.sql;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
package net.sourceforge.phpdt.sql;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.URL;
-import java.util.ResourceBundle;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.crimson.tree.XmlDocument;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
import org.eclipse.core.resources.ISavedState;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
-import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetContentProvider;
/**
* @author
*/
public class PHPEclipseSQLPlugin
- extends AbstractUIPlugin
- implements IConstants {
-
- 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 PHPSQLSaveParticipant();
- 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,
- "phpeclipse.sql.background.color",
- BACKGROUND);
- PreferenceConverter.setDefault(store, "phpeclipse.sql.text.color", DEFAULT);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.keyword.color",
- KEYWORD);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.comment.color",
- COMMENT);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.string.color",
- STRING);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.numeric.color",
- NUMERIC);
- getPreferenceStore().setDefault("phpeclipse.sql.text.bold", false);
- getPreferenceStore().setDefault("phpeclipse.sql.keyword.bold", true);
- getPreferenceStore().setDefault("phpeclipse.sql.string.bold", false);
- getPreferenceStore().setDefault("phpeclipse.sql.comment.bold", false);
- getPreferenceStore().setDefault("phpeclipse.sql.numeric.bold", false);
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.select.template",
- "$results = mysql_query(\"SELECT {0} FROM {1} WHERE {2} \");");
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.insert.template",
- "$results = mysql_query(\"INSERT INTO {0} ({1}) VALUES {2} \");");
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.update.template",
- "$results = mysql_query(\"UPDATE {0} SET {1} WHERE {2} \");");
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.delete.template",
- "$results = mysql_query(\"DELETE FROM {0} WHERE {1} \");");
-
- getPreferenceStore().setDefault("phpeclipse.sql.username.connect", "root");
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.connect.connect",
- "jdbc:mysql://localhost/test");
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.driver.connect",
- "com.mysql.jdbc.Driver");
-
- getPreferenceStore().setDefault("phpeclipse.sql.type.connect", "MySQL");
-
- getPreferenceStore().setDefault(
- "phpeclipse.sql.filename.connect",
- "C:\\apache\\mysql\\lib\\mysql-connector-java-2.0.14-bin.jar");
-
- PreferenceConverter.setDefault(
- getPreferenceStore(),
- "phpeclipse.sql.font",
- (FontData) null);
- }
+extends AbstractUIPlugin
+implements IConstants {
+
+ 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;
+ }
+ /**
+ * Reads the PHPEclipseSQL Plugin state from a file. The file has been created with writeImportantState
+ * @param target
+ */
+ protected void readStateFrom(File target) {
+ String fileName = target.getName();
+ if (!fileName.endsWith("ext")) { //$NON-NLS-1$
+ // It's the 2.0 format for preferences
+ BookmarkContentProvider.getInstance().load(target);
+ } else {
+ //It's the 2.1 format for preferences and subsets
+ XmlDocument doc = new XmlDocument();
+ FileInputStream source = null;
+ try {
+ source = new FileInputStream(target);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ return;
+ }
+ DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser;
+ try {
+ parser = factory.newDocumentBuilder();
+ doc = (XmlDocument) parser.parse(source);
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ return;
+ } catch (SAXException e) {
+ e.printStackTrace();
+ return;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ Element root = doc.getDocumentElement();
+ BookmarkContentProvider.getInstance().importXML(root);
+ SubsetContentProvider.getInstance().importXML(root);
+ }
+ }
+
+ public void startup() throws CoreException {
+ super.startup();
+ ISaveParticipant saveParticipant = new PHPSQLSaveParticipant();
+ 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) {
+ XmlDocument doc = new XmlDocument();
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(target);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ return;
+ }
+ Element root = (Element) doc.appendChild(doc.createElement(Messages.getString("ExportXMLAction.SavedData"))); //$NON-NLS-1$
+
+ BookmarkContentProvider.getInstance().exportXML(root);
+ SubsetContentProvider.getInstance().exportXML(root);
+
+ try {
+ doc.write(out);
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Gets an image descriptof from a file in the icons directory
+ * @param name of the file to get
+ * @return ImageDescriptor or null if not found
+ */
+ 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 {
+ }
+
+ protected void initializeDefaultPluginPreferences() {
+ RGB BACKGROUND = new RGB(255, 255, 255);
+ RGB COMMENT = new RGB(88, 148, 64);
+ 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,
+ "phpeclipse.sql.background.color",
+ BACKGROUND);
+ PreferenceConverter.setDefault(
+ store,
+ "phpeclipse.sql.text.color",
+ DEFAULT);
+ PreferenceConverter.setDefault(
+ store,
+ "phpeclipse.sql.keyword.color",
+ KEYWORD);
+ PreferenceConverter.setDefault(
+ store,
+ "phpeclipse.sql.comment.color",
+ COMMENT);
+ PreferenceConverter.setDefault(
+ store,
+ "phpeclipse.sql.string.color",
+ STRING);
+ PreferenceConverter.setDefault(
+ store,
+ "phpeclipse.sql.numeric.color",
+ NUMERIC);
+ getPreferenceStore().setDefault("phpeclipse.sql.text.bold", false);
+ getPreferenceStore().setDefault("phpeclipse.sql.keyword.bold", true);
+ getPreferenceStore().setDefault("phpeclipse.sql.string.bold", false);
+ getPreferenceStore().setDefault("phpeclipse.sql.comment.bold", false);
+ getPreferenceStore().setDefault("phpeclipse.sql.numeric.bold", false);
+ PreferenceConverter.setDefault(getPreferenceStore(), "phpeclipsesql.font", (FontData) null); //$NON-NLS-1$
+ }
+
+ public boolean showView(String view) {
+ IWorkbench workbench = getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ IWorkbenchPage page = window.getActivePage();
+ IViewPart viewPart = null;
+ try {
+ viewPart = page.showView(view);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.select.template",
+ "$results = mysql_query(\"SELECT {0} FROM {1} WHERE {2} \");");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.insert.template",
+ "$results = mysql_query(\"INSERT INTO {0} ({1}) VALUES {2} \");");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.update.template",
+ "$results = mysql_query(\"UPDATE {0} SET {1} WHERE {2} \");");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.delete.template",
+ "$results = mysql_query(\"DELETE FROM {0} WHERE {1} \");");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.username.connect",
+ "root");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.connect.connect",
+ "jdbc:mysql://localhost/test");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.driver.connect",
+ "com.mysql.jdbc.Driver");
+
+ getPreferenceStore().setDefault("phpeclipse.sql.type.connect", "MySQL");
+
+ getPreferenceStore().setDefault(
+ "phpeclipse.sql.filename.connect",
+ "C:\\apache\\mysql\\lib\\mysql-connector-java-2.0.14-bin.jar");
+
+ PreferenceConverter.setDefault(
+ getPreferenceStore(),
+ "phpeclipse.sql.font",
+ (FontData) null);
+ return(viewPart != null);
+ }
}
class PHPSQLSaveParticipant implements ISaveParticipant, IConstants {
- /**
- * @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 sqlPluginInstance =
- PHPEclipseSQLPlugin.getDefault();
- // save the plug in state
- if (BookmarkContentProvider.getInstance().hasChanged()) {
- int saveNumber = context.getSaveNumber();
- String saveFileName = "save " + Integer.toString(saveNumber);
- File f =
- sqlPluginInstance.getStateLocation().append(saveFileName).toFile();
- // if we fail to write, an exception is thrown and we do not update the path
- sqlPluginInstance.writeImportantState(f);
- context.map(new Path("save"), new Path(saveFileName));
- context.needSaveNumber();
- } else {
- if (DEBUG) {
- 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;
- }
- }
+ /**
+ * @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 sqlPluginInstance =
+ PHPEclipseSQLPlugin.getDefault();
+ // save the plug in state
+ if (BookmarkContentProvider.getInstance().hasChanged()) {
+ int saveNumber = context.getSaveNumber();
+ String saveFileName =
+ "save " + Integer.toString(saveNumber);
+ File f =
+ sqlPluginInstance
+ .getStateLocation()
+ .append(saveFileName)
+ .toFile();
+ // if we fail to write, an exception is thrown and we do not update the path
+ sqlPluginInstance.writeImportantState(f);
+ context.map(new Path("save"), new Path(saveFileName));
+ context.needSaveNumber();
+ } else {
+ if (DEBUG) {
+ 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;
+ }
+ }
}
bookmarkview.refresh = Refresh
bookmarkview.viewTable = View Table
bookmarkview.viewTableDetails = View Table Details
+bookmarkview.exportXML = Export XML
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
+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.confirm = Are you sure you want to delete bookmark
+bookmarkview.disconnect = Disconnecting from
sqlqueryview.executeQuery = Execute Query
sqlqueryview.importQuery = Import Query
sqlqueryview.exportQuery = Export Query
+sqlqueryview.generatePHP = Generate Query as PHP
sqlqueryview.clear = Clear
+sqlqueryview.commit = Commit
sqlqueryview.copy = Copy
sqlqueryview.paste = Paste
sqlqueryview.done = Done
tableview.update = Update...
tableview.insert = Insert...
tableview.delete = Delete...
-tableview.phpselect = PHP Select...
-tableview.phpupdate = PHP Update...
-tableview.phpinsert = PHP Insert...
-tableview.phpdelete = PHP Delete...
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)
+filedialog.xmlFiles = XML files (*.xml)
+filedialog.phpFiles = PHP files (*.php)
adapters.generic = Generic JDBC
adapters.oracle = Oracle
adapters.postgres = Postgres
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
+PHPEclipseSQLPlugin.save_2=save
+PHPEclipseSQLPlugin.icons_3=icons/
+PHPEclipseSQLPlugin.PHPEclipseSQL.keyword.color_6=PHPEclipseSQL.keyword.color
+PHPEclipseSQLPlugin.PHPEclipseSQL.string.bold_12=PHPEclipseSQL.string.bold
+PHPEclipseSQLPlugin.save_espace=save
+PHPEclipseSQLPlugin.Not_saving_unchanged_bookmarks_18=Not saving unchanged bookmarks
+PHPEclipseSQLPlugin.iconsDir=icons/
+PHPEclipseSQLPlugin.saveDir=save
+PHPEclipseSQLPlugin.saveFileExtension=.xml
+ExecuteAction.Executing_Query3=Executing Query...
+ExecuteAction.Executing_Query2=Executing Query..
+ExecuteAction.Parsing_sql_script3=Parsing sql script...
+ExecuteAction.QueriesExecuted=\ queries executed,
+ExecuteAction.RowsUpdated=\ rows updated,
+ExecuteAction.Errors=\ errors
+ExecuteAction.Done=Done
+ExecuteAction.RowUpdated=\ rows updated,
+ExecuteAction.ResultsDisplayed=\ results displayed,
+ExportXMLAction.XMLExporting=XML struct: Exporting to file:
+ExportXMLAction.Metadata=Metadata
+ExportXMLAction.Author=Author
+ExportXMLAction.PHPEclipseSQL=PHPEclipseSQL
+ExportXMLAction.Version=Version
+ExportXMLAction.XMLVersionNumber=0.4
+ExportXMLAction.Table=TABLE
+ExportXMLAction.View=VIEV
+ExportXMLAction.TableName=NAME
+ExportXMLAction.BookmarkName=BOOKMARK
+ExportXMLAction.Subsets=SUBSETS
+ExportXMLAction.Subset=SUBSET
+ExportXMLAction.SubsetName=NAME
+ExportXMLAction.SavedData=SAVED_DATA
+ExportXMLAction.TableColumn=COLUMN
+ExportXMLAction.ColumnName=NAME
+ExportXMLAction.UNKNOWN=UNKNOWN
+ExportXMLAction.NO=NO
+ExportXMLAction.YES=YES
+ExportXMLAction.ColumnNullable=Nullable
+ExportXMLAction.ColumnAutoIncrement=Auto_Increment
+ExportXMLAction.PrimaryKey=Primary_Key
+ExportXMLAction.PKName=Name
+ExportXMLAction.PKColumn=Column
+ExportXMLAction.PKColumnName=Name
+ExportXMLAction.PKSequence=Sequence
+ExportXMLAction.ForeignKey=Foreign_Key
+ExportXMLAction.FKName=Name
+ExportXMLAction.FKType=Type
+ExportXMLAction.FKImported=Imported
+ExportXMLAction.FKExported=Exported
+ExportXMLAction.FKCascadeUpdate=Cascade_Update
+ExportXMLAction.FKCascadeDelete=Cascade_Delete
+ExportXMLAction.FKColumn=Column
+ExportXMLAction.FKSequence=Sequence
+ExportXMLAction.FKPrimarySchema=Primary_Schema
+ExportXMLAction.FKPrimaryTable=Primary_Table
+ExportXMLAction.FKPrimaryColumn=Primary_Column
+ExportXMLAction.FKForeignSchema=Foreign_Schema
+ExportXMLAction.FKForeignTable=Foreign_Table
+ExportXMLAction.FKForeignColumn=Foreign_Column
+SetSchemaAction.SetSchema=Set Schema
+SetSchemaAction.PleaseEnterName=Please enter the name of new schema:
+MetaDataKey=METADATA
+MetaDataKeySeparator=:
+NoFeature.Views=Views
+NoFeature.Sequences=Sequences
+Error.NoDatabase=Database not supported:
+PreferencesPage.PickFont=Pick Font
+PreferencesPage.DefaultFont=Default Font
+PreferencesPage.BackgroundColor=Background Color
+PreferencesPage.DefaultTextColor=Default Text Color
+PreferencesPage.PHPEclipseSQL.keyword.color_26=PHPEclipseSQL.keyword.color
+PreferencesPage.KeywordTextColor=Keyword Text Color
+PreferencesPage.Bold=Bold
+PreferencesPage.CommentTextColor=Comment Text Color
+PreferencesPage.StringTextColor=String Text Color
+PreferencesPage.NumericTextColor=Numeric Text Color
+PreferencesPage.Font_Default=Font: default
+PreferencesPage.regular=regular
+PreferencesPage.bold=bold
+PreferencesPage.italic=italic
+PreferencesPage.boldItalic=bold italic
+PreferencesPage.FontPrompt=Font:
+BookmarkLabelProvider.TablePrefix=T
+BookmarkLabelProvider.ViewPrefix=V
+BookmarkLabelProvider.SequencePrefix=S
+ExportXMLAction.CannotOpenFile=Cannot open file
+ExportXMLAction.CannotOpenFileMessage=Cannot open file:
+ExportXMLAction.CannotOpenFileExplain=\nProbably is\'t read-only or owned by another user.
+DeleteColumnAction.DeleteColumns=Delete Columns...
+DeleteColumnAction.ConfirmDeleteColumns=Are you sure you want to delete the selected columns?
+DeleteObjectAction.DeleteSubset=Delete Subset...
+DeleteObjectAction.ConfirmDeleteSubset=Are you sure you want to delete the selected subset ?
+DeleteObjectAction.DeleteItems=Delete items...
+DeleteObjectAction.ConfirmDeleteItems=Are you sure you want to delete the selected tables/views?
+DeleteSubsetAction.DeleteSubset=Delete Subset...
+DeleteSubsetAction.ConfirmDeleteSubset=Are you sure you want to delete the selected subset?
+NewSubsetAction.CreatingNewSubset=Creating new subset..
+NewSubsetAction.NameOfNewSubset=Name of the new Subset
+NewSubsetAction.PleaseEnterName=Please enter name
+OracleAdapter.._3=.
+BookmarkView.ShowTableSizes=Show Table Sizes
+BookmarkView.Paste=Paste
+BookmarkView.Copy=Copy
+BookmarkView.CopyOf=Copy of
+SQLLogView.ClearLog=Clear Log
+SQLQueryView.Commit=Commit
+SQLQueryView.RollBack=RollBack
+SQLQueryView.AutoCommit=AutoCommit
+SubsetView.Paste=Paste
+SubsetView.Delete=Delete
+SubsetView.CreatesANewEmptySubset=Creates a new empty subset
+SubsetView.DeletesTheSelectedColumns=Deletes the selected column
+SubsetView.DeletesTheSelectedObject=Deletes the selected object
+SubsetView.DeletesTheSelectedSubset=Deletes the selected subset
+TableView.FilterAndSort=Filter and Sort
+TableView.UpdateRow=Update Row
+TableView.InsertRow=Insert Row
+TableView.DeleteRow=Delete Row
+TableAdapter.to=\ to
+TableAdapter.of=\ of
+TableAdapter.full=\ (FULL)
+BookmarkWizard.NewBookmark=New Bookmark
+BookmarkWizard.Testing=Testing...
+BookmarkWizard.JarFiles=Jar Files (*.jar)
+BookmarkWizard.ZipFiles=Zip Files (*.zip)
+BookmarkWizard.AllFiles=All Files (*.*)
+BookmarkWizard.BookmarkNameAst=*Bookmark Name
+BookmarkWizard.UsernameAst=*Username
+BookmarkWizard.PasswordAst=*Password
+BookmarkWizard.Schema=Schema (optional)
+BookmarkWizard.ConnectAst=*Connect
+BookmarkWizard.DriverAst=*Driver
+BookmarkWizard.TypeAst=*Type
+BookmarkWizard.DriverFilenameAst=*Driver Filename
+BookmarkWizard.Browse=Browse...
+DeleteRowPage.ColumnName=Column Name
+DeleteRowPage.Value=Value
+DeleteRowPage.IncludeIn=Include in?
+DeleteRowPage.WhereClause=Where clause
+DeleteRowPage.UpdatingQuery=Updating query
+DeleteRowPage.WarningNoWhere=Warning: no \"where clause\" columns selected, all rows will be deleted
+InsertRowPage.ColumnName=Column Name
+InsertRowPage.Value=Value
+UpdateRowPage.ColumnName=Column Name
+UpdateRowPage.OldValue=Old Value
+UpdateRowPage.NewValue=New Value
+UpdateRowPage._13=
+UpdateRowPage.SetValue=Set Value
+ConnectAction.ConnectingTo=Connecting to
+ConnectAction.ErrorConnecting=Error while connecting to
/**
* @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;
package net.sourceforge.phpdt.sql.actions;
+import java.sql.Connection;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
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.Messages;
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.
* @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.setStatus(Messages.getString("ConnectAction.ConnectingTo") + current.getName() + "..."); //$NON-NLS-2$ //$NON-NLS-1$
+ Connection con = current.getConnection();
+ if (con != null) {
view.refreshBookmarkData();
view.expandCurrent(current);
} else {
- view.setStatus("Error while connecting to " + current.getName()); //$NON-NLS-1$
+ view.setStatus(Messages.getString("ConnectAction.ErrorConnecting") + 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.Messages;
+import net.sourceforge.phpdt.sql.model.Table;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+
+/**
+ * @author root
+ *
+ */
+public class DeleteAllRowsAction 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 TableNode) {
+ TableNode node = (TableNode) selection;
+ if (node != null) {
+ Table table = (Table) node.getTable();
+System.out.println("==>" + table.getQualifiedName());
+ boolean flag = MessageDialog.openConfirm(
+ view.getSite().getShell(),
+ Messages.getString("bookmarkview.deleteAllRows") + table.getQualifiedName(),
+ Messages.getString("bookmarkview.confirmDeleteAllRows"));
+ if (flag) {
+ table.deleteAllRows();
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import net.sourceforge.phpdt.sql.Messages;
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;
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+import java.util.Iterator;
+
+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.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.bookmark.ColumnMetaData;
+
+/**
+ * Deletes the selected columns from the Subset items (Tables)
+ * @author root
+ *
+ */
+public class DeleteColumnAction extends Action implements IViewActionDelegate {
+ SubsetView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (SubsetView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ StructuredSelection selection = view.getSelection();
+ Iterator iter = selection.iterator();
+ if (! MessageDialog.openConfirm(view.getSite().getShell(),
+ Messages.getString("DeleteColumnAction.DeleteColumns"), //$NON-NLS-1$
+ Messages.getString("DeleteColumnAction.ConfirmDeleteColumns") )) //$NON-NLS-1$
+ return;
+
+ while (iter.hasNext()) {
+ Object current = iter.next();
+ if (current instanceof ColumnMetaData) {
+ ColumnMetaData column = (ColumnMetaData) current;
+ if (column != null) {
+ view.deleteColumn(column);
+ }
+ }
+ }
+ }
+
+ /**
+ * @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.Iterator;
+
+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.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+
+/**
+ * Deletes an entire object (Table) from the SubsetView
+ * @author root
+ *
+ */
+public class DeleteObjectAction extends Action implements IViewActionDelegate {
+ SubsetView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (SubsetView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ Object selection = view.getCurrent();
+ if (selection instanceof SubsetNode) {
+ SubsetNode node = (SubsetNode) selection;
+ if (node != null) {
+ boolean flag = MessageDialog.openConfirm(view.getSite().getShell(),
+ Messages.getString("DeleteObjectAction.DeleteSubset"), //$NON-NLS-1$
+ Messages.getString("DeleteObjectAction.ConfirmDeleteSubset") + node.getName()); //$NON-NLS-1$
+ if (flag) {
+ view.deleteCurrent();
+ }
+ }
+ } else if (selection instanceof ObjectNode) {
+ StructuredSelection allSelected = view.getSelection();
+ Iterator iter = allSelected.iterator();
+ if (! MessageDialog.openConfirm(view.getSite().getShell(),
+ Messages.getString("DeleteObjectAction.DeleteItems"), //$NON-NLS-1$
+ Messages.getString("DeleteObjectAction.ConfirmDeleteItems") )) //$NON-NLS-1$
+ return;
+
+ while (iter.hasNext()) {
+ Object current = iter.next();
+ if (current instanceof ObjectNode) {
+ ObjectNode node = (ObjectNode) current;
+ if (node != null) {
+ view.deleteObject(node);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @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.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+
+/**
+ * @author root
+ * Deletes a complete subset from the subset view
+ */
+public class DeleteSubsetAction extends Action implements IViewActionDelegate {
+ SubsetView view;
+ /**
+ * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+ */
+ public void init(IViewPart view) {
+ this.view = (SubsetView) view;
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ Object selection = view.getCurrent();
+ if (selection instanceof SubsetNode) {
+ SubsetNode node = (SubsetNode) selection;
+ if (node != null) {
+ boolean flag = MessageDialog.openConfirm(view.getSite().getShell(),
+ Messages.getString("DeleteSubsetAction.DeleteSubset"), //$NON-NLS-1$
+ Messages.getString("DeleteSubsetAction.ConfirmDeleteSubset") + node.getName()); //$NON-NLS-1$
+ if (flag) {
+ view.deleteCurrent();
+ }
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
/**
* @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.
+ * Disconnects from the database
*/
public class DisconnectAction extends Action implements IViewActionDelegate {
BookmarkView view;
package net.sourceforge.phpdt.sql.actions;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.view.BookmarkView;
-import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
-import net.sourceforge.phpdt.sql.wizards.BookmarkWizard;
-
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;
+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.
+ * Edits a bookmark
*/
-public class EditBookmarkAction extends Action implements IViewActionDelegate, IConstants {
+public class EditBookmarkAction extends Action implements IViewActionDelegate {
IViewPart view;
/**
* @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
run();
}
public void run() {
- if (DEBUG) {
- System.out.println("Wizard..");
- }
+ System.out.println("Wizard.."); //$NON-NLS-1$
BookmarkWizard wizard = new BookmarkWizard();
BookmarkNode b = BookmarkView.getInstance().getCurrentBookmark();
package net.sourceforge.phpdt.sql.actions;
+import java.sql.Connection;
import java.util.Vector;
-import net.sourceforge.phpdt.sql.IConstants;
+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.Messages;
import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
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.BookmarkView;
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.bookmark.BookmarkNode;
import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
-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;
-
-public class ExecuteAction
- extends Action
- implements IViewActionDelegate, IConstants {
- SQLQueryView view;
- boolean flag = false;
- String execute1 = "Executing Query...";
- String execute2 = "Executing Query..";
- public void init(IViewPart view) {
- this.view = (SQLQueryView) view;
- }
+/**
+ * @author panic
+ *
+ * Executes a query from the QueryView
+ */
+public class ExecuteAction extends Action implements IViewActionDelegate {
+ SQLQueryView view;
+ boolean flag = false;
+ String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
+ String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
+ public void init(IViewPart view) {
+ this.view = (SQLQueryView) view;
+ }
- public void run(IAction action) {
- run();
- }
+ 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);
- if (DEBUG) {
- 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);
- if (DEBUG) {
- 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 run() {
+ view.setStatus(execute1);
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
+ 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);
+ }
+ BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
+ Connection con = current.getConnection();
+
+ String query = (String) queries.elementAt(i);
+ System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (con != null && !query.equals("")) { //$NON-NLS-1$
+ SQLResults results = server.execute(con, query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
+ resultCount++;
+ if (results.isResultSet()) {
+ PHPEclipseSQLPlugin phpesqlPluginInstance = PHPEclipseSQLPlugin.getDefault();
+ phpesqlPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+ TableView.getInstance().loadQuery(current, 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());
+ }
+ Image statImage = PHPEclipseSQLPlugin.getImage((errorCount > 0) ? "stop.gif" : "success.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+ view.setStatus(statImage, Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
+ resultCount + Messages.getString("ExecuteAction.QueriesExecuted") + //$NON-NLS-1$
+ resultUpdateCount + Messages.getString("ExecuteAction.RowsUpdated") + //$NON-NLS-1$
+ resultsDisplayed + Messages.getString("ExecuteAction.ResultsDisplayed") + //$NON-NLS-1$
+ errorCount + Messages.getString("ExecuteAction.Errors") + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ view.setProgress(0, 1);
+ QueryHistoryView history = QueryHistoryView.getInstance();
+ if (history != null) history.addQuery(viewQuery);
+ }
- public void selectionChanged(IAction action, ISelection selection) {
- }
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
}
package net.sourceforge.phpdt.sql.actions;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import org.apache.crimson.tree.XmlDocument;
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 org.w3c.dom.Element;
+import net.sourceforge.phpdt.sql.Messages;
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.
+ * Asks the user for a file name and saves there the bookmarks in xml format
*/
public class ExportBookmarksAction
implements IViewActionDelegate {
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$
+ dialog.setFilterExtensions(new String[]{"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[]{Messages.getString("filedialog.xmlFiles"),Messages.getString("filedialog.xmlFiles")}); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
public void run(IAction action) {
String filename = dialog.open();
if (filename != null) {
- File exportFile = new File(filename);
- BookmarkContentProvider.getInstance().save(exportFile);
+ /*Check for the presence of a "." - either indicates an
+ * extension has been provided or that a filename with a '.'
+ * has been specified - if the latter, it is assumed the user
+ * knows what they're doing - could be dangerous! :-)
+ */
+ if (filename.indexOf(".") ==0) filename += ".xml";
+
+ File target = new File(filename);
+ XmlDocument doc = new XmlDocument();
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(target);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ return;
+ }
+ Element root = (Element) doc.appendChild(doc.createElement(Messages.getString("ExportXMLAction.SavedData"))); //$NON-NLS-1$
+
+ BookmarkContentProvider.getInstance().exportXML(root);
+
+ try {
+ doc.write(out);
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
}
}
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import net.sourceforge.phpdt.sql.Messages;
import net.sourceforge.phpdt.sql.view.LogProxy;
import net.sourceforge.phpdt.sql.view.SQLLogView;
import net.sourceforge.phpdt.sql.view.SQLQueryView;
String filename = dialog.open();
if (filename != null) {
try {
- File exportFile = new File(filename);
+ /*Check for the presence of a "." - either indicates an
+ * extension has been provided or that a filename with a '.'
+ * has been specified - if the latter, it is assumed the user
+ * knows what they're doing - could be dangerous! :-)
+ */
+ if (filename.indexOf(".") >0) filename += ".sql";
+ 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");
+ StringTokenizer tokenizer = new StringTokenizer(output, "\n"); //$NON-NLS-1$
while (tokenizer.hasMoreElements()) {
String line = (String) tokenizer.nextElement();
writer.println(line);
--- /dev/null
+package net.sourceforge.phpdt.sql.actions;
+
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.crimson.tree.XmlDocument;
+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.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.w3c.dom.Element;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.sql.metadata.MetaDataXMLInterface;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
+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 ExportXMLAction 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() {
+
+ FileDialog dialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);
+ dialog.setFilterExtensions(new String[]{"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[]{Messages.getString("filedialog.xmlFiles"),Messages.getString("filedialog.xmlFiles")}); //$NON-NLS-1$ //$NON-NLS-2$
+
+ String filename = dialog.open();
+ if (filename == null) return;
+ /*Check for the presence of a "." - either indicates an
+ * extension has been provided or that a filename with a '.'
+ * has been specified - if the latter, it is assumed the user
+ * knows what they're doing - could be dangerous! :-)
+ */
+ if (filename.indexOf(".") ==0) filename += ".xml";
+ File file = new File(filename);
+ System.out.println(Messages.getString("ExportXMLAction.XMLExporting") + file); //$NON-NLS-1$
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(file);
+ } catch (FileNotFoundException e1) {
+ MessageDialog.openConfirm(view.getSite().getShell(), Messages.getString("ExportXMLAction.CannotOpenFile"), //$NON-NLS-1$
+ Messages.getString("ExportXMLAction.CannotOpenFileMessage") + filename+ //$NON-NLS-1$
+ Messages.getString("ExportXMLAction.CannotOpenFileExplain")); //$NON-NLS-1$
+ e1.printStackTrace();
+ return;
+ }
+ XmlDocument doc = new XmlDocument();
+ StructuredSelection selection = null;
+ if (view instanceof BookmarkView){
+ BookmarkView bookmarkView = (BookmarkView) view;
+ selection = bookmarkView.getSelection();
+ } else if (view instanceof SubsetView){
+ SubsetView subsetView = (SubsetView) view;
+ selection = subsetView.getSelection();
+ }
+
+ ExportXMLSelection(doc, selection);
+ try {
+ doc.write(out);
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+ public static void ExportXMLSelection(XmlDocument doc, StructuredSelection selection) {
+ Element root = (Element) doc.appendChild(doc.createElement(Messages.getString("ExportXMLAction.Metadata"))); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(root, Messages.getString("ExportXMLAction.Author"), //$NON-NLS-1$
+ Messages.getString("ExportXMLAction.PHPEclipseSQL")); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(root, Messages.getString("ExportXMLAction.Version"), //$NON-NLS-1$
+ Messages.getString("ExportXMLAction.XMLVersionNumber")); //$NON-NLS-1$
+ Iterator iter = selection.iterator();
+ while (iter.hasNext()) {
+ TreeNode current = (TreeNode) iter.next();
+ if (current instanceof SubsetNode){
+ SubsetNode subset = (SubsetNode) current;
+ MetaDataXMLInterface.createElementText(root, Messages.getString("ExportXMLAction.Subset"), //$NON-NLS-1$
+ subset.getName()); //$NON-NLS-1$
+ Object[] children = subset.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ TreeNode objectNode = (TreeNode) children[i];
+ ExportXMLAction.exportObject(root, objectNode);
+ }
+ }
+ ExportXMLAction.exportObject(root, current);
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ /**
+ * Exports a TreeNode metadata representation to an XmlDocument, based on a an already-created root Element
+ * @param doc The XmlDocument to receive the metadata representation
+ * @param node The node with the metadata to export
+ * @param root The root element (already present in the XmlDocument) that will hold the metadata
+ */
+ public static void exportObject(Element root, TreeNode node) {
+
+ XmlDocument doc = (XmlDocument) root.getOwnerDocument();
+ String name = node.getName();
+ Element table = null;
+ if (node instanceof TableNode)
+ table = (Element) root.appendChild(doc.createElement(Messages.getString("ExportXMLAction.Table"))); //$NON-NLS-1$
+ else if (node instanceof ViewNode)
+ table = (Element) root.appendChild(doc.createElement(Messages.getString("ExportXMLAction.View"))); //$NON-NLS-1$
+ else if (node instanceof ObjectNode)
+ table = (Element) root.appendChild(doc.createElement(Messages.getString("ExportXMLAction.View"))); //$NON-NLS-1$
+ else
+ return;
+ MetaDataXMLInterface.createElementText(table,Messages.getString("ExportXMLAction.TableName"), name); //$NON-NLS-1$
+
+ if (node instanceof TableNode || node instanceof ViewNode){
+ BookmarkNode bookmark = (BookmarkNode) node.getParent();
+ if (bookmark != null){
+ MetaDataXMLInterface.createElementText(table,Messages.getString("ExportXMLAction.BookmarkName"), bookmark.getName()); //$NON-NLS-1$
+ }
+ }
+
+ ObjectMetaData objMetaData = node.getMetaData();
+ if (objMetaData != null)
+ MetaDataXMLInterface.metaDataToXML(objMetaData, doc, table);
+ }
+
+}
package net.sourceforge.phpdt.sql.actions;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.crimson.tree.XmlDocument;
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 org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+import net.sourceforge.phpdt.sql.Messages;
import net.sourceforge.phpdt.sql.view.BookmarkView;
import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
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$
+ dialog.setFilterExtensions(new String[]{"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[]{Messages.getString("filedialog.xmlFiles"),Messages.getString("filedialog.xmlFiles")}); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
String filename = dialog.open();
if (filename != null) {
File importFile = new File(filename);
- BookmarkContentProvider.getInstance().importBookmarks(importFile);
- view.refresh();
+
+ XmlDocument doc = new XmlDocument();
+ FileInputStream source = null;
+ try {
+ source = new FileInputStream(importFile);
+ } catch (FileNotFoundException e1) {
+ e1.printStackTrace();
+ return;
+ }
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser;
+ try {
+ parser = factory.newDocumentBuilder();
+ doc = (XmlDocument) parser.parse(source);
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ return;
+ } catch (SAXException e) {
+ e.printStackTrace();
+ return;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ Element root = doc.getDocumentElement();
+
+ BookmarkContentProvider.getInstance().importXML(root);
+
+ view.refresh();
+
}
}
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import net.sourceforge.phpdt.sql.Messages;
import net.sourceforge.phpdt.sql.view.LogProxy;
import net.sourceforge.phpdt.sql.view.SQLLogView;
import net.sourceforge.phpdt.sql.view.SQLQueryView;
package net.sourceforge.phpdt.sql.actions;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.wizards.BookmarkWizard;
-
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.wizards.BookmarkWizard;
+
/**
* @author root
*
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
-public class NewBookmarkAction extends Action implements IViewActionDelegate, IConstants {
+public class NewBookmarkAction extends Action implements IViewActionDelegate {
IViewPart view;
/**
* @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
run();
}
public void run() {
- if (DEBUG) {
- System.out.println("Wizard..");
- }
+ System.out.println("Wizard.."); //$NON-NLS-1$
BookmarkWizard wizard = new BookmarkWizard();
wizard.init();
--- /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.Messages;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+
+/**
+ * @author root
+ *
+ */
+public class NewSubsetAction 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(Messages.getString("NewSubsetAction.CreatingNewSubset")); //$NON-NLS-1$
+ InputDialog dialog = new InputDialog(view.getSite().getShell(),
+ Messages.getString("NewSubsetAction.NameOfNewSubset"), Messages.getString("NewSubsetAction.PleaseEnterName"), null, null); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.open();
+ String value = dialog.getValue();
+ if (value != null) {
+ SubsetNode subset = new SubsetNode(value);
+ ((SubsetView) view).addNewSubset(subset);
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
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;
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) {
+ if (node instanceof SequenceNode) {
+ SequenceNode sequence = (SequenceNode) node;
+ BookmarkNode parent = (BookmarkNode) sequence.getParent();
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(parent.getType());
+ if (adapter == null) return;
+ name = sequence.getName();
+ String query = adapter.getNextValue(name);
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ SQLResults results = server.execute(parent.getConnection(), query);
+ TableView.getInstance().loadQuery(parent, results);
}
}
/**
* @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.
+ * Implements the "Refresh Table" action for the TableView view
*/
public class RefreshTableAction extends Action implements IViewActionDelegate {
TableView view;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import net.sourceforge.phpdt.sql.Messages;
import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
import net.sourceforge.phpdt.sql.view.BookmarkView;
public void run() {
Bookmark bookmark = view.getCurrentBookmark();
InputDialog dialog = new InputDialog(view.getSite().getShell(),
- "Set Schema", "Please enter the name of new schema:",
+ Messages.getString("SetSchemaAction.SetSchema"), Messages.getString("SetSchemaAction.PleaseEnterName"), //$NON-NLS-1$ //$NON-NLS-2$
bookmark.getSchema(), null);
dialog.open();
String value = dialog.getValue();
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;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
/**
* @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.
- */
+ * Implements action for "View Table"
+*/
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;
- }
+ 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();
- }
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
+
+ public void run() {
+ PHPEclipseSQLPlugin PHPEclipsePluginPluginInstance = PHPEclipseSQLPlugin.getDefault();
+ PHPEclipsePluginPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+ TreeNode node = null;
+ BookmarkNode bookmark = null;
+ if (view instanceof BookmarkView){
+ BookmarkView bookmarkView = (BookmarkView) view;
+ node = (TreeNode) bookmarkView.getCurrent();
+ bookmark = bookmarkView.getCurrentBookmark();
+ if (bookmark != null && node != null)
+ TableView.getInstance().loadTable(bookmark, node.getName());
+ } else if (view instanceof SubsetView){
+ SubsetView subsetView = (SubsetView) view;
+ node = (TreeNode) subsetView.getCurrent();
+ if (!(node instanceof ObjectNode)) return;
+ ObjectNode objectNode = (ObjectNode) node;
+ String bookmarkName = objectNode.getBookmark();
+ bookmark = BookmarkContentProvider.getInstance().find(bookmarkName);
- 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();
- }
+ String query = objectNode.getQuery();
+ MultiSQLServer server = MultiSQLServer.getInstance();
+
+ TableView.getInstance().loadQuery(bookmark, server.execute(bookmark.getConnection(), query));
- 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) {
- }
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
}
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.Messages;
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.BookmarkNode;
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;
-
public class ViewTableDetailsAction extends Action implements IViewActionDelegate {
BookmarkView view;
public void run() {
TreeNode node = (TreeNode) view.getCurrent();
StringBuffer query = new StringBuffer();
- query.append("METADATA:");
+ query.append(Messages.getString("MetaDataKey")+Messages.getString("MetaDataKeySeparator")); //$NON-NLS-1$ //$NON-NLS-2$
if (node instanceof TableNode) {
query.append(((TableNode) node).getName());
} else if (node instanceof ViewNode) {
query.append(((ViewNode) node).getName());
}
- try {
- IWorkbenchPage page =
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- page.showView(TableView.TABLEVIEW_ID);
- } catch (PartInitException e) {
- }
MultiSQLServer server = MultiSQLServer.getInstance();
- TableView.getInstance().loadQuery(server.execute(query.toString()));
+ BookmarkNode current = view.getCurrentBookmark();
+
+ TableView.getInstance().loadQuery(current, server.execute(current.getConnection(), query.toString()));
}
public void selectionChanged(IAction action, ISelection selection) {
}
public class AdabasDAdapter extends DatabaseAdapter {
public String getShowTableQuery(DatabaseInfo info) {
- return "SELECT TABLENAME FROM TABLES";
+ return "SELECT TABLENAME FROM TABLES"; //$NON-NLS-1$
}
public String getShowViewQuery(DatabaseInfo info) {
- return "SELECT VIEWNAME FROM VIEWS";
+ return "SELECT VIEWNAME FROM VIEWS"; //$NON-NLS-1$
}
- public DatabaseAdapter getInstance() {
- return new AdabasDAdapter();
- }
}
import java.util.ArrayList;
+import net.sourceforge.phpdt.sql.Messages;
+
+/**
+ * @author root
+ * Basically this Factory is a Singleton that is used to return the proper adapter
+ */
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";
+ public static final String GENERIC = "GENERIC"; //$NON-NLS-1$
+ public static final String ORACLE = "ORACLE"; //$NON-NLS-1$
+ public static final String POSTGRES = "POSTGRES"; //$NON-NLS-1$
+ public static final String MYSQL = "MYSQL"; //$NON-NLS-1$
+ public static final String DB2 = "DB2"; //$NON-NLS-1$
+ public static final String DB2AS400 = "DB2AS400"; //$NON-NLS-1$
+ public static final String ADABASD = "ADABASD"; //$NON-NLS-1$
+ public static final String INFORMIX = "INFORMIX"; //$NON-NLS-1$
+ public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$
private static AdapterFactory instance;
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());
+ DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter()); //$NON-NLS-1$
+ DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); //$NON-NLS-1$
+ DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); //$NON-NLS-1$
+ DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); //$NON-NLS-1$
+ DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); //$NON-NLS-1$
+ DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new MySQLAdapter()); //$NON-NLS-1$
+ DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); //$NON-NLS-1$
+ DriverInfo informix = new DriverInfo(INFORMIX, Messages.getString("adapters.informix"), new GenericAdapter()); //$NON-NLS-1$
+ DriverInfo redbrick = new DriverInfo(REDBRICK, Messages.getString("adapters.redbrick"), new RedBrickAdapter()); //$NON-NLS-1$
drivers.add(generic);
drivers.add(oracle);
drivers.add(postgres);
drivers.add(mysql);
drivers.add(adabasd);
+ drivers.add(informix);
+ drivers.add(redbrick);
}
- public synchronized DatabaseAdapter getAdapter(String type) throws NoSuchAdapterException {
+ public synchronized DatabaseAdapter getAdapter(String type){
if (drivers == null) {
loadDrivers();
}
for (int i = 0; i < drivers.size(); i++) {
DriverInfo info = (DriverInfo) drivers.get(i);
if (type.equals(info.getDriverType())) {
- return info.getAdapter().getInstance();
+ return info.getAdapter();
}
}
- throw new NoSuchAdapterException(type);
+ // If its not a recognized driver, we return the generic one
+ for (int i = 0; i < drivers.size(); i++) {
+ DriverInfo info = (DriverInfo) drivers.get(i);
+ if (type.equals(GENERIC)) {
+ return info.getAdapter();
+ }
+ }
+ return null;
}
public synchronized DriverInfo[] getDriverList() {
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'";
+ return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + info.getSchema().toUpperCase() + "' AND TABLE_TYPE = 'P'"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String getShowViewQuery(DatabaseInfo info) {
- return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + info.getSchema().toUpperCase() + "' AND TABLE_TYPE = 'L'";
+ return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" + info.getSchema().toUpperCase() + "' AND TABLE_TYPE = 'L'"; //$NON-NLS-1$ //$NON-NLS-2$
}
- public DatabaseAdapter getInstance() {
- return new DB2AS400Adapter();
- }
}
public class DB2Adapter extends DatabaseAdapter {
public String getShowTableQuery(DatabaseInfo info) {
- return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + info.getSchema().toUpperCase() + "' AND TYPE='T'";
+ return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + info.getSchema().toUpperCase() + "' AND TYPE='T'"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String getShowViewQuery(DatabaseInfo info) {
- return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + info.getSchema().toUpperCase() + "' AND TYPE='V'";
+ return "SELECT TABNAME FROM syscat.tables WHERE tabschema = '" + info.getSchema().toUpperCase() + "' AND TYPE='V'"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String getShowSequenceQuery(DatabaseInfo info) {
- return "SELECT SEQNAME FROM sysibm.syssequences WHERE seqschema = '" + info.getSchema().toUpperCase() + "'";
+ return "SELECT SEQNAME FROM sysibm.syssequences WHERE seqschema = '" + info.getSchema().toUpperCase() + "'"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String getNextValue(String sequence) {
- return "VALUES NEXTVAL FOR " + sequence;
+ return "VALUES NEXTVAL FOR " + sequence; //$NON-NLS-1$
}
- public DatabaseAdapter getInstance() {
- return new DB2Adapter();
- }
}
package net.sourceforge.phpdt.sql.adapters;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.model.Entity;
+import net.sourceforge.phpdt.sql.model.EntityFactory;
+import net.sourceforge.phpdt.sql.sql.DbElementsConstants;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.sql.SQLResults;
+
+/**
+ * @author root
+ * Abstract base class for all the adapter classes
+ */
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 abstract String getShowTableQuery(DatabaseInfo info);
+ public String getShowViewQuery(DatabaseInfo info) {
+ return null;
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return null;
+ }
public final String getShowTableQuery(DatabaseInfo info, String table) {
String schema = info.getSchema();
- if (schema.equals("")) {
- return "SELECT * FROM " + table;
+ if (schema.equals("")) { //$NON-NLS-1$
+ return "SELECT * FROM " + table; //$NON-NLS-1$
} else {
- return "SELECT * FROM " + info.getSchema() + "." + table;
+ return "SELECT * FROM " + info.getSchema() + "." + table; //$NON-NLS-1$ //$NON-NLS-2$
}
}
- 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;
+
+
+
+ // BCH: Not used
+// public final String getTableCountQuery(DatabaseInfo info, String table) {
+// String schema = info.getSchema();
+// if (schema.equals("")) { //$NON-NLS-1$
+// return "SELECT COUNT(*) FROM " + table; //$NON-NLS-1$
+// } else {
+// return "SELECT COUNT(*) FROM " + info.getSchema() + "." + table; //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// }
+ public String getNextValue(String sequence) {
+ return null;
+ }
+ //Doesn't seem to be used at the moment
+// public String getTableListFilter() {
+// return null;
+// }
+
+ /**
+ * @param table
+ * @return : A query to get an empty ResultSet (null if failed) for that table or view.
+ * Subclassed if needed by the different database adapters
+ */
+ public String getEmptySetQuery(String table){
+ return "SELECT * FROM " + table + " WHERE (1 = 0)"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Quotes a string according to the type of the column
+ * @param string to be quoted
+ * @param type according to java.sql.Types
+ * @return
+ */
+ public String quote(String string, int type) {
+ if (SQLHelper.isText(type)){
+ if (string.indexOf('\'') >= 0)
+ return '"' + string + '"';
+ else
+ return "'" + string + "'"; //$NON-NLS-1$ //$NON-NLS-2$
}
+ else if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP){
+ string = string.trim();
+ String sub = string.substring(string.length() - 2, string.length() - 1);
+ if (string.length() > 1 && sub.equals(".")) //$NON-NLS-1$
+ string = string.substring(0, string.length() - 2);
+ return "'" + string + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+ return string;
+ }
+
+
+ /**
+ * Get a list of entities (tables, views, sequences) for a particular
+ * bookmark.
+ *
+ * @param bookmark -
+ * the bookmark that describes the database that is being accessed.
+ * @return
+ * an array of entity objects representing the tables, views and sequences.
+ * @throws SQLException
+ */
+ public Entity[] getEntities(Bookmark bookmark) throws SQLException {
+ Connection connection = bookmark.getConnection();
+ Entity[] result = getEntities(bookmark, connection);
+ return (result == null) ? new Entity[0] : result;
}
- public String getNextValue(String sequence) {
- throw new FeatureNotSupported("Sequences");
+
+ protected Entity[] getEntities(Bookmark bookmark, Connection connection) throws SQLException {
+
+ List list = new ArrayList();
+ String[] types = {
+ DbElementsConstants.Table,
+ DbElementsConstants.View,
+ DbElementsConstants.Sequence };
+
+ for (int i = 0; i < types.length; i++) {
+ list.addAll(getEntitiesList(bookmark, connection, types[i]));
+ }
+
+ return (Entity[]) list.toArray(new Entity[0]);
}
- public String getTableListFilter() {
- return null;
+
+ protected List getEntitiesList(Bookmark bookmark, Connection connection, String type)
+ throws SQLException {
+
+ String sql = getSQL(bookmark, type);
+ List list = new ArrayList();
+
+ if (sql != null) {
+ SQLResults results = MultiSQLServer.getInstance().execute(connection, sql);
+ for (int i = 1, size = (results == null) ? 0 : results.getRowCount(); i <= size; i++) {
+ list.add(EntityFactory.getInstance().create(
+ bookmark, bookmark.getSchema(), results.getElement(1, i).toString(), type));
+ }
+ }
+ return list;
+ }
+
+ private String getSQL(Bookmark bookmark, String type) {
+ DatabaseInfo info = DatabaseInfo.create(bookmark);
+ if (DbElementsConstants.Table.equals(type)) {
+ return getShowTableQuery(info);
+ } else if (DbElementsConstants.View.equals(type)) {
+ return getShowViewQuery(info);
+ } else if (DbElementsConstants.Sequence.equals(type)) {
+ return getShowSequenceQuery(info);
+ } else {
+ return null;
+ }
}
}
\ No newline at end of file
package net.sourceforge.phpdt.sql.adapters;
-public class GenericAdapter extends DatabaseAdapter {
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
- public DatabaseAdapter getInstance() {
- return new GenericAdapter();
- }
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.model.Entity;
+import net.sourceforge.phpdt.sql.model.EntityFactory;
+
+
+public class GenericAdapter extends DatabaseAdapter {
public String getShowTableQuery(DatabaseInfo info) {
return null;
public String getShowViewQuery(DatabaseInfo info) {
return null;
}
+
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return null;
+ }
+
+ /**
+ * @param connection -
+ * a database
+ * @param schema -
+ * a schema name to filter on, or null to return all entities from all filters
+ * @param type -
+ * the type of entities (TABLES, VIEWS, etc.) to get
+ * @return
+ */
+ protected List getEntitiesList(Bookmark bookmark, Connection connection, String type)
+ throws SQLException {
+
+ List list = new ArrayList();
+ DatabaseMetaData metaData = connection.getMetaData();
+ ResultSet set = metaData.getTables(
+ null, bookmark.getSchema(), "%", new String[] { type });
+ while (set.next()) {
+ String schema = set.getString("TABLE_SCHEM");
+ schema = (schema == null) ? "" : schema.trim();
+ String tableName = set.getString("TABLE_NAME").trim();
+
+ if (tableName.length() > 0) {
+ Entity entity = EntityFactory.getInstance().create(
+ bookmark, schema, tableName, type);
+ if (entity != null) {
+ list.add(entity);
+ }
+ }
+ }
+ set.close();
+ return list;
+ }
+
}
+++ /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 + '!';
- }
- }
-}
public class MySQLAdapter extends DatabaseAdapter {
- public String getShowTableQuery(DatabaseInfo info) {
- return "SHOW TABLES";
- }
- public DatabaseAdapter getInstance() {
- return new MySQLAdapter();
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SHOW TABLES"; //$NON-NLS-1$
}
}
\ No newline at end of file
package net.sourceforge.phpdt.sql.adapters;
+import net.sourceforge.phpdt.sql.Messages;
+
public class NoSuchAdapterException extends Exception {
public NoSuchAdapterException(String driverName) {
- super("Database not supported: ->" + driverName + "<-");
+ super(Messages.getString("Error.NoDatabase") + driverName + Messages.getString("NoSuchAdapterException.<-_2")); //$NON-NLS-1$ //$NON-NLS-2$
}
}
\ No newline at end of file
package net.sourceforge.phpdt.sql.adapters;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+
+
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();
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABLE_NAME FROM USER_TABLES"; //$NON-NLS-1$
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT VIEW_NAME FROM USER_VIEWS"; //$NON-NLS-1$
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return "SELECT SEQUENCE_NAME FROM USER_SEQUENCES"; //$NON-NLS-1$
+ }
+ public String getNextValue(String sequence) {
+ return "SELECT LAST_NUMBER FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ /**
+ * Quotes a string according to the type of the column
+ * @param string to be quoted
+ * @param type according to java.sql.Types
+ * @return
+ */
+ public String quote(String string, int type) {
+ if (SQLHelper.isText(type)) {
+ if (string.indexOf('\'') >= 0)
+ return '"' + string + '"';
+ else
+ return "'" + string + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ } else if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) {
+ string = string.trim();
+ String sub = string.substring(string.length()-2, string.length()-1);
+ if (string.length() > 1 && sub.equals(Messages.getString("OracleAdapter.._3"))) //$NON-NLS-1$
+ string = string.substring(0,string.length()-2);
+ return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return string;
}
}
\ No newline at end of file
public class PostgresAdapter extends DatabaseAdapter {
public String getShowTableQuery(DatabaseInfo info) {
- return "SELECT TABLENAME FROM PG_TABLES";
+ return "SELECT TABLENAME FROM PG_TABLES"; //$NON-NLS-1$
}
public String getShowViewQuery(DatabaseInfo info) {
- return "SELECT VIEWNAME FROM PG_VIEWS";
+ return "SELECT VIEWNAME FROM PG_VIEWS"; //$NON-NLS-1$
}
public String getShowSequenceQuery(DatabaseInfo info) {
- return "SELECT relname FROM pg_class WHERE relkind = 'S'";
+ return "SELECT relname FROM pg_class WHERE relkind = 'S'"; //$NON-NLS-1$
}
- public String getNextValue(String sequence) {
- return "select nextval('" + sequence + "')";
- }
- public String getTableListFilter() {
- return "pg_";
- }
- public DatabaseAdapter getInstance() {
- return new PostgresAdapter();
- }
+ //These lines commented because I couldn't find the string values anywhere
+// public String getNextValue(String sequence) {
+// return Messages.getString("PostgresAdapter.select_nextval(___4") + sequence + Messages.getString("PostgresAdapter.__)_5"); //$NON-NLS-1$ //$NON-NLS-2$
+// }
+// public String getTableListFilter() {
+// return Messages.getString("PostgresAdapter.pg__6"); //$NON-NLS-1$
+// }
}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.sql.adapters;
+
+/**
+ * @author bcholmes
+ */
+public class RedBrickAdapter extends DatabaseAdapter {
+
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "select name from rbw_tables where type = 'TABLE'";
+ }
+
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "select name from rbw_tables where type = 'VIEW'";
+ }
+}
package net.sourceforge.phpdt.sql.bookmarks;
+import java.sql.Connection;
+
+import net.sourceforge.phpdt.sql.sql.ConnectionEstablisher;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+
/**
* @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.
+ * Class Bookmark holds the "static" information of a bookmark, that is the data that
+ * is saved and loaded from the external file and describes a bookmark. This info will
+ * be filled up by the end user.
*/
public class Bookmark {
- String name = "";
- String username = "";
- String password = "";
- String connect = "";
- String driver = "";
- String type = "";
- String driverFile = "";
- String schema = "";
+ String name = ""; //$NON-NLS-1$
+ String username = ""; //$NON-NLS-1$
+ String password = ""; //$NON-NLS-1$
+ String connect = ""; //$NON-NLS-1$
+ String driver = ""; //$NON-NLS-1$
+ String type = ""; //$NON-NLS-1$
+ String driverFile = ""; //$NON-NLS-1$
+ String schema = ""; //$NON-NLS-1$
+ private ConnectionEstablisher connectionEstablisher;
public Bookmark() {
+ this(MultiSQLServer.getInstance());
}
+
+ public Bookmark(ConnectionEstablisher connectionEstablisher) {
+ this.connectionEstablisher = connectionEstablisher;
+ }
public Bookmark(Bookmark data) {
setName(data.getName());
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.
+ * Returns the JDBC URL.
* @return String
*/
public String getConnect() {
*/
public void setConnect(String connect) {
if (connect == null) {
- connect = "";
+ connect = ""; //$NON-NLS-1$
}
this.connect = connect;
}
*/
public void setDriver(String driver) {
if (driver == null) {
- driver = "";
+ driver = ""; //$NON-NLS-1$
}
this.driver = driver;
}
*/
public void setDriverFile(String driverFile) {
if (driverFile == null) {
- driverFile = "";
+ driverFile = ""; //$NON-NLS-1$
}
this.driverFile = driverFile;
}
*/
public void setPassword(String password) {
if (password == null) {
- password = "";
+ password = ""; //$NON-NLS-1$
}
this.password = password;
}
*/
public void setUsername(String username) {
if (username == null) {
- username = "";
+ username = ""; //$NON-NLS-1$
}
this.username = username;
}
*/
public void setName(String name) {
if (name == null) {
- name = "";
+ name = ""; //$NON-NLS-1$
}
this.name = name;
}
public boolean isEmpty() {
- if (name.equals("") &&
- username.equals("") &&
- password.equals("") &&
- connect.equals("") &&
- driver.equals("") &&
- type.equals("") &&
- driverFile.equals("")) {
+ if (name.equals("") && //$NON-NLS-1$
+ username.equals("") && //$NON-NLS-1$
+ password.equals("") && //$NON-NLS-1$
+ connect.equals("") && //$NON-NLS-1$
+ driver.equals("") && //$NON-NLS-1$
+ type.equals("") && //$NON-NLS-1$
+ driverFile.equals("")) { //$NON-NLS-1$
return true;
}
return false;
}
public String toString() {
StringBuffer buffer = new StringBuffer();
- buffer.append("[");
- buffer.append("name=");
+ buffer.append("["); //$NON-NLS-1$
+ buffer.append("name="); //$NON-NLS-1$
buffer.append(name);
- buffer.append(", ");
- buffer.append("username=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("username="); //$NON-NLS-1$
buffer.append(username);
- buffer.append(", ");
- buffer.append("password=****");
- buffer.append(", ");
- buffer.append("connect=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("password=****"); //$NON-NLS-1$
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("connect="); //$NON-NLS-1$
buffer.append(connect);
- buffer.append(", ");
- buffer.append("driver=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("driver="); //$NON-NLS-1$
buffer.append(driver);
- buffer.append(", ");
- buffer.append("type=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("type="); //$NON-NLS-1$
buffer.append(type);
- buffer.append(", ");
- buffer.append("driverFile=");
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append("driverFile="); //$NON-NLS-1$
buffer.append(driverFile);
- buffer.append("]");
+ buffer.append("]"); //$NON-NLS-1$
return buffer.toString();
}
this.schema = schema;
}
+ protected Connection connection = null;
+ /**
+ * Returns the connection object. Will automatically connect if not connected.
+ * @return the Connection object associated with the current JDBC source.
+ *
+ */
+ public Connection getConnection() {
+ // We autoconnect if needed. (After all, reusability is a myth :)
+ if (connection == null) connection = this.connectionEstablisher.connect(this);
+ return connection;
+ }
+
+ /**
+ * @return true if the BookmarkNode is connected to a JDBC source
+ */
+ public boolean isConnected() {
+ return (connection != null);
+ }
+
+ /**
+ * Sets the connection member. From that moment on the BookmarkNode is "connected" (open)
+ * @param connection : a valid connection to a JDBC source
+ */
+ public void setConnection(Connection connection) {
+ this.connection = connection;
+ }
+
+ public void disconnect() {
+ this.connectionEstablisher.disconnect(this, this.connection);
+ }
}
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.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
public class SQLConfiguration extends SourceViewerConfiguration {
private PresentationReconciler reconciler = new PresentationReconciler();
private ColorManager colorManager;
setDamageRepairer(getAttr(SQLColorConstants.NUMERIC, numericBold), SQLPartitionScanner.SQL_NUMERIC);
}
public TextAttribute getAttr(RGB color, boolean bold) {
- Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
+ colorManager.getColor(SQLColorConstants.BACKGROUND);
Color foreground = colorManager.getColor(color);
TextAttribute attr = new TextAttribute(foreground);
if (bold) {
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.widgets.Display;
import org.eclipse.ui.editors.text.TextEditor;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
public class SQLEditor extends TextEditor {
SQLConfiguration config;
private ColorManager colorManager;
config.initializeColors();
getSourceViewer().invalidateTextPresentation();
StyledText widget = getSourceViewer().getTextWidget();
- FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "phpeclipse.sql.font");
+ FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "phpeclipse.sql.font"); //$NON-NLS-1$
widget.setFont(new Font(Display.getCurrent(), font));
Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
widget.setBackground(background);
public void createPartControl(Composite arg0) {
super.createPartControl(arg0);
StyledText widget = getSourceViewer().getTextWidget();
- FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "phpeclipse.sql.font");
+ FontData font = PreferenceConverter.getFontData(getPreferenceStore(), "phpeclipse.sql.font"); //$NON-NLS-1$
widget.setFont(new Font(Display.getCurrent(), font));
Color background = colorManager.getColor(SQLColorConstants.BACKGROUND);
widget.setBackground(background);
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";
+ public final static String SQL_COMMENT = "__sql_comment"; //$NON-NLS-1$
+ public final static String SQL_IDENTIFIER = "__sql_word"; //$NON-NLS-1$
+ public final static String SQL_STRING = "__sql_string"; //$NON-NLS-1$
+ public final static String SQL_KEYWORD = "__sql_keyword"; //$NON-NLS-1$
+ public final static String SQL_SYMBOL = "__sql_symbol"; //$NON-NLS-1$
+ public final static String SQL_SEPARATOR = "__sql_separator"; //$NON-NLS-1$
+ public final static String SQL_NUMERIC = "__sql_numeric"; //$NON-NLS-1$
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"
+ "ALTER", //$NON-NLS-1$
+ "AND", //$NON-NLS-1$
+ "BY", //$NON-NLS-1$
+ "COLUMN", //$NON-NLS-1$
+ "CREATE", //$NON-NLS-1$
+ "DELETE", //$NON-NLS-1$
+ "DROP", //$NON-NLS-1$
+ "FROM", //$NON-NLS-1$
+ "GROUP", //$NON-NLS-1$
+ "INSERT", //$NON-NLS-1$
+ "INTO", //$NON-NLS-1$
+ "NOT", //$NON-NLS-1$
+ "NULL", //$NON-NLS-1$
+ "OR", //$NON-NLS-1$
+ "ORDER", //$NON-NLS-1$
+ "SELECT", //$NON-NLS-1$
+ "SEQUENCE", //$NON-NLS-1$
+ "SET", //$NON-NLS-1$
+ "TABLE", //$NON-NLS-1$
+ "UNION", //$NON-NLS-1$
+ "UNIQUE", //$NON-NLS-1$
+ "UPDATE", //$NON-NLS-1$
+ "USING", //$NON-NLS-1$
+ "VALUES", //$NON-NLS-1$
+ "VIEW", //$NON-NLS-1$
+ "WHEN", //$NON-NLS-1$
+ "WHERE" //$NON-NLS-1$
};
public SQLPartitionScanner() {
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 MultiLineRule("/*", "*/", comment)); //$NON-NLS-1$ //$NON-NLS-2$
+ rules.add(new EndOfLineRule("--", comment)); //$NON-NLS-1$
+ rules.add(new SingleLineRule("'", "'", string)); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(new PredicateRuleAdapter(new SQLNumberRule(numeric), numeric));
SQLWordRule wordRule = new SQLWordRule(identifier);
for (int i = 0; i < KEYWORDS.length; i++) {
}
public IToken evaluate(ICharacterScanner scanner) {
int val = scanner.read();
- if (val != scanner.EOF) {
+ if (val != ICharacterScanner.EOF) {
char c = (char) val;
if (!Character.isWhitespace(c) && !Character.isLetterOrDigit(c) && c != '_') {
return token;
--- /dev/null
+package net.sourceforge.phpdt.sql.model;
+
+/**
+ * @author BC
+ */
+public interface Entity {
+ public String getName();
+ public String getSchema();
+ public String getType();
+ public String getQualifiedName();
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.model;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.sql.DbElementsConstants;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+
+/**
+ *
+ *
+ * @author BC
+ */
+public class EntityFactory {
+
+ public abstract class EntityImpl implements Entity {
+ private String schema;
+ private String name;
+ private String type;
+ private Bookmark bookmark;
+
+ public EntityImpl(Bookmark bookmark, String schema, String name, String type) {
+ this.schema = schema;
+ this.name = name;
+ this.type = type;
+ this.bookmark = bookmark;
+ }
+ protected Bookmark getBookmark() {
+ return this.bookmark;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public String getSchema() {
+ return this.schema;
+ }
+ public String getType() {
+ return this.type;
+ }
+ public String getQualifiedName() {
+ return (this.schema == null || this.schema.length() == 0) ?
+ this.name : this.schema + "." + this.name;
+ }
+ }
+
+ public class TableImpl extends EntityImpl implements Table {
+ public TableImpl(Bookmark bookmark, String schema, String name) {
+ super(bookmark, schema, name, DbElementsConstants.Table);
+ }
+
+ public int getSize() {
+ return SQLHelper.getSize(getBookmark(), getQualifiedName());
+ }
+
+ public void deleteAllRows() {
+ String sql = "DELETE FROM " + getQualifiedName();
+ MultiSQLServer.getInstance().execute(getBookmark().getConnection(), sql);
+ }
+ }
+
+ public class ViewImpl extends EntityImpl implements View {
+ public ViewImpl(Bookmark bookmark, String schema, String name) {
+ super(bookmark, schema, name, DbElementsConstants.View);
+ }
+
+ public int getSize() {
+ return SQLHelper.getSize(getBookmark(), getQualifiedName());
+ }
+ }
+
+ public class SequenceImpl extends EntityImpl implements Sequence {
+ public SequenceImpl(Bookmark bookmark, String schema, String name) {
+ super(bookmark, schema, name, DbElementsConstants.Sequence);
+ }
+ }
+
+ private static EntityFactory instance = new EntityFactory();
+
+ private EntityFactory() {
+ }
+
+ public static EntityFactory getInstance() {
+ return EntityFactory.instance;
+ }
+
+ public Entity create(Bookmark bookmark, String schema, String name, String type) {
+ if (type != null) {
+ type = type.trim();
+ }
+
+ if (DbElementsConstants.Table.equals(type)) {
+ return new TableImpl(bookmark, schema, name);
+ } else if (DbElementsConstants.View.equals(type)) {
+ return new ViewImpl(bookmark, schema, name);
+ } else if (DbElementsConstants.Sequence.equals(type)) {
+ return new SequenceImpl(bookmark, schema, name);
+ } else {
+ return null;
+// throw new IllegalArgumentException("Unknown type: " + type);
+ }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.model;
+
+/**
+ * @author BC
+ */
+public interface Sequence extends Entity {
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.model;
+
+/**
+ * @author BC
+ */
+public interface Table extends Entity {
+ public int getSize();
+ public void deleteAllRows();
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.model;
+
+
+/**
+ * @author BC
+ */
+public interface View extends Entity {
+
+ public int getSize();
+
+}
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;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+
/**
* @author root
*
layout.setEditorAreaVisible(false);
IFolderLayout side =
layout.createFolder(
- "side",
+ "side", //$NON-NLS-1$
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());
+ side.addView("net.sourceforge.phpdt.sql.view.bookmarkview"); //$NON-NLS-1$
+ side.addView("net.sourceforge.phpdt.sql.view.queryhistoryview"); //$NON-NLS-1$
+ layout.addView("net.sourceforge.phpdt.sql.view.sqlqueryview", IPageLayout.TOP, 0.33F, layout.getEditorArea()); //$NON-NLS-1$
IFolderLayout bottomRight =
layout.createFolder(
- "bottomRight",
+ "bottomRight", //$NON-NLS-1$
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);
+ bottomRight.addView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+ bottomRight.addView("net.sourceforge.phpdt.sql.view.logview"); //$NON-NLS-1$
+ bottomRight.addView(PHPSourceConsole.CONSOLE_ID);
}
}
package net.sourceforge.phpdt.sql.preferences;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-
-import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
public class PHPSQLConnectionPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage {
StringFieldEditor fDriverFileFFE;
public PHPSQLConnectionPreferencePage() {
- super();
- setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
+ super();
+ setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
}
public void init(IWorkbench workbench) {
- setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
+ setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
}
protected void performDefaults() {
- fUserNameSFE.loadDefault();
- fConnectSFE.loadDefault();
- fDriverSFE.loadDefault();
- fTypeSFE.loadDefault();
- fDriverFileFFE.loadDefault();
- super.performDefaults();
+ fUserNameSFE.loadDefault();
+ fConnectSFE.loadDefault();
+ fDriverSFE.loadDefault();
+ fTypeSFE.loadDefault();
+ fDriverFileFFE.loadDefault();
+ super.performDefaults();
}
public boolean performOk() {
- fUserNameSFE.store();
- fConnectSFE.store();
- fDriverSFE.store();
- fTypeSFE.store();
- fDriverFileFFE.store();
- return super.performOk();
+ fUserNameSFE.store();
+ fConnectSFE.store();
+ fDriverSFE.store();
+ fTypeSFE.store();
+ fDriverFileFFE.store();
+ return super.performOk();
}
protected Control createContents(Composite parent) {
- initializeDialogUnits(parent);
- // final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
- Composite composite = new Composite(parent, SWT.LEFT);
- GridLayout layout = new GridLayout();
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- // layout.numColumns = 1;
+ initializeDialogUnits(parent);
+ // final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ Composite composite = new Composite(parent, SWT.LEFT);
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // layout.numColumns = 1;
- fUserNameSFE =
- new StringFieldEditor(
- "phpeclipse.sql.username.connect",
- "Default User name:",
- composite);
- fUserNameSFE.setPreferencePage(this);
- fUserNameSFE.setPreferenceStore(getPreferenceStore());
- fUserNameSFE.load();
+ fUserNameSFE =
+ new StringFieldEditor(
+ "phpeclipse.sql.username.connect",
+ "Default User name:",
+ composite);
+ fUserNameSFE.setPreferencePage(this);
+ fUserNameSFE.setPreferenceStore(getPreferenceStore());
+ fUserNameSFE.load();
- fConnectSFE =
- new StringFieldEditor(
- "phpeclipse.sql.connect.connect",
- "Connect:",
- composite);
- fConnectSFE.setPreferencePage(this);
- fConnectSFE.setPreferenceStore(getPreferenceStore());
- fConnectSFE.load();
+ fConnectSFE =
+ new StringFieldEditor(
+ "phpeclipse.sql.connect.connect",
+ "Connect:",
+ composite);
+ fConnectSFE.setPreferencePage(this);
+ fConnectSFE.setPreferenceStore(getPreferenceStore());
+ fConnectSFE.load();
- fDriverSFE =
- new StringFieldEditor(
- "phpeclipse.sql.driver.connect",
- "Driver:",
- composite);
- fDriverSFE.setPreferencePage(this);
- fDriverSFE.setPreferenceStore(getPreferenceStore());
- fDriverSFE.load();
+ fDriverSFE =
+ new StringFieldEditor(
+ "phpeclipse.sql.driver.connect",
+ "Driver:",
+ composite);
+ fDriverSFE.setPreferencePage(this);
+ fDriverSFE.setPreferenceStore(getPreferenceStore());
+ fDriverSFE.load();
- fTypeSFE =
- new StringFieldEditor("phpeclipse.sql.type.connect", "Type:", composite);
- fTypeSFE.setPreferencePage(this);
- fTypeSFE.setPreferenceStore(getPreferenceStore());
- fTypeSFE.load();
+ fTypeSFE =
+ new StringFieldEditor("phpeclipse.sql.type.connect", "Type:", composite);
+ fTypeSFE.setPreferencePage(this);
+ fTypeSFE.setPreferenceStore(getPreferenceStore());
+ fTypeSFE.load();
- // fDriverFileFFE =
- // new FileFieldEditor(
- // "phpeclipse.sql.filename.connect",
- // "Driver filename:",
- // composite);
- fDriverFileFFE =
- new StringFieldEditor(
- "phpeclipse.sql.filename.connect",
- "Driver filename:",
- composite);
- fDriverFileFFE.setPreferencePage(this);
- fDriverFileFFE.setPreferenceStore(getPreferenceStore());
- fDriverFileFFE.load();
+ // fDriverFileFFE =
+ // new FileFieldEditor(
+ // "phpeclipse.sql.filename.connect",
+ // "Driver filename:",
+ // composite);
+ fDriverFileFFE =
+ new StringFieldEditor(
+ "phpeclipse.sql.filename.connect",
+ "Driver filename:",
+ composite);
+ fDriverFileFFE.setPreferencePage(this);
+ fDriverFileFFE.setPreferenceStore(getPreferenceStore());
+ fDriverFileFFE.load();
- return composite;
+ return composite;
}
}
package net.sourceforge.phpdt.sql.preferences;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
public class PHPSQLTemplatesPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage {
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.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.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
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,
- "phpeclipse.sql.background.color",
- BACKGROUND);
- PreferenceConverter.setDefault(store, "phpeclipse.sql.text.color", DEFAULT);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.keyword.color",
- KEYWORD);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.comment.color",
- COMMENT);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.string.color",
- STRING);
- PreferenceConverter.setDefault(
- store,
- "phpeclipse.sql.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(),
- "phpeclipse.sql.font",
- fontData);
- getPreferenceStore().setValue("phpeclipse.sql.text.bold", textFlag);
- getPreferenceStore().setValue("phpeclipse.sql.keyword.bold", keywordFlag);
- getPreferenceStore().setValue("phpeclipse.sql.string.bold", stringFlag);
- getPreferenceStore().setValue("phpeclipse.sql.comment.bold", commentFlag);
- getPreferenceStore().setValue("phpeclipse.sql.numeric.bold", numericFlag);
- backgroundColorEditor.store();
- textColorEditor.store();
- keywordColorEditor.store();
- stringColorEditor.store();
- commentColorEditor.store();
- numericColorEditor.store();
- return super.performOk();
- }
-
- protected Control createContents(Composite parent) {
- Composite composite = new Composite(parent, SWT.NULL);
-
- GridLayout innerLayout = new GridLayout();
- innerLayout.numColumns = 4;
- composite.setLayout(innerLayout);
-
- fontData =
- PreferenceConverter.getFontData(
- getPreferenceStore(),
- "phpeclipse.sql.font");
- textFlag = getPreferenceStore().getBoolean("phpeclipse.sql.text.bold");
- keywordFlag =
- getPreferenceStore().getBoolean("phpeclipse.sql.keyword.bold");
- stringFlag = getPreferenceStore().getBoolean("phpeclipse.sql.string.bold");
- commentFlag =
- getPreferenceStore().getBoolean("phpeclipse.sql.comment.bold");
- numericFlag =
- getPreferenceStore().getBoolean("phpeclipse.sql.numeric.bold");
-
- fontDialog =
- new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
- Button fontButton = new Button(composite, 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(composite, 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(composite, SWT.NULL);
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- data.grabExcessHorizontalSpace = true;
- fontDisplay.setLayoutData(data);
- updateFontDisplay();
-
- ColorManager manager = new ColorManager();
-
- Composite comp = new Composite(composite, SWT.NULL);
- GridData layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- comp.setLayoutData(layoutData);
-
- Color defaultColor = manager.getColor(SQLColorConstants.DEFAULT);
- backgroundColorEditor =
- new ColorFieldEditor(
- "phpeclipse.sql.background.color",
- "Background Color",
- comp);
-
- Composite temp = new Composite(composite, SWT.NULL);
- temp.setSize(0, 0);
-
- comp = new Composite(composite, SWT.NULL);
- layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- comp.setLayoutData(layoutData);
-
- textColorEditor =
- new ColorFieldEditor(
- "phpeclipse.sql.text.color",
- "Default Text Color",
- comp);
-
- boldText = new Button(composite, 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(composite, SWT.NULL);
- layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- comp.setLayoutData(layoutData);
-
- keywordColorEditor =
- new ColorFieldEditor(
- "phpeclipse.sql.keyword.color",
- "Keyword Text Color",
- comp);
-
- boldKeyword = new Button(composite, 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(composite, SWT.NULL);
- layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- comp.setLayoutData(layoutData);
-
- commentColorEditor =
- new ColorFieldEditor(
- "phpeclipse.sql.comment.color",
- "Comment Text Color",
- comp);
-
- boldComment = new Button(composite, 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(composite, SWT.NULL);
- layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- comp.setLayoutData(layoutData);
-
- stringColorEditor =
- new ColorFieldEditor(
- "phpeclipse.sql.string.color",
- "String Text Color",
- comp);
-
- boldString = new Button(composite, 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(composite, SWT.NULL);
- layoutData = new GridData();
- layoutData.horizontalSpan = 2;
- comp.setLayoutData(layoutData);
-
- numericColorEditor =
- new ColorFieldEditor(
- "phpeclipse.sql.numeric.color",
- "Numeric Text Color",
- comp);
-
- boldNumeric = new Button(composite, 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 composite;
- }
- 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);
- }
+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 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,
+ "phpeclipse.sql.background.color",BACKGROUND);
+ PreferenceConverter.setDefault(store,
+ "phpeclipse.sql.text.color", DEFAULT);
+ PreferenceConverter.setDefault(store,
+ "phpeclipse.sql.keyword.color",KEYWORD); //$NON-NLS-1$
+ PreferenceConverter.setDefault(store,
+ "phpeclipse.sql.comment.color",COMMENT); //$NON-NLS-1$
+ PreferenceConverter.setDefault(store,
+ "phpeclipse.sql.string.color",STRING); //$NON-NLS-1$
+ PreferenceConverter.setDefault(store,
+ "phpeclipse.sql.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(), "phpeclipse.sql.font", fontData);
+ getPreferenceStore().setValue("phpeclipse.sql.text.bold", textFlag); //$NON-NLS-1$
+ getPreferenceStore().setValue("phpeclipse.sql.keyword.bold", keywordFlag); //$NON-NLS-1$
+ getPreferenceStore().setValue("phpeclipse.sql.string.bold", stringFlag); //$NON-NLS-1$
+ getPreferenceStore().setValue("phpeclipse.sql.comment.bold", commentFlag); //$NON-NLS-1$
+ getPreferenceStore().setValue("phpeclipse.sql.numeric.bold", numericFlag); //$NON-NLS-1$
+ 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(),
+ "phpeclipse.sql.font");
+ textFlag = getPreferenceStore().getBoolean("phpeclipse.sql.text.bold");
+ keywordFlag =
+ getPreferenceStore().getBoolean("phpeclipse.sql.keyword.bold");
+ stringFlag = getPreferenceStore().getBoolean("phpeclipse.sql.string.bold");
+ commentFlag =
+ getPreferenceStore().getBoolean("phpeclipse.sql.comment.bold");
+ numericFlag =
+ getPreferenceStore().getBoolean("phpeclipse.sql.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(Messages.getString("PreferencesPage.DefaultFont")); //$NON-NLS-1$
+ 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);
+
+ manager.getColor(SQLColorConstants.DEFAULT);
+ backgroundColorEditor =
+ new ColorFieldEditor(
+ "phpeclipse.sql.background.color", //$NON-NLS-1$
+ Messages.getString("PreferencesPage.BackgroundColor"), //$NON-NLS-1$
+ 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(
+ "phpeclipse.sql.text.color", //$NON-NLS-1$
+ Messages.getString("PreferencesPage.DefaultTextColor"), //$NON-NLS-1$
+ comp);
+
+ boldText = new Button(main, SWT.CHECK);
+ boldText.setSelection(textFlag);
+ boldText.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+ 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(
+ "phpeclipse.sql.keyword.color", //$NON-NLS-1$
+ Messages.getString("PreferencesPage.KeywordTextColor"), //$NON-NLS-1$
+ comp);
+
+ boldKeyword = new Button(main, SWT.CHECK);
+ boldKeyword.setSelection(keywordFlag);
+ boldKeyword.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+ 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(
+ "phpeclipse.sql.comment.color", //$NON-NLS-1$
+ Messages.getString("PreferencesPage.CommentTextColor"), //$NON-NLS-1$
+ comp);
+
+ boldComment = new Button(main, SWT.CHECK);
+ boldComment.setSelection(commentFlag);
+ boldComment.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+ 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(
+ "phpeclipse.sql.string.color", //$NON-NLS-1$
+ Messages.getString("PreferencesPage.StringTextColor"), //$NON-NLS-1$
+ comp);
+
+ boldString = new Button(main, SWT.CHECK);
+ boldString.setSelection(stringFlag);
+ boldString.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+ 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(
+ "phpeclipse.sql.numeric.color", //$NON-NLS-1$
+ Messages.getString("PreferencesPage.NumericTextColor"), //$NON-NLS-1$
+ comp);
+
+ boldNumeric = new Button(main, SWT.CHECK);
+ boldNumeric.setSelection(numericFlag);
+ boldNumeric.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+ 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(Messages.getString("PreferencesPage.Font_Default")); //$NON-NLS-1$
+ } else {
+ String style = Messages.getString("PreferencesPage.regular"); //$NON-NLS-1$
+ if (fontData.getStyle() == SWT.BOLD) {
+ style = Messages.getString("PreferencesPage.bold"); //$NON-NLS-1$
+ } else if (fontData.getStyle() == SWT.ITALIC) {
+ style = Messages.getString("PreferencesPage.italic"); //$NON-NLS-1$
+ } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
+ style = Messages.getString("PreferencesPage.boldItalic"); //$NON-NLS-1$
+ }
+ fontDisplay.setText(Messages.getString("PreferencesPage.FontPrompt") + fontData.getName() + '-' + style + '-' + fontData.getHeight()); //$NON-NLS-1$
+ }
+ }
+ 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.sql.Connection;
+
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+;
+
+/**
+ * @author BC
+ */
+public interface ConnectionEstablisher {
+
+ public Connection connect(Bookmark bookmark);
+ public void disconnect(Bookmark bookmark, Connection connection);
+
+}
--- /dev/null
+/*
+ * Created on 8/07/2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpdt.sql.sql;
+
+/**
+ * @author panic
+ * Constants for the different types of database elements that we can access
+ */
+public interface DbElementsConstants {
+ String Table = "TABLE";
+ String View = "VIEW";
+ String Sequence = "SEQUENCE";
+
+}
public String toString() {
StringBuffer text = new StringBuffer();
if (filterList.size() > 0) {
- text.append(" WHERE ");
+ text.append(" WHERE "); //$NON-NLS-1$
for (int i = 0; i < filterList.size(); i++) {
FilterRow row = (FilterRow) filterList.get(i);
text.append(row.column);
- text.append(" ");
+ text.append(" "); //$NON-NLS-1$
text.append(row.operator);
- text.append(" ");
+ text.append(" "); //$NON-NLS-1$
if (row.isString) {
text.append(escape(row.value));
} else {
text.append(row.value);
}
- text.append(" ");
+ text.append(" "); //$NON-NLS-1$
if (i < filterList.size() - 1) {
- text.append("AND ");
+ text.append("AND "); //$NON-NLS-1$
}
}
}
if (sortList.size() > 0) {
- text.append(" ORDER BY ");
+ text.append(" ORDER BY "); //$NON-NLS-1$
for (int i = 0; i < sortList.size(); i++) {
String value = (String) sortList.get(i);
text.append(value);
if (i < sortList.size() - 1) {
- text.append(",");
+ text.append(","); //$NON-NLS-1$
}
}
}
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.Statement;
import java.util.ArrayList;
import java.util.Hashtable;
+import java.util.List;
import java.util.Properties;
+import java.util.StringTokenizer;
import java.util.Vector;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
-import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
-import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
+import org.apache.xml.utils.IntVector;
+
import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
-import net.sourceforge.phpdt.sql.view.LogConstants;
+import net.sourceforge.phpdt.sql.sql.metadata.MetaDataJDBCInterface;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
import net.sourceforge.phpdt.sql.view.LogProxy;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
-public class MultiSQLServer extends Thread implements IConstants, LogConstants {
- 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(ERROR, "Error commiting: " + e);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(ERROR, writer.toString());
- }
- }
-
- public void rollback() {
- LogProxy log = LogProxy.getInstance();
- try {
- con.rollback();
- } catch (SQLException e) {
- log.addText(ERROR, "Error rolling back: " + e);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(ERROR, writer.toString());
- }
- }
-
- public void setAutoCommit(boolean enabled) {
- LogProxy log = LogProxy.getInstance();
- try {
- if (con != null) {
- con.setAutoCommit(enabled);
- } else {
- log.addText(ERROR, "Please connect before setting autocommit");
- }
- } catch (SQLException e) {
- log.addText(ERROR, "Error setting autocommit: " + e);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(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(
- 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(RESULTS, "Disconnected from: " + b.getName());
- } catch (Exception e) {
- log.addText(
- ERROR,
- "Error Disonnecting to: " + b.getName() + ":" + e.toString());
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(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(ERROR, writer.toString());
- }
- }
+/**
+ *
+ * MultiSQLServer is a Singleton, used as a interface with the sql drivers
+ * Use MultiSQLServer.getInstance() to get the object
+ */
+public class MultiSQLServer implements ConnectionEstablisher {
+ private static final int STREAM = 1024 * 2;
+ public static final String USERNAME = "user"; //$NON-NLS-1$
+ public static final String PASSWORD = "password"; //$NON-NLS-1$
+ private static MultiSQLServer instance = null;
+ private Hashtable classLoaderCache = new Hashtable();
+ boolean running = true;
+
+ public MultiSQLServer() {
+ //start();
+ }
+ public synchronized static MultiSQLServer getInstance() {
+ if (instance == null) {
+ instance = new MultiSQLServer();
+ }
+ return instance;
+ }
+
+ public void commit(Connection con) {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ con.commit();
+ } catch (SQLException e) {
+ log.addText(LogProxy.ERROR, "Error commiting: " + e, e); //$NON-NLS-1$
+ }
+ }
+
+ public void rollback(Connection con) {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ con.rollback();
+ } catch (SQLException e) {
+ log.addText(LogProxy.ERROR, "Error rolling back: " + e, e); //$NON-NLS-1$
+ }
+ }
- public void dumpDatabaseData() {
- LogProxy log = LogProxy.getInstance();
- try {
- DatabaseMetaData metadata = con.getMetaData();
- log.addText(
- WARNING,
- "[METADATA] Database type: " + metadata.getDatabaseProductName());
- if (metadata.supportsCatalogsInDataManipulation()) {
- log.addText(
- WARNING,
- "[METADATA] Database does support catalog in data manipulation");
- } else {
- log.addText(
- WARNING,
- "[METADATA] Database does not support catalog in data manipulation");
- }
- if (metadata.supportsSchemasInDataManipulation()) {
- log.addText(
- WARNING,
- "[METADATA] Database does support schema in data manipulation");
- } else {
- log.addText(
- WARNING,
- "[METADATA] Database does not support schema in data manipulation");
- }
- if (metadata.supportsCatalogsInTableDefinitions()) {
- log.addText(
- WARNING,
- "[METADATA] Database does support catalogs in table definitions");
- } else {
- log.addText(
- WARNING,
- "[METADATA] Database does not support catalogs in table definitions");
- }
- log.addText(
- WARNING,
- "[METADATA] Catalog Separator: " + metadata.getCatalogSeparator());
- log.addText(
- 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(WARNING, catalogOutput.toString());
+ public void setAutoCommit(Connection con, boolean enabled) {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ if (con != null) {
+ con.setAutoCommit(enabled);
+ } else {
+ log.addText(LogProxy.ERROR, "Please connect before setting autocommit"); //$NON-NLS-1$
+ }
+ } catch (SQLException e) {
+ log.addText(LogProxy.ERROR, "Error setting autocommit: " + e, e); //$NON-NLS-1$
+ }
+ }
+
+ public void disconnect(Bookmark b, Connection con) {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ con.close();
+ b.setConnection(null);
+ log.addText(LogProxy.RESULTS, "Disconnected from: " + b.getName()); //$NON-NLS-1$
+ } catch (Exception e) {
+ log.addText(
+ LogProxy.ERROR,
+ "Error Disonnecting to: " + b.getName() + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public void dumpDatabaseData(Connection con) {
+ LogProxy log = LogProxy.getInstance();
+ try {
+ DatabaseMetaData meta = con.getMetaData();
+ log.addText(LogProxy.WARNING, "[METADATA] Database type: " + meta.getDatabaseProductName()); //$NON-NLS-1$
+ if (meta.supportsCatalogsInDataManipulation()) {
+ log.addText(LogProxy.WARNING, "[METADATA] Database does support catalog in data manipulation"); //$NON-NLS-1$
+ } else {
+ log.addText(LogProxy.WARNING, "[METADATA] Database does not support catalog in data manipulation"); //$NON-NLS-1$
+ }
+ if (meta.supportsSchemasInDataManipulation()) {
+ log.addText(LogProxy.WARNING, "[METADATA] Database does support schema in data manipulation"); //$NON-NLS-1$
+ } else {
+ log.addText(LogProxy.WARNING, "[METADATA] Database does not support schema in data manipulation"); //$NON-NLS-1$
+ }
+ if (meta.supportsCatalogsInTableDefinitions()) {
+ log.addText(LogProxy.WARNING, "[METADATA] Database does support catalogs in table definitions"); //$NON-NLS-1$
+ } else {
+ log.addText(LogProxy.WARNING, "[METADATA] Database does not support catalogs in table definitions"); //$NON-NLS-1$
+ }
+ log.addText(LogProxy.WARNING, "[METADATA] Catalog Separator: " + meta.getCatalogSeparator()); //$NON-NLS-1$
+ log.addText(LogProxy.WARNING, "[METADATA] Catalog Term: " + meta.getCatalogTerm()); //$NON-NLS-1$
+ ResultSet set = meta.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] ["); //$NON-NLS-1$
+ for (int i = 0; i < catalogList.size(); i++) {
+ String name = (String) catalogList.get(i);
+ catalogOutput.append(name + ", "); //$NON-NLS-1$
+ }
+ catalogOutput.append("]"); //$NON-NLS-1$
+ log.addText(LogProxy.WARNING, catalogOutput.toString());
+
+ set = meta.getSchemas();
+ ArrayList schemaList = new ArrayList();
+ schemaList.add(""); //$NON-NLS-1$
+ while (set.next()) {
+ schemaList.add(set.getString(1));
+ }
+ set.close();
+ StringBuffer schemaOutput = new StringBuffer();
+ schemaOutput.append("[SCHEMA LIST] ["); //$NON-NLS-1$
+ for (int i = 0; i < schemaList.size(); i++) {
+ String name = (String) schemaList.get(i);
+ schemaOutput.append(name + ", "); //$NON-NLS-1$
+ }
+ schemaOutput.append("]"); //$NON-NLS-1$
+ log.addText(LogProxy.WARNING, schemaOutput.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(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(WARNING, tableListOutput.toString());
-
- } catch (Exception e) {
- log.addText(ERROR, "Error occured: " + e);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(ERROR, writer.toString());
- }
- }
- /**
- * type = "TABLE" "VIEW" "SEQUENCE"
- */
- public Vector listTables(String schema, String type) {
- LogProxy log = LogProxy.getInstance();
- Vector retVal = new Vector();
- log.addText(QUERY, "Retrieving list [" + type + "]");
- try {
- DatabaseMetaData meta = con.getMetaData();
- ResultSet set = meta.getTableTypes();
- int columnCount = set.getMetaData().getColumnCount();
- if (DEBUG) {
- 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 });
+ List tableTypes = getTableTypes(meta);
+
+ StringBuffer tableListOutput = new StringBuffer();
+ tableListOutput.append("[TABLE LIST] ["); //$NON-NLS-1$
+ for (int i = 0; i < tableTypes.size(); i++) {
+ String name = (String) tableTypes.get(i);
+ tableListOutput.append(name + ", "); //$NON-NLS-1$
+ }
+ tableListOutput.append("]"); //$NON-NLS-1$
+ log.addText(LogProxy.WARNING, tableListOutput.toString());
+
+
+ } catch (Exception e) {
+ log.addText(LogProxy.ERROR, e);
+ }
+ }
+ private List getTableTypes(DatabaseMetaData meta) throws SQLException {
+ ArrayList tableTypes = new ArrayList();
+ ResultSet set = meta.getTableTypes();
while (set.next()) {
- String name = set.getString("TABLE_NAME");
- String tableType = set.getString("TABLE_TYPE");
- //System.out.println(name + ":" + tableType);
- retVal.addElement(name);
+ String type = set.getString(1);
+ if (type != null) {
+ tableTypes.add(type.trim());
+ }
}
set.close();
- }
- log.addText(RESULTS, "Success");
- } catch (SQLException e) {
- log.addText(ERROR, "Error occured: " + e);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(ERROR, writer.toString());
+ return tableTypes;
}
- return retVal;
- }
- public boolean connect(Bookmark b) {
- LogProxy log = LogProxy.getInstance();
- log.addText(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);
- if (DEBUG) {
- System.out.println("Creating new classloader");
- }
- } else {
- if (DEBUG) {
- 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(RESULTS, "Connected to: " + b.getName());
- if (DEBUG) {
- System.out.println("Connected");
- }
- return true;
- } catch (Exception e) {
- log.addText(
- ERROR,
- "Error Connecting to: " + b.getName() + ":" + e.toString());
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(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();
+// /**
+// * @param con
+// * @param schema
+// * @param type of the element "TABLE", "VIEW", "SEQUENCE"
+// * @return
+// */
+// public Vector listElements(Connection con, String schema, String type) {
+// LogProxy log = LogProxy.getInstance();
+// Vector retVal = new Vector(50,5);
+// log.addText(LogProxy.QUERY, "Retrieving list [" + type + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+// try {
+// DatabaseMetaData meta = con.getMetaData();
+// List types = getTableTypes(meta);
+// if (types.contains(type)) {
+// ResultSet set = meta.getTables(
+// null, null, "%", new String[] {type}); //$NON-NLS-1$
+// while (set.next()) {
+// String tableSchema = set.getString("TABLE_SCHEM");
+// tableSchema = (tableSchema == null) ? "" : tableSchema.trim();
+// String tableName = set.getString("TABLE_NAME").trim(); //$NON-NLS-1$
+// if (tableName.length() > 0)
+// retVal.addElement(((tableSchema.length() > 0) ? tableSchema + "." : "") + tableName);
+// }
+// set.close();
+// }
+// log.addText(LogProxy.RESULTS, "Success"); //$NON-NLS-1$
+//
+// } catch (SQLException e) {
+// log.addText(LogProxy.ERROR, e);
+// }
+// return retVal;
+// }
- if (DEBUG) {
- System.out.println("Executing");
- }
- LogProxy log = LogProxy.getInstance();
- log.addText(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(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(RESULTS, "Success: " + updates + " records updated");
+ /**
+ * Makes a connection to a JDBC driver based on the data from a bookmark
+ * @param b The Bookmark with the data needed to make the connection
+ * @return The Connection object if everything went OK
+ */
+ public Connection connect(Bookmark b) {
+ Connection con;
+ LogProxy log = LogProxy.getInstance();
+ log.addText(LogProxy.QUERY, "Connecting to: " + b.getName()); //$NON-NLS-1$
+ 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"); //$NON-NLS-1$
+ } else {
+ System.out.println("Using classloader in cache"); //$NON-NLS-1$
+ }
+ 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()); //$NON-NLS-1$
+ }
+ log.addText(LogProxy.RESULTS, "Connected to: " + b.getName()); //$NON-NLS-1$
+ System.out.println("Connected"); //$NON-NLS-1$
+ return con;
+ } catch (Exception e) {
+ //log.addText(
+ // LogProxy.ERROR,
+ // "Error Connecting to: " + b.getName() + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
+ }
+ public SQLResults execute(Connection con, String s) {
+ return execute(con, s, -1, -1);
+ }
+ public SQLResults execute(Connection con, String s, int startRow, int endRow) {
+ return execute(con, s, -1, -1, Integer.MAX_VALUE);
+ }
+ public SQLResults execute(Connection con, String s, int startRow, int endRow, int maxLength) {
+ return execute(con, s, startRow, endRow, maxLength, ""); //$NON-NLS-1$
+ }
+ public SQLResults execute(Connection con, String s, int startRow, int endRow, int maxLength, String encoding) {
+ SQLResults results = new SQLResults();
- } 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(RESULTS, "Success: result set displayed");
- }
- stmt.close();
- if (DEBUG) {
- System.out.println("Executed");
- System.out.println();
- }
- } catch (Exception e) {
- results.setIsError(true);
- log.addText(ERROR, "Error occured: " + e);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- log.addText(ERROR, writer.toString());
- }
- return results;
- }
-}
+ System.out.println("Executing"); //$NON-NLS-1$
+ LogProxy log = LogProxy.getInstance();
+ log.addText(LogProxy.QUERY, "Executing Request [" + s + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+ boolean metadata = false;
+ if (s.startsWith("METADATA")) { //$NON-NLS-1$
+ metadata = true;
+ }
+ if (metadata) {
+ results.setQuery(s);
+ String table = s.substring(s.indexOf(':') + 1);
+ String query = "SELECT * FROM " + table + " WHERE (1 = 0)"; //$NON-NLS-1$ //$NON-NLS-2$
+ s = query;
+ log.addText(LogProxy.QUERY, "Metadata Request [" + s + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+ } 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(
+ LogProxy.RESULTS,
+ "Success: " + updates + " records updated"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ } else {
+ if (metadata) {
+ ResultSet set = stmt.getResultSet();
+ ResultSetMetaData metaData = set.getMetaData();
+ int columnCount = metaData.getColumnCount();
+ Vector columnNames = new Vector();
+ columnNames.addElement("ColumnName"); //$NON-NLS-1$
+ columnNames.addElement("Type"); //$NON-NLS-1$
+ columnNames.addElement("Size"); //$NON-NLS-1$
+ columnNames.addElement("Nullable"); //$NON-NLS-1$
+ columnNames.addElement("AutoIncrement"); //$NON-NLS-1$
+ 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); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ int nullable = metaData.isNullable(i);
+ if (nullable == ResultSetMetaData.columnNoNulls) {
+ row.addElement("Not Null"); //$NON-NLS-1$
+ } else if (nullable == ResultSetMetaData.columnNullable) {
+ row.addElement("Nullable"); //$NON-NLS-1$
+ } else if (nullable == ResultSetMetaData.columnNullableUnknown) {
+ row.addElement("Nullable"); //$NON-NLS-1$
+ } else {
+ row.addElement("<Error>"); //$NON-NLS-1$
+ }
+ row.addElement(Boolean.toString(metaData.isAutoIncrement(i)));
+ results.addRow(row);
+ }
+ results.setHasMore(false);
+ set.close();
+ } 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.setColumnTypes(columnTypes);
+ IntVector columnSizes = new IntVector();
+ for (int i = 1; i <= columnCount; i++) {
+ columnSizes.addElement(metaData.getColumnDisplaySize(i));
+ }
+ results.setColumnSizes(columnSizes);
+// 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.elementAt(i - 1) < STREAM && columnSizes.elementAt(i - 1) < maxLength) {
+ if (encoding.equals("")) { //$NON-NLS-1$
+ value = set.getString(i);
+ } else {
+ value = new String(set.getBytes(i), encoding);
+ }
+ } else {
+ try {
+ if (encoding.equals("")) { //$NON-NLS-1$
+ 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("...>>>"); //$NON-NLS-1$
+ 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>"); //$NON-NLS-1$
+ } 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);
+ }
+ set.close();
+ }
+ log.addText(LogProxy.RESULTS, "Success: result set displayed"); //$NON-NLS-1$
+ }
+ stmt.close();
+ System.out.println("Executed"); //$NON-NLS-1$
+ System.out.println();
+ } catch (Exception e) {
+ results.setIsError(true);
+ log.addText(LogProxy.ERROR, e); //$NON-NLS-1$
+ }
+ return results;
+ }
+
+ public ObjectMetaData getObjectMetadata(Connection con, TreeNode node) throws SQLException {
+ ObjectMetaData metadata = new ObjectMetaData();
+ String table = node.getName();
+ metadata.setColumns(MetaDataJDBCInterface.getColumns(con, getSchemaName(table), getTableName(table)));
+ if (node instanceof TableNode) {
+ String schema = getSchemaName(table);
+ String tableName = getTableName(table);
+ metadata.setPrimaryKeys(MetaDataJDBCInterface.getPrimaryKeys(con, schema, tableName));
+ metadata.setForeignKeys(MetaDataJDBCInterface.getForeignKeys(con, schema, tableName, true));
+ metadata.setIndexInfo(MetaDataJDBCInterface.getIndexInfo(con, schema, tableName));
+ }
+ return metadata;
+ }
+
+ public String getTableName(String table) {
+ StringTokenizer st = new StringTokenizer(table, "."); //$NON-NLS-1$
+ if (st.countTokens() == 2) {
+ st.nextToken();
+ return st.nextToken();
+ } else if (st.countTokens() == 1){
+ return st.nextToken();
+ } else
+ return null;
+ }
+ public String getSchemaName(String table) {
+ StringTokenizer st = new StringTokenizer(table, "."); //$NON-NLS-1$
+ if (st.countTokens() == 2) {
+ return st.nextToken();
+ } else
+ return null;
+ }
+
+}
\ No newline at end of file
package net.sourceforge.phpdt.sql.sql;
-import java.util.Vector;
-
-import net.sourceforge.phpdt.sql.IConstants;
-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 implements IConstants {
- 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();
- if (DEBUG) {
- 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;
- }
+public class SQLHelper {
+
+ public static int getSize(Bookmark current, String tableName) {
+ SQLResults results = MultiSQLServer.getInstance().execute(
+ current.getConnection(), "SELECT COUNT(*) FROM " + tableName); //$NON-NLS-1$
+ return Integer.parseInt(results.getElement(1, 1).toString());
+ }
+ public static SQLResults getResults(Bookmark current, String query, int start, int end, int maxLength, String encoding) {
+ return MultiSQLServer.getInstance().execute(current.getConnection(),
+ query, start, end, maxLength, encoding);
+ }
+ public static String getFullTableName(Bookmark current, String table) {
+ String schema = current.getSchema();
+ if (schema == null) return table;
+ if (schema.equals("")) return table; //$NON-NLS-1$
+ return schema + "." + table; //$NON-NLS-1$
+ }
+
+ /**
+ * True if the type is Real (numeric and with decimal part) according to java.sql.Types
+ * @param type
+ * @return
+ */
+ public static boolean isReal(int type) {
+ return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT ||
+ type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL );
+ }
+
+ /**
+ * True if the type is Numeric according to java.sql.Types
+ * @param type
+ * @return
+ */
+ public static boolean isNumeric(int type) {
+ return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT ||
+ type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL || type == java.sql.Types.BIGINT ||
+ type == java.sql.Types.TINYINT || type == java.sql.Types.SMALLINT || type == java.sql.Types.INTEGER );
+ }
+ /**
+ * True if the type is textual according to java.sql.Types
+ * @param type
+ * @return
+ */
+ public static boolean isText(int type) {
+ return (type == java.sql.Types.CLOB || type == java.sql.Types.VARBINARY || type ==java.sql.Types.VARCHAR );
+ }
+
}
-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;
- }
-
-}
import java.util.Vector;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.parser.SQLLexx;
-import net.sourceforge.phpdt.sql.parser.Token;
+import net.sourceforge.phpdt.sql.sql.parser.SQLLexx;
+import net.sourceforge.phpdt.sql.sql.parser.Token;
-public class SQLParser implements IConstants {
- 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();
- }
- if (DEBUG) {
- System.out.println("Returning");
- }
- return commands;
- }
+public class SQLParser {
+ public static final String COMMENT = "--"; //$NON-NLS-1$
+ public static final String ENDLINE = ";"; //$NON-NLS-1$
+ 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() == Token.COMMENT) {
+ // ignore comments
+ } else if (t.getType() == Token.SEPARATOR) {
+ String newCommand = buffer.toString().trim();
+ if (!newCommand.equals("")) { //$NON-NLS-1$
+ commands.addElement(newCommand);
+ }
+ buffer = new StringBuffer();
+ } else {
+ buffer.append(t.getValue());
+ }
+ }
+ String newCommand = buffer.toString().trim();
+ if (!newCommand.equals("")) { //$NON-NLS-1$
+ commands.addElement(newCommand);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ System.out.println("Returning"); //$NON-NLS-1$
+ return commands;
+ }
}
\ No newline at end of file
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.
- */
+import org.apache.xml.utils.IntVector;
+
public class SQLResults {
private String query;
private String table;
private ArrayList rows = new ArrayList();
private Vector columns;
private Vector columnTypes;
+ private IntVector columnSizes;
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) {
+ if (columns.size() < column) return ""; //$NON-NLS-1$
return columns.elementAt(column - 1).toString();
+
+ }
+ public void setColumnTypes(Vector columnsTypes) {
+ this.columnTypes = columnsTypes;
}
public String getColumnType(int column) {
+ if (columnTypes.size() < column) return ""; //$NON-NLS-1$
return columnTypes.elementAt(column - 1).toString();
}
+ public void setColumnSizes(IntVector columnSizes) {
+ this.columnSizes = columnSizes;
+ }
+ public int getColumnSize(int column) {
+ if (columnSizes.size() < column) return 0;
+ return columnSizes.elementAt(column - 1);
+ }
public void addRow(Vector row) {
rows.add(row);
}
public Object getElement(int column, int row) {
- return ((Vector) rows.get(row - 1)).elementAt(column - 1);
+ return ((Vector) rows.get(row - 1)).elementAt(column - 1);
}
public int getColumnCount() {
if (columns.size() > 0) {
this.table = table;
}
- public void setColumnsTypes(Vector columnsTypes) {
- this.columnTypes = columnsTypes;
- }
-
public boolean hasMore() {
return hasMore;
}
package net.sourceforge.phpdt.sql.sql;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
public class TableRow {
private String[] columnNames;
private String[] tableData;
- private String table;
+ private BookmarkNode bookmark;
+ String table;
- public TableRow(String tableName, String[] columnNames, String[] tableData) {
- this.table = tableName;
+ public TableRow(BookmarkNode bookmark, String table, String[] columnNames, String[] tableData) {
+ this.bookmark = bookmark;
+ this.table = table;
this.tableData = tableData;
this.columnNames = columnNames;
}
return table;
}
+ public BookmarkNode getBookmarkNode() {
+ return bookmark;
+ }
+
public void setColumnNames(String[] columnNames) {
this.columnNames = columnNames;
}
- public void setTable(String table) {
- this.table = table;
- }
-
public String[] getTableData() {
return tableData;
}
--- /dev/null
+/*
+ * Created on 8/04/2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpdt.sql.sql.metadata;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author panic
+ *
+ * Groups functions that allow extracting data from a JDBC connection in form of StringMatrixs
+ */
+public class MetaDataJDBCInterface {
+
+ /**
+ * @param con : A valid (open) connection to an JDBC database
+ * @param schema : Schema of the table. Must be null if not given
+ * @param table : Name of the table.
+ * @return a StringMatrix with the info of the columns' metadata
+ */
+ public static StringMatrix getColumns(Connection con, String schema, String table)
+ throws SQLException {
+
+ DatabaseMetaData meta = con.getMetaData();
+ ResultSet set = meta.getColumns(null, schema, table, null);
+
+ StringMatrix columns = fillMatrix(set);
+ set.close();
+ return columns;
+ }
+
+ /**
+ * @param con : A valid (open) connection to an JDBC database
+ * @param schema : Schema of the table. Must be null if not given
+ * @param table : Name of the table.
+ * @return a StringMatrix with the info of the primary keys
+ */
+ public static StringMatrix getPrimaryKeys(Connection con, String schema, String table)
+ throws SQLException {
+
+ DatabaseMetaData meta = con.getMetaData();
+ ResultSet set = meta.getPrimaryKeys(null, schema, table);
+
+ StringMatrix keys = fillMatrix(set);
+ set.close();
+ return keys;
+ }
+
+ /**
+ * @param con : A valid (open) connection to an JDBC database
+ * @param schema : Schema of the table. Must be null if not given
+ * @param table : Name of the table.
+ * @param imported : Determines if the foreign keys are the imported or exported ones
+ * @return a StringMatrix with the info of the foreign keys
+ */
+ public static StringMatrix getForeignKeys(Connection con, String schema, String table, boolean imported )
+ throws SQLException {
+
+ ResultSet set = null;
+ DatabaseMetaData meta = con.getMetaData();
+ if (imported){
+ set = meta.getImportedKeys(null, schema, table);
+ } else {
+ set = meta.getExportedKeys(null, schema, table);
+ }
+ StringMatrix keys = fillMatrix(set);
+ set.close();
+ return keys;
+ }
+
+ /**
+ * @param con : A valid (open) connection to an JDBC database
+ * @param schema : Schema of the table. Must be null if not given
+ * @param table : Name of the table.
+ * @return a StringMatrix with the info of the indexes on that table
+ */
+ public static StringMatrix getIndexInfo(Connection con, String schema, String table)
+ throws SQLException {
+
+ ResultSet set = null;
+ DatabaseMetaData meta = con.getMetaData();
+ set = meta.getIndexInfo(null, schema, table, false, false);
+ StringMatrix keys = fillMatrix(set);
+ set.close();
+ return keys;
+ }
+
+
+ /**
+ *
+ * @param set
+ * @return a filled StringMatrix with the set results
+ * @throws SQLException
+ */
+ public static StringMatrix fillMatrix(ResultSet set) throws SQLException {
+ int columnCount = set.getMetaData().getColumnCount();
+ StringMatrix keys = new StringMatrix();
+ for (int i = 1; i <= columnCount; i++) {
+ keys.addHeader(set.getMetaData().getColumnName(i));
+ }
+ int row = 0;
+ while (set.next()) {
+ for (int i = 1; i <= columnCount; i++) {
+ keys.add(set.getString(i), row);
+ }
+ row++;
+ }
+ return keys;
+ }
+
+
+}
--- /dev/null
+/*
+ * Created on 15/04/2003
+ *
+ */
+package net.sourceforge.phpdt.sql.sql.metadata;
+
+import org.apache.crimson.tree.TextNode;
+import org.apache.crimson.tree.XmlDocument;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+
+/**
+ * @author panic
+ * Handles interface between an ObjectMetaData and XML storage.
+ * It can write an existing metadata object to XML and generate
+ * a new ObjectMetaData from existing XML.
+ */
+public class MetaDataXMLInterface {
+
+ /**
+ * Exports an ObjectMetaData to an XML document, under a root Element
+ * @param metadata The ObjectMetaData to export
+ * @param doc A valid XML document to receive the export
+ * @param root The Element under which all the XML data will be written
+ */
+ public static void metaDataToXML(ObjectMetaData metadata, XmlDocument doc, Element root) {
+ StringMatrix columns = metadata.getColumns();
+ if (columns != null)
+ stringMatrixToXML(columns, doc, root, "COLUMN"); //$NON-NLS-1$
+ StringMatrix primaryKeys = metadata.getPrimaryKeys();
+ if (primaryKeys != null)
+ stringMatrixToXML(primaryKeys, doc, root, "PRIMARY_KEY_ITEM"); //$NON-NLS-1$
+ StringMatrix foreignKeys = metadata.getForeignKeys();
+ if (foreignKeys != null)
+ stringMatrixToXML(foreignKeys, doc, root, "FOREIGN_KEY_ITEM"); //$NON-NLS-1$
+ StringMatrix indexInfo = metadata.getIndexInfo();
+ if (indexInfo != null)
+ stringMatrixToXML(indexInfo, doc, root, "INDEX_ITEM"); //$NON-NLS-1$
+ }
+
+ /**
+ * Imports an XML element to an ObjectMetaData. The format has to be the same as extracted by
+ * the MetaDataToXML function.
+ * @param metadata The ObjectMetaData to fill up. Usually empty.
+ * @param root The Element having all the XML data
+ */
+ public static void xmlToMetaData(ObjectMetaData metadata, Element root) {
+ StringMatrix columns = new StringMatrix();
+ MetaDataXMLInterface.xmlToStringMatrix(columns, root, "COLUMN"); //$NON-NLS-1$
+ metadata.setColumns(columns);
+ StringMatrix primaryKeys = new StringMatrix();
+ MetaDataXMLInterface.xmlToStringMatrix(primaryKeys, root, "PRIMARY_KEY_ITEM"); //$NON-NLS-1$
+ metadata.setPrimaryKeys(primaryKeys);
+ StringMatrix foreignKeys = new StringMatrix();
+ MetaDataXMLInterface.xmlToStringMatrix(foreignKeys, root, "FOREIGN_KEY_ITEM"); //$NON-NLS-1$
+ metadata.setForeignKeys(foreignKeys);
+ StringMatrix indexInfo = new StringMatrix();
+ MetaDataXMLInterface.xmlToStringMatrix(indexInfo, root, "INDEX_ITEM"); //$NON-NLS-1$
+ metadata.setIndexInfo(indexInfo);
+ }
+
+ /**
+ * Adds a StringMatrix to an XML document
+ * @param matrix The StringMatrix to add
+ * @param doc The XmlDocument to which it will be added
+ * @param root An element of the previous document under which the info will be added
+ * @param sub A key under which each row of the StringMatrix will be added
+ */
+ private static void stringMatrixToXML(StringMatrix matrix, XmlDocument doc, Element root, String sub) {
+ for (int i = 0; i < matrix.size(); i++) {
+ Element localRoot = (Element) root.appendChild(doc.createElement(sub));
+ for (int j = 0; j < matrix.getNumColumns(); j++) {
+ String key = matrix.getHeaderColumn(j);
+ Element tableName = (Element) localRoot.appendChild(doc.createElement(key));
+ String value = matrix.get(key, i);
+ if (value != null)
+ tableName.appendChild(doc.createTextNode(value));
+ }
+ }
+ }
+
+ /**
+ * Fills a StringMatrix with the data from XML, usually extracted with the StringMatrixToXML function
+ * @param matrix The matrix to fill up, usually empty.
+ * @param root The Element with all the data in XML DOM
+ * @param sub The String to select the Nodes which interest us. Only the selected nodes will be added
+ * to the StringMatrix.
+ */
+ private static void xmlToStringMatrix(StringMatrix matrix, Element root, String sub) {
+ NodeList columns = root.getElementsByTagName(sub);
+ for (int i = 0; i < columns.getLength(); i++) {
+ Node column = columns.item(i);
+ NodeList columnList = column.getChildNodes();
+ for (int j = 0; j < columnList.getLength(); j++) {
+ Node node = columnList.item(j);
+ String header = node.getNodeName();
+ if (header.equals("#text")) //$NON-NLS-1$
+ continue;
+ String value = null;
+ if (node != null && node.hasChildNodes()) {
+ Node valueNode = node.getFirstChild();
+ if (valueNode instanceof TextNode) {
+ value = valueNode.getNodeValue();
+ }
+ }
+ if (!matrix.contains(header))
+ matrix.addHeader(header);
+ matrix.addAt(header, value, i);
+ }
+ }
+ }
+ /**
+ * Creates a new Element with a text value
+ * @param root
+ * @param key
+ * @param value
+ * @return
+ */
+ public static Element createElementText(Element root, String key, String value){
+ // get the XmlDocument for use as a factory
+ XmlDocument doc = (XmlDocument) root.getOwnerDocument();
+ Element newElement = doc.createElement(key);
+
+ root.appendChild(newElement);
+ if (value != null && value.length() > 0)
+ {
+ Text valueText = doc.createTextNode(value);
+ newElement.appendChild(valueText);
+ }
+ return newElement;
+ }
+
+ /**
+ * gets the text value from an element or a child of it
+ * @param root
+ * @param key
+ * @param value
+ * @return
+ */
+ public static String getElementText(Element root, String key){
+ // get the XmlDocument for use as a factory
+ String value = ""; //$NON-NLS-1$
+ if (root.getNodeName().equals(key)){
+ value = extractText(root);
+ } else {
+ NodeList children = root.getElementsByTagName(key);
+ if (children.getLength() > 0) {
+ Element column = (Element) children.item(0);
+ value = extractText(column);
+ }
+ }
+ return value;
+ }
+
+ private static String extractText(Element node){
+ String value = ""; //$NON-NLS-1$
+ if (node != null && node.hasChildNodes()) {
+ Node valueNode = node.getFirstChild();
+ if (valueNode instanceof TextNode) {
+ value = valueNode.getNodeValue();
+ }
+ }
+ return value;
+ }
+}
--- /dev/null
+/*
+ * Created on 8/04/2003
+ *
+ */
+package net.sourceforge.phpdt.sql.sql.metadata;
+
+import java.util.Vector;
+
+
+/**
+ * @author panic
+ * Class to hold the Metadata of a database element
+ */
+public class ObjectMetaData {
+ private StringMatrix columns = null;
+ private StringMatrix primaryKeys = null;
+ private StringMatrix foreignKeys = null;
+ private StringMatrix indexInfo = null;
+
+
+ /**
+ * @param matrix
+ */
+ public void setColumns(StringMatrix matrix) {
+ columns = matrix;
+ }
+
+ /**
+ * Gives the order of the column in the primary key
+ * @param column
+ * @return the order of the column in the primary key, 0 if it's not part of it.
+ */
+ public int getPrimaryKeyOrder(String column){
+ if (primaryKeys == null) return 0;
+ StringMatrix keyColumns = primaryKeys.select("COLUMN_NAME", column); //$NON-NLS-1$
+ if (keyColumns != null && keyColumns.size() > 0) {
+ String index = keyColumns.get("KEY_SEQ", 0); // We suppose there is only a primary key //$NON-NLS-1$
+ if (index != null ) return Integer.parseInt(index);
+ }
+ return 0;
+ }
+
+ /**
+ * Gives the type of the column
+ * @param column
+ * @return the type of the column using the values defined in java.sql.Types
+ */
+ public int getColumnType(String column){
+ StringMatrix selectCol = columns.select("COLUMN_NAME", column); //$NON-NLS-1$
+ if (selectCol != null && selectCol.size() > 0) {
+ String type = selectCol.get("DATA_TYPE", 0); // It should be only one column //$NON-NLS-1$
+ if (type != null ) return Integer.parseInt(type);
+ }
+ return 0;
+
+ }
+
+ /**
+ * @param matrix
+ */
+ public void setForeignKeys(StringMatrix matrix) {
+ foreignKeys = matrix;
+ }
+
+ /**
+ * @param matrix
+ */
+ public void setPrimaryKeys(StringMatrix matrix) {
+ primaryKeys = matrix;
+ }
+
+ /**
+ * @return
+ */
+ public StringMatrix getColumns() {
+ return columns;
+ }
+
+ /**
+ * @return
+ */
+ public StringMatrix getForeignKeys() {
+ return foreignKeys;
+ }
+
+ /**
+ * @return
+ */
+ public StringMatrix getPrimaryKeys() {
+ return primaryKeys;
+ }
+
+
+ /**
+ * @return
+ */
+ public StringMatrix getIndexInfo() {
+ return indexInfo;
+ }
+
+ /**
+ * @param matrix
+ */
+ public void setIndexInfo(StringMatrix matrix) {
+ indexInfo = matrix;
+ }
+
+ /**
+ * @param column
+ */
+ public void dropColumn(String columnName) {
+ columns.dropMatching("COLUMN_NAME", columnName); //$NON-NLS-1$
+ }
+
+ /**
+ * @return
+ */
+ public String getColumnsString() {
+ String result = ""; //$NON-NLS-1$
+ Vector columnNames = columns.getColumn("COLUMN_NAME"); //$NON-NLS-1$
+ for (int i = 0; i < columnNames.size(); i++) {
+ if (i > 0) result += ", "; //$NON-NLS-1$
+ result += (String) columnNames.get(i);
+ }
+ return result;
+ }
+
+
+}
--- /dev/null
+/*
+ * Created on 8/04/2003
+ *
+ */
+package net.sourceforge.phpdt.sql.sql.metadata;
+
+import java.util.Vector;
+
+/**
+ * @author jparrai
+ * Generic class to hold a Matrix of Strings, that is a Vector of Vectors of Strings.
+ * The first Vector "line" is supposed to have headers to the values of the rest.
+ */
+public class StringMatrix {
+ private Vector header = new Vector(10,10);
+ private Vector matrix = new Vector(10,10);
+
+ /**
+ * Adds a String to the end of the header keys
+ * @param header : The string to be added
+ */
+ public void addHeader(String header){
+ this.header.add(header);
+ }
+ /**
+ * Adds a whole vector to the header
+ * @param header
+ */
+ private void addVectorHeader(Vector header){
+ this.header.addAll(header);
+ }
+ /**
+ * Adds a String to the end of the row indicated
+ * @param value : The string to be added
+ * @param row : The row to
+ */
+ public void add(String value, int row) {
+ grow(row);
+ Vector rowVector = (Vector) matrix.get(row);
+ rowVector.add(value);
+ }
+ private void grow(int row) {
+ if (matrix.size() <= row)
+ for (int i = matrix.size(); i <= row; i++) {
+ matrix.add(new Vector(header.size(), 1));
+ }
+ }
+ /**
+ * Adds a StringMatrix to the end of the row indicated
+ * @param value : The string to be added
+ * @param row : The row to
+ */
+ public void add(StringMatrix value) {
+ int row = matrix.size();
+ for (int i = 0; i < value.size(); i++){
+ grow(row);
+ for (int j = 0; j < value.getNumColumns(); j++){
+ String header = value.getHeaderColumn(j);
+ addAt(header, value.get(header,i), row);
+ }
+ row++;
+ }
+ Vector rowVector = (Vector) matrix.get(row);
+ rowVector.add(value);
+ }
+ /**
+ * Adds a String to the row indicated, to the column that matches the key
+ * @param value : The string to be added
+ * @param row : The row to
+ */
+ public void addAt(String key, String value, int row) {
+ grow(row);
+ Vector rowVector = (Vector) matrix.get(row);
+ int ind = header.indexOf(key);
+ if (ind < 0) return;
+ if (rowVector.size() < ind+1) rowVector.setSize(ind);
+ rowVector.add(ind, value);
+ }
+ /**
+ * Adds a whole vector to the end of the row indicated
+ * @param value : The vector to be added
+ * @param row : The row to
+ */
+ private void addVector(Vector value, int row){
+ grow(row);
+ Vector rowVector = (Vector) matrix.get(row);
+ rowVector.addAll(value);
+ }
+
+ public boolean contains(String key){
+ return header.contains(key);
+ }
+ /**
+ * Gets a String value from the row indicated, from the column that matches the key
+ * @param key
+ * @param row
+ * @return
+ */
+ public String get(String key, int row){
+ if (matrix.size() <= row) return null;
+ int col = header.indexOf(key);
+ if (col < 0) return null;
+ Vector rowVector = (Vector) matrix.get(row);
+ if (rowVector == null) return null;
+ return (String) rowVector.get(col);
+ }
+ /**
+ * @param key: selects the column
+ * @return a Vector with all the values in the selected column; null if empty
+ */
+ public Vector getColumn(String key){
+ if (size() < 1 ) return null;
+ Vector result = new Vector(size(),1);
+ for (int i = 0; i < size(); i++){
+ result.add(get(key, i));
+ }
+ return result;
+ }
+ /**
+ * @param key: selects the column
+ * @return a Vector with all the values in the selected column, dropping duplicates; null if empty
+ */
+ public Vector getUniqueColumn(String key){
+ if (size() < 1 ) return null;
+ Vector result = new Vector(size(),1);
+ for (int i = 0; i < size(); i++){
+ if (!result.contains(get(key, i))) result.add(get(key, i));
+ }
+ return result;
+ }
+ /**
+ * @param key: selects the column
+ * @return a Vector of Integers with all the indexes of the rows
+ * matching the selected column, dropping duplicates; null if empty
+ */
+ public Vector getIndexes(String key, String value){
+ Vector result = new Vector();
+ for (int i = 0; i < size(); i++){
+ if (get(key, i).equals(value))
+ result.add(new Integer(i));
+ }
+ return result;
+ }
+ /**
+ * Deletes all the rows that matches the value for the key
+ * @param key: selects the column
+ */
+ public void dropMatching(String key, String value){
+ for (int i = 0; i < size(); i++){
+ if (get(key, i).equals(value)) deleteRow(i);
+ }
+ }
+ /**
+ * Returns a StringMatrix with all the complete rows that match the key - value pair
+ * @param key The column key
+ * @param value The value to match
+ * @return a StringMatrix with only the rows where the key equals the value
+ */
+ public StringMatrix select(String key, String value){
+ StringMatrix result = new StringMatrix();
+ result.addVectorHeader(header);
+ int j = 0;
+ for (int i = 0; i < size(); i++){
+ if (get(key, i).equals(value)) {
+ result.addVector((Vector)matrix.get(i), j);
+ j++;
+ }
+ }
+ return result;
+ }
+ /**
+ * @param i
+ * @return : a StringMatrix with only one row, the selected by i
+ */
+ public StringMatrix rowMatrix(int i){
+ StringMatrix result = new StringMatrix();
+ result.addVectorHeader(header);
+ result.addVector((Vector)matrix.get(i),0);
+ return result;
+ }
+
+ /**
+ * @return the number of rows
+ */
+ public int size() {
+ return matrix.size();
+ }
+ public int getNumColumns() {
+ return header.size();
+ }
+ public String getHeaderColumn(int i){
+ return (String) header.get(i);
+ }
+ public void deleteRow(int i){
+ matrix.remove(i);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.sql.parser;
+
+import java.util.Vector;
+
+public class SQLLexx {
+ private static String endline = ";"; //$NON-NLS-1$
+ private static String dash = "-"; //$NON-NLS-1$
+ 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("--"); //$NON-NLS-1$
+ 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.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.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 + "]"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+}
--- /dev/null
+/*
+ * Created on 14-Jul-2003
+ *
+ * To change this generated comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpdt.sql.utils;
+
+import java.util.Vector;
+
+import net.sourceforge.phpdt.sql.IConstants;
+
+public class PHPStringThing {
+ private String query = null;
+ public PHPStringThing() {
+ }
+ public PHPStringThing(String query) {
+ this.query = query;
+ }
+
+ public Vector toPHP() {
+ return toPHP(query);
+ }
+
+ static public Vector toPHP(String query) {
+ Vector buffer = new Vector();
+ buffer.add(IConstants.PHPFILEHEADER);
+ buffer.add(IConstants.PHPDBCONNHEADER);
+ buffer.add(IConstants.PHPDBRESULTHEADER.replaceAll("%%QUERY%%", query));
+ buffer.add(IConstants.PHPDBCLOSEHEADER);
+ return buffer;
+ }
+
+}
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.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
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.ColumnMetaData;
+import net.sourceforge.phpdt.sql.view.bookmark.GroupNode;
import net.sourceforge.phpdt.sql.view.bookmark.Root;
import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
/**
* @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.
+ * Implements the ILabelProvider for the Bookmarks.
*/
public class BookmarkLabelProvider implements ILabelProvider {
/**
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);
+ BookmarkNode bookmark = (BookmarkNode) element;
+ URL url = new URL(installURL, (bookmark.isConnected()) ? "icons/connected.gif" : "icons/bookmarks.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+ descriptor = ImageDescriptor.createFromURL(url);
} catch (Exception e) {
e.printStackTrace();
}
- } else {
- return null;
- }
+ } else if (element instanceof ColumnMetaData){
+ try {
+ ColumnMetaData columnMetaData = (ColumnMetaData) element;
+ return columnMetaData.getImage();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (element instanceof GroupNode){
+ try {
+ GroupNode groupNode = (GroupNode) element;
+ return groupNode.getImage();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (element instanceof TableNode){
+ try {
+ TableNode TableNode = (TableNode) element;
+ return TableNode.getImage();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (element instanceof ViewNode){
+ try {
+ ViewNode ViewNode = (ViewNode) element;
+ return ViewNode.getImage();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (element instanceof SequenceNode){
+ try {
+ SequenceNode SequenceNode = (SequenceNode) element;
+ return SequenceNode.getImage();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ return null;
+ }
return descriptor.createImage();
}
Bookmark bookmark = (Bookmark) element;
return bookmark.getName();
} else if (element.equals(Root.ROOT)) {
- return "ROOT";
+ return "ROOT"; //$NON-NLS-1$
} else if (element instanceof TableNode) {
TableNode node = (TableNode) element;
- if (node.getSize() > -1) {
- return "T " + element.toString() + " (" + node.getSize() + ")";
+ if (node.isSizeVisible()) {
+ return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
- return "T " + element.toString();
+ return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString(); //$NON-NLS-1$
}
} else if (element instanceof ViewNode) {
ViewNode node = (ViewNode) element;
- if (node.getSize() > -1) {
- return "V " + element.toString() + " (" + node.getSize() + ")";
+ if (node.isSizeVisible()) {
+ return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
- return "V " + element.toString();
+ return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString(); //$NON-NLS-1$
}
} else if (element instanceof SequenceNode) {
- return "S " + element.toString();
+ return Messages.getString("BookmarkLabelProvider.SequencePrefix") + element.toString(); //$NON-NLS-1$
}
return element.toString();
}
package net.sourceforge.phpdt.sql.view;
-import java.util.Vector;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+import org.apache.crimson.tree.XmlDocument;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
import net.sourceforge.phpdt.sql.actions.ConnectAction;
+import net.sourceforge.phpdt.sql.actions.DeleteAllRowsAction;
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.ExportXMLAction;
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.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
+import net.sourceforge.phpdt.sql.model.Entity;
+import net.sourceforge.phpdt.sql.model.Sequence;
+import net.sourceforge.phpdt.sql.model.Table;
+import net.sourceforge.phpdt.sql.model.View;
+import net.sourceforge.phpdt.sql.sql.DbElementsConstants;
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.GroupNode;
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.TreeNode;
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();
+ private ConnectAction connectAction;
+ private DisconnectAction disconnectAction;
+ private NewBookmarkAction newBookmarkAction;
+ private EditBookmarkAction editBookmarkAction;
+ private DeleteBookmarkAction deleteBookmarkAction;
+ private ViewTableAction viewTableAction;
+ private ExportXMLAction exportXMLAction;
+ private RefreshBookmarkAction refreshBookmarkAction;
+ private ViewTableDetailsAction viewTableDetailsAction;
+ private NextSequenceAction nextSequenceAction;
+
+ private DeleteAllRowsAction deleteAllRowsAction;
+
+ private Action enableTableSizes;
+ private static BookmarkView instance = null;
+ private TreeViewer treeViewer;
+ private BookmarkContentProvider provider =
+ BookmarkContentProvider.getInstance();
+ private Label status;
+ private boolean showTableSizes = false;
+ private BookmarkNode clipboard;
+ private Clipboard sysClip;
+ public synchronized static BookmarkView getInstance() {
+ return instance;
+ }
+ /**
+ * Returns the current selected object in the tree. If it's a multiple selection, return the first.
+ * @return
+ */
+ public Object getCurrent() {
+ if (treeViewer == null) return null;
+ return ((StructuredSelection) treeViewer.getSelection())
+ .getFirstElement();
+ }
+ /**
+ * Returns the current selected objects in the tree, in the form of a StructuredSelection.
+ * @return
+ */
+ public StructuredSelection getSelection() {
+ if (treeViewer == null) return null;
+ return ((StructuredSelection) treeViewer.getSelection());
+ }
+
+ /**
+ * Navigates the tree to get the current bookmark (root) of the selected element.
+ * If it's a multiple selection, it takes the first one.
+ * @return
+ */
+ public BookmarkNode getCurrentBookmark() {
+ TreeNode current = (TreeNode) getCurrent();
+
+ return getRoot(current);
+ }
+
+ public static BookmarkNode getRoot(TreeNode node){
+ while (!( node instanceof BookmarkNode))
+ {
+ node = (TreeNode) node.getParent();
+ }
+ return (BookmarkNode) node;
+
+ }
+ public void deleteCurrent() {
+ provider.removeBookmark(getCurrentBookmark());
+ treeViewer.refresh();
+ }
+
+ /**
+ * Requeries the database to get the Data from all the bookmarks
+ */
+ public void refreshBookmarkData(){
+ if (treeViewer == null) return;
+ BookmarkContentProvider provider = (BookmarkContentProvider) treeViewer.getContentProvider();
+ Object[] objects = provider.getElements(Root.ROOT);
+ // We make a loop for all the bookmarks, and refresh each one
+ for (int i = 0; i < objects.length; i++) {
+ BookmarkNode current = (BookmarkNode) objects[i];
+ if (current.isConnected()) refreshOneBookmarkData(current);
+ }
+ }
+
+ /**
+ * Requeries the database to get the Tables, Views, etc. from a Bookmark
+ * @param current The BookmarkNode to be requeried and refreshed
+ */
+ public void refreshOneBookmarkData(BookmarkNode current) {
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);
- }
+ BookmarkContentProvider provider = BookmarkContentProvider.getInstance();
+ if (current != null) {
+
+ Map groups = new HashMap();
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(current.getType());
+
+ setStatus(Messages.getString("bookmarkview.retrieveEntities")); //$NON-NLS-1$
+ Entity[] entities = adapter.getEntities(current);
+ for (int i = 0, length = (entities == null) ? 0 : entities.length; i < length; i++) {
+
+ Entity entity = entities[i];
+ String type = entity.getType();
+
+ if (!groups.containsKey(type)) {
+ groups.put(type, new GroupNode(current, type));
+ }
+ GroupNode group = (GroupNode) groups.get(type);
+ TreeNode treeNode = null;
+ if (type.equals(DbElementsConstants.Table)) {
+ treeNode = new TableNode(group, this.showTableSizes, (Table) entity);
+ } else if (type.equals(DbElementsConstants.View)) {
+ treeNode = new ViewNode(group, this.showTableSizes, (View) entity);
+ } else if (type.equals(DbElementsConstants.Sequence)) {
+ treeNode = new SequenceNode(group, (Sequence) entity);
+ }
+
+ if (treeNode != null) {
+ group.addChild(treeNode);
+ }
+ }
+
+ Vector children = new Vector(groups.values());
+ Collections.sort(children);
+
+ provider.setChildren(current, children);
+ BookmarkView.getInstance().refresh();
+ setStatus(Messages.getString("bookmarkview.done")); //$NON-NLS-1$
}
- }
- } 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$
+ } catch (SQLException e) {
+ LogProxy.getInstance().addText(LogProxy.ERROR, e);
}
- 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);
+ public void expandCurrent(BookmarkNode node) {
+ treeViewer.setExpandedState(node, true);
+ treeViewer.refresh(node, false);
+ }
+ public void refresh() {
+ treeViewer.refresh();
+ }
+ public void disconnect() {
+ //Changed for multiple connections
+ BookmarkNode current = getCurrentBookmark();
+ if (current != null) {
+ setStatus(Messages.getString("bookmarkview.disconnect") + current.getName()); //$NON-NLS-1$
+ MultiSQLServer.getInstance().disconnect(current, current.getConnection());
+ 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();
+ sysClip = 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);
- enableTableColumns = new Action() {
- public void run() {
- showTableColumns = enableTableColumns.isChecked();
- refreshBookmarkData();
- }
- };
- enableTableColumns.setText("Show Table Column Data");
- enableTableColumns.setChecked(false);
+ enableTableSizes = new Action() {
+ public void run() {
+ showTableSizes = enableTableSizes.isChecked();
+ refreshBookmarkData();
+ }
+ };
+ enableTableSizes.setText(Messages.getString("BookmarkView.ShowTableSizes")); //$NON-NLS-1$
+ enableTableSizes.setChecked(false);
+
+ IActionBars actionBars = getViewSite().getActionBars();
+ actionBars.getMenuManager().add(enableTableSizes);
+
+ 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;
+ if (!node.isConnected()) {
+ connectAction.run();
+ }
+ } else if (sel instanceof TableNode || 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;
+ if (node.isConnected()) {
+ 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(Messages.getString("BookmarkView.Copy")); //$NON-NLS-1$
+ copyAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ mgr.add(pasteAction);
+ pasteAction.setText(Messages.getString("BookmarkView.Paste")); //$NON-NLS-1$
+ pasteAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("paste.gif")); //$NON-NLS-1$
+ if (node.isConnected()) {
+ mgr.add(new Separator());
+ mgr.add(refreshBookmarkAction);
+ }
+ } else if (sel instanceof TableNode || sel instanceof ViewNode) {
+ mgr.add(copyAction);
+ copyAction.setText(Messages.getString("BookmarkView.Copy")); //$NON-NLS-1$
+ copyAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ mgr.add(viewTableAction);
+ mgr.add(exportXMLAction);
+ mgr.add(viewTableDetailsAction);
+ mgr.add(new Separator());
+ mgr.add(newBookmarkAction);
+ mgr.add(new Separator());
+ mgr.add(BookmarkView.this.deleteAllRowsAction);
+ } 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);
- IActionBars actionBars = getViewSite().getActionBars();
- actionBars.getMenuManager().add(enableTableSizes);
- actionBars.getMenuManager().add(enableTableColumns);
+ 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")); //$NON-NLS-1$
+ 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);
+ exportXMLAction = new ExportXMLAction();
+ exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
+ exportXMLAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("xml.gif")); //$NON-NLS-1$
+ exportXMLAction.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")); //$NON-NLS-1$
+ nextSequenceAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ nextSequenceAction.init(this);
- 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);
+ this.deleteAllRowsAction = new DeleteAllRowsAction();
+ this.deleteAllRowsAction.setText(Messages.getString("bookmarkview.deleteRowsAction"));
+ this.deleteAllRowsAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ this.deleteAllRowsAction.init(this);
+ }
+
+ public void setFocus() {
+ if (treeViewer == null) return;
+ BookmarkContentProvider provider = (BookmarkContentProvider) treeViewer.getContentProvider();
+ Object[] objects = provider.getElements(Root.ROOT);
+ for (int i = 0; i < objects.length; i++) {
+ BookmarkNode current = (BookmarkNode) objects[i];
+ if (current.isConnected() && (!current.hasChildren())) refreshOneBookmarkData(current);
+ }
+ }
+
+ private Action copyAction = new Action() {
+ public void run() {
+ Object sel = getCurrent();
+
+ if (sel instanceof BookmarkNode) {
+ clipboard = (BookmarkNode) sel;
+ sysClip.setContents(
+ new Object[] { clipboard.getName()},
+ new Transfer[] { TextTransfer.getInstance()});
+
+ } else if (sel instanceof TableNode || sel instanceof ViewNode) {
+ XmlDocument doc = new XmlDocument();
+ ExportXMLAction.ExportXMLSelection(doc, (StructuredSelection) treeViewer.getSelection());
+ StringWriter text = new StringWriter();
+ try {
+ doc.write(text);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ String textXml = new String(text.getBuffer());
+ sysClip.setContents(
+ new Object[] { textXml },
+ new Transfer[] { TextTransfer.getInstance()});
+
+ }
+
+ }
+ };
+ private Action pasteAction = new Action() {
+ public void run() {
+ if (clipboard != null) {
+ BookmarkNode node = new BookmarkNode(clipboard);
+ node.setName(Messages.getString("BookmarkView.CopyOf") + node.getName()); //$NON-NLS-1$
+ provider.addBookmark(node);
+ refresh();
+ }
+ }
+ };
+ public void addNewBookmark(BookmarkNode bookmark) {
+ provider.addBookmark(bookmark);
+ treeViewer.refresh();
+ }
+ public void setStatus(String text) {
+ status.setText(text);
+ }
- IActionBars bars = getViewSite().getActionBars();
- bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction);
- bars.setGlobalActionHandler(IWorkbenchActionConstants.PASTE, pasteAction);
- bars.setGlobalActionHandler(
- IWorkbenchActionConstants.DELETE,
- deleteBookmarkAction);
+ /**
+ * @return
+ */
+ public BookmarkNode getClipboard() {
+ return clipboard;
+ }
+
+ /**
+ * Finds a child of the BookmarkView with the said name
+ * @param name
+ * @return the TreeNode found. null if none
+ */
+ public BookmarkNode find(String name){
+ if (treeViewer == null) return null;
+ BookmarkContentProvider provider = (BookmarkContentProvider) treeViewer.getContentProvider();
+ Object[] objects = provider.getElements(Root.ROOT);
+ for (int i = 0; i < objects.length; i++) {
+ BookmarkNode current = (BookmarkNode) objects[i];
+ if (name.equals(current.getName())) return current;
+ }
+ return null;
+ }
+
+ /**
+ * Returs a Vector with all the elements of the treeViewer
+ * @return
+ */
+ public Vector getElements(){
+ Vector result = new Vector();
+ if (treeViewer == null) return result;
+ BookmarkContentProvider provider = (BookmarkContentProvider) treeViewer.getContentProvider();
+ Object[] objects = provider.getElements(Root.ROOT);
+ for (int i = 0; i < objects.length; i++) {
+ BookmarkNode current = (BookmarkNode) objects[i];
+ result.add(current);
+ }
+ return result;
+ }
- IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
- toolBar.add(newBookmarkAction);
+ public void dispose(){
+ sysClip.dispose();
+ super.dispose();
+ }
- 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);
- }
}
package net.sourceforge.phpdt.sql.view;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
public class LogProxy implements LogConstants {
private static LogProxy instance = null;
private SQLLogView log = null;
log.addText(type, text);
}
}
+
+ public void addText(int type, String text, Exception e) {
+ addText(type, text);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ addText(type, writer.toString());
+ }
+
+ public void addText(int type, Exception e) {
+ addText(type, "Error occured: " + e, e); //$NON-NLS-1$
+ }
}
-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 + '!';
- }
- }
-}
http://www.eclipse.org/legal/cpl-v10.html
Contributors:
- IBM Corporation - Initial implementation
- Klaus Hartlage - www.eclipseproject.de
+ 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.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
/**
* 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";
+ "net.sourceforge.phpdt.sql.view.phpsourceconsoleview";
- private TextViewer viewer = null;
+ TextViewer viewer = null;
private Document document = null;
/**
* @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);
+ 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);
}
/**
* Set the text for the viewer
*/
private void setOutputText(String text) {
- document = new Document(text);
- viewer.setDocument(document);
+ 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);
+ 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;
+ 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);
+ appendOutputText(output);
}
/**
* Prints out the string represented by the string buffer
*/
public synchronized void println(String output) {
- appendOutputText(output+'\n');
+ appendOutputText(output+'\n');
}
public synchronized void clear() {
- setOutputText("");
+ setOutputText("");
}
}
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.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+
public class SQLLogView extends ViewPart implements LogConstants {
private Color QUERY_COLOR;
private Color WARNING_COLOR;
private Color RESULTS_COLOR;
private StyledText widget;
private static SQLLogView instance = null;
- private static final String newLine = "\n";
+ private static final String newLine = "\n"; //$NON-NLS-1$
public static SQLLogView getInstance() {
return instance;
}
bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
- clearAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("clear.gif"));
- clearAction.setToolTipText("Clear Log");
+ clearAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("clear.gif")); //$NON-NLS-1$
+ clearAction.setToolTipText(Messages.getString("SQLLogView.ClearLog")); //$NON-NLS-1$
toolBar.add(clearAction);
widget.setEditable(false);
};
private Action clearAction = new Action() {
public void run() {
- widget.setText("");
+ widget.setText(""); //$NON-NLS-1$
}
};
}
import java.util.NoSuchElementException;
import java.util.Vector;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.parser.SQLLexx;
-import net.sourceforge.phpdt.sql.parser.Token;
-import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
-
import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ExtendedModifyEvent;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
+import net.sourceforge.phpdt.sql.IConstants;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.actions.ExecuteAction;
+import net.sourceforge.phpdt.sql.actions.ExportQueryAction;
+import net.sourceforge.phpdt.sql.actions.GeneratePHPAction;
+import net.sourceforge.phpdt.sql.actions.ImportQueryAction;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.parser.SQLLexx;
+import net.sourceforge.phpdt.sql.sql.parser.Token;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
public class SQLQueryView extends ViewPart implements IConstants {
- private ExecuteAction executeAction;
- private ImportQueryAction importQueryAction;
- private ExportQueryAction exportQueryAction;
+ ExecuteAction executeAction;
+ ImportQueryAction importQueryAction;
+ ExportQueryAction exportQueryAction;
+ GeneratePHPAction generatePHPAction;
private Clipboard clip;
private Label statusImage;
private Label status;
}
});
item = new ToolItem(toolbar, SWT.PUSH);
+ item.setImage(PHPEclipseSQLPlugin.getImage("php.gif")); //$NON-NLS-1$
+ item.setToolTipText(Messages.getString("sqlqueryview.generatePHP")); //$NON-NLS-1$
+ item.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ generatePHPAction.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("");
+ setQuery(""); //$NON-NLS-1$
}
});
item = new ToolItem(toolbar, SWT.PUSH);
final ToolItem commit = item;
item.setImage(PHPEclipseSQLPlugin.getImage("commit.gif")); //$NON-NLS-1$
- item.setToolTipText("Commit");
+ item.setToolTipText(Messages.getString("SQLQueryView.Commit")); //$NON-NLS-1$
item.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
- MultiSQLServer.getInstance().commit();
+ BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
+ MultiSQLServer.getInstance().commit(node.getConnection());
}
});
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.setToolTipText(Messages.getString("SQLQueryView.RollBack")); //$NON-NLS-1$
item.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
- MultiSQLServer.getInstance().rollback();
+ BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
+ MultiSQLServer.getInstance().rollback(node.getConnection());
}
});
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.setToolTipText(Messages.getString("SQLQueryView.AutoCommit")); //$NON-NLS-1$
item.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
- MultiSQLServer.getInstance().setAutoCommit(autocommit.getSelection());
+ BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
+
+ MultiSQLServer.getInstance().setAutoCommit(node.getConnection(), autocommit.getSelection());
if (autocommit.getSelection()) {
commit.setEnabled(false);
rollback.setEnabled(false);
progress = new ProgressBar(bottomStatus, SWT.HORIZONTAL);
- status.setText(Messages.getString("sqlqueryview.done"));
- statusImage.setImage(PHPEclipseSQLPlugin.getImage("success.gif"));
+ status.setText(Messages.getString("sqlqueryview.done")); //$NON-NLS-1$
+ statusImage.setImage(PHPEclipseSQLPlugin.getImage("success.gif")); //$NON-NLS-1$
progress.setMinimum(0);
}
importQueryAction.init(this);
exportQueryAction = new ExportQueryAction();
exportQueryAction.init(this);
+ generatePHPAction = new GeneratePHPAction();
+ generatePHPAction.init(this);
}
public void setStatus(String text) {
widget.setText(text);
}
- private String[] keywords = {"SELECT", "DROP", "FROM",
- "INSERT", "INTO", "VALUES",
- "CREATE", "TABLE", "VIEW", "SEQUENCE",
- "UPDATE", "SET", "WHERE"};
+ private String[] keywords = {"SELECT", "DROP", "FROM", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "INSERT", "INTO", "VALUES", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "CREATE", "TABLE", "VIEW", "SEQUENCE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ "UPDATE", "SET", "WHERE"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
SyntaxHighlighter textUpdater = new SyntaxHighlighter();
if (upper || lower || both) {
min = Math.min(start, min);
max = Math.max(max, start + length);
- if (t.getType() == t.IDENTIFIER) {
+ if (t.getType() == Token.IDENTIFIER) {
boolean keyword = false;
for (int index = 0; index < keywords.length; index++) {
if (value.equals(keywords[index])) {
styleRange.foreground = DEFAULT;
}
styles.addElement(styleRange);
- } else if (t.getType() == t.COMMENT) {
+ } else if (t.getType() == Token.COMMENT) {
styleRange.foreground = COMMENT;
styles.addElement(styleRange);
- } else if (t.getType() == t.LITERAL) {
+ } else if (t.getType() == Token.LITERAL) {
styleRange.foreground = STRING_LITERAL;
styles.addElement(styleRange);
- } else if (t.getType() == t.NUMERIC) {
+ } else if (t.getType() == Token.NUMERIC) {
styleRange.foreground = NUMERIC;
styles.addElement(styleRange);
} else {
widget.setStyleRange(styles[i]);
}
} catch (Throwable t) {
- if (DEBUG) {
- System.out.println("Error with styles: " + t.getClass().toString());
+ System.out.println("Error with styles: " + t.getClass().toString()); //$NON-NLS-1$
// ignore any errors
- }
}
}
});
--- /dev/null
+package net.sourceforge.phpdt.sql.view;
+
+import java.net.URL;
+
+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.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.view.bookmark.ColumnMetaData;
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
+
+/**
+ * @author root
+ *
+ * Implements the ILabelProvider for the Bookmarks.
+ */
+public class SubsetLabelProvider implements ILabelProvider {
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
+ */
+ public Image getImage(Object element) {
+ ImageDescriptor descriptor = null;
+ if (element instanceof SubsetNode) {
+ try {
+ URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
+ URL url = new URL(installURL, "icons/subset.gif"); //$NON-NLS-1$
+ descriptor = ImageDescriptor.createFromURL(url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (element instanceof ColumnMetaData){
+ try {
+ ColumnMetaData columnMetaData = (ColumnMetaData) element;
+ return columnMetaData.getImage();
+ } 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 SubsetNode) {
+ SubsetNode subset = (SubsetNode) element;
+ return subset.getName();
+ } else if (element.equals(Root.ROOT)) {
+ return "ROOT"; //$NON-NLS-1$
+ } else if (element instanceof TableNode) {
+ TableNode node = (TableNode) element;
+ if (node.isSizeVisible()) {
+ return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else {
+ return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString(); //$NON-NLS-1$
+ }
+ } else if (element instanceof ViewNode) {
+ ViewNode node = (ViewNode) element;
+ if (node.isSizeVisible()) {
+ return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ } else {
+ return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString(); //$NON-NLS-1$
+ }
+ } else if (element instanceof SequenceNode) {
+ return Messages.getString("BookmarkLabelProvider.SequencePrefix") + element.toString(); //$NON-NLS-1$
+ }
+ 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.io.IOException;
+import java.io.StringReader;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.crimson.tree.XmlDocument;
+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.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.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+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 org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.actions.DeleteColumnAction;
+import net.sourceforge.phpdt.sql.actions.DeleteObjectAction;
+import net.sourceforge.phpdt.sql.actions.DeleteSubsetAction;
+import net.sourceforge.phpdt.sql.actions.ExportXMLAction;
+import net.sourceforge.phpdt.sql.actions.NewSubsetAction;
+import net.sourceforge.phpdt.sql.actions.ViewTableAction;
+import net.sourceforge.phpdt.sql.view.bookmark.ColumnMetaData;
+import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
+import net.sourceforge.phpdt.sql.view.bookmark.Root;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetContentProvider;
+import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
+
+/**
+ * @author panic
+ *
+ * View for subsets
+ * */
+public class SubsetView extends ViewPart {
+
+ private SubsetContentProvider provider = SubsetContentProvider.getInstance();
+ private NewSubsetAction newSubsetAction;
+ private DeleteSubsetAction deleteSubsetAction;
+ private DeleteObjectAction deleteObjectAction;
+ private DeleteColumnAction deleteColumnAction;
+ private ViewTableAction viewTableAction;
+ private ExportXMLAction exportXMLAction;
+ private static SubsetView instance = null;
+ private TreeViewer treeViewer;
+ private Label status;
+ private Clipboard sysClip;
+ public synchronized static SubsetView getInstance() {
+ return instance;
+ }
+ /**
+ * Returns the current selected object in the tree. If it's a multiple selection, return the first.
+ * @return
+ */
+ public Object getCurrent() {
+ if (treeViewer == null) return null;
+ return ((StructuredSelection) treeViewer.getSelection())
+ .getFirstElement();
+ }
+ /**
+ * Returns the current selected objects in the tree, in the form of a StructuredSelection.
+ * @return
+ */
+ public StructuredSelection getSelection() {
+ if (treeViewer == null) return null;
+ return ((StructuredSelection) treeViewer.getSelection());
+ }
+
+ /**
+ * Navigates the tree to get the current subset (root) of the selected element.
+ * If it's a multiple selection, it takes the first one.
+ * @return
+ */
+ public SubsetNode getCurrentSubset() {
+ TreeNode current = (TreeNode) getCurrent();
+
+ return getRoot(current);
+ }
+
+ /**
+ * Navigates a given TreeNode till finds a SubsetNode
+ * @param node
+ * @return
+ */
+ private static SubsetNode getRoot(TreeNode node){
+ while (!( node instanceof SubsetNode))
+ {
+ node = (TreeNode) node.getParent();
+ }
+ return (SubsetNode) node;
+
+ }
+
+
+ /**
+ * Deletes the current node (first selected) in the tree
+ */
+ public void deleteCurrent() {
+ provider.removeSubset(getCurrentSubset());
+ treeViewer.refresh();
+ }
+
+ public void refreshSubsetData(){
+ //if (treeViewer == null) return;
+ //SubsetContentProvider provider = (SubsetContentProvider) treeViewer.getContentProvider();
+ //Object[] objects = provider.getElements(Root.ROOT);
+ //for (int i = 0; i < objects.length; i++) {
+ //SubsetNode current = (SubsetNode) objects[i];
+
+ //}
+ }
+
+ public void expandCurrent(SubsetNode node) {
+ treeViewer.setExpandedState(node, true);
+ treeViewer.refresh(node, false);
+ }
+ public void refresh() {
+ treeViewer.refresh();
+ }
+ public void disconnect() {
+ }
+
+ public void createPartControl(org.eclipse.swt.widgets.Composite parent) {
+ instance = this;
+ initActions();
+ sysClip = 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);
+
+
+ treeViewer = new TreeViewer(main);
+ treeViewer.setContentProvider(provider);
+ treeViewer.setLabelProvider(new SubsetLabelProvider());
+ 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 ObjectNode) {
+ viewTableAction.run();
+ }
+ }
+ });
+
+ manager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager mgr) {
+ Object sel = getCurrent();
+ if (sel instanceof SubsetNode) {
+ mgr.add(deleteSubsetAction);
+ deleteSubsetAction.setText(Messages.getString("SubsetView.Delete")); //$NON-NLS-1$
+ deleteSubsetAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ mgr.add(pasteAction);
+ pasteAction.setText(Messages.getString("SubsetView.Paste")); //$NON-NLS-1$
+ pasteAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("paste.gif")); //$NON-NLS-1$
+ mgr.add(exportXMLAction);
+ exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
+ exportXMLAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("xml.gif")); //$NON-NLS-1$
+ } else if (sel instanceof ObjectNode) {
+ mgr.add(deleteObjectAction);
+ deleteObjectAction.setText(Messages.getString("SubsetView.Delete")); //$NON-NLS-1$
+ deleteObjectAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ mgr.add(viewTableAction);
+ viewTableAction.setText(Messages.getString("bookmarkview.viewTable")); //$NON-NLS-1$
+ viewTableAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ mgr.add(exportXMLAction);
+ exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
+ exportXMLAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("xml.gif")); //$NON-NLS-1$
+
+ } else if (sel instanceof ColumnMetaData){
+ mgr.add(deleteColumnAction);
+ deleteColumnAction.setText(Messages.getString("SubsetView.Delete")); //$NON-NLS-1$
+ deleteColumnAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ } else {
+ mgr.add(newSubsetAction);
+ }
+ }
+ });
+
+ 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.PASTE, pasteAction);
+ bars.setGlobalActionHandler(IWorkbenchActionConstants.DELETE, deleteSubsetAction);
+
+ IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+ toolBar.add(newSubsetAction);
+
+ status.setText(Messages.getString("bookmarkview.done")); //$NON-NLS-1$
+ }
+ public void initActions() {
+ newSubsetAction = new NewSubsetAction();
+ newSubsetAction.setText("New Subset"); //$NON-NLS-1$
+ newSubsetAction.setToolTipText(Messages.getString("SubsetView.CreatesANewEmptySubset")); //$NON-NLS-1$
+ newSubsetAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("subset.gif")); //$NON-NLS-1$
+ newSubsetAction.init(this);
+ deleteColumnAction = new DeleteColumnAction();
+ deleteColumnAction.setText("Delete Column"); //$NON-NLS-1$
+ deleteColumnAction.setToolTipText(Messages.getString("SubsetView.DeletesTheSelectedColumns")); //$NON-NLS-1$
+ deleteColumnAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ deleteColumnAction.init(this);
+ deleteObjectAction = new DeleteObjectAction();
+ deleteObjectAction.setText("Delete Object"); //$NON-NLS-1$
+ deleteObjectAction.setToolTipText(Messages.getString("SubsetView.DeletesTheSelectedObject")); //$NON-NLS-1$
+ deleteObjectAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ deleteObjectAction.init(this);
+ deleteSubsetAction = new DeleteSubsetAction();
+ deleteSubsetAction.setText("Delete Subset"); //$NON-NLS-1$
+ deleteSubsetAction.setToolTipText(Messages.getString("SubsetView.DeletesTheSelectedSubset")); //$NON-NLS-1$
+ deleteSubsetAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ deleteSubsetAction.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);
+ exportXMLAction = new ExportXMLAction();
+ exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
+ exportXMLAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ exportXMLAction.init(this);
+
+ }
+ public void setFocus() {
+ }
+
+ private Action pasteAction = new Action() {
+ public void run() {
+ Object sel = getCurrent();
+ if (sel == null) return;
+ if (!(sel instanceof SubsetNode)) return;
+
+ SubsetNode subset = (SubsetNode) sel;
+
+ TextTransfer transfer = TextTransfer.getInstance();
+ String xmlMetaData = (String) sysClip.getContents(transfer);
+ StringReader text = new StringReader(xmlMetaData);
+ XmlDocument doc = new XmlDocument();
+ InputSource source = new InputSource(text);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser;
+ try {
+ parser = factory.newDocumentBuilder();
+ doc = (XmlDocument) parser.parse(source);
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ return;
+ } catch (SAXException e) {
+ e.printStackTrace();
+ return;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ Element root = doc.getDocumentElement();
+ subset.importXML(root, false);
+ treeViewer.refresh();
+ provider.setHasChanged(true);
+
+ }
+ };
+
+ public void addNewSubset(SubsetNode subset) {
+ provider.addSubset(subset);
+ treeViewer.refresh();
+ }
+ public void setStatus(String text) {
+ status.setText(text);
+ }
+ public void dispose(){
+ sysClip.dispose();
+ super.dispose();
+ }
+
+ /**
+ * Returs a Vector with all the elements of the treeViewer
+ * @return
+ */
+ public Vector getElements(){
+ Vector result = new Vector();
+ if (treeViewer == null) return result;
+ SubsetContentProvider provider = (SubsetContentProvider) treeViewer.getContentProvider();
+ Object[] objects = provider.getElements(Root.ROOT);
+ for (int i = 0; i < objects.length; i++) {
+ SubsetNode current = (SubsetNode) objects[i];
+ result.add(current);
+ }
+ return result;
+ }
+
+ public void deleteColumn (ColumnMetaData column){
+ provider.deleteColumn(column);
+ treeViewer.refresh();
+ }
+
+ public void deleteObject (ObjectNode object){
+ provider.deleteObject(object);
+ treeViewer.refresh();
+ }
+
+
+}
package net.sourceforge.phpdt.sql.view;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.PHPDeleteRowPage;
-import net.sourceforge.phpdt.sql.wizards.PHPInsertRowPage;
-import net.sourceforge.phpdt.sql.wizards.PHPSelectRowPage;
-import net.sourceforge.phpdt.sql.wizards.PHPUpdateRowPage;
-import net.sourceforge.phpdt.sql.wizards.SQLRowWizard;
-import net.sourceforge.phpdt.sql.wizards.SortFilterPage;
-import net.sourceforge.phpdt.sql.wizards.UpdateRowPage;
-
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;
-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 Generator", page, row, ta);
- WizardDialog dialog =
- new WizardDialog(getSite().getShell(), wizard);
- dialog.open();
- }
- };
- phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$
-
- Action phpUpdateAction = new Action() {
- public void run() {
- PHPUpdateRowPage page = new PHPUpdateRowPage("");
- SQLRowWizard wizard = new SQLRowWizard();
- wizard.init("PHP Update Generator", page, row, ta);
- WizardDialog dialog =
- new WizardDialog(getSite().getShell(), wizard);
- dialog.open();
- }
- };
- phpUpdateAction.setText(Messages.getString("tableview.phpupdate")); //$NON-NLS-1$
-
- Action phpInsertAction = new Action() {
- public void run() {
- PHPInsertRowPage page = new PHPInsertRowPage("");
- SQLRowWizard wizard = new SQLRowWizard();
- wizard.init("PHP Insert Generator", page, row, ta);
- WizardDialog dialog =
- new WizardDialog(getSite().getShell(), wizard);
- dialog.open();
- }
- };
- phpInsertAction.setText(Messages.getString("tableview.phpinsert")); //$NON-NLS-1$
-
- Action phpDeleteAction = new Action() {
- public void run() {
- PHPDeleteRowPage page = new PHPDeleteRowPage("");
- SQLRowWizard wizard = new SQLRowWizard();
- wizard.init("PHP Delete Generator", page, row, ta);
- WizardDialog dialog =
- new WizardDialog(getSite().getShell(), wizard);
- dialog.open();
- }
- };
- phpDeleteAction.setText(Messages.getString("tableview.phpdelete")); //$NON-NLS-1$
-
- mgr.add(phpSelectAction);
- mgr.add(phpUpdateAction);
- mgr.add(phpInsertAction);
- mgr.add(phpDeleteAction);
-
- 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);
- }
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+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.bookmark.BookmarkNode;
+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.SQLRowWizard;
+import net.sourceforge.phpdt.sql.wizards.SortFilterPage;
+import net.sourceforge.phpdt.sql.wizards.UpdateRowPage;
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- }
+public class TableView extends ViewPart implements ISelectionListener {
+ 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();
+ BookmarkView bookmarkView = BookmarkView.getInstance();
+ BookmarkNode bookmark = bookmarkView.getCurrentBookmark();
+ String table = adapter.getTable();
+ if (table == null) {
+ loadTable(bookmark, item, null, null, true, true);
+ } else {
+ loadTable(bookmark, item, null, null, true, true);
+ }
+ }
+ public void loadQuery(BookmarkNode bookmark, SQLResults results) {
+ loadTable(bookmark, null, null, results, true, false);
+ }
+ public void loadTable(BookmarkNode bookmark, String table) {
+ loadTable(bookmark, null, table, null, false, true);
+ }
+ public void loadTable(BookmarkNode bookmark, 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(bookmark, results);
+ } else {
+ adapter = TableAdapter.createFromTable(bookmark, 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")); //$NON-NLS-1$
+ 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")); //$NON-NLS-1$
+ previous.setToolTipText("Previous"); //$NON-NLS-1$
+ 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")); //$NON-NLS-1$
+ next.setToolTipText("Next"); //$NON-NLS-1$
+ 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] = ""; //$NON-NLS-1$
+ }
+
+ final TableRow emptyRow =
+ new TableRow(ta.getBookmark(), ta.getTable(), columnNames, data);
+
+ filter.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ SortFilterPage page = new SortFilterPage(""); //$NON-NLS-1$
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init(Messages.getString("TableView.FilterAndSort"), page, emptyRow, ta); //$NON-NLS-1$
+ 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] = ""; //$NON-NLS-1$
+ }
+ }
+ final TableRow row =
+ new TableRow(ta.getBookmark(), ta.getTable(), columnNames, data);
+ Action updateAction = new Action() {
+ public void run() {
+ UpdateRowPage page = new UpdateRowPage(""); //$NON-NLS-1$
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$
+ 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(""); //$NON-NLS-1$
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$
+ 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(""); //$NON-NLS-1$
+ SQLRowWizard wizard = new SQLRowWizard();
+ wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$
+ WizardDialog dialog =
+ new WizardDialog(
+ getSite().getShell(),
+ wizard);
+ dialog.open();
+ }
+ };
+ deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$
+ 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")); //$NON-NLS-1$
+ refreshTableAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("refresh.gif")); //$NON-NLS-1$
+ refreshTableAction.init(this);
+ closeTableAction = new CloseTableAction();
+ closeTableAction.setText(Messages.getString("tableview.close")); //$NON-NLS-1$
+ closeTableAction.setImageDescriptor(
+ PHPEclipseSQLPlugin.getImageDescriptor("close.gif")); //$NON-NLS-1$
+ closeTableAction.init(this);
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ }
}
\ No newline at end of file
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.util.Properties;
import java.util.Vector;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
-
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
-public class BookmarkContentProvider implements ITreeContentProvider, IConstants {
- 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;
- if (DEBUG) {
- 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) {
- if (DEBUG) {
- 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) {
- if (DEBUG) {
- 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);
+import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.sql.metadata.MetaDataXMLInterface;
+
+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() {
+ }
+
+ /**
+ * Imports the bookmars from a File, supposed to be in XML format and have the correct tags.
+ * @param file
+ */
+ public void load(File file) {
+ System.out.println("Bookmarks: Loading from file: " + file); //$NON-NLS-1$
+ try {
+ Properties props = new Properties();
+ FileInputStream in = new FileInputStream(file);
+ props.load(in);
+ in.close();
+ fromProperties(true, props);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Exports a Bookmark data to an XMLDocument Element
+ * The complementary function is importXML()
+ * @param root The Element to fill up with the bookmark info
+ */
+ public void exportXML(Element root) {
+ System.out.println("Bookmarks: Saving to Element"); //$NON-NLS-1$
+ Element bookmarkRoot = MetaDataXMLInterface.createElementText(root,"bookmarks", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < bookmarks.size(); i++) {
+ Bookmark b = (Bookmark) bookmarks.elementAt(i);
+ Element bookmark = MetaDataXMLInterface.createElementText(bookmarkRoot,"bookmark", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ MetaDataXMLInterface.createElementText(bookmark,"name", b.getName()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"username", b.getUsername()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"password", b.getPassword()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"schema", b.getSchema()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"connect", b.getConnect()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"driver", b.getDriver()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"type", b.getType()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(bookmark,"driverLocation", b.getDriverFile()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Imports a Bookmark data from an XMLDocument Element
+ * The complementary function is exportXML()
+ * @param root The Element from which to load
+ */
+ public void importXML(Element root) {
+ System.out.println("Bookmarks: Loading from Element"); //$NON-NLS-1$
+ Vector newBookmarks = new Vector();
+ NodeList nodes = root.getElementsByTagName("bookmark"); //$NON-NLS-1$
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Bookmark bookmark = new BookmarkNode();
+ Element column = (Element) nodes.item(i);
+
+ String name = MetaDataXMLInterface.getElementText(column,"name"); //$NON-NLS-1$
+ if (name == null) break;
+ bookmark.setName(name);
+
+ MetaDataXMLInterface.getElementText(column,"name"); //$NON-NLS-1$
+ bookmark.setUsername(MetaDataXMLInterface.getElementText(column,"username")); //$NON-NLS-1$
+ bookmark.setPassword(MetaDataXMLInterface.getElementText(column,"password")); //$NON-NLS-1$
+ bookmark.setConnect(MetaDataXMLInterface.getElementText(column,"connect")); //$NON-NLS-1$
+ bookmark.setDriver(MetaDataXMLInterface.getElementText(column,"driver")); //$NON-NLS-1$
+ bookmark.setSchema(MetaDataXMLInterface.getElementText(column,"schema")); //$NON-NLS-1$
+ bookmark.setType(MetaDataXMLInterface.getElementText(column,"type")); //$NON-NLS-1$
+ bookmark.setDriverFile(MetaDataXMLInterface.getElementText(column,"driverLocation")); //$NON-NLS-1$
+ System.out.println(bookmark.toString());
+ if (!bookmark.isEmpty()) {
+ newBookmarks.addElement(bookmark);
+ }
+ }
+ bookmarks = newBookmarks;
+ }
+
+ 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;
+ }
+ /**
+ * Finds a Bookmark with the specified name, and returs it. Null if nothing found.
+ * @param name
+ * @return
+ */
+ public BookmarkNode find(String name){
+ for (int i = 0; i < bookmarks.size(); i++) {
+ BookmarkNode b = (BookmarkNode) bookmarks.elementAt(i);
+ if (b.getName().equals(name)) return b;
+ }
+ return null;
+ }
+
+ 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 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("");
- }
- if (DEBUG) {
- 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;
- }
+ 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"); //$NON-NLS-1$
+ if (name == null) {
+ break;
+ }
+ bookmark.setName(name);
+ bookmark.setUsername(props.getProperty(i + ".username")); //$NON-NLS-1$
+ bookmark.setPassword(props.getProperty(i + ".password")); //$NON-NLS-1$
+ bookmark.setConnect(props.getProperty(i + ".connect")); //$NON-NLS-1$
+ bookmark.setDriver(props.getProperty(i + ".driver")); //$NON-NLS-1$
+ String schema = props.getProperty(i + ".schema"); //$NON-NLS-1$
+ if (schema != null) {
+ bookmark.setSchema(schema);
+ } else {
+ bookmark.setSchema(""); //$NON-NLS-1$
+ }
+ String type = props.getProperty(i + ".type"); //$NON-NLS-1$
+ if (type != null) {
+ bookmark.setType(type);
+ } else {
+ bookmark.setType(""); //$NON-NLS-1$
+ }
+ String driverFile = props.getProperty(i + ".driverLocation"); //$NON-NLS-1$
+ if (driverFile != null) {
+ bookmark.setDriverFile(driverFile);
+ } else {
+ bookmark.setDriverFile(""); //$NON-NLS-1$
+ }
+ System.out.println(bookmark.toString());
+ if (!bookmark.isEmpty()) {
+ newBookmarks.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()); //$NON-NLS-1$
+ props.put(i + ".username", b.getUsername()); //$NON-NLS-1$
+ props.put(i + ".password", b.getPassword()); //$NON-NLS-1$
+ props.put(i + ".schema", b.getSchema()); //$NON-NLS-1$
+ props.put(i + ".connect", b.getConnect()); //$NON-NLS-1$
+ props.put(i + ".driver", b.getDriver()); //$NON-NLS-1$
+ props.put(i + ".type", b.getType()); //$NON-NLS-1$
+ props.put(i + ".driverLocation", b.getDriverFile()); //$NON-NLS-1$
+ }
+ return props;
+ }
}
package net.sourceforge.phpdt.sql.view.bookmark;
-import java.util.Collections;
import java.util.Vector;
+import org.eclipse.core.runtime.CoreException;
+
import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
public class BookmarkNode extends Bookmark implements TreeNode {
private Vector children = new Vector();
-
+ public ObjectMetaData getMetaData() {
+ return null; //no metadata implementation for now
+ }
public BookmarkNode() {
}
Object obj = children.elementAt(i);
isValid(obj);
}
- Collections.sort(children);
this.children = children;
}
boolean valid = false;
if (child instanceof TableNode ||
child instanceof ViewNode ||
- child instanceof SequenceNode) {
+ child instanceof SequenceNode ||
+ child instanceof GroupNode) {
valid = true;
}
if (!valid) {
- throw new RuntimeException("Invalid BookmarkNode child: " + child.getClass().getName());
+ throw new RuntimeException("Invalid BookmarkNode child: " + child.getClass().getName()); //$NON-NLS-1$
+ }
+ }
+
+ public void dispose() throws CoreException {
+ if (isConnected()) {
+ disconnect();
+ }
+ }
+
+ /**
+ * Finds a child of the BookmarkNode with the said name
+ * @param name
+ * @return the TreeNode found. null if none
+ */
+ public TreeNode find(String name){
+ for (int i = 0; i < children.size(); i++) {
+ Object obj = children.elementAt(i);
+ if (obj instanceof TreeNode){
+ TreeNode node = (TreeNode) obj;
+ if (name.equals(node.getName())) return node;
+ }
}
+ return null;
}
+
}
--- /dev/null
+/*
+ * Created on 2/04/2003
+ *
+ */
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Vector;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+import net.sourceforge.phpdt.sql.sql.metadata.StringMatrix;
+
+/**
+ *
+ * Class that holds the MetaData for a Column in a table or view.
+ * primaryKeyOrder holds value 0 or the sequence number of the column in the primary key.
+ */
+public class ColumnMetaData implements TreeNode {
+
+ StringMatrix matrix = null;
+ TreeNode parent = null;
+ int primaryKeyOrder = 0;
+
+ public ColumnMetaData( StringMatrix metaData , TreeNode parent) {
+ this.matrix = metaData;
+ this.parent = parent;
+ }
+
+ /**
+ * @return the display size of the column
+ */
+ public int getDisplaySize() {
+ String result = matrix.get("COLUMN_SIZE", 0); //$NON-NLS-1$
+ if (result == null) return 0;
+ else return Integer.parseInt(result);
+ }
+
+ // Is a node that has no children
+ public Object[] getChildren() {
+ return null;
+ }
+ public boolean hasChildren() {
+ return false;
+ }
+
+
+ /**
+ * @return if the column is nullable (can have nulls). Values as constants in ResultSetMetaData
+ */
+ public boolean getIsNullable() {
+ String result = matrix.get("IS_NULLABLE", 0); //$NON-NLS-1$
+ if (result != null && result == "YES") return true; //$NON-NLS-1$
+ else return false;
+ }
+
+ /**
+ * @return the order of the column in the primary key of the table
+ * (0 is is not part of it)
+ */
+ public int getPrimaryKeyOrder() {
+ return primaryKeyOrder;
+ }
+ /**
+ * @param i : The order of the column in the primary key of the table
+ * (0 if not part of it)
+ */
+ public void setPrimaryKeyOrder(int i) {
+ primaryKeyOrder = i;
+ }
+
+ /**
+ * @return the name of the column
+ */
+ public String getName() {
+ return matrix.get("COLUMN_NAME", 0); //$NON-NLS-1$
+ }
+
+ /**
+ * @return the precision of the column (digits left of the digital point)
+ */
+ public int getPrecision() {
+ return getDisplaySize();
+ }
+
+ /**
+ * @return the scale of the column (digits right of the digital point)
+ */
+ public int getScale() {
+ String result = matrix.get("DECIMAL_DIGITS", 0); //$NON-NLS-1$
+ if (result == null) return 0;
+ else return Integer.parseInt(result);
+ }
+
+ /**
+ * @return the type of the column (as a string)
+ */
+ public String getTypeName() {
+ return matrix.get("TYPE_NAME", 0); //$NON-NLS-1$
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ String sDesc = getName() + " " + getTypeName(); //$NON-NLS-1$
+ if (isNumeric())
+ {
+ if (getPrecision() > 0 || getScale() > 0) sDesc += "(" + Integer.toString(getPrecision()); //$NON-NLS-1$
+ if (getScale() > 0) sDesc += "," + Integer.toString(getScale()); //$NON-NLS-1$
+ if (getPrecision() > 0 || getScale() > 0) sDesc += ")"; //$NON-NLS-1$
+ } else
+ {
+ if (getDisplaySize() > 0) sDesc += "(" + Integer.toString(getDisplaySize()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return sDesc;
+ }
+
+ /**
+ * @return an Image object to appear in the view
+ * @throws MalformedURLException
+ */
+ public Image getImage() throws MalformedURLException {
+ // We'll return an icon if it's part of the primary key
+ if (getPrimaryKeyOrder() > 0) {
+ URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
+ URL url = new URL(installURL, "icons/key.gif"); //$NON-NLS-1$
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
+ return descriptor.createImage();
+ } else
+ return null;
+ }
+ public boolean isReal() {
+ int type = getType();
+ return SQLHelper.isReal(type);
+ }
+
+ public boolean isNumeric() {
+ int type = getType();
+ return SQLHelper.isNumeric(type);
+ }
+
+ /**
+ * @return the type of the column, as a numeric constant definde in java.sql.
+ */
+ public int getType() {
+ String result = matrix.get("DATA_TYPE", 0); //$NON-NLS-1$
+ int type = -1;
+ if (result != null) type = Integer.parseInt(result);
+ return type;
+ }
+
+ public String getTable(){
+ return matrix.get("TABLE_NAME", 0); //$NON-NLS-1$
+ }
+
+ /**
+ * @return
+ */
+ public Object getParent() {
+ return parent;
+ }
+
+ /**
+ * @param node
+ */
+ public void setParent(TreeNode node) {
+ parent = node;
+ }
+
+ /* (non-Javadoc)
+ * @see net.sourceforge.phpdt.view.bookmark.TreeNode#getMetaData()
+ */
+ public ObjectMetaData getMetaData() {
+ return null;
+ }
+ /**
+ * @return a Vector of ColumnMetaData objects representing all the columns of
+ * the Object.
+ */
+ public static Vector getColumnsMetaData(ObjectMetaData metadata, TreeNode node)
+ {
+ StringMatrix columns = metadata.getColumns();
+ Vector ret = new Vector(columns.size(),1);
+ for (int i = 0; i< columns.size(); i++){
+ ColumnMetaData columnMD = new ColumnMetaData(columns.rowMatrix(i), node);
+ columnMD.setPrimaryKeyOrder(metadata.getPrimaryKeyOrder(columnMD.getName()));
+ ret.add(columnMD);
+ }
+
+ return ret;
+
+ }
+
+}
--- /dev/null
+/*
+ * Created on 27/06/2003
+ *
+ */
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Vector;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+
+/**
+ * GroupNode represents a level of grouping in the BookmarkView hierarchy
+ * It will have categories like "TABLE", "VIEW" and so on, usually gotten from
+ * the JDBC driver.
+ * @author panic
+ *
+ */
+public class GroupNode implements TreeNode, Comparable {
+ private BookmarkNode parent = null;
+ private Vector children = new Vector();
+ private String name = null;
+ private int size = -1;
+
+ public GroupNode(BookmarkNode parent, String name) {
+ this.parent = parent;
+ this.name = name;
+ }
+ public ObjectMetaData getMetaData() {
+ return null; //no metadata
+ }
+
+ public boolean hasChildren() {
+ if (children != null && children.size() > 0) {
+ return true;
+ }
+ return false;
+ }
+ public Object[] getChildren() {
+ return children.toArray();
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public void addChild(Object child)
+ {
+ if (!(child instanceof TreeNode)) return;
+ if (name == "TABLE" && !(child instanceof TableNode)) return;
+ if (name == "VIEW" && !(child instanceof ViewNode)) return;
+ if (name == "SEQUENCE" && !(child instanceof SequenceNode)) return;
+ children.add(child);
+ Collections.sort(children);
+ }
+
+ public int compareTo(Object o) {
+ if (o instanceof GroupNode) {
+ GroupNode node = (GroupNode) o;
+ return name.compareTo(node.getName());
+ }
+ return 0;
+ }
+ /**
+ * @return an Image object to appear in the view
+ * @throws MalformedURLException
+ */
+ public Image getImage() throws MalformedURLException {
+ // We'll return an icon if it's part of the primary key
+ URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
+ URL url = null;
+ if (name == "TABLE") {
+ url = new URL(installURL, "icons/greentable.gif"); //$NON-NLS-1$
+ } else if (name == "VIEW") {
+ url = new URL(installURL, "icons/view.gif"); //$NON-NLS-1$
+ } else if (name == "SEQUENCE") {
+ url = new URL(installURL, "icons/sequence.gif"); //$NON-NLS-1$
+ }
+
+ if (url != null) {
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
+ return descriptor.createImage();
+ } else
+ return 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;
+
+import org.apache.crimson.tree.XmlDocument;
+import org.w3c.dom.Element;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.sql.metadata.MetaDataXMLInterface;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+
+/**
+ * Defines a node for the Subset. It contains an editable ObjectMetaData
+ * where you can erase columns you are not interested in.
+ * @author jparrai
+ *
+ */
+public class ObjectNode implements TreeNode, Comparable {
+ private SubsetNode parent = null;
+ private String bookmark = null;
+ private String name = null;
+ private ObjectMetaData metadata = null;
+ private int size = -1;
+ private int order = 0;
+
+ public ObjectNode(SubsetNode parent, ObjectMetaData metadata, String bookmark, String name) {
+ this.parent = parent;
+ this.bookmark = bookmark;
+ this.metadata = metadata;
+ this.name = name;
+ }
+
+ public ObjectNode(){
+ }
+
+ /* (non-Javadoc)
+ * @see net.sourceforge.phpdt.view.bookmark.TreeNode#getChildren()
+ * We consider the columns of the metadata to be the children.
+ */
+ public Object[] getChildren() {
+ if (metadata != null && ColumnMetaData.getColumnsMetaData(metadata, this) != null) {
+ return ColumnMetaData.getColumnsMetaData(metadata, this).toArray();
+ } else {
+ return Root.EMPTY_ARRAY;
+ }
+ }
+
+ public Object getParent() {
+ return parent;
+ }
+
+ public boolean hasChildren() {
+ if (metadata == null) return false;
+ return (ColumnMetaData.getColumnsMetaData(metadata, this) != null &&
+ ColumnMetaData.getColumnsMetaData(metadata, this).size() > 0);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public int compareTo(Object o) {
+ if (o instanceof ObjectNode) {
+ ObjectNode node = (ObjectNode) o;
+ if (node.getOrder() > getOrder()) return -1;
+ if (node.getOrder() < getOrder()) return 1;
+ // If the order is the same, we use alphabetical order
+ return name.compareTo(node.getName());
+ } else throw new ClassCastException();
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public void setObjectMetadata(ObjectMetaData metadata) {
+ this.metadata = metadata;
+ }
+ /**
+ * @return
+ */
+ public ObjectMetaData getMetaData() {
+ return metadata;
+ }
+
+ /**
+ * @return The order of this ObjectNode inside the SubsetNode
+ */
+ public int getOrder() {
+ return order;
+ }
+ /**
+ * Sets an ordering (inside the SubsetNode) to the ObjectNode
+ * @param i
+ */
+ public void setOrder(int i) {
+ order = i;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ObjectNode)) return false;
+ return (getName().equals(((ObjectNode) obj).getName()));
+ }
+
+ /**
+ * Imports one ObjectNode from an XMLDocument. There must be a tag for the Table Name, another for the Bookmark
+ * name and other for the metadata. The complement function is exportXML()
+ * @param root Document to get the data from
+ * @param parent The SubsetNode to which to add the new ObjectNode
+ * @return The newly created ObjectNode, or null if some error.
+ */
+ public static ObjectNode importXML(Element root, SubsetNode parent){
+ // Get the name tag value into objName
+ String objName = MetaDataXMLInterface.getElementText(root, Messages.getString("ExportXMLAction.TableName")); //$NON-NLS-1$
+ if (objName == "") return null; //$NON-NLS-1$
+ // Get the bookmark tag value into objName
+ String bookmarkName = MetaDataXMLInterface.getElementText(root, Messages.getString("ExportXMLAction.BookmarkName")); //$NON-NLS-1$
+ if (bookmarkName == "") return null; //$NON-NLS-1$
+ ObjectMetaData metadata = new ObjectMetaData();
+ // The rest of the tags go to be the metadata
+ MetaDataXMLInterface.xmlToMetaData(metadata, root);
+ // We can finally create the new ObjectNode with the collected data
+ ObjectNode objectNode = new ObjectNode(parent, metadata, bookmarkName, objName);
+ return objectNode;
+ }
+
+ /**
+ * Exports an ObjectNode to an XMLDocument. The complement function is importXML()
+ * @param root Document to write the XML tags to
+ */
+ public void exportXML(Element root){
+ XmlDocument doc = (XmlDocument) root.getOwnerDocument();
+ Element sub = (Element) root.appendChild(doc.createElement(Messages.getString("ExportXMLAction.Table"))); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(sub,Messages.getString("ExportXMLAction.TableName"), getName()); //$NON-NLS-1$
+ MetaDataXMLInterface.createElementText(sub,Messages.getString("ExportXMLAction.BookmarkName"), bookmark); //$NON-NLS-1$
+ if (this.metadata != null)
+ MetaDataXMLInterface.metaDataToXML(this.metadata, doc, sub);
+ }
+
+ /**
+ * @return The name of the Bookmark associated with that ObjectNode
+ */
+ public String getBookmark() {
+ return bookmark;
+ }
+
+ /**
+ * Generates a query with all the columns in the metadata of the ObjectNode.
+ * "SELECT *" would not be valid because you can have less columns in the ObjectNode than in the table or view.
+ * @return String with the Query
+ */
+ public String getQuery() {
+ String result = new String(""); //$NON-NLS-1$
+ result = "SELECT " + metadata.getColumnsString() + " FROM " + getName(); //$NON-NLS-1$ //$NON-NLS-2$
+ return result;
+ }
+
+
+}
package net.sourceforge.phpdt.sql.view.bookmark;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+
/**
* @author root
*
return EMPTY_ARRAY;
}
+ public ObjectMetaData getMetaData() {
+ return null; //no metadata implementation for now
+ }
+
/**
* @see net.sourceforge.phpdt.sql.view.bookmark.TreeNode#getParent()
*/
public boolean hasChildren() {
return false;
}
-
+
+ public String getName() {
+ return "phpeclipsesql_root"; //$NON-NLS-1$
+ }
}
package net.sourceforge.phpdt.sql.view.bookmark;
+import java.net.MalformedURLException;
+
+import org.eclipse.swt.graphics.Image;
+
+import net.sourceforge.phpdt.sql.model.Sequence;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+
public class SequenceNode implements TreeNode, Comparable {
- private BookmarkNode parent;
- private String name;
+ private GroupNode parent;
+ private Sequence sequence;
- public SequenceNode(BookmarkNode parent, String seqName) {
+ public SequenceNode(GroupNode parent, Sequence sequence) {
this.parent = parent;
- this.name = seqName;
+ this.sequence = sequence;
}
+ public ObjectMetaData getMetaData() {
+ return null; //no metadata implementation for now
+ }
+
public Object[] getChildren() {
return Root.EMPTY_ARRAY;
}
}
public String getName() {
- return name;
+ return this.sequence.getQualifiedName();
}
public String toString() {
- return name;
+ return getName();
}
public int compareTo(Object o) {
if (o instanceof SequenceNode) {
SequenceNode node = (SequenceNode) o;
- return name.compareTo(node.getName());
+ return getName().compareTo(node.getName());
} else if (o instanceof TreeNode || o instanceof ViewNode) {
return 1;
}
return 0;
}
+ /**
+ * @return an Image object to appear in the view
+ * @throws MalformedURLException
+ */
+ public Image getImage() throws MalformedURLException {
+ if (parent instanceof GroupNode){
+ GroupNode group = (GroupNode) parent;
+ return group.getImage();
+ } else
+ return null;
+ }
+
+ /**
+ * @return the associated BookmarkNode, by navigating upwards in the tree
+ */
+ public BookmarkNode getBookmark() {
+ TreeNode node = parent;
+ while (!( node instanceof BookmarkNode))
+ {
+ node = (TreeNode) node.getParent();
+ }
+ return (BookmarkNode) node;
+ }
+
}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.util.Vector;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.sql.metadata.MetaDataXMLInterface;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+
+public class SubsetContentProvider implements ITreeContentProvider {
+ private Vector subsets = new Vector();
+ private static SubsetContentProvider instance = null;
+ private boolean hasChanged = false;
+
+ /**
+ * Singleton accessor
+ */
+ public static synchronized SubsetContentProvider getInstance() {
+ if (instance == null) {
+ instance = new SubsetContentProvider();
+ }
+ return instance;
+ }
+
+ private SubsetContentProvider() {
+ }
+
+ public void exportXML(Element root) {
+ System.out.println("Subsets: Saving to Element"); //$NON-NLS-1$
+ Element subsetRoot = MetaDataXMLInterface.createElementText(root,Messages.getString("ExportXMLAction.Subsets"), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < subsets.size(); i++) {
+ SubsetNode current = (SubsetNode) subsets.get(i);
+ current.exportXML(subsetRoot);
+ }
+ }
+
+ /**
+ * Imports the data from an XML file to the tree. Does not set the tree to
+ * changed because it's usually invoked from the initial import routine.
+ * @param root
+ */
+ public void importXML(Element root){
+ System.out.println("Bookmarks: Loading from Element"); //$NON-NLS-1$
+ Vector newSubsets = new Vector();
+ NodeList nodes = root.getElementsByTagName(Messages.getString("ExportXMLAction.Subset")); //$NON-NLS-1$
+ for (int i = 0; i < nodes.getLength(); i++) {
+ SubsetNode subset = new SubsetNode();
+ Element node = (Element) nodes.item(i);
+ subset.importXML(node,true);
+ newSubsets.add(subset);
+ }
+ subsets = newSubsets;
+ }
+
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement.equals(Root.ROOT)) {
+ return subsets.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(SubsetNode b, Vector tables) {
+ b.setChildren(tables);
+ }
+
+ public void addSubset(SubsetNode b) {
+ hasChanged = true;
+ if (!subsets.contains(b)) {
+ subsets.addElement(b);
+ }
+ }
+ public void removeSubset(SubsetNode b) {
+ hasChanged = true;
+ if (subsets.contains(b)) {
+ subsets.removeElement(b);
+ }
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean hasChanged() {
+ return hasChanged;
+ }
+
+ public int getSize() {
+ return subsets.size();
+ }
+
+ /**
+ * @param b
+ */
+ public void setHasChanged(boolean b) {
+ hasChanged = b;
+ }
+
+ /**
+ * @param column
+ */
+ public void deleteColumn(ColumnMetaData column) {
+ TreeNode node = (TreeNode) column.getParent();
+ ObjectMetaData metadata = node.getMetaData();
+ if (metadata == null) return;
+ metadata.dropColumn(column.getName());
+ setHasChanged(true);
+
+ }
+
+ /**
+ * @param object
+ */
+ public void deleteObject(ObjectNode object) {
+ SubsetNode node = (SubsetNode) object.getParent();
+ if (!(node instanceof SubsetNode)) return;
+ node.remove(object);
+ setHasChanged(true);
+
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.sql.view.bookmark;
+
+import java.util.Collections;
+import java.util.Vector;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.sql.metadata.MetaDataXMLInterface;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+
+public class SubsetNode implements TreeNode {
+ private String name = null;
+ private Vector children = new Vector();
+
+ public SubsetNode(SubsetNode param) {
+ name = param.name;
+ children.addAll(param.children);
+ }
+
+
+ public ObjectMetaData getMetaData() {
+ return null; //no metadata implementation for now
+ }
+ public SubsetNode() {
+ }
+
+ public SubsetNode(String name) {
+ this.name = name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName(){
+ return name;
+ }
+
+ 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 ObjectNode ) {
+ valid = true;
+ }
+ if (!valid) {
+ throw new RuntimeException("Invalid SubsetNode child: " + child.getClass().getName()); //$NON-NLS-1$
+ }
+ }
+
+
+ /**
+ * Finds a child of the SubsetNode with the said name
+ * @param name
+ * @return the TreeNode found. null if none
+ */
+ public TreeNode find(String name){
+ for (int i = 0; i < children.size(); i++) {
+ Object obj = children.elementAt(i);
+ if (obj instanceof TreeNode){
+ TreeNode node = (TreeNode) obj;
+ if (name.equals(node.getName())) return node;
+ }
+ }
+ return null;
+ }
+
+ public boolean add(ObjectNode object){
+ if (children.indexOf(object) >= 0) return false;
+ children.add(object);
+ return true;
+ }
+
+ public boolean addReplace(ObjectNode object){
+ children.remove(object);
+ return add(object);
+ }
+
+ public boolean remove(ObjectNode object){
+ return children.remove(object);
+ }
+
+ public void exportXML(Element root) {
+ Element sub = MetaDataXMLInterface.createElementText(root,Messages.getString("ExportXMLAction.Subset"), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ MetaDataXMLInterface.createElementText(sub,Messages.getString("ExportXMLAction.SubsetName"), getName()); //$NON-NLS-1$
+ for (int i = 0; i < children.size(); i++) {
+ Object obj = children.elementAt(i);
+ if (obj instanceof ObjectNode){
+ ((ObjectNode) obj).exportXML(sub);
+ }
+ }
+
+ }
+
+ /**
+ * Imports a set of XML tags (parsed into a XMLDocument) into a Subset
+ * @param root Document to get the data from
+ * @param replace True if you want to replace already-existing elements with the same name, false if not
+ */
+ public void importXML(Element root, boolean replace) {
+ if (replace) {
+ String name = MetaDataXMLInterface.getElementText(root, Messages.getString("ExportXMLAction.SubsetName")); //$NON-NLS-1$
+ if (name == "") return; //$NON-NLS-1$
+ setName(name);
+ }
+ importElementXML(root, replace, Messages.getString("ExportXMLAction.Table")); //$NON-NLS-1$
+ importElementXML(root, replace, Messages.getString("ExportXMLAction.View")); //$NON-NLS-1$
+
+ }
+
+
+ /**
+ *
+ * Imports one type of element from a XMLDocument (possibly a part of one) into a Subset
+ * @param root Document to get the data from
+ * @param replace True if you want to replace already-existing elements with the same name, false if not
+ * @param type The type of element to import, has to correspond with the XML tag
+ */
+ private void importElementXML(Element root, boolean replace, String type) {
+ // We get all the tags named as the type
+ NodeList tables = root.getElementsByTagName(type);
+ for (int i = 0; i < tables.getLength(); i++) {
+ Element table = (Element) tables.item(i);
+ ObjectNode objectNode = ObjectNode.importXML(table, this);
+ if (replace)addReplace(objectNode);
+ else add(objectNode);
+ }
+ }
+
+}
package net.sourceforge.phpdt.sql.view.bookmark;
-import java.util.Vector;
+import java.net.MalformedURLException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.eclipse.swt.graphics.Image;
+
+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.model.Table;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
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;
- }
+ private ObjectMetaData metadata = null;
+ private TreeNode parent = null;
+ private Table table;
+ private boolean sizeVisible;
+
+ public TableNode(TreeNode parent, boolean sizeVisible, Table table) {
+ this.parent = parent;
+ this.table = table;
+ this.sizeVisible = sizeVisible;
+ }
public Object[] getChildren() {
- if (metadata != null) {
- return metadata.toArray();
+ obtainMetaData();
+ if (metadata != null && ColumnMetaData.getColumnsMetaData(metadata, this) != null) {
+ return ColumnMetaData.getColumnsMetaData(metadata, this).toArray();
} else {
return Root.EMPTY_ARRAY;
}
}
+ private void obtainMetaData() {
+ Connection con = getBookmark().getConnection();
+ if (metadata == null) try {
+ metadata = MultiSQLServer.getInstance().getObjectMetadata(con, this);
+ } catch (SQLException e) {
+ metadata = null;
+ e.printStackTrace();
+ }
+ }
+
public Object getParent() {
return parent;
}
+ public DatabaseAdapter getAdapter() throws NoSuchAdapterException {
+ return AdapterFactory.getInstance().getAdapter(getBookmark().getType());
+ }
+
public boolean hasChildren() {
- return (metadata != null) && (metadata.size() > 0);
+ // If it has no metadata set, we suppose it can have some, and return true anyway
+ if (metadata == null) return true;
+ return (ColumnMetaData.getColumnsMetaData(metadata, this) != null &&
+ ColumnMetaData.getColumnsMetaData(metadata, this).size() > 0);
}
public String getName() {
- return name;
+ return this.table.getQualifiedName();
}
public String toString() {
- return name;
+ return getName();
}
public int compareTo(Object o) {
if (o instanceof TableNode) {
TableNode node = (TableNode) o;
- return name.compareTo(node.getName());
+ return getName().compareTo(node.getName());
} else if (o instanceof ViewNode ||
o instanceof SequenceNode) {
return -1;
}
public int getSize() {
- return size;
+ return this.table.getSize();
}
- public void setSize(int size) {
- this.size = size;
+ public void setObjectMetadata(ObjectMetaData metadata) {
+ this.metadata = metadata;
+ }
+ /**
+ * @return
+ */
+ public ObjectMetaData getMetaData() {
+ if (metadata == null) obtainMetaData();
+ return metadata;
+ }
+ /**
+ * @return an Image object to appear in the view
+ * @throws MalformedURLException
+ */
+ public Image getImage() throws MalformedURLException {
+ if (parent instanceof GroupNode){
+ GroupNode group = (GroupNode) parent;
+ return group.getImage();
+ } else
+ return null;
}
- public void setMetadata(Vector metadata) {
- this.metadata = metadata;
+ /**
+ * @return the associated BookmarkNode, by navigating upwards in the tree
+ */
+ public BookmarkNode getBookmark() {
+ TreeNode node = parent;
+ while (!( node instanceof BookmarkNode))
+ {
+ node = (TreeNode) node.getParent();
+ }
+ return (BookmarkNode) node;
}
+ /**
+ * @return
+ */
+ public boolean isSizeVisible() {
+ return this.sizeVisible;
+ }
+
+ public Table getTable() {
+ return this.table;
+ }
}
package net.sourceforge.phpdt.sql.view.bookmark;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
/**
* @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.
+ * Interface for all nodes of the internal tree of data
*/
public interface TreeNode {
public Object[] getChildren();
public Object getParent();
public boolean hasChildren();
+ public String getName();
+ public ObjectMetaData getMetaData();
+
}
package net.sourceforge.phpdt.sql.view.bookmark;
-import java.util.Vector;
+import java.net.MalformedURLException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.eclipse.swt.graphics.Image;
+
+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.model.View;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
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;
- }
+ private ObjectMetaData metadata = null;
+ private TreeNode parent;
+ private View view;
+ private boolean sizeVisible;
+
+ public ViewNode(TreeNode parent, boolean sizeVisible, View view) {
+ this.parent = parent;
+ this.view = view;
+ }
public Object getParent() {
return parent;
}
+ public DatabaseAdapter getAdapter() throws NoSuchAdapterException {
+ return AdapterFactory.getInstance().getAdapter(getBookmark().getType());
+ }
+
public String getName() {
- return name;
+ return this.view.getQualifiedName();
}
public String toString() {
- return name;
+ return getName();
}
public int compareTo(Object o) {
if (o instanceof ViewNode) {
ViewNode node = (ViewNode) o;
- return name.compareTo(node.getName());
+ return getName().compareTo(node.getName());
} else if (o instanceof SequenceNode) {
return -1;
} else if (o instanceof TreeNode) {
}
public int getSize() {
- return size;
- }
-
- public void setSize(int size) {
- this.size = size;
+ return this.view.getSize();
}
public boolean hasChildren() {
- return (metadata != null) && (metadata.size() > 0);
+ // If it has no metadata set, we suppose it can have some, and return true
+ if (metadata == null) return true;
+ return (ColumnMetaData.getColumnsMetaData(metadata, this) != null &&
+ ColumnMetaData.getColumnsMetaData(metadata, this).size() > 0);
}
public Object[] getChildren() {
- if (metadata != null) {
- return metadata.toArray();
+ obtainMetaData();
+ if (metadata != null && ColumnMetaData.getColumnsMetaData(metadata, this) != null) {
+ return ColumnMetaData.getColumnsMetaData(metadata, this).toArray();
} else {
return Root.EMPTY_ARRAY;
}
}
- public void setMetadata(Vector metadata) {
+ public void setObjectMetadata(ObjectMetaData metadata) {
this.metadata = metadata;
}
+
+ /**
+ * @return
+ */
+ public ObjectMetaData getMetaData() {
+ if (metadata == null) obtainMetaData();
+ return metadata;
+ }
+
+ /**
+ * Checks if there is metadata present, and if not, tries to get it
+ */
+ private void obtainMetaData() {
+ Connection con = getBookmark().getConnection();
+ if (metadata == null) try {
+ metadata = MultiSQLServer.getInstance().getObjectMetadata(con, this);
+ } catch (SQLException e) {
+ metadata = null;
+ e.printStackTrace();
+ }
+ }
+ /**
+ * @return an Image object to appear in the view
+ * @throws MalformedURLException
+ */
+ public Image getImage() throws MalformedURLException {
+ if (parent instanceof GroupNode){
+ GroupNode group = (GroupNode) parent;
+ return group.getImage();
+ } else
+ return null;
+ }
+
+ /**
+ * @return the associated BookmarkNode, by navigating upwards in the tree
+ */
+ public BookmarkNode getBookmark() {
+ TreeNode node = parent;
+ while (!( node instanceof BookmarkNode))
+ {
+ node = (TreeNode) node.getParent();
+ }
+ return (BookmarkNode) node;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isSizeVisible() {
+ return sizeVisible;
+ }
+
}
package net.sourceforge.phpdt.sql.view.query;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
import net.sourceforge.phpdt.sql.view.bookmark.Root;
import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
trimmed = true;
}
if (trimmed) {
- query += "...->";
+ query += "...->"; //$NON-NLS-1$
}
name = query;
}
+
+ public ObjectMetaData getMetaData() {
+ return null; //no metadata implementation for now
+ }
+
public String getName() {
return name;
}
import java.util.Vector;
-import net.sourceforge.phpdt.sql.IConstants;
+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.Messages;
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;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-
-public class TableAdapter implements IConstants {
- public static final String DEFAULT = "";
- public static final String UTF_8 = "UTF-8";
- public static final String UTF_16 = "UTF-16";
+public class TableAdapter {
+ public static final String DEFAULT = ""; //$NON-NLS-1$
+ public static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
+ public static final String UTF_16 = "UTF-16"; //$NON-NLS-1$
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 BookmarkNode bookmark = null;
private String table;
private String query;
- private String encoding = "";
+ private String encoding = ""; //$NON-NLS-1$
- private TableAdapter() {
+ private TableAdapter(BookmarkNode bookmark) {
+ this.bookmark = bookmark;
}
public void fullMode() {
offset = 1;
offset = 1;
pageSize = DefaultSizes.PAGE_SIZE;
}
- public static TableAdapter createFromQuery(SQLResults results) {
- TableAdapter retVal = new TableAdapter();
+ public static TableAdapter createFromQuery(BookmarkNode bookmark, SQLResults results) {
+ TableAdapter retVal = new TableAdapter(bookmark);
retVal.setQuery(results.getQuery());
retVal.setData(results);
return retVal;
}
- public static TableAdapter createFromTable(String table) {
- TableAdapter retVal = new TableAdapter();
+ public static TableAdapter createFromTable(BookmarkNode bookmark, String table) {
+ TableAdapter retVal = new TableAdapter(bookmark);
retVal.setTable(table);
return retVal;
}
private void loadSize() {
if (table != null) {
- totalSize = helper.getSize(getTableCountQuery());
+ totalSize = SQLHelper.getSize(bookmark, getTableCountQuery());
}
}
public int getStartIndex() {
return false;
}
public String getTableCountQuery() {
- if (table != null) {
- Bookmark current = MultiSQLServer.getInstance().getConnected();
- return SQLHelper.getFullTableName(current, table);
+ if (table != null && bookmark != null) {
+ return SQLHelper.getFullTableName(bookmark, 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());
- }
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+ if (adapter == null) throw new RuntimeException();
+ else return adapter.getShowTableQuery(DatabaseInfo.create(bookmark), table) + extra.toString();
}
return query;
}
}
}
String query = getQuery();
- if (DEBUG) {
- System.out.println(offset + " to " + (offset + pageSize - 1));
- }
- SQLResults results = helper.getResults(query, offset, offset + pageSize - 1, maxColumnSize, encoding);
+ System.out.println(offset + Messages.getString("TableAdapter.to") + (offset + pageSize - 1)); //$NON-NLS-1$
+ SQLResults results = SQLHelper.getResults(bookmark, query, offset, offset + pageSize - 1, maxColumnSize, encoding);
setData(results);
}
public void resetOffset() {
this.encoding = encoding;
}
public String getStatusString() {
- String status = getStartIndex() + " to " + getEndIndex() + " of " +
+ String status = getStartIndex() + Messages.getString("TableAdapter.to") + getEndIndex() + Messages.getString("TableAdapter.of") + //$NON-NLS-1$ //$NON-NLS-2$
getTotalSize();
if (!encoding.equals(DEFAULT)) {
- status += " (" + encoding + ")";
+ status += " (" + encoding + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
String filterText = extra.toString();
- if (!filterText.equals("")) {
- status += " (" + filterText + ")";
+ if (!filterText.equals("")) { //$NON-NLS-1$
+ status += " (" + filterText + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
if (pageSize == Integer.MAX_VALUE) {
- status += " (FULL)";
+ status += Messages.getString("TableAdapter.full"); //$NON-NLS-1$
}
return status;
}
+ /**
+ * @return
+ */
+ public BookmarkNode getBookmark() {
+ return bookmark;
+ }
+
}
\ No newline at end of file
package net.sourceforge.phpdt.sql.wizards;
-import net.sourceforge.phpdt.sql.IConstants;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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;
-
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-public class BookmarkWizard extends Wizard implements IConstants {
- BookmarkPage mainPage;
-
- private BookmarkNode current;
-
- public void init(BookmarkNode selection) {
- if (DEBUG) {
- System.out.println("Initing workbench");
- }
- this.current = selection;
- setWindowTitle("New Bookmark");
- }
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+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 void init() {
- if (DEBUG) {
- System.out.println("Initing workbench");
- }
- current = null;
- setWindowTitle("New Bookmark");
- }
+public class BookmarkWizard extends Wizard {
+ BookmarkPage mainPage;
- public boolean performFinish() {
- if (DEBUG) {
- System.out.println("perform finish workbench");
- }
- mainPage.performFinish();
- return true;
- }
+ private BookmarkNode current;
- public void addPages() {
- if (DEBUG) {
- System.out.println("adding pages");
- }
- if (current != null) {
- mainPage = new BookmarkPage("Testing...", current);
- } else {
- mainPage = new BookmarkPage("Testing...");
- }
- addPage(mainPage);
- if (DEBUG) {
- System.out.println("adding pages");
- }
- }
+ public void init(BookmarkNode selection) {
+ System.out.println("Initing workbench"); //$NON-NLS-1$
+ this.current = selection;
+ setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
+ }
+ public void init() {
+ System.out.println("Initing workbench"); //$NON-NLS-1$
+ current = null;
+ setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
+ }
+ public boolean performFinish() {
+ System.out.println("perform finish workbench"); //$NON-NLS-1$
+ mainPage.performFinish();
+ return true;
+ }
+ public void addPages() {
+ System.out.println("adding pages"); //$NON-NLS-1$
+ if (current != null) {
+ mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing"), current); //$NON-NLS-1$
+ } else {
+ mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
+ }
+ addPage(mainPage);
+ System.out.println("adding pages"); //$NON-NLS-1$
+ }
}
-class BookmarkPage extends WizardPage implements IConstants {
- 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;
+class BookmarkPage extends WizardPage {
+ public static final String ADD = "ADD"; //$NON-NLS-1$
+ String action = ADD;
+ Text name;
+ Text username;
+ Text password;
+ Text schema;
+ Text connect;
+ Text driver;
+ //List driverList;
+ Combo type;
+ Text driverFile;
+ private IPreferenceStore fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
- FileDialog dialog;
+ BookmarkNode initialData = null;
- 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;
- }
+ FileDialog dialog;
- public void createControl(Composite parent) {
- if (DEBUG) {
- 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;
+ 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;
+ }
- 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);
+ public void createControl(Composite parent) {
+ System.out.println("page create control"); //$NON-NLS-1$
+ dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ dialog.setFilterNames(new String[]{Messages.getString("BookmarkWizard.JarFiles"),Messages.getString("BookmarkWizard.ZipFiles"), Messages.getString("BookmarkWizard.AllFiles")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+ layout.verticalSpacing = 9;
- label = 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 label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString("BookmarkWizard.BookmarkNameAst")); //$NON-NLS-1$
+ name = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ name.setLayoutData(fullHorizontal);
- label = new Label(container, SWT.NULL);
- label.setText("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(Messages.getString("BookmarkWizard.UsernameAst")); //$NON-NLS-1$
+ username = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ username.setLayoutData(fullHorizontal);
- label = new Label(container, SWT.NULL);
- label.setText("*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(Messages.getString("BookmarkWizard.PasswordAst")); //$NON-NLS-1$
+ password = new Text(container, SWT.BORDER | SWT.SINGLE);
+ password.setEchoChar('*');
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ password.setLayoutData(fullHorizontal);
+
+ label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString("BookmarkWizard.Schema")); //$NON-NLS-1$
+ schema = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ schema.setLayoutData(fullHorizontal);
- label = new Label(container, SWT.NULL);
- label.setText("*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);
+ label.setText(Messages.getString("BookmarkWizard.ConnectAst")); //$NON-NLS-1$
+ connect = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ connect.setLayoutData(fullHorizontal);
- //label = new Label(container, SWT.NULL);
- //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(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
+ driver = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ driver.setLayoutData(fullHorizontal);
- label = new Label(container, SWT.NULL);
- label.setText("*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);
+ //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("*Driver Filename");
- driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
- fullHorizontal = new GridData();
- fullHorizontal.horizontalAlignment = GridData.FILL;
- driverFile.setLayoutData(fullHorizontal);
+ label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
+ type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
+ String driverNames[] = new String[drivers.length];
+ for (int i = 0; i < drivers.length; i++) {
+ driverNames[i] = drivers[i].getDisplayName();
+ }
+ type.setItems(driverNames);
+ type.select(0);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ type.setLayoutData(fullHorizontal);
- Button button = new Button(container, SWT.PUSH);
- button.setText("Browse...");
+ label = new Label(container, SWT.NULL);
+ label.setText(Messages.getString("BookmarkWizard.DriverFilenameAst")); //$NON-NLS-1$
+ driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
+ fullHorizontal = new GridData();
+ fullHorizontal.horizontalAlignment = GridData.FILL;
+ driverFile.setLayoutData(fullHorizontal);
- button.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();
- } else {
+ Button button = new Button(container, SWT.PUSH);
+ button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
+
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ 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();
+ }else {
- IPreferenceStore fStore =
- PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
- username.setText(fStore.getString("phpeclipse.sql.username.connect"));
- connect.setText(fStore.getString("phpeclipse.sql.connect.connect"));
- driver.setText(fStore.getString("phpeclipse.sql.driver.connect"));
- String typeData = fStore.getString("phpeclipse.sql.type.connect");
- int selectedIndex = 0;
- for (int i = 0; i < drivers.length; i++) {
- if (typeData.equals(drivers[i].getDisplayName())) {
- selectedIndex = i;
- }
- }
- type.select(selectedIndex);
- driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
- // updateDriverList();
- }
- setControl(container);
+ username.setText(fStore.getString("phpeclipse.sql.username.connect"));
+ connect.setText(fStore.getString("phpeclipse.sql.connect.connect"));
+ driver.setText(fStore.getString("phpeclipse.sql.driver.connect"));
+ String typeData = fStore.getString("phpeclipse.sql.type.connect");
+ int selectedIndex = 0;
+ for (int i = 0; i < drivers.length; i++) {
+ if (typeData.equals(drivers[i].getDisplayName())) {
+ selectedIndex = i;
+ }
+ }
+ type.select(selectedIndex);
+ driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
+ }
+ 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);
- }
+ 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);
+
+ //PHP Specific section
+ fStore.putValue("phpeclipse.sql.username.connect", username.getText());
+ fStore.putValue("phpeclipse.sql.connect.connect", connect.getText());
+ fStore.putValue("phpeclipse.sql.driver.connect", driver.getText());
+ fStore.putValue("phpeclipse.sql.filename.connect",driverFile.getText());
+ }
}
\ No newline at end of file
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
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;
+ TableRow row;
+ String[] columnNames;
+ Text[] values;
+ Button[] whereValues;
+ Text query;
- public DeleteRowPage(String pageName) {
- super(pageName);
- }
+ public DeleteRowPage(String pageName) {
+ super(pageName);
+ }
+
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
- public void init(TableRow row, TableAdapter adapter) {
- this.row = row;
- }
+ public void createControl(Composite parent) {
+ System.out.println("page create control"); //$NON-NLS-1$
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 3;
- public void createControl(Composite parent) {
- if (DEBUG) {
- 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"); //$NON-NLS-1$
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null"); //$NON-NLS-1$
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null"); //$NON-NLS-1$
+ }
+ BookmarkNode bookmark = row.getBookmarkNode();
+ TreeNode node = bookmark.find(row.getTable());
+ ObjectMetaData metadata = null;
+ if (node != null) metadata = node.getMetaData();
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ values = new Text[row.getColumnCount()];
+ whereValues = new Button[row.getColumnCount()];
+ new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.ColumnName")); //$NON-NLS-1$
+ new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.Value")); //$NON-NLS-1$
+ new Label(container, SWT.NULL).setText(Messages.getString("DeleteRowPage.IncludeIn")); //$NON-NLS-1$
+ 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]);
- if (DEBUG) {
- if (row == null) {
- System.out.println("Row is null");
- }
+ values[i].addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ updateQuery();
+ }
+ });
+
+ whereValues[i] = new Button(container, SWT.CHECK);
+ whereValues[i].setText(Messages.getString("DeleteRowPage.WhereClause")); //$NON-NLS-1$
+ // we check if it's a primary key to select it in the WHERE clause
+ if (metadata != null && metadata.getPrimaryKeyOrder(columnNames[i]) > 0)
+ whereValues[i].setSelection(true);
+ else
+ whereValues[i].setSelection(false);
+ whereValues[i].addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ updateQuery();
+ }
+ });
+ }
+ query = new Text(container, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP);
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = layout.numColumns;
+ gridData.verticalSpan = 3;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ query.setLayoutData(gridData);
- 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();
- if (DEBUG) {
- 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() {
- if (DEBUG) {
- 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;
- }
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println(Messages.getString("DeleteRowPage.UpdatingQuery")); //$NON-NLS-1$
+ StringBuffer whereClause = new StringBuffer();
+ BookmarkNode bookmark = row.getBookmarkNode();
+ TreeNode node = bookmark.find(row.getTable());
+ ObjectMetaData metadata = null;
+ if (node != null) metadata = node.getMetaData();
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+
+ int numSelected = 0;
+ for (int i = 0; i < columnNames.length; i++) {
+ if (whereValues[i].getSelection()) {
+ if (numSelected > 0) whereClause.append(" AND "); //$NON-NLS-1$
+ numSelected++;
+ whereClause.append("("); //$NON-NLS-1$
+ whereClause.append(columnNames[i]);
+ whereClause.append(" = "); //$NON-NLS-1$
+ if (adapter != null && metadata != null)
+ whereClause.append(adapter.quote(values[i].getText(), metadata.getColumnType(columnNames[i])));
+ else
+ whereClause.append(values[i].getText());
+
+ whereClause.append(")"); //$NON-NLS-1$
+ }
+ }
+ String query = "DELETE FROM " + row.getTable(); //$NON-NLS-1$
+ if (numSelected > 0) {
+ query += " WHERE " + whereClause.toString(); //$NON-NLS-1$
+ }
+ if (numSelected > 0) {
+ setMessage(""); //$NON-NLS-1$
+ } else {
+ setMessage(Messages.getString("DeleteRowPage.WarningNoWhere")); //$NON-NLS-1$
+ }
+ this.query.setText(query);
+ }
+
+
+ public boolean performFinish() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ BookmarkView bookmarkView = BookmarkView.getInstance();
+ BookmarkNode bookmark = bookmarkView.getCurrentBookmark();
+ server.execute(bookmark.getConnection(), query.getText());
+ return true;
+ }
}
\ No newline at end of file
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
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);
- }
+ 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 init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
- public void createControl(Composite parent) {
- if (DEBUG) {
- 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;
+ public void createControl(Composite parent) {
+ System.out.println("page create control"); //$NON-NLS-1$
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
- if (DEBUG) {
- 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();
- if (DEBUG) {
- 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);
+ if (row == null) {
+ System.out.println("Row is null"); //$NON-NLS-1$
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null"); //$NON-NLS-1$
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null"); //$NON-NLS-1$
+ }
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ values = new Text[row.getColumnCount()];
+ new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.ColumnName")); //$NON-NLS-1$
+ new Label(container, SWT.NULL).setText(Messages.getString("InsertRowPage.Value")); //$NON-NLS-1$
+ 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);
+ //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 = layout.numColumns;
+ 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() {
- if (DEBUG) {
- 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;
- }
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating query"); //$NON-NLS-1$
+ StringBuffer valuesClause = new StringBuffer();
+ BookmarkNode bookmark = row.getBookmarkNode();
+ TreeNode node = bookmark.find(row.getTable());
+ ObjectMetaData metadata = null;
+ if (node != null) metadata = node.getMetaData();
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+
+ int numValues = 0;
+ for (int i = 0; i < columnNames.length; i++) {
+ String value = values[i].getText();
+ if (numValues > 0) valuesClause.append(", "); //$NON-NLS-1$
+ if (adapter != null && metadata != null && value != "") //$NON-NLS-1$
+ valuesClause.append(adapter.quote(value, metadata.getColumnType(columnNames[i])));
+ else
+ valuesClause.append(value);
+ numValues++;
+ }
+ String query = "INSERT INTO " + row.getTable(); //$NON-NLS-1$
+ query += " VALUES (" + valuesClause; //$NON-NLS-1$
+ query += " )"; //$NON-NLS-1$
+ this.query.setText(query);
+ }
+ public boolean performFinish() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ BookmarkView bookmarkView = BookmarkView.getInstance();
+ BookmarkNode bookmark = bookmarkView.getCurrentBookmark();
+ server.execute(bookmark.getConnection(), query.getText());
+ return true;
+ }
}
\ No newline at end of file
import java.text.MessageFormat;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.preference.IPreferenceStore;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
public class PHPDeleteRowPage extends WizardPage implements SQLPage {
- TableRow row;
- String[] columnNames;
- Text[] values;
- Button[] whereValues;
- Label query;
- IPreferenceStore fStore;
-
- public PHPDeleteRowPage(String pageName) {
- super(pageName);
- }
-
- public void init(TableRow row, TableAdapter adapter) {
- this.row = row;
- }
-
- public void createControl(Composite parent) {
- if (DEBUG) {
- System.out.println("page create control");
- }
- fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- int layoutColumns = 3;
- layout.numColumns = layoutColumns;
-
- if (DEBUG) {
- 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();
- if (DEBUG) {
- 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);
-
- if (data[i] == null || data[i].equals("")) {
- values[i].setText('$' + columnNames[i]);
- } else {
- 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() {
- if (DEBUG) {
- System.out.println("Updating delete query");
- }
- StringBuffer whereClause = new StringBuffer();
- int numSelected = 0;
- boolean first = false;
- for (int i = 0; i < columnNames.length; i++) {
- if (whereValues[i].getSelection()) {
- numSelected++;
- if (first) {
- whereClause.append(", ");
- }
-
- whereClause.append(columnNames[i]);
- whereClause.append(" = ");
- whereClause.append("'" + values[i].getText() + "'");
-
- first = true;
- }
- }
- // if (whereClause.length() > 1) {
- // whereClause.deleteCharAt(whereClause.length() - 1);
- // whereClause.deleteCharAt(whereClause.length() - 1);
- // }
-
-
- String[] arguments = { row.getTable(), whereClause.toString() };
- MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.delete.template"));
-
- String query = form.format(arguments);
-
-// String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
-// if (numSelected > 0) {
-// query += " WHERE " + whereClause.toString() + "\");";
-// } else {
-// query += "\");";
-// }
-
- 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() {
- PHPSourceConsole console = PHPSourceConsole.getInstance();
- console.clear();
- console.print(query.getText());
- return true;
- }
+ TableRow row;
+ String[] columnNames;
+ Text[] values;
+ Button[] whereValues;
+ Label query;
+ IPreferenceStore fStore;
+
+ public PHPDeleteRowPage(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");
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+ 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);
+
+ if (data[i] == null || data[i].equals("")) {
+ values[i].setText('$' + columnNames[i]);
+ } else {
+ 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 delete query");
+ StringBuffer whereClause = new StringBuffer();
+ int numSelected = 0;
+ boolean first = false;
+ for (int i = 0; i < columnNames.length; i++) {
+ if (whereValues[i].getSelection()) {
+ numSelected++;
+ if (first) {
+ whereClause.append(", ");
+ }
+
+ whereClause.append(columnNames[i]);
+ whereClause.append(" = ");
+ whereClause.append("'" + values[i].getText() + "'");
+
+ first = true;
+ }
+ }
+ // if (whereClause.length() > 1) {
+ // whereClause.deleteCharAt(whereClause.length() - 1);
+ // whereClause.deleteCharAt(whereClause.length() - 1);
+ // }
+
+ String[] arguments = { row.getTable(), whereClause.toString()};
+ MessageFormat form =
+ new MessageFormat(
+ fStore.getString("phpeclipse.sql.delete.template"));
+
+ String query = form.format(arguments);
+
+ // String query = "$results = mysql_query(\"DELETE FROM " + row.getTable();
+ // if (numSelected > 0) {
+ // query += " WHERE " + whereClause.toString() + "\");";
+ // } else {
+ // query += "\");";
+ // }
+
+ 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() {
+ PHPSourceConsole console = PHPSourceConsole.getInstance();
+ console.clear();
+ console.print(query.getText());
+ return true;
+ }
}
\ No newline at end of file
import java.text.MessageFormat;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.preference.IPreferenceStore;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
public class PHPInsertRowPage extends WizardPage implements SQLPage {
- TableRow row;
- String[] columnNames;
- Text[] values;
- Label query;
- private IPreferenceStore fStore;
-
- public PHPInsertRowPage(String pageName) {
- super(pageName);
- }
+ TableRow row;
+ String[] columnNames;
+ Text[] values;
+ Label query;
+ private IPreferenceStore fStore;
+
+ public PHPInsertRowPage(String pageName) {
+ super(pageName);
+ }
- public void init(TableRow row, TableAdapter adapter) {
- this.row = row;
- }
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
- public void createControl(Composite parent) {
- if (DEBUG) {
- System.out.println("page create control");
- }
- fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- int layoutColumns = 2;
- layout.numColumns = layoutColumns;
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 2;
+ layout.numColumns = layoutColumns;
- if (DEBUG) {
- 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();
- if (DEBUG) {
- 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);
+ 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);
+ //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();
+ setControl(container);
+ updateQuery();
- setPageComplete(true);
- }
- public void updateQuery() {
- if (DEBUG) {
- System.out.println("Updating insert query");
- }
- StringBuffer fieldClause = new StringBuffer();
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating insert query");
+ StringBuffer fieldClause = new StringBuffer();
- StringBuffer valuesClause = new StringBuffer();
- String text;
- boolean first = false;
- for (int i = 0; i < columnNames.length; i++) {
- text = values[i].getText();
- if (! text.equals("")) {
- if (first) {
- valuesClause.append(", ");
- fieldClause.append(", ");
- }
- valuesClause.append("'"+values[i].getText()+"'");
- fieldClause.append(columnNames[i]);
- first = true;
- }
- }
-// if (valuesClause.length() > 1) {
-// valuesClause.deleteCharAt(valuesClause.length() - 1);
-// valuesClause.deleteCharAt(valuesClause.length() - 1);
-// }
- String[] arguments = { row.getTable(), fieldClause.toString(), valuesClause.toString() };
- MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.insert.template"));
+ StringBuffer valuesClause = new StringBuffer();
+ String text;
+ boolean first = false;
+ for (int i = 0; i < columnNames.length; i++) {
+ text = values[i].getText();
+ if (!text.equals("")) {
+ if (first) {
+ valuesClause.append(", ");
+ fieldClause.append(", ");
+ }
+ valuesClause.append("'" + values[i].getText() + "'");
+ fieldClause.append(columnNames[i]);
+ first = true;
+ }
+ }
+ // if (valuesClause.length() > 1) {
+ // valuesClause.deleteCharAt(valuesClause.length() - 1);
+ // valuesClause.deleteCharAt(valuesClause.length() - 1);
+ // }
+ String[] arguments =
+ { row.getTable(), fieldClause.toString(), valuesClause.toString()};
+ MessageFormat form =
+ new MessageFormat(
+ fStore.getString("phpeclipse.sql.insert.template"));
- String query = form.format(arguments);
+ String query = form.format(arguments);
-// String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
-// query += fieldClause.toString() + ") ";
-// query += " VALUES (" + valuesClause.toString();
-// query += ")\");";
- this.query.setText(query);
- }
- public boolean performFinish() {
- PHPSourceConsole console = PHPSourceConsole.getInstance();
- console.clear();
- console.print(query.getText());
- return true;
- }
+ // String query = "$results = mysql_query(\"INSERT INTO " + row.getTable() + " (";
+ // query += fieldClause.toString() + ") ";
+ // query += " VALUES (" + valuesClause.toString();
+ // query += ")\");";
+ 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
import java.text.MessageFormat;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.preference.IPreferenceStore;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
public class PHPSelectRowPage extends WizardPage implements SQLPage {
- TableRow row;
- String[] columnNames;
- Text[] whereValues;
- // Text[] newValues;
- Button[] primaryKeys;
- Button[] setValues;
- Label query;
- IPreferenceStore fStore;
-
- public PHPSelectRowPage(String pageName) {
- super(pageName);
- }
-
- public void init(TableRow row, TableAdapter adapter) {
- this.row = row;
- }
-
- public void createControl(Composite parent) {
- if (DEBUG) {
- System.out.println("page create control");
- }
- Composite container = new Composite(parent, SWT.NULL);
- fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
-
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- int layoutColumns = 4;
- layout.numColumns = layoutColumns;
-
- if (DEBUG) {
- 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();
-
- if (DEBUG) {
- for (int i = 0; i < row.getColumnCount(); i++) {
- System.out.println("data = " + i + "=" + data[i]);
- System.out.println("column = " + i + "=" + columnNames[i]);
- }
- }
-
- whereValues = 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("Value");
- temp = new Label(container, SWT.NULL);
- temp.setText("Where");
- // temp = new Label(container, SWT.NULL);
- // temp.setText("New Value");
- temp = new Label(container, SWT.NULL);
- temp.setText("Select");
- for (int i = 0; i < row.getColumnCount(); i++) {
- Label label = new Label(container, SWT.NULL);
- label.setText(columnNames[i]);
- whereValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
- if (data[i] == null || data[i].equals("")) {
- whereValues[i].setText('$' + columnNames[i]);
- } else {
- whereValues[i].setText(data[i]);
- }
-
- whereValues[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() {
- if (DEBUG) {
- 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 = whereValues[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[] arguments = { setClause.toString(), row.getTable(), whereClause.toString() };
- MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.select.template"));
-
- String query = form.format(arguments);
-// 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;
- }
+ TableRow row;
+ String[] columnNames;
+ Text[] whereValues;
+ // Text[] newValues;
+ Button[] primaryKeys;
+ Button[] setValues;
+ Label query;
+ IPreferenceStore fStore;
+
+ 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);
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+
+ 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]);
+ }
+
+ whereValues = 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("Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Where");
+ // temp = new Label(container, SWT.NULL);
+ // temp.setText("New Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Select");
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ Label label = new Label(container, SWT.NULL);
+ label.setText(columnNames[i]);
+ whereValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
+ if (data[i] == null || data[i].equals("")) {
+ whereValues[i].setText('$' + columnNames[i]);
+ } else {
+ whereValues[i].setText(data[i]);
+ }
+
+ whereValues[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 = whereValues[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[] arguments =
+ { setClause.toString(), row.getTable(), whereClause.toString()};
+ MessageFormat form =
+ new MessageFormat(
+ fStore.getString("phpeclipse.sql.select.template"));
+
+ String query = form.format(arguments);
+ // 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
import java.text.MessageFormat;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.preference.IPreferenceStore;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
public class PHPUpdateRowPage extends WizardPage implements SQLPage {
- TableRow row;
- String[] columnNames;
- Text[] oldValues;
- Text[] newValues;
- Button[] primaryKeys;
- Button[] setValues;
- Label query;
- IPreferenceStore fStore;
-
- public PHPUpdateRowPage(String pageName) {
- super(pageName);
- }
+ TableRow row;
+ String[] columnNames;
+ Text[] oldValues;
+ Text[] newValues;
+ Button[] primaryKeys;
+ Button[] setValues;
+ Label query;
+ IPreferenceStore fStore;
+
+ public PHPUpdateRowPage(String pageName) {
+ super(pageName);
+ }
- public void init(TableRow row, TableAdapter adapter) {
- this.row = row;
- }
+ public void init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
- public void createControl(Composite parent) {
- if (DEBUG) {
- System.out.println("page create control");
- }
- fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- int layoutColumns = 5;
- layout.numColumns = layoutColumns;
+ public void createControl(Composite parent) {
+ System.out.println("page create control");
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ int layoutColumns = 5;
+ layout.numColumns = layoutColumns;
- if (DEBUG) {
- 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");
- }
- }
+ 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();
- if (DEBUG) {
- 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("Where Value");
- temp = new Label(container, SWT.NULL);
- temp.setText("Where");
- temp = new Label(container, SWT.NULL);
- temp.setText("Set Value");
- temp = new Label(container, SWT.NULL);
- temp.setText("Set");
- 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");
- 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);
+ 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("Where Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Where");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Set Value");
+ temp = new Label(container, SWT.NULL);
+ temp.setText("Set");
+ 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");
+ 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);
- if (data[i] == null || data[i].equals("")) {
- newValues[i].setText('$' + columnNames[i]);
- } else {
- 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);
+ if (data[i] == null || data[i].equals("")) {
+ newValues[i].setText('$' + columnNames[i]);
+ } else {
+ 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();
+ setControl(container);
+ updateQuery();
- setPageComplete(true);
- }
- public void updateQuery() {
- if (DEBUG) {
- System.out.println("Updating update 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[] arguments = { setClause.toString(), row.getTable(), whereClause.toString() };
- MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.update.template"));
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating update 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[] arguments =
+ { setClause.toString(), row.getTable(), whereClause.toString()};
+ MessageFormat form =
+ new MessageFormat(
+ fStore.getString("phpeclipse.sql.update.template"));
- String query = form.format(arguments);
-//
-// String query = "$results = mysql_query(\"UPDATE " + row.getTable();
-// query += " SET " + setClause.toString();
-// query += " WHERE " + whereClause.toString() + "\");";
- this.query.setText(query);
- }
- public boolean performFinish() {
- PHPSourceConsole console = PHPSourceConsole.getInstance();
- console.clear();
- console.print(query.getText());
- return true;
- }
+ String query = form.format(arguments);
+ //
+ // String query = "$results = mysql_query(\"UPDATE " + row.getTable();
+ // query += " SET " + setClause.toString();
+ // 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
package net.sourceforge.phpdt.sql.wizards;
-import net.sourceforge.phpdt.sql.IConstants;
+import org.eclipse.jface.wizard.IWizardPage;
+
import net.sourceforge.phpdt.sql.sql.TableRow;
import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
-import org.eclipse.jface.wizard.IWizardPage;
-
-public interface SQLPage extends IWizardPage, IConstants {
+public interface SQLPage extends IWizardPage {
public void init(TableRow row, TableAdapter adapter);
public boolean performFinish();
}
-
\ No newline at end of file
package net.sourceforge.phpdt.sql.wizards;
-import net.sourceforge.phpdt.sql.IConstants;
+import org.eclipse.jface.wizard.Wizard;
+
import net.sourceforge.phpdt.sql.sql.TableRow;
import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
-import org.eclipse.jface.wizard.Wizard;
-
-public class SQLRowWizard extends Wizard implements IConstants {
- SQLPage page;
- TableRow row;
- TableAdapter adapter;
- public void init(
- String title,
- SQLPage page,
- TableRow row,
- TableAdapter adapter) {
- if (DEBUG) {
- System.out.println("Init SQL row wizard");
- }
- this.row = row;
- this.adapter = adapter;
- this.page = page;
- setWindowTitle(title);
- }
- public boolean performFinish() {
- if (DEBUG) {
- System.out.println("Perform SQL row wizard finish");
- }
- return page.performFinish();
- }
- public void addPages() {
- if (DEBUG) {
- System.out.println("SQL row wizard adding pages");
- }
- page.init(row, adapter);
- addPage(page);
- }
+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"); //$NON-NLS-1$
+ this.row = row;
+ this.adapter = adapter;
+ this.page = page;
+ setWindowTitle(title);
+ }
+ public boolean performFinish() {
+ System.out.println("Perform SQL row wizard finish"); //$NON-NLS-1$
+ return page.performFinish();
+ }
+ public void addPages() {
+ System.out.println("SQL row wizard adding pages"); //$NON-NLS-1$
+ page.init(row, adapter);
+ addPage(page);
+ }
}
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) {
- if (DEBUG) {
- 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 (DEBUG) {
- 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();
- if (DEBUG) {
- 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;
- }
+ 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"); //$NON-NLS-1$
+
+ 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"); //$NON-NLS-1$
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null"); //$NON-NLS-1$
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null"); //$NON-NLS-1$
+ }
+
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ 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("="); //$NON-NLS-1$
+ operator[i].add("<>"); //$NON-NLS-1$
+ operator[i].add("<"); //$NON-NLS-1$
+ operator[i].add(">"); //$NON-NLS-1$
+ 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"); //$NON-NLS-1$
+ 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;
+ }
}
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
+import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
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);
- }
+ 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 init(TableRow row, TableAdapter adapter) {
+ this.row = row;
+ }
+
+ public void createControl(Composite parent) {
+ System.out.println("page create control"); //$NON-NLS-1$
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ BookmarkNode bookmark = row.getBookmarkNode();
+ TreeNode node = bookmark.find(row.getTable());
+ ObjectMetaData metadata = null;
+ if (node != null) metadata = node.getMetaData();
+
+ int layoutColumns = 5;
+ layout.numColumns = layoutColumns;
- public void createControl(Composite parent) {
- if (DEBUG) {
- 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"); //$NON-NLS-1$
+ }
+ if (row.getColumnNames() == null) {
+ System.out.println("Columns are null"); //$NON-NLS-1$
+ }
+ if (row.getTableData() == null) {
+ System.out.println("Data is null"); //$NON-NLS-1$
+ }
+ columnNames = row.getColumnNames();
+ String[] data = row.getTableData();
+ for (int i = 0; i < row.getColumnCount(); i++) {
+ System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ 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(Messages.getString("UpdateRowPage.ColumnName")); //$NON-NLS-1$
+ temp = new Label(container, SWT.NULL);
+ temp.setText(Messages.getString("UpdateRowPage.OldValue")); //$NON-NLS-1$
+ temp = new Label(container, SWT.NULL);
+ temp.setText(""); //$NON-NLS-1$
+ temp = new Label(container, SWT.NULL);
+ temp.setText(Messages.getString("UpdateRowPage.NewValue")); //$NON-NLS-1$
+ temp = new Label(container, SWT.NULL);
+ temp.setText(Messages.getString("UpdateRowPage._13")); //$NON-NLS-1$
+ 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("Where"); //$NON-NLS-1$
+ if (metadata != null && metadata.getPrimaryKeyOrder(columnNames[i]) > 0) primaryKeys[i].setSelection(true);
+ 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(Messages.getString("UpdateRowPage.SetValue")); //$NON-NLS-1$
+ 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);
- if (DEBUG) {
- 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();
- if (DEBUG) {
- 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() {
- if (DEBUG) {
- 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;
- }
+ setControl(container);
+ updateQuery();
+
+ setPageComplete(true);
+ }
+ public void updateQuery() {
+ System.out.println("Updating query"); //$NON-NLS-1$
+ StringBuffer setClause = new StringBuffer();
+ StringBuffer whereClause = new StringBuffer();
+ BookmarkNode bookmark = row.getBookmarkNode();
+ TreeNode node = bookmark.find(row.getTable());
+ ObjectMetaData metadata = null;
+ if (node != null) metadata = node.getMetaData();
+ DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(bookmark.getType());
+
+ int numValuesSet = 0;
+ int numValuesWhere = 0;
+ for (int i = 0; i < columnNames.length; i++) {
+ if (primaryKeys[i].getSelection()) {
+ String value = oldValues[i].getText();
+ if (numValuesWhere > 0) whereClause.append(" AND "); //$NON-NLS-1$
+ whereClause.append("("); //$NON-NLS-1$
+ whereClause.append(columnNames[i]);
+ whereClause.append(" = "); //$NON-NLS-1$
+ if (adapter != null && metadata != null && value != "") //$NON-NLS-1$
+ whereClause.append(adapter.quote(value, metadata.getColumnType(columnNames[i])));
+ else
+ whereClause.append(value);
+ whereClause.append(")"); //$NON-NLS-1$
+ numValuesWhere++;
+ }
+ if (setValues[i].getSelection()) {
+ String value = newValues[i].getText();
+ if (numValuesSet > 0) setClause.append(", "); //$NON-NLS-1$
+ setClause.append(columnNames[i]);
+ setClause.append(" = "); //$NON-NLS-1$
+ if (adapter != null && metadata != null && value != "") //$NON-NLS-1$
+ setClause.append(adapter.quote(value, metadata.getColumnType(columnNames[i])));
+ else
+ setClause.append(value);
+ numValuesSet++;
+
+ }
+ }
+ String query = "UPDATE " + row.getTable(); //$NON-NLS-1$
+ query += " SET " + setClause.toString(); //$NON-NLS-1$
+ query += " WHERE " + whereClause.toString(); //$NON-NLS-1$
+ this.query.setText(query);
+ }
+ public boolean performFinish() {
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ BookmarkView bookmarkView = BookmarkView.getInstance();
+ BookmarkNode bookmark = bookmarkView.getCurrentBookmark();
+ server.execute(bookmark.getConnection(), query.getText());
+ return true;
+ }
}
\ No newline at end of file