10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
|
|
11 * fix for bug 163317,200558
|
|
12 * Port to the D programming language:
|
|
13 * Frank Benoit <benoit@tionex.de>
|
|
14 *******************************************************************************/
|
|
15
|
|
16 module dwtx.jface.viewers.ViewerColumn;
|
|
17
|
|
18 import dwtx.jface.viewers.CellLabelProvider;
|
|
19 import dwtx.jface.viewers.EditingSupport;
|
|
20 import dwtx.jface.viewers.ILabelProviderListener;
|
|
21 import dwtx.jface.viewers.ColumnViewer;
|
|
22 import dwtx.jface.viewers.ViewerCell;
|
|
23 import dwtx.jface.viewers.LabelProviderChangedEvent;
|
|
24
|
|
25 import dwt.events.DisposeEvent;
|
|
26 import dwt.events.DisposeListener;
|
|
27 import dwt.widgets.Widget;
|
|
28 import dwtx.jface.util.Policy;
|
|
29
|
|
30 import dwt.dwthelper.utils;
|
|
31
|
|
32 /**
|
|
33 * Instances of this class represent a column of a {@link ColumnViewer}. Label
|
|
34 * providers and editing support can be configured for each column separately.
|
|
35 * Concrete subclasses of {@link ColumnViewer} should implement a matching
|
|
36 * concrete subclass of {@link ViewerColumn}.
|
|
37 *
|
|
38 * @since 3.3
|
|
39 *
|
|
40 */
|
|
41 public abstract class ViewerColumn {
|
|
42
|
|
43 private CellLabelProvider labelProvider;
|
|
44
|
|
45 static String COLUMN_VIEWER_KEY = Policy.JFACE ~ ".columnViewer";//$NON-NLS-1$
|
|
46
|
|
47 private EditingSupport editingSupport;
|
|
48
|
|
49 private ILabelProviderListener listener;
|
|
50
|
|
51 private bool listenerRegistered = false;
|
|
52
|
|
53 /**
|
|
54 * Create a new instance of the receiver at columnIndex.
|
|
55 *
|
|
56 * @param viewer
|
|
57 * the viewer the column is part of
|
|
58 * @param columnOwner
|
|
59 * the widget owning the viewer in case the widget has no columns
|
|
60 * this could be the widget itself
|
|
61 */
|
|
62 protected this(ColumnViewer viewer, Widget columnOwner) {
|
|
63 columnOwner.setData(ViewerColumn.COLUMN_VIEWER_KEY, this);
|
39
|
64 this.listener = new class(viewer) ILabelProviderListener {
|
10
|
65 ColumnViewer viewer_;
|
39
|
66 this(ColumnViewer a){
|
|
67 viewer_= a;
|
10
|
68 }
|
|
69 public void labelProviderChanged(LabelProviderChangedEvent event) {
|
|
70 viewer_.handleLabelProviderChanged_package(event);
|
|
71 }
|
|
72
|
|
73 };
|
39
|
74 columnOwner.addDisposeListener(new class(viewer) DisposeListener {
|
10
|
75 ColumnViewer viewer_;
|
39
|
76 this(ColumnViewer a){
|
|
77 viewer_= a;
|
10
|
78 }
|
|
79 public void widgetDisposed(DisposeEvent e) {
|
|
80 handleDispose(viewer_);
|
|
81 }
|
|
82 });
|
|
83 }
|
|
84
|
|
85 /**
|
|
86 * Return the label provider for the receiver.
|
|
87 *
|
|
88 * @return ViewerLabelProvider
|
|
89 */
|
|
90 /* package */CellLabelProvider getLabelProvider() {
|
|
91 return labelProvider;
|
|
92 }
|
|
93
|
|
94 /**
|
|
95 * Set the label provider for the column. Subclasses may extend but must
|
|
96 * call the super implementation.
|
|
97 *
|
|
98 * @param labelProvider
|
|
99 * the new {@link CellLabelProvider}
|
|
100 */
|
|
101 public void setLabelProvider(CellLabelProvider labelProvider) {
|
|
102 setLabelProvider(labelProvider, true);
|
|
103 }
|
|
104
|
|
105 /**
|
|
106 * @param labelProvider
|
|
107 * @param registerListener
|
|
108 */
|
|
109 /* package */void setLabelProvider(CellLabelProvider labelProvider,
|
|
110 bool registerListener) {
|
|
111 if (listenerRegistered && this.labelProvider !is null) {
|
|
112 this.labelProvider.removeListener(listener);
|
|
113 listenerRegistered = false;
|
|
114 }
|
|
115
|
|
116 this.labelProvider = labelProvider;
|
|
117
|
|
118 if (registerListener) {
|
|
119 this.labelProvider.addListener(listener);
|
|
120 listenerRegistered = true;
|
|
121 }
|
|
122 }
|
|
123
|
|
124 /**
|
|
125 * Return the editing support for the receiver.
|
|
126 *
|
|
127 * @return {@link EditingSupport}
|
|
128 */
|
|
129 /* package */EditingSupport getEditingSupport() {
|
|
130 return editingSupport;
|
|
131 }
|
|
132
|
|
133 /**
|
|
134 * Set the editing support. Subclasses may extend but must call the super
|
|
135 * implementation.
|
|
136 *
|
|
137 * @param editingSupport
|
|
138 * The {@link EditingSupport} to set.
|
|
139 */
|
|
140 public void setEditingSupport(EditingSupport editingSupport) {
|
|
141 this.editingSupport = editingSupport;
|
|
142 }
|
|
143
|
|
144 /**
|
|
145 * Refresh the cell for the given columnIndex. <strong>NOTE:</strong>the
|
|
146 * {@link ViewerCell} provided to this method is no longer valid after this
|
|
147 * method returns. Do not cache the cell for future use.
|
|
148 *
|
|
149 * @param cell
|
|
150 * {@link ViewerCell}
|
|
151 */
|
|
152 /* package */void refresh(ViewerCell cell) {
|
|
153 getLabelProvider().update(cell);
|
|
154 }
|
|
155
|
|
156 /**
|
|
157 * Disposes of the label provider (if set), unregisters the listener and
|
|
158 * nulls the references to the label provider and editing support. This
|
|
159 * method is called when the underlying widget is disposed. Subclasses may
|
|
160 * extend but must call the super implementation.
|
|
161 */
|
|
162 protected void handleDispose() {
|
|
163 bool disposeLabelProvider = listenerRegistered;
|
|
164 CellLabelProvider cellLabelProvider = labelProvider;
|
|
165 setLabelProvider(null, false);
|
|
166 if (disposeLabelProvider) {
|
|
167 cellLabelProvider.dispose();
|
|
168 }
|
|
169 editingSupport = null;
|
|
170 listener = null;
|
|
171 }
|
|
172
|
|
173 private void handleDispose(ColumnViewer viewer) {
|
|
174 handleDispose();
|
|
175 viewer.clearLegacyEditingSetup();
|
|
176 }
|
|
177 }
|