diff options
author | Veronika Irvine | 2005-08-10 16:19:04 +0000 |
---|---|---|
committer | Veronika Irvine | 2005-08-10 16:19:04 +0000 |
commit | 1892b96441d5df27eff3326846647872f369d7a2 (patch) | |
tree | b95297f0696f700efee9e561ac47c70d0b5902ed /examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java | |
parent | c94d457c96c4085292fadea397c26e705fe48550 (diff) | |
download | eclipse.platform.swt-1892b96441d5df27eff3326846647872f369d7a2.tar.gz eclipse.platform.swt-1892b96441d5df27eff3326846647872f369d7a2.tar.xz eclipse.platform.swt-1892b96441d5df27eff3326846647872f369d7a2.zip |
*** empty log message ***
Diffstat (limited to 'examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java')
-rw-r--r-- | examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java index 106ae6c0fe..9f25acf2a6 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java @@ -30,9 +30,9 @@ public static void main (String [] args) { shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER); table.setHeaderVisible(true); - TableColumn column1 = new TableColumn(table, SWT.NONE); + final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText("Column 1"); - TableColumn column2 = new TableColumn(table, SWT.NONE); + final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText("Column 2"); TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] {"a", "3"}); @@ -40,17 +40,18 @@ public static void main (String [] args) { item.setText(new String[] {"b", "2"}); item = new TableItem(table, SWT.NONE); item.setText(new String[] {"c", "1"}); - column1.pack(); - column2.pack(); - column1.addListener(SWT.Selection, new Listener() { + column1.setWidth(100); + column2.setWidth(100); + Listener sortListener = new Listener() { public void handleEvent(Event e) { - // sort column 1 TableItem[] items = table.getItems(); Collator collator = Collator.getInstance(Locale.getDefault()); + TableColumn column = (TableColumn)e.widget; + int index = column == column1 ? 0 : 1; for (int i = 1; i < items.length; i++) { - String value1 = items[i].getText(0); + String value1 = items[i].getText(index); for (int j = 0; j < i; j++){ - String value2 = items[j].getText(0); + String value2 = items[j].getText(index); if (collator.compare(value1, value2) < 0) { String[] values = {items[i].getText(0), items[i].getText(1)}; items[i].dispose(); @@ -61,30 +62,15 @@ public static void main (String [] args) { } } } + table.setSortColumn(column); } - }); - column2.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - // sort column 2 - TableItem[] items = table.getItems(); - Collator collator = Collator.getInstance(Locale.getDefault()); - for (int i = 1; i < items.length; i++) { - String value1 = items[i].getText(1); - for (int j = 0; j < i; j++){ - String value2 = items[j].getText(1); - if (collator.compare(value1, value2) < 0) { - String[] values = {items[i].getText(0), items[i].getText(1)}; - items[i].dispose(); - TableItem item = new TableItem(table, SWT.NONE, j); - item.setText(values); - items = table.getItems(); - break; - } - } - } - } - }); - shell.open (); + }; + column1.addListener(SWT.Selection, sortListener); + column2.addListener(SWT.Selection, sortListener); + table.setSortColumn(column1); + table.setSortDirection(SWT.UP); + shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); + shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } |