From: axelcl Date: Sat, 28 May 2005 09:44:48 +0000 (+0000) Subject: New (Quantum SQL) wizard module which extends Quantum context menus (Bookmark-Tables... X-Git-Url: http://git.phpeclipse.com?hp=26065ff9ccda89ea850ba2b8f093f1c806916320 New (Quantum SQL) wizard module which extends Quantum context menus (Bookmark-Tables and Tableview-Rowdata) - at the moment only the data is extracted as an example from the extensions - the data output can de found in the development console (System.out.println()'s) --- diff --git a/net.sourceforge.phpeclipse.wizards/.classpath b/net.sourceforge.phpeclipse.wizards/.classpath new file mode 100644 index 0000000..065ac06 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/net.sourceforge.phpeclipse.wizards/.project b/net.sourceforge.phpeclipse.wizards/.project new file mode 100644 index 0000000..b297e1a --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/.project @@ -0,0 +1,28 @@ + + + net.sourceforge.phpeclipse.wizards + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/net.sourceforge.phpeclipse.wizards/build.properties b/net.sourceforge.phpeclipse.wizards/build.properties new file mode 100644 index 0000000..186d8c9 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/build.properties @@ -0,0 +1,6 @@ +source.wizards.jar = src/ +output.wizards.jar = bin/ +bin.includes = plugin.xml,\ + wizards.jar +src.includes = src/,\ + build.properties diff --git a/net.sourceforge.phpeclipse.wizards/build.xml b/net.sourceforge.phpeclipse.wizards/build.xml new file mode 100644 index 0000000..7301464 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/build.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.wizards/plugin.xml b/net.sourceforge.phpeclipse.wizards/plugin.xml new file mode 100644 index 0000000..f4d23b3 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/plugin.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/WizardsPlugin.java b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/WizardsPlugin.java new file mode 100644 index 0000000..19f5718 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/WizardsPlugin.java @@ -0,0 +1,71 @@ +package net.sourceforge.phpeclipse.wizards; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class WizardsPlugin extends AbstractUIPlugin { + //The shared instance. + private static WizardsPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + /** + * The constructor. + */ + public WizardsPlugin() { + super(); + plugin = this; + try { + resourceBundle = ResourceBundle.getBundle("net.sourceforge.phpeclipse.wizards.WizardsPluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + } + + /** + * Returns the shared instance. + */ + public static WizardsPlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, + * or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = WizardsPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } +} diff --git a/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/PHPOpenSQLTableEditorAction.java b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/PHPOpenSQLTableEditorAction.java new file mode 100644 index 0000000..e7c67e8 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/PHPOpenSQLTableEditorAction.java @@ -0,0 +1,316 @@ +/*********************************************************************************************************************************** + * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made + * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: www.phpeclipse.de + **********************************************************************************************************************************/ +package net.sourceforge.phpeclipse.wizards.actions; + +import java.sql.SQLException; + +import net.sourceforge.phpeclipse.phpeditor.PHPEditor; +import net.sourceforge.phpeclipse.ui.WebUI; +import net.sourceforge.phpeclipse.ui.overlaypages.ProjectPrefUtil; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IEditorActionDelegate; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.actions.ActionDelegate; + +import com.quantum.ExternalInterface; +import com.quantum.QuantumPlugin; +// import com.quantum.util.connection.NotConnectedException; + +public class PHPOpenSQLTableEditorAction extends ActionDelegate implements IEditorActionDelegate { + + private IWorkbenchWindow fWindow; + + private PHPEditor fEditor; + + private IProject fProject; + + public void dispose() { + } + + public void init(IWorkbenchWindow window) { + this.fWindow = window; + } + + public void selectionChanged(IAction action, ISelection selection) { + if (!selection.isEmpty()) { + if (selection instanceof TextSelection) { + action.setEnabled(true); + } else if (fWindow.getActivePage() != null && fWindow.getActivePage().getActivePart() != null) { + // + } + } + } + + private IWorkbenchPage getActivePage() { + fWindow = fEditor.getEditorSite().getWorkbenchWindow(); + IWorkbenchPage page = fWindow.getActivePage(); + return page; + } + + public IContainer getWorkingLocation(IFileEditorInput editorInput) { + if (editorInput == null || editorInput.getFile() == null) { + return null; + } + return editorInput.getFile().getParent(); + } + + private IFile getIncludeFile(IProject project, IFileEditorInput editorInput, String relativeFilename) { + // IContainer container = getWorkingLocation(editorInput); + // String fullPath = project.getLocation().toString(); + Path path = new Path(relativeFilename); + IFile file = project.getFile(path); + return file; + } + + public void run(IAction action) { + if (fEditor == null) { + IEditorPart targetEditor = fWindow.getActivePage().getActiveEditor(); + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + fEditor = (PHPEditor) targetEditor; + } + } + if (fEditor != null) { + fWindow = fEditor.getEditorSite().getWorkbenchWindow(); + IFile f = ((IFileEditorInput) fEditor.getEditorInput()).getFile(); + fProject = f.getProject(); + String bookmarkString = ProjectPrefUtil.getMiscProjectsPreferenceValue(fProject, WebUI.PHP_BOOKMARK_DEFAULT); + if (bookmarkString != null && !bookmarkString.equals("")) { + ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection(); + IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); + int pos = selection.getOffset(); + // System.out.println(selection.getText()); + String tableName = getSQLTableName(doc, pos); + if (tableName != null && tableName.length() > 0) + try { + ExternalInterface.displayTable(bookmarkString, tableName); + + IViewPart viewPart = null; + String view = "com.quantum.view.tableview.TableView"; + try { + IWorkbenchPage page = QuantumPlugin.getDefault().getActivePage(); + viewPart = page.findView(view); + if (viewPart == null) { + viewPart = page.showView(view); + } + page.bringToTop(viewPart); + } catch (PartInitException e) { + e.printStackTrace(); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception /* NotConnectedException */ e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // + // IViewPart viewPart = null; + // String view = "com.quantum.view.tableview.TableView"; + // try { + // IWorkbenchPage page = QuantumPlugin.getDefault().getActivePage(); + // viewPart = page.findView(view); + // if (viewPart == null) { + // viewPart = page.showView(view); + // } + // page.bringToTop(viewPart); + // getTables((TableView) viewPart, fProject, tableName); + // } catch (PartInitException e) { + // e.printStackTrace(); + // } + + } + } + + public void setActiveEditor(IAction action, IEditorPart targetEditor) { + if (targetEditor != null && (targetEditor instanceof PHPEditor)) { + fEditor = (PHPEditor) targetEditor; + } + } + + private String getSQLTableName(IDocument doc, int pos) { + Point word = null; + int start = -1; + int end = -1; + + try { + + int position = pos; + char character; + + while (position >= 0) { + character = doc.getChar(position); + if (Character.isWhitespace(character) || (character == '\"') || (character == '\'') || (character == '\r') + || (character == '\n')) + break; + --position; + } + + start = position; + + position = pos; + int length = doc.getLength(); + + while (position < length) { + character = doc.getChar(position); + if (Character.isWhitespace(character) || (character == '\"') || (character == '\'') || (character == '\r') + || (character == '\n')) + break; + ++position; + } + + start++; + end = position; + + if (end > start) + word = new Point(start, end - start); + + } catch (BadLocationException x) { + } + + if (word != null) { + try { + return doc.get(word.x, word.y); + } catch (BadLocationException e) { + } + } + return ""; + } + + // public void getTables(TableView tableView, IProject project, String tableName) { + // // Get The Database bookmark from the Quantum SQL plugin: + // BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance(); + // if (sqlBookMarks != null) { + // String bookmarkString = ProjectPrefUtil.getMiscProjectsPreferenceValue(project, + // WebUI.PHP_BOOKMARK_DEFAULT); + // if (bookmarkString != null && !bookmarkString.equals("")) { + // Bookmark bookmark = sqlBookMarks.find(bookmarkString); + // ArrayList sqlList = new ArrayList(); + // if (bookmark != null && !bookmark.isConnected()) { + // new ConnectionUtil().connect(bookmark, null); + // } + // if (bookmark != null && bookmark.isConnected()) { + // try { + // Connection connection = bookmark.getConnection(); + // DatabaseMetaData metaData = connection.getMetaData(); + // ConnectionUtil connectionUtil = new ConnectionUtil(); + // Entity entity; + // DatabaseAdapter adapter; + // + // if (metaData != null) { + // String columnName; + // String prefixWithoutDollar = tableName; + // if (prefixWithoutDollar.charAt(0) == '$') { + // prefixWithoutDollar = prefixWithoutDollar.substring(1); + // } + // ResultSet set; + // set = metaData.getTables(null, null, "%" + prefixWithoutDollar + // + "%", null); + // while (set.next()) { + // tableName = set.getString("TABLE_NAME"); + // tableName = (tableName == null) ? "" : tableName.trim(); + // if (tableName != null && tableName.length() > 0) { + // sqlList.add(tableName); + // } + // } + // set.close(); + // EntityFactory entityFactory = EntityFactory.getInstance(); + // if (sqlList.size() == 1) { + // adapter = bookmark.getAdapter(); + // entity = entityFactory.create(bookmark, null, (String) sqlList + // .get(0), Entity.TABLE_TYPE, false); + // String query = adapter.getTableQuery(entity.getQualifiedName()); + // + // try { + // SQLResults results = MultiSQLServer.getInstance().execute( + // bookmark, connectionUtil.connect(bookmark, fWindow.getShell()), + // entity, query); + // + // if (results != null && results.isResultSet()) { + // SQLResultSetCollection.getInstance().addSQLResultSet( + // (SQLResultSetResults) results); + // } + // } catch (SQLException e) { + // ExceptionDisplayDialog.openError(fWindow.getShell(), null, null, e); + // } + // // tableView.loadTable(entityFactory.create( + // // bookmark, null, + // // (String) sqlList.get(0), + // // Entity.TABLE_TYPE)); + // } else if (sqlList.size() > 1) { + // ListSelectionDialog listSelectionDialog = new ListSelectionDialog( + // PHPeclipsePlugin.getDefault().getWorkbench() + // .getActiveWorkbenchWindow().getShell(), sqlList, + // new ListContentProvider(), new LabelProvider(), + // "Select the SQL table to open."); + // listSelectionDialog.setTitle("Multiple tablenames found"); + // if (listSelectionDialog.open() == Window.OK) { + // Object[] locations = listSelectionDialog.getResult(); + // if (locations != null) { + // for (int i = 0; i < locations.length; i++) { + // adapter = bookmark.getAdapter(); + // entity = entityFactory.create(bookmark, null, + // (String) locations[i], Entity.TABLE_TYPE, false); + // String query = adapter.getTableQuery(entity + // .getQualifiedName()); + // + // try { + // SQLResults results = MultiSQLServer.getInstance() + // .execute(bookmark, + // connectionUtil.connect(bookmark, fWindow.getShell()), + // entity, query); + // + // if (results != null && results.isResultSet()) { + // SQLResultSetCollection.getInstance().addSQLResultSet( + // (SQLResultSetResults) results); + // } + // } catch (SQLException e) { + // ExceptionDisplayDialog.openError(fWindow.getShell(), null, null, e); + // } + // + // // tableView + // // .loadTable(entityFactory + // // .create( + // // bookmark, + // // null, + // // (String) locations[i], + // // Entity.TABLE_TYPE)); + // } + // + // } + // } + // } + // } + // } catch (NotConnectedException e) { + // // ignore this - not mission critical + // } catch (SQLException e) { + // e.printStackTrace(); + // } + // } + // } + // } + // } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/data/PHPDataWizard.java b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/data/PHPDataWizard.java new file mode 100644 index 0000000..483a689 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/data/PHPDataWizard.java @@ -0,0 +1,45 @@ +package net.sourceforge.phpeclipse.wizards.actions.data; + +import net.sourceforge.phpeclipse.wizards.xml.ModelUtil; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import com.quantum.extensions.IDataExtension; +import com.quantum.model.Column; +import com.quantum.model.xml.XMLToModelConverter; +import com.quantum.util.StringMatrix; + +public class PHPDataWizard implements IDataExtension { + + /* + * (non-Javadoc) + * + * @see com.quantum.extensions.IDataExtension#run(org.w3c.dom.Document) + */ + public void run(Document doc) { + Element root = doc.getDocumentElement(); + + // matrix contains the actual selected data in the row: +// StringMatrix matrix = new StringMatrix(); +// String sub = "DataRow"; +// ModelUtil.xmlToStringMatrix(matrix, root, sub); +// System.out.println(matrix.toString()); + + try { + XMLToModelConverter c = new XMLToModelConverter(root); + String name = ModelUtil.getTableName(root); + System.out.print("Table-name: "); + System.out.println(name); + Column[] cols = c.getColumns(); + for (int i = 0; i < cols.length; i++) { + System.out.print("Column-name: " + i + " "); + System.out.println(cols[i].getName()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/metadata/PHPMetadataWizard.java b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/metadata/PHPMetadataWizard.java new file mode 100644 index 0000000..da589b3 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/metadata/PHPMetadataWizard.java @@ -0,0 +1,40 @@ +package net.sourceforge.phpeclipse.wizards.actions.metadata; + +import net.sourceforge.phpeclipse.wizards.xml.ModelUtil; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import com.quantum.extensions.IMetadataExtension; +import com.quantum.model.Column; +import com.quantum.model.xml.XMLToModelConverter; + +public class PHPMetadataWizard implements IMetadataExtension { + + /* + * (non-Javadoc) + * + * @see com.quantum.extensions.IDataExtension#run(org.w3c.dom.Document) + */ + public void run(Document doc) { +// System.out.println(doc); + + Element root = doc.getDocumentElement(); + + try { + XMLToModelConverter c = new XMLToModelConverter(root); + String name = ModelUtil.getTableName(root); + System.out.print("Table-name: "); + System.out.println(name); + Column[] cols = c.getColumns(); + for (int i = 0; i < cols.length; i++) { + System.out.print("Column-name: "+i+" "); + System.out.println(cols[i].getName()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/xml/ModelUtil.java b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/xml/ModelUtil.java new file mode 100644 index 0000000..17ae760 --- /dev/null +++ b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/xml/ModelUtil.java @@ -0,0 +1,54 @@ +package net.sourceforge.phpeclipse.wizards.xml; + +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +import com.quantum.util.StringMatrix; + +public class ModelUtil { + + public static String getTableName(Element root) { + NodeList columns = root.getElementsByTagName("table"); + for (int i = 0; i < columns.getLength(); i++) { + Node column = columns.item(i); + String header = column.getNodeName(); + if (header.equals("table")) { + NamedNodeMap map = column.getAttributes(); + Node name = map.getNamedItem("name"); + if (name == null) { + return ""; + } + return name.getNodeValue(); + } + } + return ""; + } + + + public 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 Text) { + value = valueNode.getNodeValue(); + } + } + if (!matrix.contains(header)) + matrix.addHeader(header); + matrix.addAt(header, value, i); + } + } + } +} \ No newline at end of file