Refactory: removed unnecessary local variables and imports.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / view / TableView.java
index 97c351f..eb24275 100644 (file)
@@ -1,6 +1,22 @@
 package net.sourceforge.phpdt.sql.view;
 
+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.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;
@@ -30,21 +46,7 @@ import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.part.ViewPart;
 
-import net.sourceforge.phpdt.sql.actions.CloseTableAction;
-import net.sourceforge.phpdt.sql.actions.RefreshTableAction;
-import net.sourceforge.phpdt.sql.sql.SQLResults;
-import net.sourceforge.phpdt.sql.sql.TableRow;
-import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
-import net.sourceforge.phpdt.sql.wizards.DeleteRowPage;
-import net.sourceforge.phpdt.sql.wizards.InsertRowPage;
-import net.sourceforge.phpdt.sql.wizards.PHPSelectRowPage;
-import net.sourceforge.phpdt.sql.wizards.SQLRowWizard;
-import net.sourceforge.phpdt.sql.wizards.SortFilterPage;
-import net.sourceforge.phpdt.sql.wizards.UpdateRowPage;
-import net.sourceforge.phpdt.sql.wizards.PHPSelectRowPage;
-
 public class TableView extends ViewPart implements ISelectionListener {
-  public static String TABLEVIEW_ID = "net.sourceforge.phpdt.sql.view.tableview";
   private Clipboard clip;
   private RefreshTableAction refreshTableAction;
   private CloseTableAction closeTableAction;
@@ -66,32 +68,29 @@ public class TableView extends ViewPart implements ISelectionListener {
   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(item, null, null, true, true);
+      loadTable(bookmark, item, null, null, true, true);
     } else {
-      loadTable(item, null, null, true, true);
+      loadTable(bookmark, item, null, null, true, true);
     }
   }
-  public void loadQuery(SQLResults results) {
-    loadTable(null, null, results, true, false);
+  public void loadQuery(BookmarkNode bookmark, SQLResults results) {
+    loadTable(bookmark, null, null, results, true, false);
   }
-  public void loadTable(String table) {
-    loadTable(null, table, null, false, true);
+  public void loadTable(BookmarkNode bookmark, String table) {
+    loadTable(bookmark, null, table, null, false, true);
   }
-  public void loadTable(
-    TabItem tabItem,
-    String entity,
-    SQLResults results,
-    boolean query,
-    boolean reload) {
+  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(results);
+        adapter = TableAdapter.createFromQuery(bookmark, results);
       } else {
-        adapter = TableAdapter.createFromTable(entity);
+        adapter = TableAdapter.createFromTable(bookmark, entity);
       }
       tabItem.setData(adapter);
     } else {
@@ -123,9 +122,7 @@ public class TableView extends ViewPart implements ISelectionListener {
           }
           text.append('\n');
         }
-        clip.setContents(
-          new Object[] { text.toString()},
-          new Transfer[] { TextTransfer.getInstance()});
+        clip.setContents(new Object[] { text.toString()}, new Transfer[] { TextTransfer.getInstance()});
       }
     };
     final Action selectAllAction = new Action() {
@@ -177,7 +174,7 @@ public class TableView extends ViewPart implements ISelectionListener {
     final ToolItem previous = new ToolItem(toolbar, SWT.PUSH);
     final ToolItem next = new ToolItem(toolbar, SWT.PUSH);
 
-    fullMode.setImage(PHPEclipseSQLPlugin.getImage("fulldata.gif"));
+    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() {
@@ -200,8 +197,8 @@ public class TableView extends ViewPart implements ISelectionListener {
         next.setEnabled(ta.hasNextPage());
       }
     });
-    previous.setImage(PHPEclipseSQLPlugin.getImage("previous.gif"));
-    previous.setToolTipText("Previous");
+    previous.setImage(PHPEclipseSQLPlugin.getImage("previous.gif")); //$NON-NLS-1$
+    previous.setToolTipText("Previous"); //$NON-NLS-1$
     previous.addSelectionListener(new SelectionListener() {
       public void widgetDefaultSelected(SelectionEvent e) {
       }
@@ -218,8 +215,8 @@ public class TableView extends ViewPart implements ISelectionListener {
         next.setEnabled(ta.hasNextPage());
       }
     });
-    next.setImage(PHPEclipseSQLPlugin.getImage("next.gif"));
-    next.setToolTipText("Next");
+    next.setImage(PHPEclipseSQLPlugin.getImage("next.gif")); //$NON-NLS-1$
+    next.setToolTipText("Next"); //$NON-NLS-1$
     next.addSelectionListener(new SelectionListener() {
       public void widgetDefaultSelected(SelectionEvent e) {
       }
@@ -286,17 +283,18 @@ public class TableView extends ViewPart implements ISelectionListener {
     }
     String data[] = new String[columnNames.length];
     for (int i = 0; i < columns.length; i++) {
-      data[i] = "";
+      data[i] = ""; //$NON-NLS-1$
     }
-    final TableRow emptyRow = new TableRow(ta.getTable(), columnNames, data);
+
+    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("");
+        SortFilterPage page = new SortFilterPage(""); //$NON-NLS-1$
         SQLRowWizard wizard = new SQLRowWizard();
-        wizard.init("Filter and Sort", page, emptyRow, ta);
+        wizard.init(Messages.getString("TableView.FilterAndSort"), page, emptyRow, ta); //$NON-NLS-1$
         WizardDialog dialog = new WizardDialog(getSite().getShell(), wizard);
         dialog.open();
       }
@@ -338,63 +336,90 @@ public class TableView extends ViewPart implements ISelectionListener {
             }
           } else {
             for (int i = 0; i < columns.length; i++) {
-              data[i] = "";
+              data[i] = ""; //$NON-NLS-1$
             }
           }
-          final TableRow row = new TableRow(ta.getTable(), columnNames, data);
-          Action updateAction = new Action() {
+          final TableRow row = new TableRow(ta.getBookmark(), ta.getTable(), columnNames, data);
+          Action phpSelectAction = new Action() {
             public void run() {
-              UpdateRowPage page = new UpdateRowPage("");
+                                                       PHPSelectRowPage page = new PHPSelectRowPage(""); //$NON-NLS-1$
               SQLRowWizard wizard = new SQLRowWizard();
-              wizard.init("Update Row", page, row, ta);
-              WizardDialog dialog =
-                new WizardDialog(getSite().getShell(), wizard);
+              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() {
+          phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$
+
+          Action phpUpdateAction = new Action() {
             public void run() {
-              InsertRowPage page = new InsertRowPage("");
+                                                       PHPUpdateRowPage page = new PHPUpdateRowPage(""); //$NON-NLS-1$
               SQLRowWizard wizard = new SQLRowWizard();
-              wizard.init("Insert Row", page, row, ta);
-              WizardDialog dialog =
-                new WizardDialog(getSite().getShell(), wizard);
+              wizard.init(Messages.getString("TableView.UpdateRow"), 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() {
+          phpUpdateAction.setText(Messages.getString("tableview.phpupdate")); //$NON-NLS-1$
+          Action phpInsertAction = new Action() {
             public void run() {
-              DeleteRowPage page = new DeleteRowPage("");
+              PHPInsertRowPage page = new PHPInsertRowPage(""); //$NON-NLS-1$
               SQLRowWizard wizard = new SQLRowWizard();
-              wizard.init("Delete Row", page, row, ta);
-              WizardDialog dialog =
-                new WizardDialog(getSite().getShell(), wizard);
+              wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$
+              WizardDialog dialog = new WizardDialog(getSite().getShell(), wizard);
               dialog.open();
             }
           };
-          deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$
-
-          Action phpSelectAction = new Action() {
+          phpInsertAction.setText(Messages.getString("tableview.phpinsert")); //$NON-NLS-1$
+          Action phpDeleteAction = new Action() {
             public void run() {
-              PHPSelectRowPage page = new PHPSelectRowPage("");
+              PHPDeleteRowPage page = new PHPDeleteRowPage(""); //$NON-NLS-1$
               SQLRowWizard wizard = new SQLRowWizard();
-              wizard.init("PHP Select Generation", page, row, ta);
-              WizardDialog dialog =
-                new WizardDialog(getSite().getShell(), wizard);
+              wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$
+              WizardDialog dialog = new WizardDialog(getSite().getShell(), wizard);
               dialog.open();
             }
           };
-          phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$
+          phpDeleteAction.setText(Messages.getString("tableview.phpdelete")); //$NON-NLS-1$
 
+          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(phpSelectAction);
-          
+          mgr.add(phpInsertAction);
+          mgr.add(phpUpdateAction);
+          mgr.add(phpDeleteAction);
+
           mgr.add(insertAction);
           mgr.add(updateAction);
           mgr.add(deleteAction);
-          
-          
         }
         mgr.add(defaultEncodingAction);
         mgr.add(UTF8EncodingAction);
@@ -423,14 +448,12 @@ public class TableView extends ViewPart implements ISelectionListener {
   }
   public void initActions() {
     refreshTableAction = new RefreshTableAction();
-    refreshTableAction.setText(Messages.getString("tableview.refresh"));
-    refreshTableAction.setImageDescriptor(
-      PHPEclipseSQLPlugin.getImageDescriptor("refresh.gif"));
+    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"));
-    closeTableAction.setImageDescriptor(
-      PHPEclipseSQLPlugin.getImageDescriptor("close.gif"));
+    closeTableAction.setText(Messages.getString("tableview.close")); //$NON-NLS-1$
+    closeTableAction.setImageDescriptor(PHPEclipseSQLPlugin.getImageDescriptor("close.gif")); //$NON-NLS-1$
     closeTableAction.init(this);
   }