Changeset 143:42c3056512ba
- Timestamp:
- 08/07/08 16:21:50
(4 months ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
redirect the jface examples to the new collection wrappers
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r136 |
r143 |
|
| 41 | 41 | import tango.util.log.Trace; |
|---|
| 42 | 42 | |
|---|
| 43 | | import tango.util.collection.model.Seq; |
|---|
| 44 | | import tango.util.collection.ArraySeq; |
|---|
| | 43 | import dwtx.dwtxhelper.Collection; |
|---|
| 45 | 44 | import tango.text.convert.Utf; |
|---|
| 46 | 45 | |
|---|
| … | … | |
| 150 | 149 | class FileTreeLabelProvider : ILabelProvider { |
|---|
| 151 | 150 | |
|---|
| 152 | | private Seq!(ILabelProviderListener) listeners; |
|---|
| | 151 | private ArrayList listeners; |
|---|
| 153 | 152 | |
|---|
| 154 | 153 | private Image file; |
|---|
| … | … | |
| 158 | 157 | |
|---|
| 159 | 158 | public this(){ |
|---|
| 160 | | listeners = new ArraySeq!(ILabelProviderListener); |
|---|
| | 159 | listeners = new ArrayList(); |
|---|
| 161 | 160 | |
|---|
| 162 | 161 | file = new Image( null, new ImageData( new ByteArrayInputStream( cast(byte[])import( "file.png" )))); |
|---|
| … | … | |
| 168 | 167 | auto event = new LabelProviderChangedEvent(this); |
|---|
| 169 | 168 | for( int i = 0, n = listeners.size(); i < n; i++ ){ |
|---|
| 170 | | auto ilpl = listeners.get(i); |
|---|
| | 169 | auto ilpl = cast(ILabelProviderListener)listeners.get(i); |
|---|
| 171 | 170 | ilpl.labelProviderChanged(event); |
|---|
| 172 | 171 | } |
|---|
| … | … | |
| 193 | 192 | |
|---|
| 194 | 193 | public void addListener( ILabelProviderListener arg0 ){ |
|---|
| 195 | | listeners.append(arg0); |
|---|
| | 194 | listeners.add(cast(Object)arg0); |
|---|
| 196 | 195 | } |
|---|
| 197 | 196 | |
|---|
| … | … | |
| 206 | 205 | |
|---|
| 207 | 206 | public void removeListener(ILabelProviderListener arg0){ |
|---|
| 208 | | listeners.remove(arg0); |
|---|
| 209 | | } |
|---|
| 210 | | } |
|---|
| 211 | | |
|---|
| 212 | | |
|---|
| 213 | | |
|---|
| 214 | | |
|---|
| 215 | | |
|---|
| 216 | | |
|---|
| 217 | | |
|---|
| 218 | | |
|---|
| 219 | | |
|---|
| 220 | | |
|---|
| 221 | | |
|---|
| 222 | | |
|---|
| 223 | | |
|---|
| 224 | | |
|---|
| | 207 | listeners.remove(cast(Object)arg0); |
|---|
| | 208 | } |
|---|
| | 209 | } |
|---|
| | 210 | |
|---|
| | 211 | |
|---|
| | 212 | |
|---|
| | 213 | |
|---|
| | 214 | |
|---|
| | 215 | |
|---|
| | 216 | |
|---|
| | 217 | |
|---|
| | 218 | |
|---|
| | 219 | |
|---|
| | 220 | |
|---|
| | 221 | |
|---|
| | 222 | |
|---|
| | 223 | |
|---|
| r73 |
r143 |
|
| 47 | 47 | |
|---|
| 48 | 48 | import tango.text.convert.Format; |
|---|
| 49 | | import tango.util.collection.LinkSeq; |
|---|
| 50 | 49 | import tango.io.FilePath; |
|---|
| 51 | 50 | import tango.io.File; |
|---|
| … | … | |
| 55 | 54 | import tango.text.stream.LineIterator; |
|---|
| 56 | 55 | import tango.util.log.Trace; |
|---|
| | 56 | import dwtx.dwtxhelper.Collection; |
|---|
| 57 | 57 | |
|---|
| 58 | 58 | version(JIVE) import jive.stacktrace; |
|---|
| … | … | |
| 955 | 955 | |
|---|
| 956 | 956 | // The books |
|---|
| 957 | | private LinkSeq!(Book) books; |
|---|
| | 957 | private LinkedList books; |
|---|
| 958 | 958 | |
|---|
| 959 | 959 | // The dirty flag |
|---|
| … | … | |
| 964 | 964 | */ |
|---|
| 965 | 965 | public this() { |
|---|
| 966 | | books = new LinkSeq!(Book); |
|---|
| | 966 | books = new LinkedList(); |
|---|
| 967 | 967 | } |
|---|
| 968 | 968 | |
|---|
| … | … | |
| 998 | 998 | scope ostr = (new FileOutput(filename)).output; |
|---|
| 999 | 999 | scope printer = new Print!(char)( Format, ostr ); |
|---|
| 1000 | | foreach ( book; books ) { |
|---|
| | 1000 | foreach ( o; books ) { |
|---|
| | 1001 | Book book = cast(Book)o; |
|---|
| 1001 | 1002 | printer.formatln( "{}|{}",book.getTitle(), (book.getCheckedOutTo() is null ? "" : book.getCheckedOutTo())); |
|---|
| 1002 | 1003 | } |
|---|
| … | … | |
| 1013 | 1014 | */ |
|---|
| 1014 | 1015 | public bool add(Book book) { |
|---|
| 1015 | | books.append(book); |
|---|
| | 1016 | books.add(book); |
|---|
| 1016 | 1017 | setDirty(); |
|---|
| 1017 | 1018 | return true; |
|---|
| … | … | |
| 1033 | 1034 | * @return Collection |
|---|
| 1034 | 1035 | */ |
|---|
| 1035 | | public LinkSeq!(Book) getBooks() { |
|---|
| | 1036 | public LinkedList getBooks() { |
|---|
| 1036 | 1037 | return books; |
|---|
| 1037 | 1038 | } |
|---|
| r89 |
r143 |
|
| 26 | 26 | |
|---|
| 27 | 27 | import tango.util.Convert; |
|---|
| 28 | | import tango.util.collection.ArraySeq; |
|---|
| | 28 | import dwtx.dwtxhelper.Collection; |
|---|
| 29 | 29 | |
|---|
| 30 | 30 | /** |
|---|
| 31 | 31 | * A simple TableViewer to demonstrate usage |
|---|
| 32 | | * |
|---|
| | 32 | * |
|---|
| 33 | 33 | * @author Tom Schindl <tom.schindl@bestsolution.at> |
|---|
| 34 | 34 | * |
|---|
| … | … | |
| 41 | 41 | */ |
|---|
| 42 | 42 | public Object[] getElements(Object inputElement) { |
|---|
| 43 | | return (cast(ArraySeq!(MyModel))inputElement).toArray; |
|---|
| | 43 | return (cast(ArrayList)inputElement).toArray; |
|---|
| 44 | 44 | } |
|---|
| 45 | 45 | |
|---|
| … | … | |
| 48 | 48 | */ |
|---|
| 49 | 49 | public void dispose() { |
|---|
| 50 | | |
|---|
| | 50 | |
|---|
| 51 | 51 | } |
|---|
| 52 | 52 | |
|---|
| … | … | |
| 55 | 55 | */ |
|---|
| 56 | 56 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|---|
| 57 | | |
|---|
| | 57 | |
|---|
| 58 | 58 | } |
|---|
| 59 | | |
|---|
| | 59 | |
|---|
| 60 | 60 | } |
|---|
| 61 | | |
|---|
| | 61 | |
|---|
| 62 | 62 | public class MyModel { |
|---|
| 63 | 63 | public int counter; |
|---|
| 64 | | |
|---|
| | 64 | |
|---|
| 65 | 65 | public this(int counter) { |
|---|
| 66 | 66 | this.counter = counter; |
|---|
| 67 | 67 | } |
|---|
| 68 | | |
|---|
| | 68 | |
|---|
| 69 | 69 | public String toString() { |
|---|
| 70 | 70 | return "Item " ~ to!(char[])(this.counter); |
|---|
| 71 | 71 | } |
|---|
| 72 | 72 | } |
|---|
| 73 | | |
|---|
| | 73 | |
|---|
| 74 | 74 | public this(Shell shell) { |
|---|
| 75 | 75 | final TableViewer v = new TableViewer(shell); |
|---|
| 76 | 76 | v.setLabelProvider(new LabelProvider()); |
|---|
| 77 | 77 | v.setContentProvider(new MyContentProvider()); |
|---|
| 78 | | ArraySeq!(MyModel) model = createModel(); |
|---|
| | 78 | ArrayList model = createModel(); |
|---|
| 79 | 79 | v.setInput(model); |
|---|
| 80 | 80 | v.getTable().setLinesVisible(true); |
|---|
| 81 | 81 | } |
|---|
| 82 | | |
|---|
| 83 | | private ArraySeq!(MyModel) createModel() { |
|---|
| 84 | | ArraySeq!(MyModel) elements = new ArraySeq!(MyModel); |
|---|
| 85 | | elements.capacity = 10; |
|---|
| | 82 | |
|---|
| | 83 | private ArrayList createModel() { |
|---|
| | 84 | ArrayList elements = new ArrayList(10); |
|---|
| 86 | 85 | |
|---|
| 87 | 86 | for( int i = 0; i < 10; i++ ) { |
|---|
| 88 | | elements ~= new MyModel(i); |
|---|
| | 87 | elements.add( new MyModel(i)); |
|---|
| 89 | 88 | } |
|---|
| 90 | | |
|---|
| | 89 | |
|---|
| 91 | 90 | return elements; |
|---|
| 92 | 91 | } |
|---|
| 93 | | |
|---|
| | 92 | |
|---|
| 94 | 93 | } |
|---|
| 95 | 94 | |
|---|
| 96 | | void main() |
|---|
| | 95 | void main() |
|---|
| 97 | 96 | { |
|---|
| 98 | 97 | Display display = new Display (); |
|---|
| … | … | |
| 101 | 100 | new Snippet001TableViewer(shell); |
|---|
| 102 | 101 | shell.open (); |
|---|
| 103 | | |
|---|
| | 102 | |
|---|
| 104 | 103 | while (!shell.isDisposed ()) { |
|---|
| 105 | 104 | if (!display.readAndDispatch ()) display.sleep (); |
|---|
| 106 | 105 | } |
|---|
| 107 | | |
|---|
| | 106 | |
|---|
| 108 | 107 | display.dispose (); |
|---|
| 109 | 108 | |
|---|
| r89 |
r143 |
|
| 28 | 28 | |
|---|
| 29 | 29 | import dwt.dwthelper.utils; |
|---|
| | 30 | import dwtx.dwtxhelper.Collection; |
|---|
| 30 | 31 | |
|---|
| 31 | 32 | import tango.util.Convert; |
|---|
| 32 | | import tango.util.collection.ArraySeq; |
|---|
| 33 | 33 | |
|---|
| 34 | 34 | /** |
|---|
| 35 | 35 | * Snippet that hides the selection when nothing is selected. |
|---|
| 36 | | * |
|---|
| | 36 | * |
|---|
| 37 | 37 | * @author Tom Schindl <tom.schindl@bestsolution.at> |
|---|
| 38 | 38 | * |
|---|
| 39 | 39 | */ |
|---|
| 40 | 40 | public class Snippet004HideSelection { |
|---|
| 41 | | alias ArraySeq!(MyModel) MyModelArray; |
|---|
| 42 | 41 | private class MyContentProvider : IStructuredContentProvider { |
|---|
| 43 | 42 | |
|---|
| … | … | |
| 46 | 45 | */ |
|---|
| 47 | 46 | public Object[] getElements(Object inputElement) { |
|---|
| 48 | | return (cast(MyModelArray)inputElement).toArray; |
|---|
| | 47 | return (cast(ArrayList)inputElement).toArray; |
|---|
| 49 | 48 | } |
|---|
| 50 | 49 | |
|---|
| … | … | |
| 53 | 52 | */ |
|---|
| 54 | 53 | public void dispose() { |
|---|
| 55 | | |
|---|
| | 54 | |
|---|
| 56 | 55 | } |
|---|
| 57 | 56 | |
|---|
| … | … | |
| 60 | 59 | */ |
|---|
| 61 | 60 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|---|
| 62 | | |
|---|
| | 61 | |
|---|
| 63 | 62 | } |
|---|
| 64 | 63 | } |
|---|
| 65 | | |
|---|
| | 64 | |
|---|
| 66 | 65 | public class MyModel { |
|---|
| 67 | 66 | public int counter; |
|---|
| 68 | | |
|---|
| | 67 | |
|---|
| 69 | 68 | public this(int counter) { |
|---|
| 70 | 69 | this.counter = counter; |
|---|
| 71 | 70 | } |
|---|
| 72 | | |
|---|
| | 71 | |
|---|
| 73 | 72 | public String toString() { |
|---|
| 74 | 73 | return "Item " ~ to!(char[])(this.counter); |
|---|
| 75 | 74 | } |
|---|
| 76 | 75 | } |
|---|
| 77 | | |
|---|
| | 76 | |
|---|
| 78 | 77 | public this(Shell shell) { |
|---|
| 79 | 78 | final TableViewer v = new TableViewer(shell,DWT.BORDER|DWT.FULL_SELECTION); |
|---|
| 80 | 79 | v.setLabelProvider(new LabelProvider()); |
|---|
| 81 | 80 | v.setContentProvider(new MyContentProvider()); |
|---|
| 82 | | MyModelArray model = createModel(); |
|---|
| | 81 | ArrayList model = createModel(); |
|---|
| 83 | 82 | v.setInput(model); |
|---|
| 84 | 83 | v.getTable().setLinesVisible(true); |
|---|
| … | … | |
| 97 | 96 | } |
|---|
| 98 | 97 | } |
|---|
| 99 | | |
|---|
| | 98 | |
|---|
| 100 | 99 | }); |
|---|
| 101 | 100 | } |
|---|
| 102 | | |
|---|
| 103 | | private MyModelArray createModel() { |
|---|
| 104 | | MyModelArray elements = new MyModelArray; |
|---|
| 105 | | elements.capacity = 10; |
|---|
| | 101 | |
|---|
| | 102 | private ArrayList createModel() { |
|---|
| | 103 | ArrayList elements = new ArrayList(10); |
|---|
| 106 | 104 | for( int i = 0; i < 10; i++ ) { |
|---|
| 107 | | elements ~= new MyModel(i); |
|---|
| | 105 | elements.add( new MyModel(i)); |
|---|
| 108 | 106 | } |
|---|
| 109 | | |
|---|
| | 107 | |
|---|
| 110 | 108 | return elements; |
|---|
| 111 | 109 | } |
|---|
| … | … | |
| 119 | 117 | new Snippet004HideSelection(shell); |
|---|
| 120 | 118 | shell.open (); |
|---|
| 121 | | |
|---|
| | 119 | |
|---|
| 122 | 120 | while (!shell.isDisposed ()) { |
|---|
| 123 | 121 | if (!display.readAndDispatch ()) display.sleep (); |
|---|
| 124 | 122 | } |
|---|
| 125 | | |
|---|
| | 123 | |
|---|
| 126 | 124 | display.dispose (); |
|---|
| 127 | 125 | |
|---|
| r89 |
r143 |
|
| 35 | 35 | |
|---|
| 36 | 36 | import tango.util.Convert; |
|---|
| 37 | | import tango.util.collection.ArraySeq; |
|---|
| | 37 | import dwtx.dwtxhelper.Collection; |
|---|
| 38 | 38 | |
|---|
| 39 | 39 | /** |
|---|
| 40 | 40 | * TableViewer: Hide full selection |
|---|
| 41 | | * |
|---|
| | 41 | * |
|---|
| 42 | 42 | * @author Tom Schindl <tom.schindl@bestsolution.at> |
|---|
| 43 | 43 | * |
|---|
| 44 | 44 | */ |
|---|
| 45 | 45 | public class Snippet007FullSelection { |
|---|
| 46 | | alias ArraySeq!(MyModel) MyModelArray; |
|---|
| 47 | 46 | |
|---|
| 48 | 47 | private class MyContentProvider : IStructuredContentProvider { |
|---|
| … | … | |
| 52 | 51 | */ |
|---|
| 53 | 52 | public Object[] getElements(Object inputElement) { |
|---|
| 54 | | return (cast(MyModelArray)inputElement).toArray; |
|---|
| | 53 | return (cast(ArrayList)inputElement).toArray; |
|---|
| 55 | 54 | } |
|---|
| 56 | 55 | |
|---|
| … | … | |
| 59 | 58 | */ |
|---|
| 60 | 59 | public void dispose() { |
|---|
| 61 | | |
|---|
| | 60 | |
|---|
| 62 | 61 | } |
|---|
| 63 | 62 | |
|---|
| … | … | |
| 66 | 65 | */ |
|---|
| 67 | 66 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|---|
| 68 | | |
|---|
| | 67 | |
|---|
| 69 | 68 | } |
|---|
| 70 | | |
|---|
| | 69 | |
|---|
| 71 | 70 | } |
|---|
| 72 | | |
|---|
| | 71 | |
|---|
| 73 | 72 | public class MyModel { |
|---|
| 74 | 73 | public int counter; |
|---|
| 75 | | |
|---|
| | 74 | |
|---|
| 76 | 75 | public this(int counter) { |
|---|
| 77 | 76 | this.counter = counter; |
|---|
| 78 | 77 | } |
|---|
| 79 | | |
|---|
| | 78 | |
|---|
| 80 | 79 | public String toString() { |
|---|
| 81 | 80 | return "Item " ~ to!(char[])(this.counter); |
|---|
| 82 | 81 | } |
|---|
| 83 | 82 | } |
|---|
| 84 | | |
|---|
| | 83 | |
|---|
| 85 | 84 | public this(Shell shell) { |
|---|
| 86 | 85 | final TableViewer v = new TableViewer(shell,DWT.BORDER|DWT.FULL_SELECTION); |
|---|
| … | … | |
| 105 | 104 | v.update(item.getData(), null); |
|---|
| 106 | 105 | } |
|---|
| 107 | | |
|---|
| | 106 | |
|---|
| 108 | 107 | }); |
|---|
| 109 | 108 | v.setColumnProperties(["column1", "column2" ]); |
|---|
| 110 | 109 | v.setCellEditors([ new TextCellEditor(v.getTable()),new TextCellEditor(v.getTable()) ]); |
|---|
| 111 | | |
|---|
| | 110 | |
|---|
| 112 | 111 | TableColumn column = new TableColumn(v.getTable(),DWT.NONE); |
|---|
| 113 | 112 | column.setWidth(100); |
|---|
| 114 | 113 | column.setText("Column 1"); |
|---|
| 115 | | |
|---|
| | 114 | |
|---|
| 116 | 115 | column = new TableColumn(v.getTable(),DWT.NONE); |
|---|
| 117 | 116 | column.setWidth(100); |
|---|
| 118 | 117 | column.setText("Column 2"); |
|---|
| 119 | | |
|---|
| 120 | | MyModelArray model = createModel(); |
|---|
| | 118 | |
|---|
| | 119 | ArrayList model = createModel(); |
|---|
| 121 | 120 | v.setInput(model); |
|---|
| 122 | 121 | v.getTable().setLinesVisible(true); |
|---|
| 123 | 122 | v.getTable().setHeaderVisible(true); |
|---|
| 124 | | |
|---|
| | 123 | |
|---|
| 125 | 124 | v.getTable().addListener(DWT.EraseItem, new class Listener { |
|---|
| 126 | 125 | |
|---|
| … | … | |
| 132 | 131 | } |
|---|
| 133 | 132 | }); |
|---|
| 134 | | |
|---|
| | 133 | |
|---|
| 135 | 134 | } |
|---|
| 136 | | |
|---|
| 137 | | private MyModelArray createModel() { |
|---|
| 138 | | auto elements = new MyModelArray; |
|---|
| 139 | | elements.capacity = 10; |
|---|
| 140 | | |
|---|
| | 135 | |
|---|
| | 136 | private ArrayList createModel() { |
|---|
| | 137 | auto elements = new ArrayList(10); |
|---|
| | 138 | |
|---|
| 141 | 139 | for( int i = 0; i < 10; i++ ) { |
|---|
| 142 | | elements ~= new MyModel(i); |
|---|
| | 140 | elements.add( new MyModel(i)); |
|---|
| 143 | 141 | } |
|---|
| 144 | | |
|---|
| | 142 | |
|---|
| 145 | 143 | return elements; |
|---|
| 146 | 144 | } |
|---|
| 147 | | |
|---|
| | 145 | |
|---|
| 148 | 146 | } |
|---|
| 149 | 147 | |
|---|
| … | … | |
| 155 | 153 | new Snippet007FullSelection(shell); |
|---|
| 156 | 154 | shell.open (); |
|---|
| 157 | | |
|---|
| | 155 | |
|---|
| 158 | 156 | while (!shell.isDisposed ()) { |
|---|
| 159 | 157 | if (!display.readAndDispatch ()) display.sleep (); |
|---|
| 160 | 158 | } |
|---|
| 161 | | |
|---|
| | 159 | |
|---|
| 162 | 160 | display.dispose (); |
|---|
| 163 | 161 | |
|---|
| r140 |
r143 |
|
| 9 | 9 | * Tom Schindl - initial API and implementation |
|---|
| 10 | 10 | * Port to the D programming language: |
|---|
| 11 | | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| | 11 | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| 12 | 12 | *******************************************************************************/ |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 37 | 37 | import tango.util.container.LinkedList; |
|---|
| 38 | 38 | |
|---|
| | 39 | version(JIVE) import jive.stacktrace; |
|---|
| 39 | 40 | |
|---|
| 40 | 41 | |
|---|
| … | … | |
| 56 | 57 | /** |
|---|
| 57 | 58 | * A simple TreeViewer to demonstrate usage |
|---|
| 58 | | * |
|---|
| | 59 | * |
|---|
| 59 | 60 | * @author Tom Schindl <tom.schindl@bestsolution.at> |
|---|
| 60 | | * |
|---|
| | 61 | * |
|---|
| 61 | 62 | */ |
|---|
| 62 | 63 | public class Snippet014TreeViewerNoMandatoryLabelProvider { |
|---|
| 63 | 64 | alias LinkedList!(MyModel) ArrayList; |
|---|
| 64 | | |
|---|
| | 65 | |
|---|
| 65 | 66 | private class MyContentProvider : ITreeContentProvider { |
|---|
| 66 | 67 | |
|---|
| 67 | 68 | /* |
|---|
| 68 | 69 | * (non-Javadoc) |
|---|
| 69 | | * |
|---|
| | 70 | * |
|---|
| 70 | 71 | * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|---|
| 71 | 72 | */ |
|---|
| … | … | |
| 76 | 77 | /* |
|---|
| 77 | 78 | * (non-Javadoc) |
|---|
| 78 | | * |
|---|
| | 79 | * |
|---|
| 79 | 80 | * @see dwtx.jface.viewers.IContentProvider#dispose() |
|---|
| 80 | 81 | */ |
|---|
| … | … | |
| 85 | 86 | /* |
|---|
| 86 | 87 | * (non-Javadoc) |
|---|
| 87 | | * |
|---|
| | 88 | * |
|---|
| 88 | 89 | * @see dwtx.jface.viewers.IContentProvider#inputChanged(dwtx.jface.viewers.Viewer, |
|---|
| 89 | 90 | * java.lang.Object, java.lang.Object) |
|---|
| … | … | |
| 95 | 96 | /* |
|---|
| 96 | 97 | * (non-Javadoc) |
|---|
| 97 | | * |
|---|
| | 98 | * |
|---|
| 98 | 99 | * @see dwtx.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|---|
| 99 | 100 | */ |
|---|
| … | … | |
| 104 | 105 | /* |
|---|
| 105 | 106 | * (non-Javadoc) |
|---|
| 106 | | * |
|---|
| | 107 | * |
|---|
| 107 | 108 | * @see dwtx.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|---|
| 108 | 109 | */ |
|---|
| … | … | |
| 117 | 118 | /* |
|---|
| 118 | 119 | * (non-Javadoc) |
|---|
| 119 | | * |
|---|
| | 120 | * |
|---|
| 120 | 121 | * @see dwtx.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
|---|
| 121 | 122 | */ |
|---|
| … | … | |
| 156 | 157 | this() |
|---|
| 157 | 158 | { |
|---|
| 158 | | registry = new FontRegistry(); |
|---|
| | 159 | registry = new FontRegistry(); |
|---|
| 159 | 160 | } |
|---|
| 160 | 161 | |
|---|
| … | … | |
| 193 | 194 | public this(Shell shell) { |
|---|
| 194 | 195 | final TreeViewer v = new TreeViewer(shell); |
|---|
| 195 | | |
|---|
| | 196 | |
|---|
| 196 | 197 | TreeColumn column = new TreeColumn(v.getTree(),DWT.NONE); |
|---|
| 197 | 198 | column.setWidth(200); |
|---|
| 198 | 199 | column.setText("Column 1"); |
|---|
| 199 | | |
|---|
| | 200 | |
|---|
| 200 | 201 | column = new TreeColumn(v.getTree(),DWT.NONE); |
|---|
| 201 | 202 | column.setWidth(200); |
|---|
| 202 | 203 | column.setText("Column 2"); |
|---|
| 203 | | |
|---|
| | 204 | |
|---|
| 204 | 205 | v.setLabelProvider(new MyLabelProvider()); |
|---|
| 205 | 206 | v.setContentProvider(new MyContentProvider()); |
|---|
| r140 |
r143 |
|
| 9 | 9 | * Tom Schindl - initial API and implementation |
|---|
| 10 | 10 | * Port to the D programming language: |
|---|
| 11 | | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| | 11 | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| 12 | 12 | *******************************************************************************/ |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 40 | 40 | |
|---|
| 41 | 41 | import dwt.dwthelper.utils; |
|---|
| | 42 | import dwtx.dwtxhelper.Collection; |
|---|
| 42 | 43 | |
|---|
| 43 | 44 | import tango.util.Convert; |
|---|
| 44 | | import tango.util.container.LinkedList; |
|---|
| | 45 | |
|---|
| | 46 | version(JIVE) import jive.stacktrace; |
|---|
| 45 | 47 | |
|---|
| 46 | 48 | |
|---|
| … | … | |
| 62 | 64 | /** |
|---|
| 63 | 65 | * A simple TreeViewer to demonstrate usage |
|---|
| 64 | | * |
|---|
| | 66 | * |
|---|
| 65 | 67 | * @author Tom Schindl <tom.schindl@bestsolution.at> |
|---|
| 66 | | * |
|---|
| | 68 | * |
|---|
| 67 | 69 | */ |
|---|
| 68 | 70 | public class Snippet026TreeViewerTabEditing { |
|---|
| 69 | | alias LinkedList!(MyModel) ArrayList; |
|---|
| 70 | 71 | public this(Shell shell) { |
|---|
| 71 | 72 | Button b = new Button(shell,DWT.PUSH); |
|---|
| … | … | |
| 82 | 83 | } |
|---|
| 83 | 84 | public void widgetDefaultSelected(SelectionEvent e) { |
|---|
| 84 | | |
|---|
| | 85 | |
|---|
| 85 | 86 | } |
|---|
| 86 | 87 | |
|---|
| … | … | |
| 88 | 89 | v.getTree().getColumn(1).dispose(); |
|---|
| 89 | 90 | } |
|---|
| 90 | | |
|---|
| 91 | | }); |
|---|
| 92 | | |
|---|
| | 91 | |
|---|
| | 92 | }); |
|---|
| | 93 | |
|---|
| 93 | 94 | TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v)); |
|---|
| 94 | 95 | ColumnViewerEditorActivationStrategy actSupport = new class(v) ColumnViewerEditorActivationStrategy { |
|---|
| … | … | |
| 105 | 106 | } |
|---|
| 106 | 107 | }; |
|---|
| 107 | | |
|---|
| | 108 | |
|---|
| 108 | 109 | TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL |
|---|
| 109 | 110 | | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
|---|
| 110 | 111 | | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); |
|---|
| 111 | | |
|---|
| | 112 | |
|---|
| 112 | 113 | final TextCellEditor textCellEditor = new TextCellEditor(v.getTree()); |
|---|
| 113 | 114 | |
|---|
| … | … | |
| 179 | 180 | } |
|---|
| 180 | 181 | }); |
|---|
| 181 | | |
|---|
| | 182 | |
|---|
| 182 | 183 | column = new TreeViewerColumn(v, DWT.NONE); |
|---|
| 183 | 184 | column.getColumn().setWidth(200); |
|---|
| … | … | |
| 212 | 213 | } |
|---|
| 213 | 214 | }); |
|---|
| 214 | | |
|---|
| | 215 | |
|---|
| 215 | 216 | v.setContentProvider(new MyContentProvider()); |
|---|
| 216 | 217 | |
|---|
| … | … | |
| 277 | 278 | this.parent = parent; |
|---|
| 278 | 279 | this.counter = counter; |
|---|
| 279 | | child = new ArrayList(); |
|---|
| | 280 | child = new ArrayList(); |
|---|
| 280 | 281 | } |
|---|
| 281 | 282 | |
|---|
| r93 |
r143 |
|
| 9 | 9 | * Adam Neal - initial API and implementation |
|---|
| 10 | 10 | * Port to the D programming language: |
|---|
| 11 | | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| | 11 | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| 12 | 12 | *******************************************************************************/ |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 16 | 16 | // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java?view=markup |
|---|
| 17 | 17 | |
|---|
| 18 | | import tango.util.collection.ArrayBag; |
|---|
| 19 | | alias ArrayBag!(MyModel) ArrayList; |
|---|
| | 18 | import dwtx.dwtxhelper.Collection; |
|---|
| 20 | 19 | import tango.util.Convert; |
|---|
| 21 | 20 | |
|---|
| … | … | |
| 47 | 46 | |
|---|
| 48 | 47 | /** |
|---|
| 49 | | * A simple TableViewer to demonstrate how custom tooltips could be created easily while preserving |
|---|
| | 48 | * A simple TableViewer to demonstrate how custom tooltips could be created easily while preserving |
|---|
| 50 | 49 | * the multiple selection. |
|---|
| 51 | | * |
|---|
| | 50 | * |
|---|
| 52 | 51 | * This is a modified example taken from Tom Schindl's Snippet023TreeViewerCustomTooltips.java |
|---|
| 53 | | * |
|---|
| | 52 | * |
|---|
| 54 | 53 | * This code is for users pre 3.3 others could use newly added tooltip support in {@link CellLabelProvider} |
|---|
| 55 | 54 | * @author Adam Neal <Adam_Neal@ca.ibm.com> |
|---|
| 56 | | * |
|---|
| | 55 | * |
|---|
| 57 | 56 | */ |
|---|
| 58 | 57 | public class Snippet031TableViewerCustomTooltipsMultiSelection { |
|---|
| … | … | |
| 64 | 63 | |
|---|
| 65 | 64 | public String getColumnText(Object element, int columnIndex) { |
|---|
| 66 | | //if (element instanceof MyModel) { |
|---|
| | 65 | //if (element instanceof MyModel) { |
|---|
| 67 | 66 | switch (columnIndex) { |
|---|
| 68 | 67 | case 0: return (cast(MyModel)element).col1; |
|---|
| … | … | |
| 227 | 226 | TableItem [] newSelection = null; |
|---|
| 228 | 227 | if (isCTRLDown(event)) { |
|---|
| 229 | | /* We have 2 scenario's. |
|---|
| | 228 | /* We have 2 scenario's. |
|---|
| 230 | 229 | * 1) We are selecting an already selected element - so remove it from the selected indices |
|---|
| 231 | 230 | * 2) We are selecting a non-selected element - so add it to the selected indices |
|---|
| r140 |
r143 |
|
| 9 | 9 | * Tom Schindl - initial API and implementation |
|---|
| 10 | 10 | * Port to the D programming language: |
|---|
| 11 | | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| | 11 | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| 12 | 12 | *******************************************************************************/ |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 42 | 42 | import tango.util.container.LinkedList; |
|---|
| 43 | 43 | |
|---|
| | 44 | version(JIVE) import jive.stacktrace; |
|---|
| | 45 | |
|---|
| 44 | 46 | |
|---|
| 45 | 47 | void main(String[] args) { |
|---|
| … | … | |
| 57 | 59 | display.dispose(); |
|---|
| 58 | 60 | } |
|---|
| 59 | | |
|---|
| | 61 | |
|---|
| 60 | 62 | /** |
|---|
| 61 | 63 | * Demonstrates how to use keyboard-editing support in a TreeViewer with no column |
|---|
| 62 | | * |
|---|
| | 64 | * |
|---|
| 63 | 65 | * @author Tom Schindl <tom.schindl@bestsolution.at> |
|---|
| 64 | | * |
|---|
| | 66 | * |
|---|
| 65 | 67 | */ |
|---|
| 66 | 68 | public class Snippet043NoColumnTreeViewerKeyboardEditing { |
|---|
| … | … | |
| 77 | 79 | this.v = v_; |
|---|
| 78 | 80 | } |
|---|
| 79 | | |
|---|
| | 81 | |
|---|
| 80 | 82 | public void widgetDefaultSelected(SelectionEvent e) { |
|---|
| 81 | 83 | |
|---|
| r140 |
r143 |
|
| 9 | 9 | * Tom Schindl - initial API and implementation |
|---|
| 10 | 10 | * Port to the D programming language: |
|---|
| 11 | | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| | 11 | * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) |
|---|
| 12 | 12 | *******************************************************************************/ |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 27 | 27 | import tango.util.Convert; |
|---|
| 28 | 28 | import tango.util.container.LinkedList; |
|---|
| | 29 | |
|---|
| | 30 | version(JIVE) import jive.stacktrace; |
|---|
| 29 | 31 | |
|---|
| 30 | 32 | |
|---|
| … | … | |
| 50 | 52 | /** |
|---|
| 51 | 53 | * A simple TreeViewer to demonstrate usage of an ILazyContentProvider. |
|---|
| 52 | | * |
|---|
| | 54 | * |
|---|
| 53 | 55 | */ |
|---|
| 54 | 56 | public class Snippet047VirtualLazyTreeViewer { |
|---|
| 55 | | alias ArrayWrapperT!(IntermediateNode) ArrayWrapperIntermediateNode; |
|---|
| 56 | | alias ArrayWrapperT!(LeafNode) ArrayWrapperLeafNode; |
|---|
| 57 | | |
|---|
| | 57 | alias ArrayWrapperT!(IntermediateNode) ArrayWrapperIntermediateNode; |
|---|
| | 58 | alias ArrayWrapperT!(LeafNode) ArrayWrapperLeafNode; |
|---|
| | 59 | |
|---|
| 58 | 60 | private class MyContentProvider : ILazyTreeContentProvider { |
|---|
| 59 | 61 | private TreeViewer viewer; |
|---|
| … | … | |
| 75 | 77 | /* |
|---|
| 76 | 78 | * (non-Javadoc) |
|---|
| 77 | | * |
|---|
| | 79 | * |
|---|
| 78 | 80 | * @see dwtx.jface.viewers.ILazyTreeContentProvider#getParent(java.lang.Object) |
|---|
| 79 | 81 | */ |
|---|
| … | … | |
| 86 | 88 | /* |
|---|
| 87 | 89 | * (non-Javadoc) |
|---|
| 88 | | * |
|---|
| | 90 | * |
|---|
| 89 | 91 | * @see dwtx.jface.viewers.ILazyTreeContentProvider#updateChildCount(java.lang.Object, |
|---|
| 90 | 92 | * int) |
|---|
| 91 | 93 | */ |
|---|
| 92 | 94 | public void updateChildCount(Object element, int currentChildCount) { |
|---|
| 93 | | |
|---|
| | 95 | |
|---|
| 94 | 96 | int length = 0; |
|---|
| 95 | 97 | if (cast(IntermediateNode)element) { |
|---|
| 96 | 98 | IntermediateNode node = cast(IntermediateNode) element; |
|---|
| 97 | 99 | length = node.children.length; |
|---|
| 98 | | } |
|---|
| | 100 | } |
|---|
| 99 | 101 | /// TODO: fix me access violation here |
|---|
| 100 | 102 | if(element !is null && elements !is null && (cast(ArrayWrapperIntermediateNode)element) && (cast(ArrayWrapperIntermediateNode)element).array is elements) |
|---|
| 101 | 103 | length = elements.length; |
|---|
| 102 | | viewer.setChildCount(element, length); |
|---|
| | 104 | viewer.setChildCount(element, length); |
|---|
| 103 | 105 | } |
|---|
| 104 | 106 | |
|---|
| 105 | 107 | /* |
|---|
| 106 | 108 | * (non-Javadoc) |
|---|
| 107 | | * |
|---|
| | 109 | * |
|---|
| 108 | 110 | * @see dwtx.jface.viewers.ILazyTreeContentProvider#updateElement(java.lang.Object, |
|---|
| 109 | 111 | * int) |
|---|
| 110 | 112 | */ |
|---|
| 111 | 113 | public void updateElement(Object parent, int index) { |
|---|
| 112 | | |
|---|
| | 114 | |
|---|
| 113 | 115 | Object element; |
|---|
| 114 | | if (cast(IntermediateNode)parent) |
|---|
| | 116 | if (cast(IntermediateNode)parent) |
|---|
| 115 | 117 | element = (cast(IntermediateNode) parent).children[index]; |
|---|
| 116 | | |
|---|
| | 118 | |
|---|
| 117 | 119 | else |
|---|
| 118 | 120 | element = elements[index]; |
|---|
| 119 | 121 | viewer.replace(parent, index, element); |
|---|
| 120 | 122 | updateChildCount(element, -1); |
|---|
| 121 | | |
|---|
| | 123 | |
|---|
| 122 | 124 | } |
|---|
| 123 | 125 | |
|---|