From 492da636b6c71a24348c28883890c5a1e44038d9 Mon Sep 17 00:00:00 2001 From: khartlage Date: Tue, 8 Jun 2004 20:00:06 +0000 Subject: [PATCH] "Open SQL Table View" actiun (right mouse click in editor on table fragment-string) --- net.sourceforge.phpeclipse/plugin.xml | 10 + .../corext/template/php/PHPUnitContext.java | 5 +- .../actions/PHPOpenIncludeEditorAction.java | 9 +- .../actions/PHPOpenSQLTableEditorAction.java | 284 ++++++++++++++++++++ 4 files changed, 302 insertions(+), 6 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPOpenSQLTableEditorAction.java diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index da75286..0eb9dd0 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -870,6 +870,16 @@ id="net.sourceforge.phpeclipse.actions.openinclude"> + + + + = 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 = Util.getMiscProjectsPreferenceValue( + project, IPreferenceConstants.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(); + + 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) { + 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 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++) { + 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 -- 1.7.1