annotate jface/snippets/viewers/Snippet040TableViewerSorting.d @ 146:7c4b76583cb8

Added new JFace snippets
author Frank Benoit <benoit@tionex.de>
date Mon, 11 Aug 2008 11:17:37 +0200
parents 161f7698cfb8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2006 Tom Schindl and others.
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * Tom Schindl - initial API and implementation
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ )
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
145
161f7698cfb8 Moved jface snippets to viewers subpackage, there are more with conflicting numbers for other packages
Frank Benoit <benoit@tionex.de>
parents: 88
diff changeset
13 module snippets.viewers.Snippet040TableViewerSorting;
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java?view=markup
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 import dwtx.jface.viewers.CellEditor;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import dwtx.jface.viewers.ColumnLabelProvider;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 import dwtx.jface.viewers.ColumnViewer;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import dwtx.jface.viewers.EditingSupport;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import dwtx.jface.viewers.IStructuredContentProvider;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import dwtx.jface.viewers.TableViewer;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import dwtx.jface.viewers.TableViewerColumn;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 import dwtx.jface.viewers.TextCellEditor;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 import dwtx.jface.viewers.Viewer;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 import dwtx.jface.viewers.ViewerComparator;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 import dwt.DWT;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 import dwt.events.SelectionAdapter;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 import dwt.events.SelectionEvent;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 import dwt.layout.FillLayout;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 import dwt.widgets.Display;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 import dwt.widgets.Shell;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 import dwt.dwthelper.utils;
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
34
146
7c4b76583cb8 Added new JFace snippets
Frank Benoit <benoit@tionex.de>
parents: 145
diff changeset
35 version(JIVE) import jive.stacktrace;
7c4b76583cb8 Added new JFace snippets
Frank Benoit <benoit@tionex.de>
parents: 145
diff changeset
36
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 /**
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 * Example usage of ViewerComparator in tables to allow sorting
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 *
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 * @author Tom Schindl <tom.schindl@bestsolution.at>
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 *
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 */
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 void main(String[] args) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 Snippet040TableViewerSorting.main(args);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 private class MyContentProvider : IStructuredContentProvider {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 public Object[] getElements(Object inputElement) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
51 return (cast(ArrayWrapperT!(Person)) inputElement).array;
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 public void dispose() {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 public class Person {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 public String givenname;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 public String surname;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 public String email;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 public this(String givenname, String surname, String email) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 this.givenname = givenname;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 this.surname = surname;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 this.email = email;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 protected abstract class AbstractEditingSupport : EditingSupport {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 private TextCellEditor editor;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 public this(TableViewer viewer) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 super(viewer);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 this.editor = new TextCellEditor(viewer.getTable());
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 protected bool canEdit(Object element) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 return true;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 protected CellEditor getCellEditor(Object element) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 return editor;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 protected void setValue(Object element, Object value) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 doSetValue(element, value);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 getViewer().update(element, null);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 protected abstract void doSetValue(Object element, Object value);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
99 private abstract class ColumnViewerSorter : ViewerComparator {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
100 public static final int ASC = 1;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
101
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
102 public static final int NONE = 0;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
103
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
104 public static final int DESC = -1;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
105
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
106 private int direction = 0;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
107
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
108 private TableViewerColumn column;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
109
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
110 private ColumnViewer viewer;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
111
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
112 public this(ColumnViewer viewer_, TableViewerColumn column_) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
113 this.column = column_;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
114 this.viewer = viewer_;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
115 this.column.getColumn().addSelectionListener(new class() SelectionAdapter {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
116 public void widgetSelected(SelectionEvent e) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
117 this.outer.widgetSelected(e);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
118 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
119 });
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
120 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
121
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
122 private void widgetSelected(SelectionEvent e){
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
123 if( viewer.getComparator() !is null ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
124 if( viewer.getComparator() is this ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
125 int tdirection = direction;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
126
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
127 if( tdirection is ASC ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
128 setSorter(this, DESC);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
129 } else if( tdirection is DESC ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
130 setSorter(this, NONE);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
131 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
132 } else {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
133 setSorter(this, ASC);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
134 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
135 } else {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
136 setSorter(this, ASC);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
137 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
138 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
139 public void setSorter(ColumnViewerSorter sorter, int direction) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
140 if( direction is NONE ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
141 column.getColumn().getParent().setSortColumn(null);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
142 column.getColumn().getParent().setSortDirection(DWT.NONE);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
143 viewer.setComparator(null);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
144 } else {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
145 column.getColumn().getParent().setSortColumn(column.getColumn());
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
146 sorter.direction = direction;
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
147
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
148 if( direction is ASC ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
149 column.getColumn().getParent().setSortDirection(DWT.DOWN);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
150 } else {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
151 column.getColumn().getParent().setSortDirection(DWT.UP);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
152 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
153
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
154 if( viewer.getComparator() is sorter ) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
155 viewer.refresh();
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
156 } else {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
157 viewer.setComparator(sorter);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
158 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
159
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
160 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
161 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
162
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
163 public int compare(Viewer viewer, Object e1, Object e2) {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
164 return direction * doCompare(viewer, e1, e2);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
165 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
166
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
167 protected abstract int doCompare(Viewer viewer, Object e1, Object e2);
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
168 }
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
169
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
170 public class Snippet040TableViewerSorting {
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
171
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
172
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 public this(Shell shell) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 TableViewer v = new TableViewer(shell, DWT.BORDER | DWT.FULL_SELECTION);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
175 v.setContentProvider(new MyContentProvider());
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177 TableViewerColumn column = new TableViewerColumn(v, DWT.NONE);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 column.getColumn().setWidth(200);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
179 column.getColumn().setText("Givenname");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
180 column.getColumn().setMoveable(true);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181 column.setLabelProvider(new class() ColumnLabelProvider {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
182 public String getText(Object element) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
183 return (cast(Person) element).givenname;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
184 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
185 });
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 column.setEditingSupport(new class(v) AbstractEditingSupport {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188 public this(TableViewer t ){
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189 super(t);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
190 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 protected Object getValue(Object element) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
192 return new ArrayWrapperString((cast(Person) element).givenname);
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194 protected void doSetValue(Object element, Object value) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
195 (cast(Person) element).givenname = stringcast(value);
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197 });
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 ColumnViewerSorter cSorter = new class(v,column) ColumnViewerSorter {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200 this(TableViewer t, TableViewerColumn c ){
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 super(t,c);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 protected int doCompare(Viewer viewer, Object e1, Object e2) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 Person p1 = cast(Person) e1;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 Person p2 = cast(Person) e2;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 return p1.givenname.compareToIgnoreCase(p2.givenname);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
208 };
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 column = new TableViewerColumn(v, DWT.NONE);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 column.getColumn().setWidth(200);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 column.getColumn().setText("Surname");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213 column.getColumn().setMoveable(true);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 column.setLabelProvider(new class() ColumnLabelProvider {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215 public String getText(Object element) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 return (cast(Person) element).surname;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218 });
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
219
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220 column.setEditingSupport(new class(v) AbstractEditingSupport {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221 this(TableViewer t ){
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 super(t);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224 protected Object getValue(Object element) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
225 return stringcast((cast(Person) element).surname);
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
227 protected void doSetValue(Object element, Object value) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
228 (cast(Person) element).surname = stringcast(value);
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
229 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
230 });
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
231
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
232 new class(v,column) ColumnViewerSorter {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
233 this(TableViewer t, TableViewerColumn c ){
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
234 super(t,c);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
235 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
236 protected int doCompare(Viewer viewer, Object e1, Object e2) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
237 Person p1 = cast(Person) e1;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
238 Person p2 = cast(Person) e2;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
239 return p1.surname.compareToIgnoreCase(p2.surname);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
240 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
241 };
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
242
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
243 column = new TableViewerColumn(v, DWT.NONE);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
244 column.getColumn().setWidth(200);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
245 column.getColumn().setText("E-Mail");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
246 column.getColumn().setMoveable(true);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
247 column.setLabelProvider(new class() ColumnLabelProvider {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
248 public String getText(Object element) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
249 return (cast(Person) element).email;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
250 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
251 });
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
252
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
253 column.setEditingSupport(new class(v) AbstractEditingSupport {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
254 this(TableViewer t ){
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
255 super(t);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
256 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
257 protected Object getValue(Object element) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
258 return stringcast((cast(Person) element).email);
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
259 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
260 protected void doSetValue(Object element, Object value) {
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
261 (cast(Person) element).email = stringcast(value);
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
262 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
263 });
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
264 new class(v,column) ColumnViewerSorter {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
265 this(TableViewer t, TableViewerColumn c ){
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
266 super(t,c);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
267 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
268 protected int doCompare(Viewer viewer, Object e1, Object e2) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
269 Person p1 = cast(Person) e1;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
270 Person p2 = cast(Person) e2;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
271 return p1.email.compareToIgnoreCase(p2.email);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
272 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
273 };
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
274
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
275 Person[] model = createModel();
88
9ed020f0c2a5 Fix the snippet040 example
Frank Benoit <benoit@tionex.de>
parents: 87
diff changeset
276 v.setInput( new ArrayWrapperT!(Person)(model));
87
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
277 v.getTable().setLinesVisible(true);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
278 v.getTable().setHeaderVisible(true);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
279 cSorter.setSorter(cSorter, ColumnViewerSorter.ASC);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
280 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
281
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
282 private Person[] createModel() {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
283 Person[] elements = new Person[4];
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
284 elements[0] = new Person("Tom", "Schindl",
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
285 "tom.schindl@bestsolution.at");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
286 elements[1] = new Person("Boris", "Bokowski",
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
287 "Boris_Bokowski@ca.ibm.com");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
288 elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
289 elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org");
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
290
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
291 return elements;
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
292 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
293
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
294 /**
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
295 * @param args
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
296 */
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
297 public static void main(String[] args) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
298 Display display = new Display();
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
299
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
300 Shell shell = new Shell(display);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
301 shell.setLayout(new FillLayout());
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
302 new Snippet040TableViewerSorting(shell);
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
303 shell.open();
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
304
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
305 while (!shell.isDisposed()) {
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
306 if (!display.readAndDispatch())
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
307 display.sleep();
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
308 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
309 display.dispose();
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
310 }
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
311
604fa1feb76a Added jface snippet040, thanks to yidabu. It still has compile problems, that need further examination.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
312 }