2 * Created on 28-jul-2003
5 package com.quantum.view.tableview;
7 import java.util.Vector;
9 import com.quantum.Messages;
10 import com.quantum.extensions.ExtensionAction;
11 import com.quantum.sql.TableRow;
12 import com.quantum.util.StringMatrix;
13 import com.quantum.wizards.DeleteRowPage;
14 import com.quantum.wizards.InsertRowPage;
15 import com.quantum.wizards.SQLRowWizard;
16 import com.quantum.wizards.UpdateRowPage;
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.action.IMenuListener;
20 import org.eclipse.jface.action.IMenuManager;
21 import org.eclipse.jface.action.MenuManager;
22 import org.eclipse.jface.wizard.WizardDialog;
23 import org.eclipse.swt.widgets.Table;
24 import org.eclipse.swt.widgets.TableColumn;
25 import org.eclipse.swt.widgets.TableItem;
28 public final class TableViewMenuListener implements IMenuListener {
29 private final TableView tableView;
30 private final Table table;
31 private final Action UTF16EncodingAction;
32 private final TableAdapter ta;
33 private final Action defaultEncodingAction;
34 private final Action UTF8EncodingAction;
35 private final Vector extensionVector;
37 public TableViewMenuListener(
40 Action UTF16EncodingAction,
42 Action defaultEncodingAction,
43 Action UTF8EncodingAction,
44 Vector extensionVector ) {
47 this.tableView = view;
49 this.UTF16EncodingAction = UTF16EncodingAction;
51 this.defaultEncodingAction = defaultEncodingAction;
52 this.UTF8EncodingAction = UTF8EncodingAction;
53 this.extensionVector = extensionVector;
55 public void menuAboutToShow(IMenuManager mgr) {
56 if (ta.getTable() != null) {
57 TableItem[] selection = table.getSelection();
58 TableColumn[] columns = table.getColumns();
59 // Copy in columnNames the names of the columns of the selected rows
60 String columnNames[] = new String[columns.length];
61 for (int i = 0; i < columns.length; i++) {
62 columnNames[i] = columns[i].getText();
64 // Copy in data the values of the data columns of the selected rows
65 StringMatrix data = new StringMatrix();
66 data.addMatrixHeader(columnNames);
67 if (selection != null && selection.length > 0) {
68 for (int iRow = 0; iRow < selection.length; iRow++) {
69 TableItem sel = selection[iRow];
70 for (int i = 0; i < columns.length; i++) {
71 data.addAt(columnNames[i], sel.getText(i), iRow );
75 // Create dummy values in case nothing selected
76 for (int i = 0; i < columns.length; i++) {
77 data.addAt(columnNames[i], "", 0); //$NON-NLS-1$
81 new TableRow(ta.getEntity(), ta.getBookmark(), ta.getTable(), data);
82 Action updateAction = new Action() {
84 UpdateRowPage page = new UpdateRowPage(""); //$NON-NLS-1$
85 SQLRowWizard wizard = new SQLRowWizard();
86 wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$
89 tableView.getSite().getShell(),
94 updateAction.setText(Messages.getString("tableview.update")); //$NON-NLS-1$
95 Action insertAction = new Action() {
97 InsertRowPage page = new InsertRowPage(""); //$NON-NLS-1$
98 SQLRowWizard wizard = new SQLRowWizard();
99 wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$
100 WizardDialog dialog =
102 tableView.getSite().getShell(),
107 insertAction.setText(Messages.getString("tableview.insert")); //$NON-NLS-1$
108 Action deleteAction = new Action() {
110 DeleteRowPage page = new DeleteRowPage(""); //$NON-NLS-1$
111 SQLRowWizard wizard = new SQLRowWizard();
112 wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$
113 WizardDialog dialog =
115 tableView.getSite().getShell(),
120 deleteAction.setText(Messages.getString("tableview.delete")); //$NON-NLS-1$
121 mgr.add(insertAction);
122 mgr.add(updateAction);
123 mgr.add(deleteAction);
125 MenuManager subMenuExtension = new MenuManager("Extensions");
126 for (int i = 0; i < extensionVector.size(); i++) {
127 ExtensionAction extensionAction = (ExtensionAction) extensionVector.get(i);
128 extensionAction.addRowData(row);
129 subMenuExtension.add(extensionAction);
131 if (extensionVector.size() > 0) mgr.add(subMenuExtension);
134 mgr.add(defaultEncodingAction);
135 mgr.add(UTF8EncodingAction);
136 mgr.add(UTF16EncodingAction);