private void handleAdd() { IStructuredSelection ssel = (IStructuredSelection) fAvailableListViewer.getSelection(); if (ssel.size() > 0) { Table table = fAvailableListViewer.getTable(); int index = table.getSelectionIndices()[0]; doAdd(ssel.toList()); table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); pageChanged(true, false); } }
private void handleRemove() { IStructuredSelection ssel = (IStructuredSelection) fImportListViewer.getSelection(); if (ssel.size() > 0) { Table table = fImportListViewer.getTable(); int index = table.getSelectionIndices()[0]; doRemove(ssel.toList()); table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); pageChanged(false, true); } }
private void sort(int column) { if (table.getItemCount() <= 1) return; TableItem[] items = table.getItems(); String[][] data = new String[items.length][table.getColumnCount()]; for (int i = 0; i < items.length; i++) { for (int j = 0; j < table.getColumnCount(); j++) { data[i][j] = items[i].getText(j); } } Arrays.sort(data, new RowComparator(column)); if (lastSortColumn != column) { table.setSortColumn(table.getColumn(column)); table.setSortDirection(SWT.DOWN); for (int i = 0; i < data.length; i++) { items[i].setText(data[i]); } lastSortColumn = column; } else { // reverse order if the current column is selected again table.setSortDirection(SWT.UP); int j = data.length - 1; for (int i = 0; i < data.length; i++) { items[i].setText(data[j--]); } lastSortColumn = -1; } }
private boolean findEntry() { Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); shell.setCursor(waitCursor); boolean matchCase = searchDialog.getMatchCase(); boolean matchWord = searchDialog.getMatchWord(); String searchString = searchDialog.getSearchString(); int column = searchDialog.getSelectedSearchArea(); searchString = matchCase ? searchString : searchString.toLowerCase(); boolean found = false; if (searchDialog.getSearchDown()) { for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) { if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) { table.setSelection(i); break; } } } else { for (int i = table.getSelectionIndex() - 1; i > -1; i--) { if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) { table.setSelection(i); break; } } } shell.setCursor(null); return found; }
@Override public void modelChanged(IModelChangedEvent event) { if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { fHeader = null; markStale(); return; } if (getExportedPackageHeader().equals(event.getChangedProperty())) { refresh(); // Bug 171896 // Since the model sends a CHANGE event instead of // an INSERT event on the very first addition to the empty table // Selection should fire here to take this first insertion into account Object lastElement = fPackageViewer.getElementAt(fPackageViewer.getTable().getItemCount() - 1); if (lastElement != null) { fPackageViewer.setSelection(new StructuredSelection(lastElement)); } return; } Object[] objects = event.getChangedObjects(); for (Object changedObject : objects) { if (changedObject instanceof ExportPackageObject) { ExportPackageObject object = (ExportPackageObject) changedObject; switch (event.getChangeType()) { case IModelChangedEvent.INSERT: fPackageViewer.add(object); fPackageViewer.setSelection(new StructuredSelection(object), false); fPackageViewer.getTable().setFocus(); break; case IModelChangedEvent.REMOVE: Table table = fPackageViewer.getTable(); int index = table.getSelectionIndex(); fPackageViewer.remove(object); table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); break; default: fPackageViewer.refresh(object); } } } }
private void sort(int column) { if (table.getItemCount() <= 1) return; TableItem[] items = table.getItems(); String[][] data = new String[items.length][table.getColumnCount()]; for (int i = 0; i < items.length; i++) { for (int j = 0; j < table.getColumnCount(); j++) { data[i][j] = items[i].getText(j); } } Arrays.sort(data, new RowComparator(column)); for (int i = 0; i < data.length; i++) { items[i].setText(data[i]); } }
/* (non-Javadoc) * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent) */ public void modelChanged(IModelChangedEvent e) { // No need to call super, handling world changed event here if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { handleModelEventWorldChanged(e); return; } Object[] objects = e.getChangedObjects(); if (e.getChangeType() == IModelChangedEvent.INSERT) { for (int i = 0; i < objects.length; i++) { if (objects[i] instanceof IProductPlugin) fPluginTable.add(objects[i]); } } else if (e.getChangeType() == IModelChangedEvent.REMOVE) { Table table = fPluginTable.getTable(); int index = table.getSelectionIndex(); for (int i = 0; i < objects.length; i++) { if (objects[i] instanceof IProductPlugin) fPluginTable.remove(objects[i]); } // Update Selection int count = table.getItemCount(); if (count == 0) { // Nothing to select } else if (index < count) { table.setSelection(index); } else { table.setSelection(count - 1); } } else if (e.getChangeType() == IModelChangedEvent.CHANGE) { fPluginTable.refresh(); } updateRemoveButtons(false, true); }