2 * Created on 28-jul-2003
5 package com.quantum.view.tableview;
6 import java.util.Vector;
7 import org.eclipse.jface.action.Action;
8 import org.eclipse.jface.action.IMenuListener;
9 import org.eclipse.jface.action.IMenuManager;
10 import org.eclipse.jface.action.MenuManager;
11 import org.eclipse.jface.wizard.WizardDialog;
12 import org.eclipse.swt.widgets.Table;
13 import org.eclipse.swt.widgets.TableColumn;
14 import org.eclipse.swt.widgets.TableItem;
15 import com.quantum.Messages;
16 import com.quantum.extensions.ExtensionAction;
17 import com.quantum.sql.TableRow;
18 import com.quantum.util.StringMatrix;
19 import com.quantum.wizards.DeleteRowPage;
20 import com.quantum.wizards.InsertRowPage;
21 import com.quantum.wizards.PHPDeleteRowPage;
22 import com.quantum.wizards.PHPInsertRowPage;
23 import com.quantum.wizards.PHPSelectRowPage;
24 import com.quantum.wizards.PHPUpdateRowPage;
25 import com.quantum.wizards.SQLRowWizard;
26 import com.quantum.wizards.UpdateRowPage;
27 public final class TableViewMenuListener implements IMenuListener {
28 private final TableView tableView;
29 private final Table table;
30 private final Action UTF16EncodingAction;
31 private final TableAdapter ta;
32 private final Action defaultEncodingAction;
33 private final Action UTF8EncodingAction;
34 private final Vector extensionVector;
35 public TableViewMenuListener(TableView view, Table table,
36 Action UTF16EncodingAction, TableAdapter ta,
37 Action defaultEncodingAction, Action UTF8EncodingAction,
38 Vector extensionVector) {
40 this.tableView = view;
42 this.UTF16EncodingAction = UTF16EncodingAction;
44 this.defaultEncodingAction = defaultEncodingAction;
45 this.UTF8EncodingAction = UTF8EncodingAction;
46 this.extensionVector = extensionVector;
48 public void menuAboutToShow(IMenuManager mgr) {
49 if (ta.getTable() != null) {
50 TableItem[] selection = table.getSelection();
51 TableColumn[] columns = table.getColumns();
52 // Copy in columnNames the names of the columns of the selected rows
53 String columnNames[] = new String[columns.length];
54 for (int i = 0; i < columns.length; i++) {
55 columnNames[i] = columns[i].getText();
57 // Copy in data the values of the data columns of the selected rows
58 StringMatrix data = new StringMatrix();
59 data.addMatrixHeader(columnNames);
60 if (selection != null && selection.length > 0) {
61 for (int iRow = 0; iRow < selection.length; iRow++) {
62 TableItem sel = selection[iRow];
63 for (int i = 0; i < columns.length; i++) {
64 data.addAt(columnNames[i], sel.getText(i), iRow);
68 // Create dummy values in case nothing selected
69 for (int i = 0; i < columns.length; i++) {
70 data.addAt(columnNames[i], "", 0); //$NON-NLS-1$
73 final TableRow row = new TableRow(ta.getEntity(), ta.getBookmark(), ta
75 Action phpSelectAction = new Action() {
77 PHPSelectRowPage page = new PHPSelectRowPage(""); //$NON-NLS-1$
78 SQLRowWizard wizard = new SQLRowWizard();
79 wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$
80 WizardDialog dialog = new WizardDialog(tableView.getSite().getShell()
85 phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$
86 Action phpUpdateAction = new Action() {
88 PHPUpdateRowPage page = new PHPUpdateRowPage(""); //$NON-NLS-1$
89 SQLRowWizard wizard = new SQLRowWizard();
90 wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$
91 WizardDialog dialog = new WizardDialog(
92 tableView.getSite().getShell(), wizard);
96 phpUpdateAction.setText(Messages.getString("tableview.phpupdate")); //$NON-NLS-1$
97 Action phpInsertAction = new Action() {
99 PHPInsertRowPage page = new PHPInsertRowPage(""); //$NON-NLS-1$
100 SQLRowWizard wizard = new SQLRowWizard();
101 wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$
102 WizardDialog dialog = new WizardDialog(
103 tableView.getSite().getShell(), wizard);
107 phpInsertAction.setText(Messages.getString("tableview.phpinsert")); //$NON-NLS-1$
108 Action phpDeleteAction = new Action() {
110 PHPDeleteRowPage page = new PHPDeleteRowPage(""); //$NON-NLS-1$
111 SQLRowWizard wizard = new SQLRowWizard();
112 wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$
113 WizardDialog dialog = new WizardDialog(
114 tableView.getSite().getShell(), wizard);
118 phpDeleteAction.setText(Messages.getString("tableview.phpdelete")); //$NON-NLS-1$
119 Action updateAction = new Action() {
121 UpdateRowPage page = new UpdateRowPage(""); //$NON-NLS-1$
122 SQLRowWizard wizard = new SQLRowWizard();
123 wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$
124 WizardDialog dialog = new WizardDialog(
125 tableView.getSite().getShell(), wizard);
129 updateAction.setText(Messages.getString("tableview.update")); //$NON-NLS-1$
130 Action insertAction = new Action() {
132 InsertRowPage page = new InsertRowPage(""); //$NON-NLS-1$
133 SQLRowWizard wizard = new SQLRowWizard();
134 wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$
135 WizardDialog dialog = new WizardDialog(
136 tableView.getSite().getShell(), wizard);
140 insertAction.setText(Messages.getString("tableview.insert")); //$NON-NLS-1$
141 Action deleteAction = new Action() {
143 DeleteRowPage page = new DeleteRowPage(""); //$NON-NLS-1$
144 SQLRowWizard wizard = new SQLRowWizard();
145 wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$
146 WizardDialog dialog = new WizardDialog(
147 tableView.getSite().getShell(), wizard);
151 deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$
152 mgr.add(phpSelectAction);
153 mgr.add(phpInsertAction);
154 mgr.add(phpUpdateAction);
155 mgr.add(phpDeleteAction);
156 mgr.add(insertAction);
157 mgr.add(updateAction);
158 mgr.add(deleteAction);
159 MenuManager subMenuExtension = new MenuManager("Extensions");
160 for (int i = 0; i < extensionVector.size(); i++) {
161 ExtensionAction extensionAction = (ExtensionAction) extensionVector
163 extensionAction.addRowData(row);
164 subMenuExtension.add(extensionAction);
166 if (extensionVector.size() > 0)
167 mgr.add(subMenuExtension);
169 mgr.add(defaultEncodingAction);
170 mgr.add(UTF8EncodingAction);
171 mgr.add(UTF16EncodingAction);