Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 172646 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (-9 / +7 lines)
Lines 134-143 Link Here
134
				return new StructuredSelection(element);
134
				return new StructuredSelection(element);
135
			}
135
			}
136
136
137
			protected Item[] getSelection() {
138
				return table.getSelection();
139
			}
140
141
			protected void setEditor(Control w, Item item, int fColumnNumber) {
137
			protected void setEditor(Control w, Item item, int fColumnNumber) {
142
				tableEditor.setEditor(w, (TableItem) item, fColumnNumber);
138
				tableEditor.setEditor(w, (TableItem) item, fColumnNumber);
143
			}
139
			}
Lines 148-157 Link Here
148
				tableEditor.minimumWidth = layoutData.minimumWidth;
144
				tableEditor.minimumWidth = layoutData.minimumWidth;
149
			}
145
			}
150
146
151
			protected void showSelection() {
152
				table.showSelection();
153
			}
154
155
		};
147
		};
156
	}
148
	}
157
	
149
	
Lines 303-306 Link Here
303
	protected void doClear(int index) {
295
	protected void doClear(int index) {
304
		table.clear(index);
296
		table.clear(index);
305
	}
297
	}
306
}
298
	
299
300
	protected ViewerCell getFocusCell() {
301
		//TODO Focus tracking has to be implemented in M6
302
		return null;
303
	}
304
}
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-8 / +5 lines)
Lines 284-293 Link Here
284
				return new StructuredSelection(element);
284
				return new StructuredSelection(element);
285
			}
285
			}
286
286
287
			protected Item[] getSelection() {
288
				return tree.getSelection();
289
			}
290
291
			protected void setEditor(Control w, Item item, int fColumnNumber) {
287
			protected void setEditor(Control w, Item item, int fColumnNumber) {
292
				treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
288
				treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
293
			}
289
			}
Lines 298-307 Link Here
298
				treeEditor.minimumWidth = layoutData.minimumWidth;
294
				treeEditor.minimumWidth = layoutData.minimumWidth;
299
			}
295
			}
300
296
301
			protected void showSelection() {
302
				getTree().showSelection();
303
			}
304
305
		};
297
		};
306
	}
298
	}
307
299
Lines 913-916 Link Here
913
	protected int doGetColumnCount() {
905
	protected int doGetColumnCount() {
914
		return tree.getColumnCount();
906
		return tree.getColumnCount();
915
	}
907
	}
908
	
909
	protected ViewerCell getFocusCell() {
910
		//TODO Focus tracking has to be implemented in M6
911
		return null;
912
	}
916
}
913
}
(-)src/org/eclipse/jface/viewers/AbstractTreeViewer.java (+7 lines)
Lines 2950-2953 Link Here
2950
			return false;
2950
			return false;
2951
		return ((TreePath) elementOrTreePath).getSegmentCount() == 0;
2951
		return ((TreePath) elementOrTreePath).getSegmentCount() == 0;
2952
	}
2952
	}
2953
	
2954
	// --------------------------------------------------
2955
	// These methods should be overwritten by subclasses and are only here to provide backwards compatility
2956
	
2957
	protected ViewerCell getFocusCell() {
2958
		return null;
2959
	}
2953
}
2960
}
(-)src/org/eclipse/jface/viewers/EditingSupport.java (-2 / +12 lines)
Lines 13-18 Link Here
13
13
14
package org.eclipse.jface.viewers;
14
package org.eclipse.jface.viewers;
15
15
16
import java.util.List;
17
16
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.TraverseEvent;
20
import org.eclipse.swt.events.TraverseEvent;
Lines 170-177 Link Here
170
		}
172
		}
171
173
172
		if (cell2edit != null) {
174
		if (cell2edit != null) {
173
			viewer.editElement(cell2edit.getElement(), cell2edit
175
			List l = viewer.getSelectionFromWidget();
174
					.getColumnIndex());
176
			
177
			viewer.getControl().setRedraw(false);
178
			if( l.size() > 1 || ! l.contains(cell2edit.getElement()) ) {
179
				viewer.setSelection(new StructuredSelection(cell2edit.getElement()));
180
			}
181
			
182
			EditorActivationEvent acEvent = new EditorActivationEvent(cell2edit,event);
183
			viewer.fireEditorActivationEvent(acEvent);
184
			viewer.getControl().setRedraw(true);
175
		}
185
		}
176
	}
186
	}
177
187
(-)src/org/eclipse/jface/viewers/ColumnViewer.java (-3 / +114 lines)
Lines 14-20 Link Here
14
14
15
package org.eclipse.jface.viewers;
15
package org.eclipse.jface.viewers;
16
16
17
18
import java.util.List;
19
17
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.swt.events.KeyEvent;
22
import org.eclipse.swt.events.KeyListener;
18
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseAdapter;
19
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.MouseEvent;
20
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.graphics.Point;
Lines 50-55 Link Here
50
55
51
	private int tabEditingStyle = EditingSupport.TABING_NONE;
56
	private int tabEditingStyle = EditingSupport.TABING_NONE;
52
	
57
	
58
	private KeyListener keyboardActivationListener;
59
	
53
	/**
60
	/**
54
	 * Create a new instance of the receiver.
61
	 * Create a new instance of the receiver.
55
	 */
62
	 */
Lines 76-82 Link Here
76
		if (viewerEditor != null) {
83
		if (viewerEditor != null) {
77
			control.addMouseListener(new MouseAdapter() {
84
			control.addMouseListener(new MouseAdapter() {
78
				public void mouseDown(MouseEvent e) {
85
				public void mouseDown(MouseEvent e) {
79
					viewerEditor.handleMouseDown(e);
86
					handleMouseDown(e);
80
				}
87
				}
81
			});
88
			});
82
		}
89
		}
Lines 371-380 Link Here
371
	 */
378
	 */
372
	public void editElement(Object element, int column) {
379
	public void editElement(Object element, int column) {
373
		if (viewerEditor != null) {
380
		if (viewerEditor != null) {
374
			viewerEditor.editElement(element, column);
381
			Widget item = findItem(element);
382
			if( item != null ) {
383
				ViewerRow row = getViewerRowFromItem(item);
384
				if( row != null ) {
385
					ViewerCell cell = row.getCell(column);
386
					if( cell != null ) {
387
						getControl().setRedraw(false);
388
						
389
						List l = getSelectionFromWidget();
390
						
391
						if( l.size() > 1 || ! l.contains(cell.getElement()) ) {
392
							setSelection(new StructuredSelection(cell.getElement()));
393
						}
394
395
						fireEditorActivationEvent(new EditorActivationEvent(cell));
396
						getControl().setRedraw(true);
397
					}
398
				}
399
			}
375
		}
400
		}
376
	}
401
	}
377
402
	
403
	/**
404
	 * Invoking this method fires an editor activation event which tries to enable the editor 
405
	 * but before this event is passed to {@link EditorActivationStrategy} to see 
406
	 * if this event should really trigger editor activation
407
	 * @param event the activation event
408
	 */
409
	protected void fireEditorActivationEvent(EditorActivationEvent event) {
410
		viewerEditor.handleEditorActivationEvent(event);
411
	}
412
	
378
	/**
413
	/**
379
	 * Return the CellEditors for the receiver, or <code>null</code> if no
414
	 * Return the CellEditors for the receiver, or <code>null</code> if no
380
     * cell editors are set.
415
     * cell editors are set.
Lines 546-551 Link Here
546
	}
581
	}
547
	
582
	
548
	/**
583
	/**
584
	 * To fully control the strategy used to control on which cell-selection
585
	 * events the editor has to be activated you can pass your customized
586
	 * strategy using this method.
587
	 * 
588
	 * @param editorActivationStrategy
589
	 *            the strategy used to activate an editor
590
	 */
591
	public void setEditorActivationStrategy(
592
			EditorActivationStrategy editorActivationStrategy) {
593
		if( viewerEditor != null ) {
594
			viewerEditor.setEditorActivationStrategy(editorActivationStrategy);
595
		} else {
596
			throw new IllegalStateException("This feature is not supported by the widget"); //$NON-NLS-1$
597
		}
598
	}
599
	
600
	/**
601
	 * Enable activation of cell editors by keyboard
602
	 * @param enable <code>true</code> to enable
603
	 */
604
	public void setEnableEditorActivationWithKeyboard(boolean enable) {
605
		if( enable ) {
606
			if( keyboardActivationListener == null ) {
607
				keyboardActivationListener = new KeyListener() {
608
609
					public void keyPressed(KeyEvent e) {
610
						ViewerCell cell = getFocusCell();
611
						
612
						if( cell != null ) {
613
							fireEditorActivationEvent(new EditorActivationEvent(cell,e));
614
						}
615
					}
616
617
					public void keyReleased(KeyEvent e) {
618
						
619
					}
620
					
621
				};
622
				getControl().addKeyListener(keyboardActivationListener);
623
			}
624
		} else {
625
			if( keyboardActivationListener != null ) {
626
				getControl().removeKeyListener(keyboardActivationListener);
627
				keyboardActivationListener = null;
628
			}
629
		}
630
	}
631
	
632
	/**
633
	 * @param listener
634
	 */
635
	public void addEditorActivationListner(AbstractViewerEditorActivationListener listener) {
636
		this.viewerEditor.addEditorActivationListener(listener);
637
	}
638
		
639
	/**
640
	 * @param listener
641
	 */
642
	public void removeEditorActivationListener(AbstractViewerEditorActivationListener listener) {
643
		this.viewerEditor.removeEditorActivationListener(listener);
644
	}
645
	
646
	private void handleMouseDown(MouseEvent e) {
647
		ViewerCell cell = getCell(new Point(e.x,e.y));
648
		
649
		if( cell != null ) {
650
			fireEditorActivationEvent(new EditorActivationEvent(cell,e));
651
		}
652
	}
653
	
654
	/**
655
	 * @return the cell currently focused or <code>null</code>
656
	 */
657
	protected abstract ViewerCell getFocusCell();
658
	
659
	/**
549
	 * Returns the number of columns contained in the receiver. If no columns
660
	 * Returns the number of columns contained in the receiver. If no columns
550
	 * were created by the programmer, this value is zero, despite the fact that
661
	 * were created by the programmer, this value is zero, despite the fact that
551
	 * visually, one column of items may be visible. This occurs when the
662
	 * visually, one column of items may be visible. This occurs when the
(-)src/org/eclipse/jface/viewers/CellEditor.java (-814 / +839 lines)
Lines 22-856 Link Here
22
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Control;
23
23
24
/**
24
/**
25
 * Abstract base class for cell editors. Implements property change listener handling,
25
 * Abstract base class for cell editors. Implements property change listener
26
 * and SWT window management.
26
 * handling, and SWT window management.
27
 * <p>
27
 * <p>
28
 * Subclasses implement particular kinds of cell editors. This package contains various
28
 * Subclasses implement particular kinds of cell editors. This package contains
29
 * specialized cell editors:
29
 * various specialized cell editors:
30
 * <ul>
30
 * <ul>
31
 *   <li><code>TextCellEditor</code> - for simple text strings</li>
31
 * <li><code>TextCellEditor</code> - for simple text strings</li>
32
 *   <li><code>ColorCellEditor</code> - for colors</li>
32
 * <li><code>ColorCellEditor</code> - for colors</li>
33
 *   <li><code>ComboBoxCellEditor</code> - value selected from drop-down combo box</li>
33
 * <li><code>ComboBoxCellEditor</code> - value selected from drop-down combo
34
 *   <li><code>CheckboxCellEditor</code> - boolean valued checkbox</li>
34
 * box</li>
35
 *   <li><code>DialogCellEditor</code> - value from arbitrary dialog</li>
35
 * <li><code>CheckboxCellEditor</code> - boolean valued checkbox</li>
36
 * <li><code>DialogCellEditor</code> - value from arbitrary dialog</li>
36
 * </ul>
37
 * </ul>
37
 * </p>
38
 * </p>
38
 */
39
 */
39
public abstract class CellEditor {
40
public abstract class CellEditor {
40
41
41
    /**
42
	/**
42
     * List of cell editor listeners (element type: <code>ICellEditorListener</code>).
43
	 * List of cell editor listeners (element type:
43
     */
44
	 * <code>ICellEditorListener</code>).
44
    private ListenerList listeners = new ListenerList();
45
	 */
45
46
	private ListenerList listeners = new ListenerList();
46
    /**
47
47
     * List of cell editor property change listeners 
48
	/**
48
     * (element type: <code>IPropertyChangeListener</code>).
49
	 * List of cell editor property change listeners (element type:
49
     */
50
	 * <code>IPropertyChangeListener</code>).
50
    private ListenerList propertyChangeListeners = new ListenerList();
51
	 */
51
52
	private ListenerList propertyChangeListeners = new ListenerList();
52
    /**
53
53
     * Indicates whether this cell editor's current value is valid.
54
	/**
54
     */
55
	 * Indicates whether this cell editor's current value is valid.
55
    private boolean valid = false;
56
	 */
56
57
	private boolean valid = false;
57
    /**
58
58
     * Optional cell editor validator; <code>null</code> if none.
59
	/**
59
     */
60
	 * Optional cell editor validator; <code>null</code> if none.
60
    private ICellEditorValidator validator = null;
61
	 */
61
62
	private ICellEditorValidator validator = null;
62
    /**
63
63
     * The error message string to display for invalid values;
64
	/**
64
     * <code>null</code> if none (that is, the value is valid).
65
	 * The error message string to display for invalid values; <code>null</code>
65
     */
66
	 * if none (that is, the value is valid).
66
    private String errorMessage = null;
67
	 */
67
68
	private String errorMessage = null;
68
    /**
69
69
     * Indicates whether this cell editor has been changed recently.
70
	/**
70
     */
71
	 * Indicates whether this cell editor has been changed recently.
71
    private boolean dirty = false;
72
	 */
72
73
	private boolean dirty = false;
73
    /**
74
74
     * This cell editor's control, or <code>null</code>
75
	/**
75
     * if not created yet.
76
	 * This cell editor's control, or <code>null</code> if not created yet.
76
     */
77
	 */
77
    private Control control = null;
78
	private Control control = null;
78
79
79
    /**
80
	/**
80
     * Default cell editor style
81
	 * Default cell editor style
81
     */
82
	 */
82
    private static final int defaultStyle = SWT.NONE;
83
	private static final int defaultStyle = SWT.NONE;
83
84
84
    /**
85
	/**
85
     * This cell editor's style
86
	 * This cell editor's style
86
     */
87
	 */
87
    private int style = defaultStyle;
88
	private int style = defaultStyle;
88
89
89
    /** 
90
	/**
90
     * Struct-like layout data for cell editors, with reasonable defaults
91
	 * Struct-like layout data for cell editors, with reasonable defaults for
91
     * for all fields.
92
	 * all fields.
92
     */
93
	 */
93
    public static class LayoutData {
94
	public static class LayoutData {
94
        /**
95
		/**
95
         * Horizontal alignment; <code>SWT.LEFT</code> by default.
96
		 * Horizontal alignment; <code>SWT.LEFT</code> by default.
96
         */
97
		 */
97
        public int horizontalAlignment = SWT.LEFT;
98
		public int horizontalAlignment = SWT.LEFT;
98
99
99
        /**
100
		/**
100
         * Indicates control grabs additional space; <code>true</code> by default.
101
		 * Indicates control grabs additional space; <code>true</code> by
101
         */
102
		 * default.
102
        public boolean grabHorizontal = true;
103
		 */
103
104
		public boolean grabHorizontal = true;
104
        /**
105
105
         * Minimum width in pixels; <code>50</code> pixels by default.
106
		/**
106
         */
107
		 * Minimum width in pixels; <code>50</code> pixels by default.
107
        public int minimumWidth = 50;
108
		 */
108
    }
109
		public int minimumWidth = 50;
109
110
	}
110
    /**
111
111
     * Property name for the copy action
112
	/**
112
     */
113
	 * Property name for the copy action
113
    public static final String COPY = "copy"; //$NON-NLS-1$
114
	 */
114
115
	public static final String COPY = "copy"; //$NON-NLS-1$
115
    /**
116
116
     * Property name for the cut action
117
	/**
117
     */
118
	 * Property name for the cut action
118
    public static final String CUT = "cut"; //$NON-NLS-1$
119
	 */
119
120
	public static final String CUT = "cut"; //$NON-NLS-1$
120
    /**
121
121
     * Property name for the delete action
122
	/**
122
     */
123
	 * Property name for the delete action
123
    public static final String DELETE = "delete"; //$NON-NLS-1$
124
	 */
124
125
	public static final String DELETE = "delete"; //$NON-NLS-1$
125
    /**
126
126
     * Property name for the find action
127
	/**
127
     */
128
	 * Property name for the find action
128
    public static final String FIND = "find"; //$NON-NLS-1$
129
	 */
129
130
	public static final String FIND = "find"; //$NON-NLS-1$
130
    /**
131
131
     * Property name for the paste action
132
	/**
132
     */
133
	 * Property name for the paste action
133
    public static final String PASTE = "paste"; //$NON-NLS-1$
134
	 */
134
135
	public static final String PASTE = "paste"; //$NON-NLS-1$
135
    /**
136
136
     * Property name for the redo action
137
	/**
137
     */
138
	 * Property name for the redo action
138
    public static final String REDO = "redo"; //$NON-NLS-1$
139
	 */
139
140
	public static final String REDO = "redo"; //$NON-NLS-1$
140
    /**
141
141
     * Property name for the select all action
142
	/**
142
     */
143
	 * Property name for the select all action
143
    public static final String SELECT_ALL = "selectall"; //$NON-NLS-1$
144
	 */
144
145
	public static final String SELECT_ALL = "selectall"; //$NON-NLS-1$
145
    /**
146
146
     * Property name for the undo action
147
	/**
147
     */
148
	 * Property name for the undo action
148
    public static final String UNDO = "undo"; //$NON-NLS-1$
149
	 */
149
150
	public static final String UNDO = "undo"; //$NON-NLS-1$
150
    /**
151
151
     * Creates a new cell editor with no control 
152
	/**
152
     * The cell editor has no cell validator.
153
	 * Creates a new cell editor with no control The cell editor has no cell
153
     * @since 2.1
154
	 * validator.
154
     */
155
	 * 
155
    protected CellEditor() {
156
	 * @since 2.1
156
    }
157
	 */
157
158
	protected CellEditor() {
158
    /**
159
	}
159
     * Creates a new cell editor under the given parent control.
160
160
     * The cell editor has no cell validator.
161
	/**
161
     *
162
	 * Creates a new cell editor under the given parent control. The cell editor
162
     * @param parent the parent control
163
	 * has no cell validator.
163
     */
164
	 * 
164
    protected CellEditor(Composite parent) {
165
	 * @param parent
165
        this(parent, defaultStyle);
166
	 *            the parent control
166
    }
167
	 */
167
168
	protected CellEditor(Composite parent) {
168
    /**
169
		this(parent, defaultStyle);
169
     * Creates a new cell editor under the given parent control.
170
	}
170
     * The cell editor has no cell validator.
171
171
     *
172
	/**
172
     * @param parent the parent control
173
	 * Creates a new cell editor under the given parent control. The cell editor
173
     * @param style the style bits
174
	 * has no cell validator.
174
     * @since 2.1
175
	 * 
175
     */
176
	 * @param parent
176
    protected CellEditor(Composite parent, int style) {
177
	 *            the parent control
177
        this.style = style;
178
	 * @param style
178
        create(parent);
179
	 *            the style bits
179
    }
180
	 * @since 2.1
180
181
	 */
181
    /**
182
	protected CellEditor(Composite parent, int style) {
182
     * Activates this cell editor.
183
		this.style = style;
183
     * <p>
184
		create(parent);
184
     * The default implementation of this framework method
185
	}
185
     * does nothing. Subclasses may reimplement.
186
186
     * </p>
187
	/**
187
     */
188
	 * Activates this cell editor.
188
    public void activate() {
189
	 * <p>
189
    }
190
	 * The default implementation of this framework method does nothing.
190
191
	 * Subclasses may reimplement.
191
    /**
192
	 * </p>
192
     * Adds a listener to this cell editor.
193
	 */
193
     * Has no effect if an identical listener is already registered.
194
	public void activate() {
194
     *
195
	}
195
     * @param listener a cell editor listener
196
196
     */
197
	/**
197
    public void addListener(ICellEditorListener listener) {
198
	 * Activate the editor but also inform the editor which event triggered its activation.
198
        listeners.add(listener);
199
	 * <b>The default implementation simply calls {@link #activate()}</b>
199
    }
200
	 * 
200
201
	 * @param activationEvent the editor activation event
201
    /**
202
	 */
202
     * Adds a property change listener to this cell editor.
203
	public void activate(EditorActivationEvent activationEvent) {
203
     * Has no effect if an identical property change listener 
204
		activate();
204
     * is already registered.
205
	}
205
     *
206
206
     * @param listener a property change listener
207
	/**
207
     */
208
	 * Adds a listener to this cell editor. Has no effect if an identical
208
    public void addPropertyChangeListener(IPropertyChangeListener listener) {
209
	 * listener is already registered.
209
        propertyChangeListeners.add(listener);
210
	 * 
210
    }
211
	 * @param listener
211
212
	 *            a cell editor listener
212
    /**
213
	 */
213
     * Creates the control for this cell editor under the given parent control.
214
	public void addListener(ICellEditorListener listener) {
214
     * <p>
215
		listeners.add(listener);
215
     * This framework method must be implemented by concrete
216
	}
216
     * subclasses.
217
217
     * </p>
218
	/**
218
     *
219
	 * Adds a property change listener to this cell editor. Has no effect if an
219
     * @param parent the parent control
220
	 * identical property change listener is already registered.
220
     * @return the new control, or <code>null</code> if this cell editor has no control
221
	 * 
221
     */
222
	 * @param listener
222
    protected abstract Control createControl(Composite parent);
223
	 *            a property change listener
223
224
	 */
224
    /**
225
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
225
     * Creates the control for this cell editor under the given parent control.
226
		propertyChangeListeners.add(listener);
226
     * 
227
	}
227
     * @param parent the parent control
228
228
     * @since 2.1
229
	/**
229
     */
230
	 * Creates the control for this cell editor under the given parent control.
230
    public void create(Composite parent) {
231
	 * <p>
231
        Assert.isTrue(control == null);
232
	 * This framework method must be implemented by concrete subclasses.
232
        control = createControl(parent);
233
	 * </p>
233
        // See 1GD5CA6: ITPUI:ALL - TaskView.setSelection does not work
234
	 * 
234
        // Control is created with getVisible()==true by default.
235
	 * @param parent
235
        // This causes composite.setFocus() to work incorrectly.
236
	 *            the parent control
236
        // The cell editor's control grabs focus instead, even if it is not active.
237
	 * @return the new control, or <code>null</code> if this cell editor has
237
        // Make the control invisible here by default.
238
	 *         no control
238
        deactivate();
239
	 */
239
    }
240
	protected abstract Control createControl(Composite parent);
240
241
241
    /**
242
	/**
242
     * Hides this cell editor's control. Does nothing if this 
243
	 * Creates the control for this cell editor under the given parent control.
243
     * cell editor is not visible.
244
	 * 
244
     */
245
	 * @param parent
245
    public void deactivate() {
246
	 *            the parent control
246
        if (control != null && !control.isDisposed()) {
247
	 * @since 2.1
248
	 */
249
	public void create(Composite parent) {
250
		Assert.isTrue(control == null);
251
		control = createControl(parent);
252
		// See 1GD5CA6: ITPUI:ALL - TaskView.setSelection does not work
253
		// Control is created with getVisible()==true by default.
254
		// This causes composite.setFocus() to work incorrectly.
255
		// The cell editor's control grabs focus instead, even if it is not
256
		// active.
257
		// Make the control invisible here by default.
258
		deactivate();
259
	}
260
261
	/**
262
	 * Hides this cell editor's control. Does nothing if this cell editor is not
263
	 * visible.
264
	 */
265
	public void deactivate() {
266
		if (control != null && !control.isDisposed()) {
247
			control.setVisible(false);
267
			control.setVisible(false);
248
		}
268
		}
249
    }
269
	}
250
270
251
    /**
271
	/**
252
     * Disposes of this cell editor and frees any associated SWT resources.
272
	 * Disposes of this cell editor and frees any associated SWT resources.
253
     */
273
	 */
254
    public void dispose() {
274
	public void dispose() {
255
        if (control != null && !control.isDisposed()) {
275
		if (control != null && !control.isDisposed()) {
256
            control.dispose();
276
			control.dispose();
257
        }
277
		}
258
        control = null;
278
		control = null;
259
    }
279
	}
260
280
261
    /**
281
	/**
262
     * Returns this cell editor's value.
282
	 * Returns this cell editor's value.
263
     * <p>
283
	 * <p>
264
     * This framework method must be implemented by concrete subclasses.
284
	 * This framework method must be implemented by concrete subclasses.
265
     * </p>
285
	 * </p>
266
     *
286
	 * 
267
     * @return the value of this cell editor
287
	 * @return the value of this cell editor
268
     * @see #getValue
288
	 * @see #getValue
269
     */
289
	 */
270
    protected abstract Object doGetValue();
290
	protected abstract Object doGetValue();
271
291
272
    /**
292
	/**
273
     * Sets the focus to the cell editor's control.
293
	 * Sets the focus to the cell editor's control.
274
     * <p>
294
	 * <p>
275
     * This framework method must be implemented by concrete subclasses.
295
	 * This framework method must be implemented by concrete subclasses.
276
     * </p>
296
	 * </p>
277
     *
297
	 * 
278
     * @see #setFocus
298
	 * @see #setFocus
279
     */
299
	 */
280
    protected abstract void doSetFocus();
300
	protected abstract void doSetFocus();
281
301
282
    /**
302
	/**
283
     * Sets this cell editor's value.
303
	 * Sets this cell editor's value.
284
     * <p>
304
	 * <p>
285
     * This framework method must be implemented by concrete subclasses.
305
	 * This framework method must be implemented by concrete subclasses.
286
     * </p>
306
	 * </p>
287
     *
307
	 * 
288
     * @param value the value of this cell editor
308
	 * @param value
289
     * @see #setValue
309
	 *            the value of this cell editor
290
     */
310
	 * @see #setValue
291
    protected abstract void doSetValue(Object value);
311
	 */
292
312
	protected abstract void doSetValue(Object value);
293
    /**
313
294
     * Notifies all registered cell editor listeners of an apply event.
314
	/**
295
     * Only listeners registered at the time this method is called are notified.
315
	 * Notifies all registered cell editor listeners of an apply event. Only
296
     *
316
	 * listeners registered at the time this method is called are notified.
297
     * @see ICellEditorListener#applyEditorValue
317
	 * 
298
     */
318
	 * @see ICellEditorListener#applyEditorValue
299
    protected void fireApplyEditorValue() {
319
	 */
300
        Object[] array = listeners.getListeners();
320
	protected void fireApplyEditorValue() {
301
        for (int i = 0; i < array.length; i++) {
321
		Object[] array = listeners.getListeners();
302
            final ICellEditorListener l = (ICellEditorListener) array[i];
322
		for (int i = 0; i < array.length; i++) {
303
            SafeRunnable.run(new SafeRunnable() {
323
			final ICellEditorListener l = (ICellEditorListener) array[i];
304
                public void run() {
324
			SafeRunnable.run(new SafeRunnable() {
305
                    l.applyEditorValue();
325
				public void run() {
306
                }
326
					l.applyEditorValue();
307
            });
327
				}
308
        }
328
			});
309
    }
329
		}
310
330
	}
311
    /**
331
312
     * Notifies all registered cell editor listeners that editing has been
332
	/**
313
     * canceled.
333
	 * Notifies all registered cell editor listeners that editing has been
314
     *
334
	 * canceled.
315
     * @see ICellEditorListener#cancelEditor
335
	 * 
316
     */
336
	 * @see ICellEditorListener#cancelEditor
317
    protected void fireCancelEditor() {
337
	 */
318
        Object[] array = listeners.getListeners();
338
	protected void fireCancelEditor() {
319
        for (int i = 0; i < array.length; i++) {
339
		Object[] array = listeners.getListeners();
320
            final ICellEditorListener l = (ICellEditorListener) array[i];
340
		for (int i = 0; i < array.length; i++) {
321
            SafeRunnable.run(new SafeRunnable() {
341
			final ICellEditorListener l = (ICellEditorListener) array[i];
322
                public void run() {
342
			SafeRunnable.run(new SafeRunnable() {
323
                    l.cancelEditor();
343
				public void run() {
324
                }
344
					l.cancelEditor();
325
            });
345
				}
326
        }
346
			});
327
    }
347
		}
328
348
	}
329
    /**
349
330
     * Notifies all registered cell editor listeners of a value change.
350
	/**
331
     *
351
	 * Notifies all registered cell editor listeners of a value change.
332
     * @param oldValidState the valid state before the end user changed the value
352
	 * 
333
     * @param newValidState the current valid state
353
	 * @param oldValidState
334
     * @see ICellEditorListener#editorValueChanged
354
	 *            the valid state before the end user changed the value
335
     */
355
	 * @param newValidState
336
    protected void fireEditorValueChanged(final boolean oldValidState,
356
	 *            the current valid state
337
            final boolean newValidState) {
357
	 * @see ICellEditorListener#editorValueChanged
338
        Object[] array = listeners.getListeners();
358
	 */
339
        for (int i = 0; i < array.length; i++) {
359
	protected void fireEditorValueChanged(final boolean oldValidState,
340
            final ICellEditorListener l = (ICellEditorListener) array[i];
360
			final boolean newValidState) {
341
            SafeRunnable.run(new SafeRunnable() {
361
		Object[] array = listeners.getListeners();
342
                public void run() {
362
		for (int i = 0; i < array.length; i++) {
343
                    l.editorValueChanged(oldValidState, newValidState);
363
			final ICellEditorListener l = (ICellEditorListener) array[i];
344
                }
364
			SafeRunnable.run(new SafeRunnable() {
345
            });
365
				public void run() {
346
        }
366
					l.editorValueChanged(oldValidState, newValidState);
347
    }
367
				}
348
368
			});
349
    /**
369
		}
350
     * Notifies all registered property listeners
370
	}
351
     * of an enablement change.
371
352
     *
372
	/**
353
     * @param actionId the id indicating what action's enablement has changed.
373
	 * Notifies all registered property listeners of an enablement change.
354
     */
374
	 * 
355
    protected void fireEnablementChanged(final String actionId) {
375
	 * @param actionId
356
        Object[] array = propertyChangeListeners.getListeners();
376
	 *            the id indicating what action's enablement has changed.
357
        for (int i = 0; i < array.length; i++) {
377
	 */
358
            final IPropertyChangeListener l = (IPropertyChangeListener) array[i];
378
	protected void fireEnablementChanged(final String actionId) {
359
            SafeRunnable.run(new SafeRunnable() {
379
		Object[] array = propertyChangeListeners.getListeners();
360
                public void run() {
380
		for (int i = 0; i < array.length; i++) {
361
                    l.propertyChange(new PropertyChangeEvent(this, actionId,
381
			final IPropertyChangeListener l = (IPropertyChangeListener) array[i];
362
                            null, null));
382
			SafeRunnable.run(new SafeRunnable() {
363
                }
383
				public void run() {
364
            });
384
					l.propertyChange(new PropertyChangeEvent(this, actionId,
365
        }
385
							null, null));
366
    }
386
				}
367
387
			});
368
    /**
388
		}
369
     * Sets the style bits for this cell editor.
389
	}
370
     * 
390
371
     * @param style the SWT style bits for this cell editor
391
	/**
372
     * @since 2.1
392
	 * Sets the style bits for this cell editor.
373
     */
393
	 * 
374
    public void setStyle(int style) {
394
	 * @param style
375
        this.style = style;
395
	 *            the SWT style bits for this cell editor
376
    }
396
	 * @since 2.1
377
397
	 */
378
    /**
398
	public void setStyle(int style) {
379
     * Returns the style bits for this cell editor.
399
		this.style = style;
380
     *
400
	}
381
     * @return the style for this cell editor
401
382
     * @since 2.1
402
	/**
383
     */
403
	 * Returns the style bits for this cell editor.
384
    public int getStyle() {
404
	 * 
385
        return style;
405
	 * @return the style for this cell editor
386
    }
406
	 * @since 2.1
387
407
	 */
388
    /**
408
	public int getStyle() {
389
     * Returns the control used to implement this cell editor.
409
		return style;
390
     *
410
	}
391
     * @return the control, or <code>null</code> if this cell editor has no control
411
392
     */
412
	/**
393
    public Control getControl() {
413
	 * Returns the control used to implement this cell editor.
394
        return control;
414
	 * 
395
    }
415
	 * @return the control, or <code>null</code> if this cell editor has no
396
416
	 *         control
397
    /**
417
	 */
398
     * Returns the current error message for this cell editor.
418
	public Control getControl() {
399
     * 
419
		return control;
400
     * @return the error message if the cell editor is in an invalid state,
420
	}
401
     *  and <code>null</code> if the cell editor is valid
421
402
     */
422
	/**
403
    public String getErrorMessage() {
423
	 * Returns the current error message for this cell editor.
404
        return errorMessage;
424
	 * 
405
    }
425
	 * @return the error message if the cell editor is in an invalid state, and
406
426
	 *         <code>null</code> if the cell editor is valid
407
    /**
427
	 */
408
     * Returns a layout data object for this cell editor.
428
	public String getErrorMessage() {
409
     * This is called each time the cell editor is activated
429
		return errorMessage;
410
     * and controls the layout of the SWT table editor.
430
	}
411
     * <p>
431
412
     * The default implementation of this method sets the 
432
	/**
413
     * minimum width to the control's preferred width.
433
	 * Returns a layout data object for this cell editor. This is called each
414
     * Subclasses may extend or reimplement.
434
	 * time the cell editor is activated and controls the layout of the SWT
415
     * </p>
435
	 * table editor.
416
     *
436
	 * <p>
417
     * @return the layout data object 
437
	 * The default implementation of this method sets the minimum width to the
418
     */
438
	 * control's preferred width. Subclasses may extend or reimplement.
419
    public LayoutData getLayoutData() {
439
	 * </p>
420
        LayoutData result = new LayoutData();
440
	 * 
421
        Control control = getControl();
441
	 * @return the layout data object
422
        if (control != null) {
442
	 */
423
            result.minimumWidth = control.computeSize(SWT.DEFAULT, SWT.DEFAULT,
443
	public LayoutData getLayoutData() {
424
                    true).x;
444
		LayoutData result = new LayoutData();
425
        }
445
		Control control = getControl();
426
        return result;
446
		if (control != null) {
427
    }
447
			result.minimumWidth = control.computeSize(SWT.DEFAULT, SWT.DEFAULT,
428
448
					true).x;
429
    /**
449
		}
430
     * Returns the input validator for this cell editor.
450
		return result;
431
     *
451
	}
432
     * @return the input validator, or <code>null</code> if none
452
433
     */
453
	/**
434
    public ICellEditorValidator getValidator() {
454
	 * Returns the input validator for this cell editor.
435
        return validator;
455
	 * 
436
    }
456
	 * @return the input validator, or <code>null</code> if none
437
457
	 */
438
    /**
458
	public ICellEditorValidator getValidator() {
439
     * Returns this cell editor's value provided that it has a valid one.
459
		return validator;
440
     *
460
	}
441
     * @return the value of this cell editor, or <code>null</code>
461
442
     *   if the cell editor does not contain a valid value
462
	/**
443
     */
463
	 * Returns this cell editor's value provided that it has a valid one.
444
    public final Object getValue() {
464
	 * 
445
        if (!valid) {
465
	 * @return the value of this cell editor, or <code>null</code> if the cell
466
	 *         editor does not contain a valid value
467
	 */
468
	public final Object getValue() {
469
		if (!valid) {
446
			return null;
470
			return null;
447
		}
471
		}
448
472
449
        return doGetValue();
473
		return doGetValue();
450
    }
474
	}
451
475
452
    /**
476
	/**
453
     * Returns whether this cell editor is activated.
477
	 * Returns whether this cell editor is activated.
454
     *
478
	 * 
455
     * @return <code>true</code> if this cell editor's control is
479
	 * @return <code>true</code> if this cell editor's control is currently
456
     *   currently activated, and <code>false</code> if not activated
480
	 *         activated, and <code>false</code> if not activated
457
     */
481
	 */
458
    public boolean isActivated() {
482
	public boolean isActivated() {
459
    	// Use the state of the visible style bit (getVisible()) rather than the
483
		// Use the state of the visible style bit (getVisible()) rather than the
460
    	// window's actual visibility (isVisible()) to get correct handling when
484
		// window's actual visibility (isVisible()) to get correct handling when
461
    	// an ancestor control goes invisible, see bug 85331.
485
		// an ancestor control goes invisible, see bug 85331.
462
        return control != null && control.getVisible();
486
		return control != null && control.getVisible();
463
    }
487
	}
464
488
465
    /**
489
	/**
466
     * Returns <code>true</code> if this cell editor is
490
	 * Returns <code>true</code> if this cell editor is able to perform the
467
     * able to perform the copy action.
491
	 * copy action.
468
     * <p>
492
	 * <p>
469
     * This default implementation always returns 
493
	 * This default implementation always returns <code>false</code>.
470
     * <code>false</code>.
494
	 * </p>
471
     * </p>
495
	 * <p>
472
     * <p>
496
	 * Subclasses may override
473
     * Subclasses may override
497
	 * </p>
474
     * </p>
498
	 * 
475
     * @return <code>true</code> if copy is possible,
499
	 * @return <code>true</code> if copy is possible, <code>false</code>
476
     *  <code>false</code> otherwise
500
	 *         otherwise
477
     */
501
	 */
478
    public boolean isCopyEnabled() {
502
	public boolean isCopyEnabled() {
479
        return false;
503
		return false;
480
    }
504
	}
481
505
482
    /**
506
	/**
483
     * Returns whether the given value is valid for this cell editor.
507
	 * Returns whether the given value is valid for this cell editor. This cell
484
     * This cell editor's validator (if any) makes the actual determination.
508
	 * editor's validator (if any) makes the actual determination.
485
     * @param value the value to check for
509
	 * 
486
     *
510
	 * @param value
487
     * @return <code>true</code> if the value is valid, and <code>false</code>
511
	 *            the value to check for
488
     *  if invalid
512
	 * 
489
     */
513
	 * @return <code>true</code> if the value is valid, and <code>false</code>
490
    protected boolean isCorrect(Object value) {
514
	 *         if invalid
491
        errorMessage = null;
515
	 */
492
        if (validator == null) {
516
	protected boolean isCorrect(Object value) {
517
		errorMessage = null;
518
		if (validator == null) {
493
			return true;
519
			return true;
494
		}
520
		}
495
521
496
        errorMessage = validator.isValid(value);
522
		errorMessage = validator.isValid(value);
497
        return (errorMessage == null || errorMessage.equals(""));//$NON-NLS-1$
523
		return (errorMessage == null || errorMessage.equals(""));//$NON-NLS-1$
498
    }
524
	}
499
525
500
    /**
526
	/**
501
     * Returns <code>true</code> if this cell editor is
527
	 * Returns <code>true</code> if this cell editor is able to perform the
502
     * able to perform the cut action.
528
	 * cut action.
503
     * <p>
529
	 * <p>
504
     * This default implementation always returns 
530
	 * This default implementation always returns <code>false</code>.
505
     * <code>false</code>.
531
	 * </p>
506
     * </p>
532
	 * <p>
507
     * <p>
533
	 * Subclasses may override
508
     * Subclasses may override
534
	 * </p>
509
     * </p>
535
	 * 
510
     * @return <code>true</code> if cut is possible,
536
	 * @return <code>true</code> if cut is possible, <code>false</code>
511
     *  <code>false</code> otherwise
537
	 *         otherwise
512
     */
538
	 */
513
    public boolean isCutEnabled() {
539
	public boolean isCutEnabled() {
514
        return false;
540
		return false;
515
    }
541
	}
516
542
517
    /**
543
	/**
518
     * Returns <code>true</code> if this cell editor is
544
	 * Returns <code>true</code> if this cell editor is able to perform the
519
     * able to perform the delete action.
545
	 * delete action.
520
     * <p>
546
	 * <p>
521
     * This default implementation always returns 
547
	 * This default implementation always returns <code>false</code>.
522
     * <code>false</code>.
548
	 * </p>
523
     * </p>
549
	 * <p>
524
     * <p>
550
	 * Subclasses may override
525
     * Subclasses may override
551
	 * </p>
526
     * </p>
552
	 * 
527
     * @return <code>true</code> if delete is possible,
553
	 * @return <code>true</code> if delete is possible, <code>false</code>
528
     *  <code>false</code> otherwise
554
	 *         otherwise
529
     */
555
	 */
530
    public boolean isDeleteEnabled() {
556
	public boolean isDeleteEnabled() {
531
        return false;
557
		return false;
532
    }
558
	}
533
559
534
    /**
560
	/**
535
     * Returns whether the value of this cell editor has changed since the
561
	 * Returns whether the value of this cell editor has changed since the last
536
     * last call to <code>setValue</code>.
562
	 * call to <code>setValue</code>.
537
     *
563
	 * 
538
     * @return <code>true</code> if the value has changed, and <code>false</code>
564
	 * @return <code>true</code> if the value has changed, and
539
     *  if unchanged
565
	 *         <code>false</code> if unchanged
540
     */
566
	 */
541
    public boolean isDirty() {
567
	public boolean isDirty() {
542
        return dirty;
568
		return dirty;
543
    }
569
	}
544
570
545
    /**
571
	/**
546
     * Marks this cell editor as dirty.
572
	 * Marks this cell editor as dirty.
547
     * @since 2.1
573
	 * 
548
     */
574
	 * @since 2.1
549
    protected void markDirty() {
575
	 */
550
        dirty = true;
576
	protected void markDirty() {
551
    }
577
		dirty = true;
552
578
	}
553
    /**
579
554
     * Returns <code>true</code> if this cell editor is
580
	/**
555
     * able to perform the find action.
581
	 * Returns <code>true</code> if this cell editor is able to perform the
556
     * <p>
582
	 * find action.
557
     * This default implementation always returns 
583
	 * <p>
558
     * <code>false</code>.
584
	 * This default implementation always returns <code>false</code>.
559
     * </p>
585
	 * </p>
560
     * <p>
586
	 * <p>
561
     * Subclasses may override
587
	 * Subclasses may override
562
     * </p>
588
	 * </p>
563
     * @return <code>true</code> if find is possible,
589
	 * 
564
     *  <code>false</code> otherwise
590
	 * @return <code>true</code> if find is possible, <code>false</code>
565
     */
591
	 *         otherwise
566
    public boolean isFindEnabled() {
592
	 */
567
        return false;
593
	public boolean isFindEnabled() {
568
    }
594
		return false;
569
595
	}
570
    /**
596
571
     * Returns <code>true</code> if this cell editor is
597
	/**
572
     * able to perform the paste action.
598
	 * Returns <code>true</code> if this cell editor is able to perform the
573
     * <p>
599
	 * paste action.
574
     * This default implementation always returns 
600
	 * <p>
575
     * <code>false</code>.
601
	 * This default implementation always returns <code>false</code>.
576
     * </p>
602
	 * </p>
577
     * <p>
603
	 * <p>
578
     * Subclasses may override
604
	 * Subclasses may override
579
     * </p>
605
	 * </p>
580
     * @return <code>true</code> if paste is possible,
606
	 * 
581
     *  <code>false</code> otherwise
607
	 * @return <code>true</code> if paste is possible, <code>false</code>
582
     */
608
	 *         otherwise
583
    public boolean isPasteEnabled() {
609
	 */
584
        return false;
610
	public boolean isPasteEnabled() {
585
    }
611
		return false;
586
612
	}
587
    /**
613
588
     * Returns <code>true</code> if this cell editor is
614
	/**
589
     * able to perform the redo action.
615
	 * Returns <code>true</code> if this cell editor is able to perform the
590
     * <p>
616
	 * redo action.
591
     * This default implementation always returns 
617
	 * <p>
592
     * <code>false</code>.
618
	 * This default implementation always returns <code>false</code>.
593
     * </p>
619
	 * </p>
594
     * <p>
620
	 * <p>
595
     * Subclasses may override
621
	 * Subclasses may override
596
     * </p>
622
	 * </p>
597
     * @return <code>true</code> if redo is possible,
623
	 * 
598
     *  <code>false</code> otherwise
624
	 * @return <code>true</code> if redo is possible, <code>false</code>
599
     */
625
	 *         otherwise
600
    public boolean isRedoEnabled() {
626
	 */
601
        return false;
627
	public boolean isRedoEnabled() {
602
    }
628
		return false;
603
629
	}
604
    /**
630
605
     * Returns <code>true</code> if this cell editor is
631
	/**
606
     * able to perform the select all action.
632
	 * Returns <code>true</code> if this cell editor is able to perform the
607
     * <p>
633
	 * select all action.
608
     * This default implementation always returns 
634
	 * <p>
609
     * <code>false</code>.
635
	 * This default implementation always returns <code>false</code>.
610
     * </p>
636
	 * </p>
611
     * <p>
637
	 * <p>
612
     * Subclasses may override
638
	 * Subclasses may override
613
     * </p>
639
	 * </p>
614
     * @return <code>true</code> if select all is possible,
640
	 * 
615
     *  <code>false</code> otherwise
641
	 * @return <code>true</code> if select all is possible, <code>false</code>
616
     */
642
	 *         otherwise
617
    public boolean isSelectAllEnabled() {
643
	 */
618
        return false;
644
	public boolean isSelectAllEnabled() {
619
    }
645
		return false;
620
646
	}
621
    /**
647
622
     * Returns <code>true</code> if this cell editor is
648
	/**
623
     * able to perform the undo action.
649
	 * Returns <code>true</code> if this cell editor is able to perform the
624
     * <p>
650
	 * undo action.
625
     * This default implementation always returns 
651
	 * <p>
626
     * <code>false</code>.
652
	 * This default implementation always returns <code>false</code>.
627
     * </p>
653
	 * </p>
628
     * <p>
654
	 * <p>
629
     * Subclasses may override
655
	 * Subclasses may override
630
     * </p>
656
	 * </p>
631
     * @return <code>true</code> if undo is possible,
657
	 * 
632
     *  <code>false</code> otherwise
658
	 * @return <code>true</code> if undo is possible, <code>false</code>
633
     */
659
	 *         otherwise
634
    public boolean isUndoEnabled() {
660
	 */
635
        return false;
661
	public boolean isUndoEnabled() {
636
    }
662
		return false;
637
663
	}
638
    /**
664
639
     * Returns whether this cell editor has a valid value.
665
	/**
640
     * The default value is false.
666
	 * Returns whether this cell editor has a valid value. The default value is
641
     *
667
	 * false.
642
     * @return <code>true</code> if the value is valid, and <code>false</code>
668
	 * 
643
     *  if invalid
669
	 * @return <code>true</code> if the value is valid, and <code>false</code>
644
     *
670
	 *         if invalid
645
     * @see #setValueValid(boolean)
671
	 * 
646
     */
672
	 * @see #setValueValid(boolean)
647
    public boolean isValueValid() {
673
	 */
648
        return valid;
674
	public boolean isValueValid() {
649
    }
675
		return valid;
650
676
	}
651
    /**
677
652
     * Processes a key release event that occurred in this cell editor.
678
	/**
653
     * <p>
679
	 * Processes a key release event that occurred in this cell editor.
654
     * The default implementation of this framework method cancels editing
680
	 * <p>
655
     * when the ESC key is pressed.  When the RETURN key is pressed the current
681
	 * The default implementation of this framework method cancels editing when
656
     * value is applied and the cell editor deactivates.
682
	 * the ESC key is pressed. When the RETURN key is pressed the current value
657
     * Subclasses should call this method at appropriate times. 
683
	 * is applied and the cell editor deactivates. Subclasses should call this
658
     * Subclasses may also extend or reimplement.
684
	 * method at appropriate times. Subclasses may also extend or reimplement.
659
     * </p>
685
	 * </p>
660
     *
686
	 * 
661
     * @param keyEvent the key event
687
	 * @param keyEvent
662
     */
688
	 *            the key event
663
    protected void keyReleaseOccured(KeyEvent keyEvent) {
689
	 */
664
        if (keyEvent.character == '\u001b') { // Escape character
690
	protected void keyReleaseOccured(KeyEvent keyEvent) {
665
            fireCancelEditor();
691
		if (keyEvent.character == '\u001b') { // Escape character
666
        } else if (keyEvent.character == '\r') { // Return key
692
			fireCancelEditor();
667
            fireApplyEditorValue();
693
		} else if (keyEvent.character == '\r') { // Return key
668
            deactivate();
694
			fireApplyEditorValue();
669
        }
695
			deactivate();
670
    }
696
		}
671
697
	}
672
    /**
698
673
     * Processes a focus lost event that occurred in this cell editor.
699
	/**
674
     * <p>
700
	 * Processes a focus lost event that occurred in this cell editor.
675
     * The default implementation of this framework method applies the current
701
	 * <p>
676
     * value and deactivates the cell editor.
702
	 * The default implementation of this framework method applies the current
677
     * Subclasses should call this method at appropriate times. 
703
	 * value and deactivates the cell editor. Subclasses should call this method
678
     * Subclasses may also extend or reimplement.
704
	 * at appropriate times. Subclasses may also extend or reimplement.
679
     * </p>
705
	 * </p>
680
     */
706
	 */
681
    protected void focusLost() {
707
	protected void focusLost() {
682
        if (isActivated()) {
708
		if (isActivated()) {
683
            fireApplyEditorValue();
709
			fireApplyEditorValue();
684
            deactivate();
710
			deactivate();
685
        }
711
		}
686
    }
712
	}
687
713
688
    /**
714
	/**
689
     * Performs the copy action.
715
	 * Performs the copy action. This default implementation does nothing.
690
     * This default implementation does nothing.
716
	 * <p>
691
     * <p>
717
	 * Subclasses may override
692
     * Subclasses may override
718
	 * </p>
693
     * </p>
719
	 */
694
     */
720
	public void performCopy() {
695
    public void performCopy() {
721
	}
696
    }
722
697
723
	/**
698
    /**
724
	 * Performs the cut action. This default implementation does nothing.
699
     * Performs the cut action.
725
	 * <p>
700
     * This default implementation does nothing.
726
	 * Subclasses may override
701
     * <p>
727
	 * </p>
702
     * Subclasses may override
728
	 */
703
     * </p>
729
	public void performCut() {
704
     */
730
	}
705
    public void performCut() {
731
706
    }
732
	/**
707
733
	 * Performs the delete action. This default implementation does nothing.
708
    /**
734
	 * <p>
709
     * Performs the delete action.
735
	 * Subclasses may override
710
     * This default implementation does nothing.
736
	 * </p>
711
     * <p>
737
	 */
712
     * Subclasses may override
738
	public void performDelete() {
713
     * </p>
739
	}
714
     */
740
715
    public void performDelete() {
741
	/**
716
    }
742
	 * Performs the find action. This default implementation does nothing.
717
743
	 * <p>
718
    /**
744
	 * Subclasses may override
719
     * Performs the find action.
745
	 * </p>
720
     * This default implementation does nothing.
746
	 */
721
     * <p>
747
	public void performFind() {
722
     * Subclasses may override
748
	}
723
     * </p>
749
724
     */
750
	/**
725
    public void performFind() {
751
	 * Performs the paste action. This default implementation does nothing.
726
    }
752
	 * <p>
727
753
	 * Subclasses may override
728
    /**
754
	 * </p>
729
     * Performs the paste action.
755
	 */
730
     * This default implementation does nothing.
756
	public void performPaste() {
731
     * <p>
757
	}
732
     * Subclasses may override
758
733
     * </p>
759
	/**
734
     */
760
	 * Performs the redo action. This default implementation does nothing.
735
    public void performPaste() {
761
	 * <p>
736
    }
762
	 * Subclasses may override
737
763
	 * </p>
738
    /**
764
	 */
739
     * Performs the redo action.
765
	public void performRedo() {
740
     * This default implementation does nothing.
766
	}
741
     * <p>
767
742
     * Subclasses may override
768
	/**
743
     * </p>
769
	 * Performs the select all action. This default implementation does nothing.
744
     */
770
	 * <p>
745
    public void performRedo() {
771
	 * Subclasses may override
746
    }
772
	 * </p>
747
773
	 */
748
    /**
774
	public void performSelectAll() {
749
     * Performs the select all action.
775
	}
750
     * This default implementation does nothing.
776
751
     * <p>
777
	/**
752
     * Subclasses may override
778
	 * Performs the undo action. This default implementation does nothing.
753
     * </p>
779
	 * <p>
754
     */
780
	 * Subclasses may override
755
    public void performSelectAll() {
781
	 * </p>
756
    }
782
	 */
757
783
	public void performUndo() {
758
    /**
784
	}
759
     * Performs the undo action.
785
760
     * This default implementation does nothing.
786
	/**
761
     * <p>
787
	 * Removes the given listener from this cell editor. Has no affect if an
762
     * Subclasses may override
788
	 * identical listener is not registered.
763
     * </p>
789
	 * 
764
     */
790
	 * @param listener
765
    public void performUndo() {
791
	 *            a cell editor listener
766
    }
792
	 */
767
793
	public void removeListener(ICellEditorListener listener) {
768
    /**
794
		listeners.remove(listener);
769
     * Removes the given listener from this cell editor.
795
	}
770
     * Has no affect if an identical listener is not registered.
796
771
     *
797
	/**
772
     * @param listener a cell editor listener
798
	 * Removes the given property change listener from this cell editor. Has no
773
     */
799
	 * affect if an identical property change listener is not registered.
774
    public void removeListener(ICellEditorListener listener) {
800
	 * 
775
        listeners.remove(listener);
801
	 * @param listener
776
    }
802
	 *            a property change listener
777
803
	 */
778
    /**
804
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
779
     * Removes the given property change listener from this cell editor.
805
		propertyChangeListeners.remove(listener);
780
     * Has no affect if an identical property change listener is not 
806
	}
781
     * registered.
807
782
     *
808
	/**
783
     * @param listener a property change listener
809
	 * Sets or clears the current error message for this cell editor.
784
     */
810
	 * <p>
785
    public void removePropertyChangeListener(IPropertyChangeListener listener) {
811
	 * No formatting is done here, the message to be set is expected to be fully
786
        propertyChangeListeners.remove(listener);
812
	 * formatted before being passed in.
787
    }
813
	 * </p>
788
814
	 * 
789
    /**
815
	 * @param message
790
     * Sets or clears the current error message for this cell editor.
816
	 *            the error message, or <code>null</code> to clear
791
     * <p>
817
	 */
792
     * No formatting is done here, the message to be set is expected to be fully formatted
818
	protected void setErrorMessage(String message) {
793
     * before being passed in.
819
		errorMessage = message;
794
     * </p>
820
	}
795
     * @param message the error message, or <code>null</code> to clear
821
796
     */
822
	/**
797
    protected void setErrorMessage(String message) {
823
	 * Sets the focus to the cell editor's control.
798
        errorMessage = message;
824
	 */
799
    }
825
	public void setFocus() {
800
826
		doSetFocus();
801
    /**
827
	}
802
     * Sets the focus to the cell editor's control.
828
803
     */
829
	/**
804
    public void setFocus() {
830
	 * Sets the input validator for this cell editor.
805
        doSetFocus();
831
	 * 
806
    }
832
	 * @param validator
807
833
	 *            the input validator, or <code>null</code> if none
808
    /**
834
	 */
809
     * Sets the input validator for this cell editor.
835
	public void setValidator(ICellEditorValidator validator) {
810
     *
836
		this.validator = validator;
811
     * @param validator the input validator, or <code>null</code> if none
837
	}
812
     */
838
813
    public void setValidator(ICellEditorValidator validator) {
839
	/**
814
        this.validator = validator;
840
	 * Sets this cell editor's value.
815
    }
841
	 * 
816
842
	 * @param value
817
    /**
843
	 *            the value of this cell editor
818
     * Sets this cell editor's value.
844
	 */
819
     *
845
	public final void setValue(Object value) {
820
     * @param value the value of this cell editor
846
		valid = isCorrect(value);
821
     */
847
		dirty = false;
822
    public final void setValue(Object value) {
848
		doSetValue(value);
823
        valid = isCorrect(value);
849
	}
824
        dirty = false;
850
825
        doSetValue(value);
851
	/**
826
    }
852
	 * Sets the valid state of this cell editor. The default value is false.
827
853
	 * Subclasses should call this method on construction.
828
    /**
854
	 * 
829
     * Sets the valid state of this cell editor.
855
	 * @param valid
830
     * The default value is false.
856
	 *            <code>true</code> if the current valie is valid, and
831
     * Subclasses should call this method on construction.
857
	 *            <code>false</code> if invalid
832
     *
858
	 * 
833
     * @param valid <code>true</code> if the current valie is valid,
859
	 * @see #isValueValid
834
     *  and <code>false</code> if invalid
860
	 */
835
     *
861
	protected void setValueValid(boolean valid) {
836
     * @see #isValueValid
862
		this.valid = valid;
837
     */
863
	}
838
    protected void setValueValid(boolean valid) {
864
839
        this.valid = valid;
865
	/**
840
    }
866
	 * The value has changed. Updates the valid state flag, marks this cell
841
867
	 * editor as dirty, and notifies all registered cell editor listeners of a
842
    /**
868
	 * value change.
843
     * The value has changed.  
869
	 * 
844
     * Updates the valid state flag, marks this cell editor as dirty,
870
	 * @param oldValidState
845
     * and notifies all registered cell editor listeners of a value change.
871
	 *            the valid state before the end user changed the value
846
     *
872
	 * @param newValidState
847
     * @param oldValidState the valid state before the end user changed the value
873
	 *            the current valid state
848
     * @param newValidState the current valid state
874
	 * @see ICellEditorListener#editorValueChanged
849
     * @see ICellEditorListener#editorValueChanged
875
	 */
850
     */
876
	protected void valueChanged(boolean oldValidState, boolean newValidState) {
851
    protected void valueChanged(boolean oldValidState, boolean newValidState) {
877
		valid = newValidState;
852
        valid = newValidState;
878
		dirty = true;
853
        dirty = true;
879
		fireEditorValueChanged(oldValidState, newValidState);
854
        fireEditorValueChanged(oldValidState, newValidState);
880
	}
855
    }
856
}
881
}
(-)src/org/eclipse/jface/viewers/AbstractViewerEditor.java (-114 / +105 lines)
Lines 14-19 Link Here
14
14
15
package org.eclipse.jface.viewers;
15
package org.eclipse.jface.viewers;
16
16
17
18
import org.eclipse.core.runtime.ListenerList;
17
import org.eclipse.swt.events.FocusAdapter;
19
import org.eclipse.swt.events.FocusAdapter;
18
import org.eclipse.swt.events.FocusEvent;
20
import org.eclipse.swt.events.FocusEvent;
19
import org.eclipse.swt.events.FocusListener;
21
import org.eclipse.swt.events.FocusListener;
Lines 22-28 Link Here
22
import org.eclipse.swt.events.MouseListener;
24
import org.eclipse.swt.events.MouseListener;
23
import org.eclipse.swt.events.TraverseEvent;
25
import org.eclipse.swt.events.TraverseEvent;
24
import org.eclipse.swt.events.TraverseListener;
26
import org.eclipse.swt.events.TraverseListener;
25
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Item;
29
import org.eclipse.swt.widgets.Item;
Lines 46-67 Link Here
46
47
47
	private String[] columnProperties;
48
	private String[] columnProperties;
48
49
49
	private int columnNumber;
50
51
	private ICellEditorListener cellEditorListener;
50
	private ICellEditorListener cellEditorListener;
52
51
53
	private FocusListener focusListener;
52
	private FocusListener focusListener;
54
53
55
	private MouseListener mouseListener;
54
	private MouseListener mouseListener;
56
55
57
	private int doubleClickExpirationTime;
58
59
	private ColumnViewer viewer;
56
	private ColumnViewer viewer;
60
57
61
	private Item item;
62
63
	private TraverseListener tabeditingListener;
58
	private TraverseListener tabeditingListener;
64
59
60
	private int activationTime;
61
		
62
	private ViewerCell cell;
63
	
64
	private EditorActivationEvent activationEvent;
65
	
66
	private ListenerList editorActivationListener;
67
	
68
	private static EditorActivationStrategy defaultStrategy = new EditorActivationStrategy() {
69
		protected boolean isEditorActivationEvent(EditorActivationEvent event) {
70
			return event.eventType == EditorActivationEvent.MOUSE_CLICK_SELECTION
71
				|| event.eventType == EditorActivationEvent.PROGRAMATIC
72
				|| event.eventType == EditorActivationEvent.TRAVERSAL;
73
			}
74
	};
75
	
76
	private EditorActivationStrategy editorActivationStrategy = defaultStrategy;
77
	
65
	/**
78
	/**
66
	 * Create a new editor implementation for the viewer
79
	 * Create a new editor implementation for the viewer
67
	 * 
80
	 * 
Lines 92-104 Link Here
92
105
93
	void activateCellEditor() {
106
	void activateCellEditor() {
94
107
95
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
108
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
96
		Object element = item.getData();
109
		Object element = cell.getElement();
97
110
98
		if (part != null && part.getEditingSupport() != null
111
		if (part != null && part.getEditingSupport() != null
99
				&& part.getEditingSupport().canEdit(element)) {
112
				&& part.getEditingSupport().canEdit(element)) {
100
			cellEditor = part.getEditingSupport().getCellEditor(element);
113
			cellEditor = part.getEditingSupport().getCellEditor(element);
101
			if (cellEditor != null) {
114
			if (cellEditor != null) {
115
				if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
116
					Object[] ls = editorActivationListener.getListeners();
117
					for( int i = 0; i < ls.length; i++ ) {
118
						((AbstractViewerEditorActivationListener)ls[i]).beforeEditorActivated(activationEvent);
119
					}
120
				}
121
				
102
				cellEditor.addListener(cellEditorListener);
122
				cellEditor.addListener(cellEditorListener);
103
				Object value = part.getEditingSupport().getValue(element);
123
				Object value = part.getEditingSupport().getValue(element);
104
				cellEditor.setValue(value);
124
				cellEditor.setValue(value);
Lines 108-119 Link Here
108
				// so must get control first, but must still call activate()
128
				// so must get control first, but must still call activate()
109
				// even if there is no control.
129
				// even if there is no control.
110
				final Control control = cellEditor.getControl();
130
				final Control control = cellEditor.getControl();
111
				cellEditor.activate();
131
				cellEditor.activate(activationEvent);
112
				if (control == null) {
132
				if (control == null) {
113
					return;
133
					return;
114
				}
134
				}
115
				setLayoutData(cellEditor.getLayoutData());
135
				setLayoutData(cellEditor.getLayoutData());
116
				setEditor(control, item, columnNumber);
136
				setEditor(control, cell.getItem(), cell.getColumnIndex());
117
				cellEditor.setFocus();
137
				cellEditor.setFocus();
118
				if (focusListener == null) {
138
				if (focusListener == null) {
119
					focusListener = new FocusAdapter() {
139
					focusListener = new FocusAdapter() {
Lines 128-134 Link Here
128
					public void mouseDown(MouseEvent e) {
148
					public void mouseDown(MouseEvent e) {
129
						// time wrap?
149
						// time wrap?
130
						// check for expiration of doubleClickTime
150
						// check for expiration of doubleClickTime
131
						if (e.time <= doubleClickExpirationTime) {
151
						if (e.time <= activationTime) {
132
							control.removeMouseListener(mouseListener);
152
							control.removeMouseListener(mouseListener);
133
							cancelEditing();
153
							cancelEditing();
134
							handleDoubleClickEvent();
154
							handleDoubleClickEvent();
Lines 143-195 Link Here
143
					tabeditingListener = new TraverseListener() {
163
					tabeditingListener = new TraverseListener() {
144
164
145
						public void keyTraversed(TraverseEvent e) {
165
						public void keyTraversed(TraverseEvent e) {
146
							ViewerColumn col = viewer.getViewerColumn(columnNumber);
166
							ViewerColumn col = viewer.getViewerColumn(cell.getColumnIndex());
147
							if ( col != null && col.getEditingSupport().isTabingSupported() ) {
167
							if ( col != null && col.getEditingSupport().isTabingSupported() ) {
148
								col.getEditingSupport().processTraversEvent(
168
								col.getEditingSupport().processTraversEvent(
149
										columnNumber,
169
										cell.getColumnIndex(),
150
										viewer.getViewerRowFromItem(item), e);
170
										viewer.getViewerRowFromItem(cell.getItem()), e);
151
							}
171
							}
152
						}
172
						}
153
					};
173
					};
154
				}
174
				}
155
				
175
				
156
				control.addTraverseListener(tabeditingListener);
176
				control.addTraverseListener(tabeditingListener);
157
177
				
158
			}
178
				if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
159
		}
179
					Object[] ls = editorActivationListener.getListeners();
160
	}
180
					for( int i = 0; i < ls.length; i++ ) {
161
181
						((AbstractViewerEditorActivationListener)ls[i]).afterEditorActivated(activationEvent);
162
	/**
182
					}
163
	 * Activate a cell editor for the given mouse position.
164
	 */
165
	private void activateCellEditor(MouseEvent event) {
166
		if (item == null || item.isDisposed()) {
167
			// item no longer exists
168
			return;
169
		}
170
		int columnToEdit;
171
		ViewerRow row = viewer.getViewerRowFromItem(item);
172
		int columns = row.getColumnCount();
173
		if (columns == 0) {
174
			// If no TableColumn, Table acts as if it has a single column
175
			// which takes the whole width.
176
			columnToEdit = 0;
177
		} else {
178
			columnToEdit = -1;
179
			for (int i = 0; i < columns; i++) {
180
				Rectangle bounds = row.getBounds(i);
181
				if (bounds.contains(event.x, event.y)) {
182
					columnToEdit = i;
183
					break;
184
				}
183
				}
185
			}
184
			}
186
			if (columnToEdit == -1) {
187
				return;
188
			}
189
		}
185
		}
190
191
		columnNumber = columnToEdit;
192
		activateCellEditor();
193
	}
186
	}
194
187
195
	/**
188
	/**
Lines 203-210 Link Here
203
			// in case save results in applyEditorValue being re-entered
196
			// in case save results in applyEditorValue being re-entered
204
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
197
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
205
			// using cell editor ?
198
			// using cell editor ?
199
			
200
			EditorDeactivationEvent tmp = new EditorDeactivationEvent(cell);
201
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
202
				Object[] ls = editorActivationListener.getListeners();
203
				for( int i = 0; i < ls.length; i++ ) {
204
					((AbstractViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp);
205
				}
206
			}
207
			
206
			this.cellEditor = null;
208
			this.cellEditor = null;
207
			Item t = this.item;
209
			this.activationEvent = null;
210
			Item t = this.cell.getItem();
208
			// don't null out table item -- same item is still selected
211
			// don't null out table item -- same item is still selected
209
			if (t != null && !t.isDisposed()) {
212
			if (t != null && !t.isDisposed()) {
210
				saveEditorValue(c, t);
213
				saveEditorValue(c, t);
Lines 227-232 Link Here
227
				}
230
				}
228
			}
231
			}
229
			c.deactivate();
232
			c.deactivate();
233
			
234
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
235
				Object[] ls = editorActivationListener.getListeners();
236
				for( int i = 0; i < ls.length; i++ ) {
237
					((AbstractViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp);
238
				}
239
			}
230
		}
240
		}
231
	}
241
	}
232
242
Lines 235-240 Link Here
235
	 */
245
	 */
236
	void cancelEditing() {
246
	void cancelEditing() {
237
		if (cellEditor != null) {
247
		if (cellEditor != null) {
248
			EditorDeactivationEvent tmp = new EditorDeactivationEvent(cell);
249
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
250
				Object[] ls = editorActivationListener.getListeners();
251
				for( int i = 0; i < ls.length; i++ ) {
252
					((AbstractViewerEditorActivationListener)ls[i]).beforeEditorDeactivated(tmp);
253
				}
254
			}
255
238
			setEditor(null, null, 0);
256
			setEditor(null, null, 0);
239
			cellEditor.removeListener(cellEditorListener);
257
			cellEditor.removeListener(cellEditorListener);
240
258
Lines 256-325 Link Here
256
274
257
			CellEditor oldEditor = cellEditor;
275
			CellEditor oldEditor = cellEditor;
258
			cellEditor = null;
276
			cellEditor = null;
277
			activationEvent=null;
259
			oldEditor.deactivate();
278
			oldEditor.deactivate();
279
			
280
			if( editorActivationListener != null && ! editorActivationListener.isEmpty() ) {
281
				Object[] ls = editorActivationListener.getListeners();
282
				for( int i = 0; i < ls.length; i++ ) {
283
					((AbstractViewerEditorActivationListener)ls[i]).afterEditorDeactivated(tmp);
284
				}
285
			}
260
		}
286
		}
261
	}
287
	}
262
288
	
263
	/**
289
	/**
264
	 * Enable the editor by mouse down
290
	 * Enable the editor by mouse down
265
	 * 
291
	 * 
266
	 * @param event
292
	 * @param event
267
	 */
293
	 */
268
	void handleMouseDown(MouseEvent event) {
294
	void handleEditorActivationEvent(EditorActivationEvent event) {
269
		if (event.button != 1) {
295
		if( editorActivationStrategy.isEditorActivationEvent(event) ) {
270
			return;
296
			if (cellEditor != null) {
271
		}
297
				applyEditorValue();
272
298
			}
273
		if (cellEditor != null) {
274
			applyEditorValue();
275
		}
276
277
		// activate the cell editor immediately. If a second mouseDown
278
		// is received prior to the expiration of the doubleClick time then
279
		// the cell editor will be deactivated and a doubleClick event will
280
		// be processed.
281
		//
282
		doubleClickExpirationTime = event.time
283
				+ Display.getCurrent().getDoubleClickTime();
284
285
		Item[] items = getSelection();
286
		// Do not edit if more than one row is selected.
287
		if (items.length != 1) {
288
			item = null;
289
			return;
290
		}
291
		item = items[0];
292
		activateCellEditor(event);
293
	}
294
295
	/**
296
	 * Start editing the given element.
297
	 * 
298
	 * @param element
299
	 * @param column
300
	 */
301
	void editElement(Object element, int column) {
302
		if (cellEditor != null) {
303
			applyEditorValue();
304
		}
305
299
306
		setSelection(createSelection(element), true);
300
			this.cell = (ViewerCell)event.getSource();			
307
		Item[] selection = getSelection();
301
			activationEvent = event;
308
		if (selection.length != 1) {
302
			activationTime = event.time + Display.getCurrent().getDoubleClickTime();
309
			return;
303
			
304
			activateCellEditor();
310
		}
305
		}
311
312
		item = selection[0];
313
314
		// Make sure selection is visible
315
		showSelection();
316
		columnNumber = column;
317
		activateCellEditor();
318
319
	}
306
	}
320
307
321
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
308
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
322
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
309
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
323
310
324
		if (part != null && part.getEditingSupport() != null) {
311
		if (part != null && part.getEditingSupport() != null) {
325
			part.getEditingSupport().setValue(tableItem.getData(),
312
			part.getEditingSupport().setValue(tableItem.getData(),
Lines 391-406 Link Here
391
		return cellEditors;
378
		return cellEditors;
392
	}
379
	}
393
380
394
	void setSelection(StructuredSelection selection, boolean b) {
395
		viewer.setSelection(selection, b);
396
	}
397
398
	void handleDoubleClickEvent() {
381
	void handleDoubleClickEvent() {
399
		viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer
382
		viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer
400
				.getSelection()));
383
				.getSelection()));
401
		viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection()));
384
		viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection()));
402
	}
385
	}
403
386
387
	void addEditorActivationListener(AbstractViewerEditorActivationListener listener) {
388
		if( editorActivationListener == null ) {
389
			editorActivationListener = new ListenerList();
390
		}
391
		editorActivationListener.add(listener);
392
	}
393
	
394
	void removeEditorActivationListener(AbstractViewerEditorActivationListener listener) {
395
		if( editorActivationListener != null ) {
396
			editorActivationListener.remove(listener);
397
		}
398
	}
399
	
400
	void setEditorActivationStrategy(
401
			EditorActivationStrategy editorActivationStrategy) {
402
		this.editorActivationStrategy = editorActivationStrategy;
403
	}
404
	
404
	/**
405
	/**
405
	 * Create a selection for this model element
406
	 * Create a selection for this model element
406
	 * 
407
	 * 
Lines 429-442 Link Here
429
	 *            the layout data used when editor is displayed
430
	 *            the layout data used when editor is displayed
430
	 */
431
	 */
431
	protected abstract void setLayoutData(CellEditor.LayoutData layoutData);
432
	protected abstract void setLayoutData(CellEditor.LayoutData layoutData);
432
433
	/**
434
	 * Show up the current selection (scroll the selection into view)
435
	 */
436
	protected abstract void showSelection();
437
438
	/**
439
	 * @return the current selection
440
	 */
441
	protected abstract Item[] getSelection();
442
}
433
}
(-)src/org/eclipse/jface/viewers/AbstractViewerEditorActivationListener.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * Parties interested in activation and deactivation of editors extend this
16
 * class and implement any or all of the methods
17
 * 
18
 * @since 3.3
19
 * 
20
 */
21
public abstract class AbstractViewerEditorActivationListener {
22
	/**
23
	 * Called before an editor is activated
24
	 * 
25
	 * @param event
26
	 *            the event
27
	 */
28
	public abstract void beforeEditorActivated(EditorActivationEvent event);
29
30
	/**
31
	 * Called after an editor has been activated
32
	 * 
33
	 * @param event the event
34
	 */
35
	public abstract void afterEditorActivated(EditorActivationEvent event);
36
37
	/**
38
	 * Called before an editor is deactivated
39
	 * 
40
	 * @param event
41
	 *            the event
42
	 */
43
	public abstract void beforeEditorDeactivated(EditorDeactivationEvent event);
44
45
	
46
	/**
47
	 * Called after an editor is deactivated
48
	 * 
49
	 * @param event the event
50
	 */
51
	public abstract void afterEditorDeactivated(EditorDeactivationEvent event);
52
}
(-)src/org/eclipse/jface/viewers/EditorDeactivationEvent.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import java.util.EventObject;
15
16
/**
17
 * This event is fired when an editor deactivated
18
 * 
19
 * @since 3.3
20
 * 
21
 */
22
public class EditorDeactivationEvent extends EventObject {
23
24
	/**
25
	 * 
26
	 */
27
	private static final long serialVersionUID = 1L;
28
29
	/**
30
	 * @param source
31
	 */
32
	public EditorDeactivationEvent(Object source) {
33
		super(source);
34
	}
35
36
}
(-)src/org/eclipse/jface/viewers/EditorActivationEvent.java (+159 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import java.util.EventObject;
15
16
import org.eclipse.swt.events.KeyEvent;
17
import org.eclipse.swt.events.MouseEvent;
18
import org.eclipse.swt.events.TraverseEvent;
19
20
/**
21
 * This event is passed on when a cell-editor is going to be activated
22
 * 
23
 * @since 3.3
24
 * 
25
 */
26
public class EditorActivationEvent extends EventObject {
27
	/**
28
	 * 
29
	 */
30
	private static final long serialVersionUID = 1L;
31
32
	/**
33
	 * if a key is pressed on a selected cell
34
	 */
35
	public static final int KEY_PRESSED = 1;
36
37
	/**
38
	 * if a cell is selected using a single click of the mouse
39
	 */
40
	public static final int MOUSE_CLICK_SELECTION = 2;
41
42
	/**
43
	 * if a cell is selected using double clicking of the mouse
44
	 */
45
	public static final int MOUSE_DOUBLE_CLICK_SELECTION = 3;
46
47
	/**
48
	 * if a cell is activated using code like e.g
49
	 * {@link ColumnViewer#editElement(Object, int)}
50
	 */
51
	public static final int PROGRAMATIC = 4;
52
53
	/**
54
	 * is a cell is activated by traversing
55
	 */
56
	public static final int TRAVERSAL = 5;
57
58
	/**
59
	 * the original event triggered
60
	 */
61
	public EventObject sourceEvent;
62
63
	/**
64
	 * The time the event is triggered
65
	 */
66
	public int time;
67
68
	/**
69
	 * The event type triggered:
70
	 * <ul>
71
	 * <li>{@link #KEY_PRESSED} if a key is pressed on a selected cell</li>
72
	 * <li>{@link #MOUSE_CLICK_SELECTION} if a cell is selected using a single
73
	 * click of the mouse</li>
74
	 * <li>{@link #MOUSE_DOUBLE_CLICK_SELECTION} if a cell is selected using
75
	 * double clicking of the mouse</li>
76
	 * </ul>
77
	 */
78
	public int eventType;
79
80
	/**
81
	 * <b>Only set for {@link #KEY_PRESSED}</b>
82
	 */
83
	public int keyCode;
84
85
	/**
86
	 * <b>Only set for {@link #KEY_PRESSED}</b>
87
	 */
88
	public char character;
89
90
	/**
91
	 * The statemask
92
	 */
93
	public int stateMask;
94
95
	/**
96
	 * This constructor can be used when no event exists. The type set is
97
	 * {@link #PROGRAMATIC}
98
	 * 
99
	 * @param cell
100
	 *            the cell
101
	 */
102
	public EditorActivationEvent(ViewerCell cell) {
103
		super(cell);
104
		eventType = PROGRAMATIC;
105
	}
106
107
	/**
108
	 * This constructor is used for all types of mouse events. Currently the
109
	 * type is can be {@link #MOUSE_CLICK_SELECTION} and
110
	 * {@link #MOUSE_DOUBLE_CLICK_SELECTION}
111
	 * 
112
	 * @param cell
113
	 *            the cell source of the event
114
	 * @param event
115
	 *            the event
116
	 */
117
	public EditorActivationEvent(ViewerCell cell, MouseEvent event) {
118
		super(cell);
119
120
		if (event.count >= 2) {
121
			eventType = MOUSE_DOUBLE_CLICK_SELECTION;
122
		} else {
123
			eventType = MOUSE_CLICK_SELECTION;
124
		}
125
126
		this.sourceEvent = event;
127
		this.time = event.time;
128
	}
129
130
	/**
131
	 * @param cell
132
	 *            the cell source of the event
133
	 * @param event
134
	 *            the event
135
	 */
136
	public EditorActivationEvent(ViewerCell cell, KeyEvent event) {
137
		super(cell);
138
		this.eventType = KEY_PRESSED;
139
		this.sourceEvent = event;
140
		this.time = 0;
141
		this.keyCode = event.keyCode;
142
		this.character = event.character;
143
		this.stateMask = event.stateMask;
144
	}
145
146
	/**
147
	 * This constructur is used to mark the activation triggered by a traversal
148
	 * 
149
	 * @param cell
150
	 *            the cell source of the event
151
	 * @param event
152
	 *            the event
153
	 */
154
	public EditorActivationEvent(ViewerCell cell, TraverseEvent event) {
155
		super(cell);
156
		this.eventType = TRAVERSAL;
157
		this.sourceEvent = event;
158
	}
159
}
(-)src/org/eclipse/jface/viewers/EditorActivationStrategy.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 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
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * This class is responsible to determin if a cell selection event is triggers
16
 * an editor activation
17
 * 
18
 * @since 3.3
19
 */
20
public abstract class EditorActivationStrategy {
21
	/**
22
	 * @param event
23
	 * @return bla bl
24
	 */
25
	protected abstract boolean isEditorActivationEvent(EditorActivationEvent event);
26
}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 4-10 Link Here
4
Bundle-SymbolicName: org.eclipse.swt.nebula.nebface
4
Bundle-SymbolicName: org.eclipse.swt.nebula.nebface
5
Bundle-Version: 1.0.0
5
Bundle-Version: 1.0.0
6
Bundle-Localization: plugin
6
Bundle-Localization: plugin
7
Require-Bundle: org.eclipse.jface,
7
Require-Bundle: org.eclipse.jface;visibility:=reexport,
8
 org.eclipse.swt.nebula;visibility:=reexport,
8
 org.eclipse.swt.nebula;visibility:=reexport,
9
 org.eclipse.equinox.common;visibility:=reexport
9
 org.eclipse.equinox.common;visibility:=reexport
10
Bundle-RequiredExecutionEnvironment: J2SE-1.4
10
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)src/org/eclipse/swt/nebula/nebface/viewers/CheckEditingSupport.java (-5 / +32 lines)
Lines 1-29 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 *    chris.gross@us.ibm.com - initial API and implementation
10
 *******************************************************************************/ 
11
1
package org.eclipse.swt.nebula.nebface.viewers;
12
package org.eclipse.swt.nebula.nebface.viewers;
2
13
3
import org.eclipse.jface.viewers.CellEditor;
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.jface.viewers.ColumnViewer;
4
import org.eclipse.jface.viewers.EditingSupport;
16
import org.eclipse.jface.viewers.EditingSupport;
5
17
18
/**
19
 * .
20
 *
21
 * @author chris.gross@us.ibm.com
22
 * @since 3.3
23
 */
6
public abstract class CheckEditingSupport extends EditingSupport
24
public abstract class CheckEditingSupport extends EditingSupport
7
{
25
{
26
    /**
27
     * Checkbox editing support.
28
     * 
29
     * @param viewer column to add check box support for.
30
     */
31
    public CheckEditingSupport(ColumnViewer viewer)
32
    {
33
        super(viewer);
34
    }
8
35
36
    /** {@inheritDoc} */
9
    protected boolean canEdit(Object element)
37
    protected boolean canEdit(Object element)
10
    {
38
    {
11
        // TODO Auto-generated method stub
12
        return false;
39
        return false;
13
    }
40
    }
14
41
42
    /** {@inheritDoc} */
15
    protected CellEditor getCellEditor(Object element)
43
    protected CellEditor getCellEditor(Object element)
16
    {
44
    {
17
        // TODO Auto-generated method stub
18
        return null;
45
        return null;
19
    }
46
    }
20
47
48
    /** {@inheritDoc} */
21
    protected Object getValue(Object element)
49
    protected Object getValue(Object element)
22
    {
50
    {
23
        // TODO Auto-generated method stub
24
        return null;
51
        return null;
25
    }
52
    }
26
53
27
    protected abstract void setValue(Object element, Object value);
54
    /** {@inheritDoc} */
28
55
    public abstract void setValue(Object element, Object value);
29
}
56
}
(-)src/org/eclipse/swt/nebula/nebface/viewers/GridViewer.java (-140 / +249 lines)
Lines 1-22 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006 Tom Schindl and others.
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
9
 *    rmcamara@us.ibm.com - initial API and implementation
10
 *     IBM Corporation
10
 *******************************************************************************/ 
11
 *******************************************************************************/
11
12
package org.eclipse.swt.nebula.nebface.viewers;
12
package org.eclipse.swt.nebula.nebface.viewers;
13
13
14
import org.eclipse.jface.viewers.AbstractTableViewer;
14
import org.eclipse.jface.viewers.AbstractViewerEditor;
15
import org.eclipse.jface.viewers.AbstractViewerEditor;
15
import org.eclipse.jface.viewers.BaseTableViewer;
16
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.jface.viewers.ViewerCell;
17
import org.eclipse.jface.viewers.ViewerRow;
18
import org.eclipse.jface.viewers.ViewerRow;
18
import org.eclipse.jface.viewers.CellEditor.LayoutData;
19
import org.eclipse.jface.viewers.CellEditor.LayoutData;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.nebula.widgets.grid.Grid;
23
import org.eclipse.swt.nebula.widgets.grid.Grid;
22
import org.eclipse.swt.nebula.widgets.grid.GridEditor;
24
import org.eclipse.swt.nebula.widgets.grid.GridEditor;
Lines 24-210 Link Here
24
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Item;
28
import org.eclipse.swt.widgets.Item;
29
import org.eclipse.swt.widgets.TableItem;
27
import org.eclipse.swt.widgets.Widget;
30
import org.eclipse.swt.widgets.Widget;
28
31
29
public class GridViewer extends BaseTableViewer {
32
/**
30
	private static final int DEFAULT_STYLE = SWT.MULTI | SWT.H_SCROLL
33
 * A concrete viewer based on an Grid control.
31
			| SWT.V_SCROLL | SWT.BORDER;
34
 * <p>
32
35
 * This class is not intended to be subclassed outside the viewer framework. It
33
	private Grid grid;
36
 * is designed to be instantiated with a pre-existing Grid control and
34
37
 * configured with a domain-specific content provider, label provider, element
35
	private GridEditor gridEditor;
38
 * filter (optional), and element sorter (optional).
36
39
 * <p>
37
	public GridViewer(Composite parent) {
40
 * Content providers for grid viewers must not implement the
38
		this(parent, DEFAULT_STYLE);
41
 * {@code ITreeContentProvider} interface.
39
	}
42
 * <p>
43
 * 
44
 * @author rmcamara@us.ibm.com
45
 * @since
46
 * @3.3
47
 */
48
public class GridViewer extends AbstractTableViewer
49
{
50
    /** This viewer's grid control. */
51
    private Grid grid;
52
    
53
    /** Editor support for tables. */
54
    private GridEditor gridEditor;
55
56
    /**
57
     * Creates a grid viewer on a newly-created grid control under the given
58
     * parent. The grid control is created using the SWT style bits
59
     * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
60
     * viewer has no input, no content provider, a default label provider, no
61
     * sorter, and no filters.
62
     * 
63
     * @param parent the parent control
64
     */
65
    public GridViewer(Composite parent)
66
    {
67
        this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
68
    }
40
69
41
	public GridViewer(Composite parent, int style) {
70
    /**
42
		this(new Grid(parent, style));
71
     * Creates a grid viewer on a newly-created grid control under the given
43
	}
72
     * parent. The grid control is created using the given SWT style bits. The
73
     * viewer has no input, no content provider, a default label provider, no
74
     * sorter, and no filters.
75
     * 
76
     * @param parent the parent control
77
     * @param style the SWT style bits used to create the grid.
78
     */
79
    public GridViewer(Composite parent, int style)
80
    {
81
        this(new Grid(parent, style));
82
    }
44
83
45
	public GridViewer(Grid gridControl) {
84
    /**
46
		super();
85
     * Creates a grid viewer on the given grid control. The viewer has no
47
        grid = gridControl;
86
     * input, no content provider, a default label provider, no sorter, and no
48
		gridEditor = new GridEditor(gridControl);
87
     * filters.
88
     * 
89
     * @param grid the grid control
90
     */
91
    public GridViewer(Grid grid)
92
    {
93
        this.grid = grid;
94
        gridEditor = new GridEditor(grid);
49
        hookControl(grid);
95
        hookControl(grid);
50
	}
96
    }
51
97
    
52
	public Grid getGrid() {
98
    /**
53
		return grid;
99
     * Returns the underlying Grid Control. 
54
	}
100
     * 
55
101
     * @return grid control.
56
	protected ViewerRow createNewRowPart(int style, int rowIndex) {
102
     */
57
		GridItem item;
103
    public Grid getGrid()
58
104
    {
59
		if (rowIndex >= 0) {
105
        return grid;
60
			item = new GridItem(grid, style, rowIndex);
106
    }
61
		} else {
62
			item = new GridItem(grid, style);
63
		}
64
65
		return getViewerRowFromItem(item);
66
	}
67
107
68
    protected ViewerRow getViewerRowFromItem(Widget item) {
108
    /** {@inheritDoc} */
69
        ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);
109
    protected ViewerRow internalCreateNewRowPart(int style, int rowIndex)
110
    {
111
        GridItem item;
70
112
71
        if (part == null) {
113
        if (rowIndex >= 0) 
72
            part = new GridViewerRow(((GridItem) item));
114
        {
115
            item = new GridItem(grid, style, rowIndex);
116
        } 
117
        else 
118
        {
119
            item = new GridItem(grid, style);
73
        }
120
        }
74
121
75
        return part;
122
        return getViewerRowFromItem(item);
76
    }
123
    }
77
124
78
	protected AbstractViewerEditor createViewerEditor() {
125
    /** {@inheritDoc} */
79
        return new AbstractViewerEditor(this) {
126
    protected AbstractViewerEditor createViewerEditor() 
80
127
    {
81
            protected StructuredSelection createSelection(Object element) {
128
        return new AbstractViewerEditor(this) 
129
        {
130
            protected StructuredSelection createSelection(Object element) 
131
            {
82
                return new StructuredSelection(element);
132
                return new StructuredSelection(element);
83
            }
133
            }
84
134
85
            protected Item[] getSelection() {
135
            protected void setEditor(Control w, Item item, int fColumnNumber) 
86
                return getGrid().getSelection();
136
            {
87
            }
88
89
            protected void setEditor(Control w, Item item, int fColumnNumber) {
90
                gridEditor.setEditor(w, (GridItem) item, fColumnNumber);
137
                gridEditor.setEditor(w, (GridItem) item, fColumnNumber);
91
            }
138
            }
92
139
93
            protected void setLayoutData(LayoutData layoutData) {
140
            protected void setLayoutData(LayoutData layoutData) 
141
            {
94
                gridEditor.grabHorizontal = layoutData.grabHorizontal;
142
                gridEditor.grabHorizontal = layoutData.grabHorizontal;
95
                gridEditor.horizontalAlignment = layoutData.horizontalAlignment;
143
                gridEditor.horizontalAlignment = layoutData.horizontalAlignment;
96
                gridEditor.minimumWidth = layoutData.minimumWidth;
144
                gridEditor.minimumWidth = layoutData.minimumWidth;
97
            }
145
            }
98
99
            protected void showSelection() {
100
                getGrid().showSelection();
101
            }
102
103
        };
146
        };
104
	}
147
    }
105
106
	protected void internalClear(int index) {
107
		// TODO NEEDS IMP
108
	}
109
148
110
	protected void internalClearAll() {
149
    /** {@inheritDoc} */
111
		// TODO NEEDS IMP
150
    protected void doClear(int index)
112
	}
151
    {
152
        // TODO Fix when grid supports virtual
153
    }
113
154
114
	protected void internalDeselectAll() {
155
    /** {@inheritDoc} */
115
		grid.deselectAll();
156
    protected void doClearAll()
116
	}
157
    {
158
        //TODO Fix when grid supports virtual
159
    }
160
    
161
    /** {@inheritDoc} */
162
    protected void doSetItemCount(int count)
163
    {
164
        //TODO Once grid supports virtual
165
    }
117
166
118
	protected Widget internalGetColumn(int index) {
167
    /** {@inheritDoc} */
119
		return grid.getColumn(index);
168
    protected void doDeselectAll()
120
	}
169
    {
170
        grid.deselectAll();
171
    }
121
172
122
	protected int internalGetColumnCount() {
173
    /** {@inheritDoc} */
123
		return grid.getColumnCount();
174
    protected Widget doGetColumn(int index)
124
	}
175
    {
176
        return grid.getColumn(index);
177
    }
125
178
126
	protected Widget[] internalGetColumns() {
179
    /** {@inheritDoc} */
127
		return grid.getColumns();
180
    protected int doGetColumnCount()
128
	}
181
    {
182
        return grid.getColumnCount();
183
    }
129
184
130
	protected Item internalGetItem(int index) {
185
    /** {@inheritDoc} */
131
		return grid.getItem(index);
186
    protected Item doGetItem(int index)
132
	}
187
    {
188
        return grid.getItem(index);
189
    }
133
190
134
	protected Item internalGetItem(Point point) {
191
    /** {@inheritDoc} */
135
		return grid.getItem(point);
192
    protected int doGetItemCount()
136
	}
193
    {
194
        return grid.getItemCount();
195
    }
137
196
138
	protected int internalGetItemCount() {
197
    /** {@inheritDoc} */
139
		return grid.getItemCount();
198
    protected Item[] doGetItems()
140
	}
199
    {
200
        return grid.getItems();
201
    }
141
202
142
	protected Item[] internalGetItems() {
203
    /** {@inheritDoc} */
143
		return grid.getItems();
204
    protected Item[] doGetSelection()
144
	}
205
    {
206
        return grid.getSelection();
207
    }
145
208
146
	protected Widget[] internalGetSelection() {
209
    /** {@inheritDoc} */
147
		return grid.getSelection();
210
    protected int[] doGetSelectionIndices()
148
	}
211
    {
212
        return grid.getSelectionIndices();
213
    }
149
214
150
	protected int[] internalGetSelectionIndices() {
215
    /** {@inheritDoc} */
151
		return grid.getSelectionIndices();
216
    protected int doIndexOf(Item item)
152
	}
217
    {
218
        return grid.indexOf((GridItem) item);
219
    }
153
220
154
	protected int internalIndexOf(Item item) {
221
    /** {@inheritDoc} */
155
		return grid.indexOf((GridItem) item);
222
    protected void doRemove(int[] indices)
156
	}
223
    {
224
        grid.remove(indices);
225
    }
157
226
158
	protected void internalRemove(int start, int end) {
227
    /** {@inheritDoc} */
159
		grid.remove(start, end);
228
    protected void doRemove(int start, int end)
160
	}
229
    {
230
        grid.remove(start, end);
231
    }
161
232
162
	protected void internalRemove(int[] indices) {
233
    /** {@inheritDoc} */
163
		grid.remove(indices);
234
    protected void doRemoveAll()
164
	}
235
    {
236
        grid.removeAll();
237
    }
165
238
166
	protected void internalRemoveAll() {
239
    /** {@inheritDoc} */
167
		grid.removeAll();
240
    protected void doSetSelection(Item[] items)
168
	}
241
    {
242
        GridItem[] items2 = new GridItem[items.length];
243
        for (int i = 0; i < items.length; i++)
244
        {
245
            items2[i] = (GridItem) items[i];
246
        }
247
        grid.setSelection(items2);
248
    }
169
249
170
	protected void internalSetItemCount(int count) {
250
    /** {@inheritDoc} */
171
		// TODO NEEDS IMP
251
    protected void doSetSelection(int[] indices)
172
	}
252
    {
253
        grid.setSelection(indices);
254
    }
173
255
174
	protected void internalSetSelection(Item[] items) {
256
    /** {@inheritDoc} */
175
		if (items != null) {
257
    protected void doShowItem(Item item)
176
			grid.setSelection(new GridItem[0]);
258
    {
177
		} else {
259
        grid.showItem((GridItem)item);
178
			GridItem[] tmp = new GridItem[items.length];
260
    }
179
			System.arraycopy(items, 0, tmp, 0, items.length);
180
			grid.setSelection(tmp);
181
		}
182
261
183
	}
262
    /** {@inheritDoc} */
263
    protected void doShowSelection()
264
    {
265
        grid.showSelection();
266
    }
184
267
185
	protected void internalSetSelection(int[] indices) {
268
    /** {@inheritDoc} */
186
		grid.setSelection(indices);
269
    protected Item getItemAt(Point point)
187
	}
270
    {
271
        return grid.getItem(point);
272
    }
188
273
189
	protected void internalShowItem(Item item) {
274
    /** {@inheritDoc} */
190
		grid.showItem((GridItem) item);
275
    public Control getControl()
191
	}
276
    {
277
        return grid;
278
    }
279
    
280
    /** {@inheritDoc} */
281
    protected ViewerRow getViewerRowFromItem(Widget item) 
282
    {
283
        ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);
192
284
193
	protected void internalShowSelection() {
285
        if (part == null) 
194
		grid.showSelection();
286
        {
195
	}
287
            part = new GridViewerRow(((GridItem) item));
288
        }
196
289
197
	protected void internalSetControl(Control table) {
290
        return part;
198
		grid = (Grid) table;
291
    }
199
	}
200
292
201
	public Control getControl() {
293
    
202
		return grid;
294
    
295
    protected void doResetItem(Item item) {
296
		GridItem gridItem = (GridItem) item;
297
		int columnCount = Math.max(1, grid.getColumnCount());
298
		for (int i = 0; i < columnCount; i++) {
299
			gridItem.setText(i, ""); //$NON-NLS-1$
300
			gridItem.setImage(null);
301
		}
203
	}
302
	}
204
303
205
    protected Item getItemAt(Point point)
304
	protected ViewerCell getFocusCell() {
206
    {
305
		if( getGrid().getCellSelectionEnabled() ) {
207
        return grid.getItem(point);
306
			Point p = getGrid().getFocusCell();
208
    }
307
			
308
			if( p.x >= 0 && p.y >= 0 ) {
309
				GridItem item = getGrid().getItem(p.y);
310
				if( item != null ) {
311
					ViewerRow row = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);
312
					return row.getCell(p.x);
313
				}
314
			}
315
		}
209
316
317
		return null;
318
	}
210
}
319
}
(-)src/org/eclipse/swt/nebula/nebface/viewers/GridViewerRow.java (-76 / +145 lines)
Lines 1-14 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006 Tom Schindl and others.
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
9
 *    rmcamara@us.ibm.com - initial API and implementation
10
 *     IBM Corporation
10
 *******************************************************************************/ 
11
 *******************************************************************************/
11
12
package org.eclipse.swt.nebula.nebface.viewers;
12
package org.eclipse.swt.nebula.nebface.viewers;
13
13
14
import org.eclipse.jface.viewers.ViewerRow;
14
import org.eclipse.jface.viewers.ViewerRow;
Lines 20-101 Link Here
20
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Item;
21
import org.eclipse.swt.widgets.Item;
22
22
23
public class GridViewerRow extends ViewerRow {
23
/**
24
	private GridItem item;
24
 * GridViewerRow is the concrete implementation of the part that represents items in a
25
25
 * Grid.
26
	public GridViewerRow(GridItem item) {
26
 *
27
		super(item);
27
 * @author rmcamara@us.ibm.com
28
		this.item = item;
28
 * @since 3.3
29
	}
29
 */
30
30
public class GridViewerRow extends ViewerRow
31
	public void clear() {
31
{
32
		item.setText("");
32
    private GridItem item;
33
		if (getColumnCount() == 0) {
33
34
			item.setImage(null);
34
    /**
35
     * Create a new instance of the receiver.
36
     * 
37
     * @param item GridItem source.
38
     */
39
    public GridViewerRow(Item item)
40
    {
41
        super(item);
42
        this.item = (GridItem)item;
43
    }
44
45
    /** {@inheritDoc} */
46
    public Rectangle getBounds(int columnIndex)
47
    {
48
        return item.getBounds(columnIndex);
49
    }
50
51
    /** {@inheritDoc} */
52
    public Rectangle getBounds()
53
    {
54
        // TODO This is not correct. Update once item returns the correct information.
55
        return item.getBounds(0);
56
    }
57
58
    /** {@inheritDoc} */
59
    public Item getItem()
60
    {
61
        return item;
62
    }
63
64
    /** {@inheritDoc} */
65
    public int getColumnCount()
66
    {
67
        return item.getParent().getColumnCount();
68
    }
69
70
    /** {@inheritDoc} */
71
    public Color getBackground(int columnIndex)
72
    {
73
        return item.getBackground(columnIndex);
74
    }
75
76
    /** {@inheritDoc} */
77
    public Font getFont(int columnIndex)
78
    {
79
        return item.getFont(columnIndex);
80
    }
81
82
    /** {@inheritDoc} */
83
    public Color getForeground(int columnIndex)
84
    {
85
        return item.getForeground(columnIndex);
86
    }
87
88
    /** {@inheritDoc} */
89
    public Image getImage(int columnIndex)
90
    {
91
        return item.getImage(columnIndex);
92
    }
93
94
    /** {@inheritDoc} */
95
    public String getText(int columnIndex)
96
    {
97
        return item.getText(columnIndex);
98
    }
99
100
    /** {@inheritDoc} */
101
    public void setBackground(int columnIndex, Color color)
102
    {
103
        item.setBackground(columnIndex, color);
104
    }
105
106
    /** {@inheritDoc} */
107
    public void setFont(int columnIndex, Font font)
108
    {
109
        item.setFont(columnIndex, font);
110
    }
111
112
    /** {@inheritDoc} */
113
    public void setForeground(int columnIndex, Color color)
114
    {
115
        item.setForeground(columnIndex, color);
116
    }
117
118
    /** {@inheritDoc} */
119
    public void setImage(int columnIndex, Image image)
120
    {
121
        item.setImage(columnIndex, image);
122
    }
123
124
    /** {@inheritDoc} */
125
    public void setText(int columnIndex, String text)
126
    {
127
        item.setText(columnIndex, text == null ? "" : text); //$NON-NLS-1$
128
    }
129
130
    /** {@inheritDoc} */
131
    public Control getControl()
132
    {
133
        return item.getParent();
134
    }
135
136
    public ViewerRow getNeighbor(int direction, boolean sameLevel) {
137
		if( direction == ViewerRow.ABOVE ) {
138
			return getRowAbove();
139
		} else if( direction == ViewerRow.BELOW ) {
140
			return getRowBelow();
35
		} else {
141
		} else {
36
			for (int i = 0; i < getColumnCount(); i++) {
142
			throw new IllegalArgumentException("Illegal value of direction argument."); //$NON-NLS-1$
37
				item.setImage(i, null);
38
			}
39
		}
143
		}
40
	}
144
	}
41
145
42
	public Color getBackground(int columnIndex) {
146
	
43
		return item.getBackground(columnIndex);
147
	private ViewerRow getRowAbove() {
44
	}
148
		int index = item.getParent().indexOf(item) - 1;
45
149
		
46
	public Rectangle getBounds(int columnIndex) {
150
		if( index >= 0 ) {
47
		return item.getBounds(columnIndex);
151
			return (ViewerRow)item.getParent().getItem(index).getData(ViewerRow.ROWPART_KEY); 
48
	}
152
		}
49
153
		
50
	public Rectangle getBounds() {
154
		return null;
51
		return item.getBounds(0); // TODO IS THIS CORRECT
52
	}
53
54
	public int getColumnCount() {
55
		return item.getParent().getColumnCount();
56
	}
57
58
	public Font getFont(int columnIndex) {
59
		return item.getFont(columnIndex);
60
	}
61
62
	public Color getForeground(int columnIndex) {
63
		return item.getForeground(columnIndex);
64
	}
65
66
	public Image getImage(int columnIndex) {
67
		return item.getImage(columnIndex);
68
	}
69
70
	public Item getItem() {
71
		return item;
72
	}
73
74
	public String getText(int columnIndex) {
75
		return item.getText(columnIndex);
76
	}
77
78
	public void setBackground(int columnIndex, Color color) {
79
		item.setBackground(columnIndex, color);
80
	}
81
82
	public void setFont(int columnIndex, Font font) {
83
		item.setFont(columnIndex, font);
84
	}
85
86
	public void setForeground(int columnIndex, Color color) {
87
		item.setForeground(columnIndex, color);
88
	}
89
90
	public void setImage(int columnIndex, Image image) {
91
		item.setImage(columnIndex, image);
92
	}
93
94
	public void setText(int columnIndex, String text) {
95
		item.setText(columnIndex, text);
96
	}
155
	}
97
156
98
	public Control getControl() {
157
	private ViewerRow getRowBelow() {
99
		return item.getParent();
158
		int index = item.getParent().indexOf(item) + 1;
159
		
160
		if( index < item.getParent().getItemCount() ) {
161
			GridItem tmp = item.getParent().getItem(index);
162
			//TODO NULL can happen in case of VIRTUAL => How do we deal with that
163
			if( tmp != null ) {
164
				return (ViewerRow)tmp.getData(ViewerRow.ROWPART_KEY);
165
			}
166
		}
167
		
168
		return null;
100
	}
169
	}
101
}
170
}
(-)src/org/eclipse/swt/nebula/nebface/viewers/GridViewerColumn.java (-27 / +38 lines)
Lines 1-18 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *    rmcamara@us.ibm.com - initial API and implementation
10
 ******************************************************************************/
10
 *******************************************************************************/ 
11
11
12
package org.eclipse.swt.nebula.nebface.viewers;
12
package org.eclipse.swt.nebula.nebface.viewers;
13
13
14
import org.eclipse.jface.viewers.EditingSupport;
14
import org.eclipse.jface.viewers.EditingSupport;
15
import org.eclipse.jface.viewers.TableViewer;
16
import org.eclipse.jface.viewers.ViewerColumn;
15
import org.eclipse.jface.viewers.ViewerColumn;
17
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.nebula.widgets.grid.Grid;
17
import org.eclipse.swt.nebula.widgets.grid.Grid;
Lines 20-68 Link Here
20
import org.eclipse.swt.nebula.widgets.grid.GridItem;
19
import org.eclipse.swt.nebula.widgets.grid.GridItem;
21
import org.eclipse.swt.widgets.Event;
20
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.swt.widgets.Listener;
21
import org.eclipse.swt.widgets.Listener;
23
import org.eclipse.swt.widgets.Table;
24
import org.eclipse.swt.widgets.TableColumn;
25
22
26
/**
23
/**
27
 * This is the JFace' implementation of SWT's {@link TableColumn} like
24
 * The concrete implementation of the ColumnViewer for the grid.
28
 * {@link TableViewer} is JFace' implementation of {@link Table}
25
 *
29
 * 
26
 * @author rmcamara@us.ibm.com
30
 * @since 3.3
27
 * @since 3.3
31
 */
28
 */
32
public final class GridViewerColumn extends ViewerColumn {
29
public final class GridViewerColumn extends ViewerColumn 
33
30
{
31
    /** The concrete grid column that is being represented by the {@code ViewerColumn}.*/
34
    private GridColumn column;
32
    private GridColumn column;
33
    
34
    /** Editor support for handling check events. */
35
    private CheckEditingSupport checkEditingSupport;
35
    private CheckEditingSupport checkEditingSupport;
36
    
37
    /** The parent grid viewer. */
36
    private GridViewer viewer;
38
    private GridViewer viewer;
37
39
38
    /**
40
    /**
39
     * Create a new column in the {@link TableViewer}
41
     * Create a new column in the {@link GridViewer}
40
     * 
42
     * 
41
     * @param viewer
43
     * @param viewer
42
     *            the viewer the column belongs to
44
     *            the viewer the column belongs to
43
     * @param style
45
     * @param style
44
     *            the style used to create the column for style bits see
46
     *            the style used to create the column for style bits see
45
     *            {@link TableColumn}
47
     *            {@link GridColumn}
46
     * @see TableColumn#TableColumn(Table, int)
48
     * @see GridColumn#GridColumn(Grid, int)
47
     */
49
     */
48
    public GridViewerColumn(GridViewer viewer, int style) {
50
    public GridViewerColumn(GridViewer viewer, int style) 
51
    {
49
        this(viewer, style, -1);
52
        this(viewer, style, -1);
50
        this.viewer = viewer;
53
        this.viewer = viewer;
51
    }
54
    }
52
55
53
    /**
56
    /**
54
     * Create a new column in the {@link TableViewer}
57
     * Create a new column in the {@link GridViewer}
55
     * 
58
     * 
56
     * @param viewer
59
     * @param viewer
57
     *            the viewer the column belongs to
60
     *            the viewer the column belongs to
58
     * @param style
61
     * @param style
59
     *            the style used to create the column for style bits see
62
     *            the style used to create the column for style bits see
60
     *            {@link TableColumn}
63
     *            {@link GridColumn}
61
     * @param index
64
     * @param index
62
     *            the index of the newly created column
65
     *            the index of the newly created column
63
     * @see TableColumn#TableColumn(Table, int, int)
66
     * @see GridColumn#GridColumn(Grid, int, int)
64
     */
67
     */
65
    public GridViewerColumn(GridViewer viewer, int style, int index) {
68
    public GridViewerColumn(GridViewer viewer, int style, int index) 
69
    {
66
        this(viewer, createColumn((Grid) viewer.getControl(), style, index));
70
        this(viewer, createColumn((Grid) viewer.getControl(), style, index));
67
        this.viewer = viewer;
71
        this.viewer = viewer;
68
    }
72
    }
Lines 74-100 Link Here
74
     * @param column
78
     * @param column
75
     *            the column the viewer is attached to
79
     *            the column the viewer is attached to
76
     */
80
     */
77
    public GridViewerColumn(GridViewer viewer, GridColumn column) {
81
    public GridViewerColumn(GridViewer viewer, GridColumn column) 
82
    {
78
        super(viewer, column);
83
        super(viewer, column);
79
        this.column = column;
84
        this.column = column;
80
        this.viewer = viewer;
85
        this.viewer = viewer;
81
    }
86
    }
82
    
87
    
83
    private static GridColumn createColumn(Grid grid, int style, int index) {
88
    private static GridColumn createColumn(Grid table, int style, int index) 
84
        if (index >= 0) {
89
    {
85
            return new GridColumn(grid, style, index);
90
        if (index >= 0) 
91
        {
92
            return new GridColumn(table, style, index);
86
        }
93
        }
87
94
88
        return new GridColumn(grid, style);
95
        return new GridColumn(table, style);
89
    }
96
    }
90
97
91
    /**
98
    /**
92
     * @return the underlying SWT column
99
     * Returns the underlying column.
100
     * 
101
     * @return the underlying Nebula column
93
     */
102
     */
94
    public GridColumn getColumn() {
103
    public GridColumn getColumn() 
104
    {
95
        return column;
105
        return column;
96
    }
106
    }
97
    
107
    
108
    /** {@inheritDoc} */
98
    public void setEditingSupport(EditingSupport editingSupport)
109
    public void setEditingSupport(EditingSupport editingSupport)
99
    {
110
    {
100
        if (editingSupport instanceof CheckEditingSupport)
111
        if (editingSupport instanceof CheckEditingSupport)
Lines 123-126 Link Here
123
            super.setEditingSupport(editingSupport);
134
            super.setEditingSupport(editingSupport);
124
        }        
135
        }        
125
    }
136
    }
126
}
137
}
(-)src/org/eclipse/swt/nebula/nebface/viewers/GridTreeViewer.java (+392 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
 *    rmcamara@us.ibm.com - initial API and implementation
10
 *******************************************************************************/ 
11
12
package org.eclipse.swt.nebula.nebface.viewers;
13
14
import org.eclipse.jface.viewers.AbstractTreeViewer;
15
import org.eclipse.jface.viewers.AbstractViewerEditor;
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.jface.viewers.TreePath;
18
import org.eclipse.jface.viewers.TreeSelection;
19
import org.eclipse.jface.viewers.ViewerRow;
20
import org.eclipse.jface.viewers.CellEditor.LayoutData;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.TreeListener;
23
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.nebula.widgets.grid.Grid;
25
import org.eclipse.swt.nebula.widgets.grid.GridEditor;
26
import org.eclipse.swt.nebula.widgets.grid.GridItem;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Item;
30
import org.eclipse.swt.widgets.Widget;
31
32
import java.util.List;
33
34
35
/**
36
 * A concrete viewer based on an {@link Grid} control. This viewer is meant
37
 * to provide grid like support for a grid.
38
 * <p>
39
 * This class is not intended to be subclassed outside the viewer framework. It
40
 * is designed to be instantiated with a pre-existing grid control and
41
 * configured with a domain-specific content provider, label provider, element
42
 * filter (optional), and element sorter (optional).
43
 * <p>
44
 * Content providers for grid viewers must implement the
45
 * {@code ITreeContentProvider} interface.
46
 * 
47
 * @author rmcamara@us.ibm.com
48
 * @since 3.3
49
 */
50
public class GridTreeViewer extends AbstractTreeViewer
51
{
52
    /** This viewer's grid control. */
53
    private Grid grid;
54
55
    /** Table editor. */
56
    private GridEditor gridEditor;
57
58
    /**
59
     * Creates a grid viewer on a newly-created grid control under the given
60
     * parent. The grid control is created using the SWT style bits
61
     * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
62
     * viewer has no input, no content provider, a default label provider, no
63
     * sorter, and no filters.
64
     * 
65
     * @param parent the parent control.
66
     */
67
    public GridTreeViewer(Composite parent)
68
    {
69
        this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
70
    }
71
72
    /**
73
     * Creates a grid viewer on a newly-created grid control under the given
74
     * parent. The grid control is created using the given SWT style bits. The
75
     * viewer has no input, no content provider, a default label provider, no
76
     * sorter, and no filters.
77
     * 
78
     * @param parent the parent control.
79
     * @param style the SWT style bits used to create the grid.
80
     */
81
    public GridTreeViewer(Composite parent, int style)
82
    {
83
        this(new Grid(parent, style));
84
    }
85
86
    /**
87
     * Creates a grid viewer on the given grid control. The viewer has no
88
     * input, no content provider, a default label provider, no sorter, and no
89
     * filters.
90
     * 
91
     * @param grid the grid control.
92
     */
93
    public GridTreeViewer(Grid table)
94
    {
95
        this.grid = table;
96
        gridEditor = new GridEditor(table);
97
        hookControl(table);
98
    }
99
100
    /**
101
     * {@inheritDoc}
102
     */
103
    public Control getControl()
104
    {
105
        return grid;
106
    }
107
108
    /**
109
     * Returns this grid viewer's grid control.
110
     * 
111
     * @return the grid control
112
     */
113
    public Grid getGrid()
114
    {
115
        return grid;
116
    }
117
118
    /** {@inheritDoc} */
119
    protected void addTreeListener(Control c, TreeListener listener)
120
    {
121
        ((Grid)c).addTreeListener(listener);
122
    }
123
124
    /** {@inheritDoc} */
125
    protected Widget doGetColumn(int index)
126
    {
127
        return grid.getColumn(index);
128
    }
129
130
    /** {@inheritDoc} */
131
    protected int doGetColumnCount()
132
    {
133
        return grid.getColumnCount();
134
    }
135
136
    /** {@inheritDoc} */
137
    protected Item[] getChildren(Widget o)
138
    {
139
        if (o instanceof GridItem)
140
        {
141
            return ((GridItem)o).getItems();
142
        }
143
        if (o instanceof Grid)
144
        {
145
            List rootlist = ((Grid)o).getRootItems();
146
            GridItem[] roots = new GridItem[rootlist.size()];
147
            
148
            for (int i = 0; i < roots.length; i++)
149
            {
150
                roots[i] = (GridItem) rootlist.get(i);
151
            }
152
            
153
            return roots;
154
        }
155
        return null;
156
    }
157
158
    /** {@inheritDoc} */
159
    protected boolean getExpanded(Item item)
160
    {
161
        return ((GridItem)item).isExpanded();
162
    }
163
164
    /** {@inheritDoc} */
165
    protected Item getItemAt(Point p)
166
    {
167
        return grid.getItem(p);
168
    }
169
170
    /** {@inheritDoc} */
171
    protected Item[] getItems(Item item)
172
    {
173
        return ((GridItem)item).getItems();
174
    }
175
176
    /** {@inheritDoc} */
177
    protected Item getParentItem(Item item)
178
    {
179
        return ((GridItem)item).getParentItem();
180
    }
181
182
    /** {@inheritDoc} */
183
    protected Item[] getSelection(Control widget)
184
    {
185
        return ((Grid)widget).getSelection();
186
    }
187
188
    /** {@inheritDoc} */
189
    protected Item doGetParentItem(Item item)
190
    {
191
        return ((GridItem)item).getParentItem();
192
    }
193
194
    /** {@inheritDoc} */
195
    protected int doIndexOf(Item parentItem, Item item)
196
    {
197
        return ((GridItem)parentItem).indexOf((GridItem)item);
198
    }
199
200
    /** {@inheritDoc} */
201
    protected int doIndexOf(Item item)
202
    {
203
        return grid.indexOf((GridItem)item);
204
    }
205
206
    /** {@inheritDoc} */
207
    protected AbstractViewerEditor createViewerEditor()
208
    {
209
        return new AbstractViewerEditor(this)
210
        {
211
            protected StructuredSelection createSelection(Object element)
212
            {
213
                if (element instanceof TreePath)
214
                {
215
                    return new TreeSelection((TreePath)element, getComparer());
216
                }
217
218
                return new StructuredSelection(element);
219
            }
220
221
            protected void setEditor(Control w, Item item, int fColumnNumber)
222
            {
223
                gridEditor.setEditor(w, (GridItem)item, fColumnNumber);
224
            }
225
226
            protected void setLayoutData(LayoutData layoutData)
227
            {
228
                gridEditor.grabHorizontal = layoutData.grabHorizontal;
229
                gridEditor.horizontalAlignment = layoutData.horizontalAlignment;
230
                gridEditor.minimumWidth = layoutData.minimumWidth;
231
            }
232
        };
233
    }
234
235
    /** {@inheritDoc} */
236
    protected void removeAll(Control widget)
237
    {
238
        ((Grid)widget).removeAll();
239
    }
240
241
    /** {@inheritDoc} */
242
    protected void doSetExpanded(Item item, boolean expanded)
243
    {
244
        ((GridItem)item).setExpanded(expanded);
245
    }
246
247
    /** {@inheritDoc} */
248
    protected void doSetSelection(List items)
249
    {
250
        GridItem[] newItems = new GridItem[items.size()];
251
        items.toArray(newItems);
252
        getGrid().setSelection(newItems);
253
    }
254
255
    /** {@inheritDoc} */
256
    protected void showItem(Item item)
257
    {
258
        getGrid().showItem((GridItem)item);
259
    }
260
261
    /** {@inheritDoc} */
262
    protected Item getChild(Widget widget, int index)
263
    {
264
        if (widget instanceof GridItem)
265
        {
266
            return ((GridItem)widget).getItem(index);
267
        }
268
        if (widget instanceof Grid)
269
        {
270
            return (GridItem) ((Grid)widget).getRootItems().get(index);
271
        }
272
        return null;
273
    }
274
275
    /** {@inheritDoc} */
276
    protected int doGetItemCount()
277
    {
278
        return grid.getItemCount();
279
    }
280
281
    /** {@inheritDoc} */
282
    protected Item doGetItem(int index)
283
    {
284
        return grid.getItem(index);
285
    }
286
287
    /** {@inheritDoc} */
288
    protected Item doGetItem(Item item, int index)
289
    {
290
        return ((GridItem)item).getItem(index);
291
    }
292
    
293
    /** {@inheritDoc} */
294
    protected int doGetItemCount(Item item)
295
    {
296
        return ((GridItem)item).getItemCount();
297
    }
298
299
    /** {@inheritDoc} */
300
    protected void doSetItemCount(int count)
301
    {
302
        // TODO Implement once grid supports virtual
303
    }
304
305
    /** {@inheritDoc} */
306
    protected void doSetItemCount(Item item, int count)
307
    {
308
        // TODO Implement once grid supports virtual
309
    }
310
    
311
    /** {@inheritDoc} */
312
    protected void doClear(Item item, boolean all)
313
    {
314
        // TODO Once grid implements virtual.
315
    }
316
317
    /** {@inheritDoc} */
318
    protected void doClearAll(Item item, boolean all)
319
    {
320
        //TODO implement once grid supports virtual.
321
    }
322
323
    /** {@inheritDoc} */
324
    protected void doClearAll(boolean all)
325
    {
326
        //TODO implement once grid supports virtual.
327
    }
328
329
    /** {@inheritDoc} */
330
    protected ViewerRow getViewerRowFromItem(Widget item)
331
    {
332
        ViewerRow part = (ViewerRow)item.getData(ViewerRow.ROWPART_KEY);
333
334
        if (part == null)
335
        {
336
            part = new GridViewerRow(((GridItem)item));
337
        }
338
339
        return part;
340
    }
341
342
    /** {@inheritDoc} */
343
    protected ViewerRow doCreateNewRowPart(ViewerRow parent, int style, int rowIndex)
344
    {
345
        if (parent == null)
346
        {
347
            if (rowIndex >= 0)
348
            {
349
                return getViewerRowFromItem(new GridItem(grid, style, rowIndex));
350
            }
351
            return getViewerRowFromItem(new GridItem(grid, style));
352
        }
353
354
        if (rowIndex >= 0)
355
        {
356
            return getViewerRowFromItem(new GridItem((GridItem)parent.getItem(), 
357
                                                       SWT.NONE, rowIndex));
358
        }
359
360
        return getViewerRowFromItem(new GridItem((GridItem)parent.getItem(), SWT.NONE));
361
    }
362
363
    protected int getItemCount(Control control)
364
    {
365
        // TODO Auto-generated method stub
366
        return 0;
367
    }
368
369
    protected int getItemCount(Item item)
370
    {
371
        // TODO Auto-generated method stub
372
        return 0;
373
    }
374
375
    protected Item newItem(Widget parent, int style, int index)
376
    {
377
        // TODO Auto-generated method stub
378
        return null;
379
    }
380
381
    protected void setExpanded(Item item, boolean expand)
382
    {
383
        // TODO Auto-generated method stub
384
        
385
    }
386
387
    protected void setSelection(List items)
388
    {
389
        // TODO Auto-generated method stub
390
        
391
    }
392
}
(-)src/org/eclipse/swt/nebula/widgets/grid/Grid.java (-1 / +1 lines)
Lines 6675-6681 Link Here
6675
    /**
6675
    /**
6676
     * Returns the current cell in focus.  If cell selection is disabled, this method returns null.
6676
     * Returns the current cell in focus.  If cell selection is disabled, this method returns null.
6677
     * 
6677
     * 
6678
     * @return cell in focus or {@code null}.
6678
     * @return cell in focus or {@code null}. x represents the column and y the row the cell is in
6679
     * @throws org.eclipse.swt.SWTException
6679
     * @throws org.eclipse.swt.SWTException
6680
     * <ul>
6680
     * <ul>
6681
     * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
6681
     * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
(-).settings/org.eclipse.jdt.ui.prefs (-1 / +1 lines)
Lines 1-3 Link Here
1
#Thu Jun 01 15:04:52 EDT 2006
1
#Thu Feb 01 11:43:25 CET 2007
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\r\n * Copyright (c) ${year} ${todo}\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n *    ${user} - initial API and implementation\r\n *******************************************************************************/ \r\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * \r\n *\r\n * @author ${user}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/** \r\n * {@inheritDoc}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
3
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\r\n * Copyright (c) ${year} ${todo}\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n *    ${user} - initial API and implementation\r\n *******************************************************************************/ \r\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * \r\n *\r\n * @author ${user}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/** \r\n * {@inheritDoc}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
(-).settings/org.eclipse.jdt.core.prefs (-1 / +13 lines)
Lines 1-4 Link Here
1
#Thu Jun 01 12:46:14 EDT 2006
1
#Thu Feb 01 16:16:19 CET 2007
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
Lines 7-12 Link Here
7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
10
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
11
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
12
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
13
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
14
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
15
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
16
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
17
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
18
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning
19
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
20
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
21
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
22
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
23
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected
12
org.eclipse.jdt.core.compiler.source=1.3
24
org.eclipse.jdt.core.compiler.source=1.3
(-)META-INF/MANIFEST.MF (-3 / +3 lines)
Lines 5-10 Link Here
5
Bundle-Version: 1.0.0
5
Bundle-Version: 1.0.0
6
Bundle-Localization: plugin
6
Bundle-Localization: plugin
7
Require-Bundle: org.eclipse.swt,
7
Require-Bundle: org.eclipse.swt,
8
 org.eclipse.swt.nebula
8
 org.eclipse.swt.nebula,
9
Export-Package: org.eclipse.swt.nebula.snippets.ctree,
9
 org.eclipse.swt.nebula.nebface
10
 org.eclipse.swt.nebula.snippets.grid
10
Export-Package: org.eclipse.swt.nebula.snippets.grid
(-)src/org/eclipse/swt/nebface/snippets/viewers/GridViewerSnippet1.java (+206 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Tom Schindl 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
 *     Tom Schindl - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.swt.nebface.snippets.viewers;
13
14
import org.eclipse.jface.resource.FontRegistry;
15
import org.eclipse.jface.viewers.CellEditor;
16
import org.eclipse.jface.viewers.EditingSupport;
17
import org.eclipse.jface.viewers.EditorActivationEvent;
18
import org.eclipse.jface.viewers.EditorActivationStrategy;
19
import org.eclipse.jface.viewers.ICellModifier;
20
import org.eclipse.jface.viewers.IStructuredContentProvider;
21
import org.eclipse.jface.viewers.ITableColorProvider;
22
import org.eclipse.jface.viewers.ITableFontProvider;
23
import org.eclipse.jface.viewers.ITableLabelProvider;
24
import org.eclipse.jface.viewers.LabelProvider;
25
import org.eclipse.jface.viewers.TextCellEditor;
26
import org.eclipse.jface.viewers.Viewer;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.graphics.Color;
29
import org.eclipse.swt.graphics.Font;
30
import org.eclipse.swt.graphics.Image;
31
import org.eclipse.swt.layout.FillLayout;
32
import org.eclipse.swt.nebula.nebface.viewers.GridViewer;
33
import org.eclipse.swt.nebula.widgets.grid.GridColumn;
34
import org.eclipse.swt.widgets.Display;
35
import org.eclipse.swt.widgets.Shell;
36
37
/**
38
 * Example usage of none mandatory interfaces of ITableFontProvider and
39
 * ITableColorProvider
40
 * 
41
 * @author Tom Schindl <tom.schindl@bestsolution.at>
42
 * 
43
 */
44
public class GridViewerSnippet1 {
45
46
	private class MyContentProvider implements IStructuredContentProvider {
47
48
		/*
49
		 * (non-Javadoc)
50
		 * 
51
		 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
52
		 */
53
		public Object[] getElements(Object inputElement) {
54
			return (MyModel[]) inputElement;
55
		}
56
57
		/*
58
		 * (non-Javadoc)
59
		 * 
60
		 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
61
		 */
62
		public void dispose() {
63
64
		}
65
66
		/*
67
		 * (non-Javadoc)
68
		 * 
69
		 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
70
		 *      java.lang.Object, java.lang.Object)
71
		 */
72
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
73
74
		}
75
76
	}
77
78
	public static boolean flag = true;
79
	
80
	public class MyModel {
81
		public int counter;
82
83
		public MyModel(int counter) {
84
			this.counter = counter;
85
		}
86
87
		public String toString() {
88
			return "Item " + this.counter;
89
		}
90
	}
91
92
	public class MyLabelProvider extends LabelProvider implements
93
			ITableLabelProvider, ITableFontProvider, ITableColorProvider {
94
		FontRegistry registry = new FontRegistry();
95
96
		public Image getColumnImage(Object element, int columnIndex) {
97
			return null;
98
		}
99
100
		public String getColumnText(Object element, int columnIndex) {
101
			return "Column " + columnIndex + " => " + element.toString();
102
		}
103
104
		public Font getFont(Object element, int columnIndex) {
105
			if (((MyModel) element).counter % 2 == 0) {
106
				return registry.getBold(Display.getCurrent().getSystemFont()
107
						.getFontData()[0].getName());
108
			}
109
			return null;
110
		}
111
112
		public Color getBackground(Object element, int columnIndex) {
113
			if (((MyModel) element).counter % 2 == 0) {
114
				return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
115
			}
116
			return null;
117
		}
118
119
		public Color getForeground(Object element, int columnIndex) {
120
			if (((MyModel) element).counter % 2 == 1) {
121
				return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
122
			}
123
			return null;
124
		}
125
126
	}
127
128
	public GridViewerSnippet1(Shell shell) {
129
		final GridViewer v = new GridViewer(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
130
		v.setLabelProvider(new MyLabelProvider());
131
		v.setContentProvider(new MyContentProvider());
132
		v.getGrid().setCellSelectionEnabled(true);
133
				
134
		v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getGrid()), new TextCellEditor(v.getGrid()) });
135
		v.setCellModifier(new ICellModifier() {
136
137
			public boolean canModify(Object element, String property) {
138
				return true;
139
			}
140
141
			public Object getValue(Object element, String property) {
142
				return "Column " + property + " => " + element.toString();
143
			}
144
145
			public void modify(Object element, String property, Object value) {
146
				
147
			}
148
			
149
		});
150
		
151
		v.setColumnProperties(new String[] {"1","2"});
152
		
153
		v.setEditorActivationStrategy(new EditorActivationStrategy() {
154
			protected boolean isEditorActivationEvent(
155
					EditorActivationEvent event) {
156
				return event.eventType == EditorActivationEvent.TRAVERSAL || event.eventType == EditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || ( event.eventType == EditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR ) || event.eventType == EditorActivationEvent.PROGRAMATIC;
157
			}
158
		});
159
		v.setEnableEditorActivationWithKeyboard(true);
160
		v.setTabEditingStyle(EditingSupport.TABING_HORIZONTAL|EditingSupport.TABING_MOVE_TO_ROW_NEIGHBOR|EditingSupport.TABING_VERTICAL);
161
		
162
		GridColumn column = new GridColumn(v.getGrid(), SWT.NONE);
163
		column.setWidth(200);
164
		column.setText("Column 1");
165
166
		column = new GridColumn(v.getGrid(), SWT.NONE);
167
		column.setWidth(200);
168
		column.setText("Column 2");
169
170
		MyModel[] model = createModel();
171
		v.setInput(model);
172
		v.getGrid().setLinesVisible(true);
173
		v.getGrid().setHeaderVisible(true);
174
	}
175
176
	private MyModel[] createModel() {
177
		MyModel[] elements = new MyModel[10];
178
179
		for (int i = 0; i < 10; i++) {
180
			elements[i] = new MyModel(i);
181
		}
182
183
		return elements;
184
	}
185
186
	/**
187
	 * @param args
188
	 */
189
	public static void main(String[] args) {
190
		Display display = new Display();
191
192
		Shell shell = new Shell(display);
193
		shell.setLayout(new FillLayout());
194
		new GridViewerSnippet1(shell);
195
		shell.open();
196
197
		while (!shell.isDisposed()) {
198
			if (!display.readAndDispatch())
199
				display.sleep();
200
		}
201
202
		display.dispose();
203
204
	}
205
206
}

Return to bug 172646