private void createTable(Composite parent) { final int gdHeightSubtrahend = 100; final int iconRowSize = 10; int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; style = style | SWT.SINGLE | SWT.FULL_SELECTION; viewer = new TableViewer(parent, style); viewer.setContentProvider(new ArrayContentProvider()); TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer)); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) { @Override protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { boolean retVal = event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION; retVal = retVal || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR); return retVal || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; } }; TableViewerEditor.create( viewer, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); Table table = viewer.getTable(); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = SIZE_X - gdHeightSubtrahend; table.setLayoutData(gd); table.addListener( SWT.MeasureItem, new Listener() { @Override public void handleEvent(Event event) { // height cannot be per row so simply set event.height = getThumbnailSize() + ICON_SPACING; } }); table.addMouseListener( new MouseListener() { @Override public void mouseUp(MouseEvent e) {} @Override public void mouseDown(MouseEvent e) { ViewerCell cell = viewer.getCell(new Point(e.x, e.y)); if (cell != null) { selectedPath = getRelativePath( ((IconDescriptor[]) cell.getElement())[cell.getColumnIndex()].getPath()); if (LOG.isDebugEnabled()) { LOG.debug("Icon: " + selectedPath); // $NON-NLS-1$ } } } @Override public void mouseDoubleClick(MouseEvent e) {} }); for (int i = 0; i < iconRowSize; i++) { TableViewerColumn imageColumn = new TableViewerColumn(viewer, SWT.LEFT); imageColumn.setLabelProvider(new IconCellProvider(i)); imageColumn.getColumn().setWidth(getThumbnailSize() + ICON_SPACING); } if (!dirComboModel.isEmpty()) { dirComboModel.setSelectedIndex(2); dirCombo.select(2); directory = dirComboModel.getSelectedObject(); loadIcons(directory.getPath()); } else { loadIcons(ICON_DIRECTORY + "silk"); // $NON-NLS-1$ } }
public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); layout.numColumns = 1; container.setLayout(layout); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessVerticalSpace = true; tableViewer = new TableViewer(container, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION); tableViewer.getTable().setLayoutData(gridData); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.CENTER); column.getColumn().setText("Import"); column.getColumn().setWidth(50); column.setEditingSupport(new AccountEditingSupport(tableViewer, 0)); column = new TableViewerColumn(tableViewer, SWT.NONE); column.getColumn().setText("Nickname"); column.getColumn().setWidth(300); column.setEditingSupport(new AccountEditingSupport(tableViewer, 1)); column = new TableViewerColumn(tableViewer, SWT.NONE); column.getColumn().setText("Account #"); column.getColumn().setWidth(200); tableViewer.getTable().setFont(RcpConstants.STANDARD_FONT); tableViewer.getTable().setHeaderVisible(true); tableViewer.getTable().setLinesVisible(true); tableViewer.setContentProvider(new AccountContentProvider()); tableViewer.setLabelProvider(new AccountLabelProvider()); ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tableViewer) { protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; } }; TableViewerEditor.create( tableViewer, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); setControl(tableViewer.getTable()); ((WizardDialog) getWizard().getContainer()) .addPageChangedListener( new IPageChangedListener() { public void pageChanged(PageChangedEvent event) { if (event.getSelectedPage() == AvailableAccountsPage.this) { availableAccounts.clear(); final FinancialInstitution fi = ((NewAccountWizard) getWizard()).getFinancialInstitution(); try { getContainer() .run( false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { progressMonitor = monitor; monitor.beginTask( "Fetching Available accounts from " + fi.getName(), 100); monitor.worked(5); running = true; exception = null; Thread progressWorker = new Thread(AvailableAccountsPage.this); progressWorker.start(); while (running) { progressMonitor.worked(5); Thread.sleep(1000); } } }); } catch (Exception e) { e.printStackTrace(); } finally { progressMonitor = null; } if (exception != null) { if (exception instanceof NoOFXResponseException) { MessageDialog.openError( getShell(), "Download Error", "No response from " + fi.getName()); } else if (exception instanceof OFXRequestException) { MessageDialog.openError( getShell(), "Download Error", "Invalid request to " + fi.getName() + ". Check your username and password and try again."); } else { MessageDialog.openError( getShell(), "Download Error", "Unknown error from " + fi.getName() + ". Verify (with " + fi.getName() + ") that you have access to download transactions."); } ((NewAccountWizard) getWizard()).getContainer().showPage(getPreviousPage()); } else { tableViewer.setInput(availableAccounts); setPageComplete(true); } } } }); List<Account> dummyAccountList = new LinkedList<Account>(); for (int i = 0; i < 10; i++) { dummyAccountList.add(new Account()); } tableViewer.setInput(dummyAccountList); setPageComplete(false); }