/* * Created on 28-jul-2003 * */ package com.quantum.view.tableview; import com.quantum.ImageStore; import com.quantum.Messages; 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 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; final Action copyAction = new CopyAction(view, table); final Action selectAllAction = new Action() { public void run() { table.selectAll(); } }; ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH); toolItem.setImage(ImageStore.getImage(ImageStore.COPY)); 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(ImageStore.getImage(ImageStore.OPEN_TABLE)); //$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(ImageStore.getImage(ImageStore.FILTER)); 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(ImageStore.getImage(ImageStore.FULLDATA)); 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(ImageStore.getImage(ImageStore.PREVIOUS)); 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(ImageStore.getImage(ImageStore.NEXT)); 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); } } }); } 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; } }