public static void sortTable(Table table, Comparator<TableItem> comparator) { int columnCount = table.getColumnCount(); String[] values = new String[columnCount]; TableItem[] items = table.getItems(); for (int i = 1; i < items.length; i++) { for (int j = 0; j < i; j++) { TableItem item = items[i]; if (comparator.compare(item, items[j]) < 0) { for (int k = 0; k < columnCount; k++) { values[k] = item.getText(k); } Object data = item.getData(); boolean checked = item.getChecked(); item.dispose(); item = new TableItem(table, SWT.NONE, j); item.setText(values); item.setData(data); item.setChecked(checked); items = table.getItems(); break; } } } }
public static TableItem getNextTableItem(Table table, TableItem item) { TableItem[] items = table.getItems(); for (int i = 0; i < items.length - 1; i++) { if (items[i] == item) { return items[i + 1]; } } return null; }
protected TableItem newOrderedTableItem(Mapping mapping, boolean selected) { TableItem[] items = fOrderedTable.getItems(); int i = 0; while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0) i++; TableItem item = new TableItem(fOrderedTable, SWT.NULL, i); String[] values = new String[] {mapping.getElement(), mapping.getSignature()}; item.setText(values); item.setData(mapping); if (selected) fOrderedTable.setSelection(i); return item; }
private void removeIdMap(Shell shell) { TableItem[] itemsIdMap = fIdMapsTable.getSelection(); if (itemsIdMap.length > 0) { // fIdMaps.remove(itemsIdMap[0].getText()); String IdMapName = ((IdMap) itemsIdMap[0].getData()).getName(); fIdMaps.remove(IdMapName); fOrderedElements.remove(IdMapName); // All the corresponding ID Mappings must be removed as well TableItem[] itemsMappings = fMappingsTable.getItems(); for (int i = 0; i < itemsMappings.length; i++) { itemsMappings[i].dispose(); } // All the corresponding Ordered entries must be removed as well TableItem[] itemsOrdered = fOrderedTable.getItems(); for (int i = 0; i < itemsOrdered.length; i++) { itemsOrdered[i].dispose(); } // Remove extension if (!itemsIdMap[0].getText(2).equals("")) { // $NON-NLS-1$ fIdExtensionToName.remove(itemsIdMap[0].getText(2)); } itemsIdMap[0].dispose(); // Table is single selection } }
protected TableItem newMappingsTableItem(Mapping mapping, boolean selected) { TableItem[] items = fMappingsTable.getItems(); int i = 0; while (i < items.length && mapping.getElement().compareToIgnoreCase(items[i].getText(0)) > 0) i++; TableItem item = new TableItem(fMappingsTable, SWT.NULL, i); String idtext = mapping.getIdAttribute(); String idtype; if (idtext.charAt(0) == XMLStructureCreator.ID_TYPE_BODY) { idtext = idtext.substring(1, idtext.length()); idtype = IDTYPE_CHILDBODY; } else idtype = IDTYPE_ATTRIBUTE; String[] values = new String[] {mapping.getElement(), mapping.getSignature(), idtext, idtype}; item.setText(values); item.setData(mapping); if (selected) fMappingsTable.setSelection(i); return item; }
protected TableItem newIdMapsTableItem(IdMap idmap, boolean selected) { // find index where to insert table entry TableItem[] items = fIdMapsTable.getItems(); int i = 0; while (i < items.length && idmap.getName().compareToIgnoreCase(items[i].getText(0)) > 0) i++; TableItem item = new TableItem(fIdMapsTable, SWT.NULL, i); String[] values = new String[] { idmap.getName(), (idmap.isInternal()) ? XMLCompareMessages.XMLComparePreference_topTableColumn2internal : XMLCompareMessages.XMLComparePreference_topTableColumn2user, idmap.getExtension() }; item.setText(values); item.setData(idmap); if (selected) { fIdMapsTable.setSelection(i); fIdMapsTable.setFocus(); selectionChanged(); } return item; }