/* * Created on 28-jul-2003 * */ package com.quantum.view.tableview; import com.quantum.Messages; import com.quantum.QuantumPlugin; import com.quantum.actions.CloseTableAction; import com.quantum.actions.RefreshTableAction; import com.quantum.model.NotConnectedException; import com.quantum.sql.TableRow; import com.quantum.util.StringMatrix; import com.quantum.view.CopyAction; import com.quantum.wizards.SQLRowWizard; import com.quantum.wizards.SortFilterPage; import org.eclipse.jface.action.Action; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; /** * @author panic * */ public class TableViewToolBar { private ToolBar toolBar; private RefreshTableAction refreshTableAction; private CloseTableAction closeTableAction; private ToolItem previous; private ToolItem next; ToolItem filter; public TableViewToolBar( final TableView view, final ToolBar toolBar, final Table table, final TableAdapter ta, final Label label) { this.toolBar = toolBar; refreshTableAction = new RefreshTableAction(); refreshTableAction.setText(Messages.getString("tableview.refresh")); //$NON-NLS-1$ refreshTableAction.setImageDescriptor( QuantumPlugin.getImageDescriptor("refresh.gif")); //$NON-NLS-1$ refreshTableAction.init(view); closeTableAction = new CloseTableAction(); closeTableAction.setText(Messages.getString("tableview.close")); //$NON-NLS-1$ closeTableAction.setImageDescriptor( QuantumPlugin.getImageDescriptor("close.gif")); //$NON-NLS-1$ closeTableAction.init(view); ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(QuantumPlugin.getImage("refresh.gif")); //$NON-NLS-1$ toolItem.setToolTipText(Messages.getString("tableview.refresh")); //$NON-NLS-1$ toolItem.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { refreshTableAction.run(); } }); final Action copyAction = new CopyAction(view, table); final Action selectAllAction = new Action() { public void run() { table.selectAll(); } }; toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(QuantumPlugin.getImage("copy.gif")); //$NON-NLS-1$ toolItem.setToolTipText(Messages.getString("tableview.copy")); //$NON-NLS-1$ toolItem.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { copyAction.run(); } }); toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(QuantumPlugin.getImage("table.gif")); //$NON-NLS-1$ toolItem.setToolTipText(Messages.getString("tableview.selectAll")); //$NON-NLS-1$ toolItem.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { selectAllAction.run(); } }); filter = new ToolItem(toolBar, SWT.PUSH); filter.setImage(QuantumPlugin.getImage("filter.gif")); //$NON-NLS-1$ filter.setToolTipText(Messages.getString("tableview.filterSort")); //$NON-NLS-1$ toolItem = new ToolItem(toolBar, SWT.SEPARATOR); final ToolItem fullMode = new ToolItem(toolBar, SWT.PUSH | SWT.CHECK); previous = new ToolItem(toolBar, SWT.PUSH); next = new ToolItem(toolBar, SWT.PUSH); fullMode.setImage(QuantumPlugin.getImage("fulldata.gif")); //$NON-NLS-1$ fullMode.setToolTipText(Messages.getString("tableview.showAll")); //$NON-NLS-1$ fullMode.setSelection(false); fullMode.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent event) { try { if (ta.getPageSize() == Integer.MAX_VALUE) { ta.resetMode(); } else { ta.fullMode(); } ta.loadData(); table.removeAll(); for (int i = table.getColumnCount() - 1; i >= 0; i--) { table.getColumn(i).dispose(); } ta.loadTable(table); label.setText(ta.getStatusString()); previous.setEnabled(ta.hasPreviousPage()); next.setEnabled(ta.hasNextPage()); } catch (NotConnectedException e) { view.handleException(e); } } }); previous.setImage(QuantumPlugin.getImage("previous.gif")); //$NON-NLS-1$ previous.setToolTipText("Previous"); //$NON-NLS-1$ previous.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent event) { try { ta.previousPage(); ta.loadData(); table.removeAll(); for (int i = table.getColumnCount() - 1; i >= 0; i--) { table.getColumn(i).dispose(); } ta.loadTable(table); label.setText(ta.getStatusString()); previous.setEnabled(ta.hasPreviousPage()); next.setEnabled(ta.hasNextPage()); } catch (NotConnectedException e) { view.handleException(e); } } }); next.setImage(QuantumPlugin.getImage("next.gif")); //$NON-NLS-1$ next.setToolTipText("Next"); //$NON-NLS-1$ next.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent event) { try { ta.nextPage(); ta.loadData(); table.removeAll(); for (int i = table.getColumnCount() - 1; i >= 0; i--) { table.getColumn(i).dispose(); } ta.loadTable(table); label.setText(ta.getStatusString()); previous.setEnabled(ta.hasPreviousPage()); next.setEnabled(ta.hasNextPage()); } catch (NotConnectedException e) { view.handleException(e); } } }); toolItem = new ToolItem(toolBar, SWT.SEPARATOR); toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(QuantumPlugin.getImage("close.gif")); //$NON-NLS-1$ toolItem.setToolTipText(Messages.getString("tableview.close")); //$NON-NLS-1$ toolItem.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { closeTableAction.run(); } }); } public void setColumns( final TableView view, final TableAdapter ta, Table table) { // We create a matrix of TableColumn (columns in the Table widget) with // the columns in the table object TableColumn[] columns = table.getColumns(); 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); // 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 emptyRow = new TableRow(ta.getEntity(), ta.getBookmark(), ta.getTable(), data); filter.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { SortFilterPage page = new SortFilterPage(""); //$NON-NLS-1$ SQLRowWizard wizard = new SQLRowWizard(); wizard.init(Messages.getString("TableView.FilterAndSort"), page, emptyRow, ta); //$NON-NLS-1$ WizardDialog dialog = new WizardDialog(view.getSite().getShell(), wizard); dialog.open(); } }); } /** * @return */ public ToolItem getNext() { return next; } /** * @return */ public ToolItem getPrevious() { return previous; } }