/* * Created on 28-jul-2003 * */ package com.quantum.view.tableview; import java.util.Vector; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import com.quantum.Messages; import com.quantum.extensions.ExtensionAction; import com.quantum.sql.TableRow; import com.quantum.util.StringMatrix; import com.quantum.wizards.DeleteRowPage; import com.quantum.wizards.InsertRowPage; import com.quantum.wizards.PHPDeleteRowPage; import com.quantum.wizards.PHPInsertRowPage; import com.quantum.wizards.PHPSelectRowPage; import com.quantum.wizards.PHPUpdateRowPage; import com.quantum.wizards.SQLRowWizard; import com.quantum.wizards.UpdateRowPage; public final class TableViewMenuListener implements IMenuListener { private final TableView tableView; private final Table table; private final Action UTF16EncodingAction; private final TableAdapter ta; private final Action defaultEncodingAction; private final Action UTF8EncodingAction; private final Vector extensionVector; public TableViewMenuListener(TableView view, Table table, Action UTF16EncodingAction, TableAdapter ta, Action defaultEncodingAction, Action UTF8EncodingAction, Vector extensionVector) { super(); this.tableView = view; this.table = table; this.UTF16EncodingAction = UTF16EncodingAction; this.ta = ta; this.defaultEncodingAction = defaultEncodingAction; this.UTF8EncodingAction = UTF8EncodingAction; this.extensionVector = extensionVector; } public void menuAboutToShow(IMenuManager mgr) { if (ta.getTable() != null) { TableItem[] selection = table.getSelection(); TableColumn[] columns = table.getColumns(); // Copy in columnNames the names of the columns of the selected rows String columnNames[] = new String[columns.length]; for (int i = 0; i < columns.length; i++) { columnNames[i] = columns[i].getText(); } // Copy in data the values of the data columns of the selected rows StringMatrix data = new StringMatrix(); data.addMatrixHeader(columnNames); if (selection != null && selection.length > 0) { for (int iRow = 0; iRow < selection.length; iRow++) { TableItem sel = selection[iRow]; for (int i = 0; i < columns.length; i++) { data.addAt(columnNames[i], sel.getText(i), iRow); } } } else { // Create dummy values in case nothing selected for (int i = 0; i < columns.length; i++) { data.addAt(columnNames[i], "", 0); //$NON-NLS-1$ } } final TableRow row = new TableRow(ta.getEntity(), ta.getBookmark(), ta .getTable(), data); Action phpSelectAction = new Action() { public void run() { PHPSelectRowPage page = new PHPSelectRowPage(""); //$NON-NLS-1$ SQLRowWizard wizard = new SQLRowWizard(); wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$ WizardDialog dialog = new WizardDialog(tableView.getSite().getShell() .getShell(), wizard); dialog.open(); } }; phpSelectAction.setText(Messages.getString("tableview.phpselect")); //$NON-NLS-1$ Action phpUpdateAction = new Action() { public void run() { PHPUpdateRowPage page = new PHPUpdateRowPage(""); //$NON-NLS-1$ SQLRowWizard wizard = new SQLRowWizard(); wizard.init(Messages.getString("TableView.UpdateRow"), page, row, ta); //$NON-NLS-1$ WizardDialog dialog = new WizardDialog( tableView.getSite().getShell(), wizard); dialog.open(); } }; phpUpdateAction.setText(Messages.getString("tableview.phpupdate")); //$NON-NLS-1$ Action phpInsertAction = new Action() { public void run() { PHPInsertRowPage page = new PHPInsertRowPage(""); //$NON-NLS-1$ SQLRowWizard wizard = new SQLRowWizard(); wizard.init(Messages.getString("TableView.InsertRow"), page, row, ta); //$NON-NLS-1$ WizardDialog dialog = new WizardDialog( tableView.getSite().getShell(), wizard); dialog.open(); } }; phpInsertAction.setText(Messages.getString("tableview.phpinsert")); //$NON-NLS-1$ Action phpDeleteAction = new Action() { public void run() { PHPDeleteRowPage page = new PHPDeleteRowPage(""); //$NON-NLS-1$ SQLRowWizard wizard = new SQLRowWizard(); wizard.init(Messages.getString("TableView.DeleteRow"), page, row, ta); //$NON-NLS-1$ WizardDialog dialog = new WizardDialog( tableView.getSite().getShell(), wizard); dialog.open(); } }; 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( tableView.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( tableView.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( tableView.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); MenuManager subMenuExtension = new MenuManager("Extensions"); for (int i = 0; i < extensionVector.size(); i++) { ExtensionAction extensionAction = (ExtensionAction) extensionVector .get(i); extensionAction.addRowData(row); subMenuExtension.add(extensionAction); } if (extensionVector.size() > 0) mgr.add(subMenuExtension); } mgr.add(defaultEncodingAction); mgr.add(UTF8EncodingAction); mgr.add(UTF16EncodingAction); } }