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

(-)Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java (-2 / +4 lines)
Lines 12-21 Link Here
12
package org.eclipse.jface.snippets.viewers;
12
package org.eclipse.jface.snippets.viewers;
13
13
14
import org.eclipse.jface.viewers.CellEditor;
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.jface.viewers.ColumnViewerEditor;
16
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
15
import org.eclipse.jface.viewers.EditingSupport;
17
import org.eclipse.jface.viewers.EditingSupport;
16
import org.eclipse.jface.viewers.ICellModifier;
18
import org.eclipse.jface.viewers.ICellModifier;
17
import org.eclipse.jface.viewers.IStructuredContentProvider;
19
import org.eclipse.jface.viewers.IStructuredContentProvider;
18
import org.eclipse.jface.viewers.LabelProvider;
20
import org.eclipse.jface.viewers.LabelProvider;
21
import org.eclipse.jface.viewers.TableViewerEditor;
19
import org.eclipse.jface.viewers.TableViewer;
22
import org.eclipse.jface.viewers.TableViewer;
20
import org.eclipse.jface.viewers.TextCellEditor;
23
import org.eclipse.jface.viewers.TextCellEditor;
21
import org.eclipse.jface.viewers.Viewer;
24
import org.eclipse.jface.viewers.Viewer;
Lines 111-118 Link Here
111
		
114
		
112
		v.setColumnProperties(new String[] { "column1", "column2" });
115
		v.setColumnProperties(new String[] { "column1", "column2" });
113
		v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
116
		v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
114
		v.setTabEditingStyle(EditingSupport.TABBING_HORIZONTAL|EditingSupport.TABBING_MOVE_TO_ROW_NEIGHBOR|EditingSupport.TABBING_VERTICAL);
117
		TableViewerEditor.create(v,new ColumnViewerEditorActivationStrategy(v),ColumnViewerEditor.TABBING_HORIZONTAL|ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR|ColumnViewerEditor.TABBING_VERTICAL);
115
		
116
		
118
		
117
		MyModel[] model = createModel();
119
		MyModel[] model = createModel();
118
		v.setInput(model);
120
		v.setInput(model);
(-)Eclipse (+240 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.jface.snippets.viewers;
13
14
import java.util.ArrayList;
15
16
import org.eclipse.jface.viewers.CellEditor;
17
import org.eclipse.jface.viewers.CellNavigationStrategy;
18
import org.eclipse.jface.viewers.ColumnLabelProvider;
19
import org.eclipse.jface.viewers.ColumnViewerEditor;
20
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
21
import org.eclipse.jface.viewers.EditingSupport;
22
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
23
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
24
import org.eclipse.jface.viewers.ITreeContentProvider;
25
import org.eclipse.jface.viewers.TextCellEditor;
26
import org.eclipse.jface.viewers.TreePath;
27
import org.eclipse.jface.viewers.TreeViewerFocusCellManager;
28
import org.eclipse.jface.viewers.TreeViewerEditor;
29
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.jface.viewers.TreeViewerColumn;
31
import org.eclipse.jface.viewers.Viewer;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.events.SelectionListener;
35
import org.eclipse.swt.layout.FillLayout;
36
import org.eclipse.swt.widgets.Button;
37
import org.eclipse.swt.widgets.Display;
38
import org.eclipse.swt.widgets.Shell;
39
40
/**
41
 * A simple TreeViewer to demonstrate usage
42
 * 
43
 * @author Tom Schindl <tom.schindl@bestsolution.at>
44
 * 
45
 */
46
public class Snippet026TreeViewerTabEditing {
47
	public Snippet026TreeViewerTabEditing(final Shell shell) {
48
		Button b = new Button(shell,SWT.PUSH);
49
		b.setText("BBB");
50
		final TreeViewer v = new TreeViewer(shell, SWT.BORDER
51
				| SWT.FULL_SELECTION);
52
		v.getTree().setLinesVisible(true);
53
		v.getTree().setHeaderVisible(true);
54
		b.addSelectionListener(new SelectionListener() {
55
56
			public void widgetDefaultSelected(SelectionEvent e) {
57
				
58
			}
59
60
			public void widgetSelected(SelectionEvent e) {
61
				MyModel root = (MyModel)v.getInput();
62
				TreePath path = new TreePath(new Object[]{root,root.child.get(1), ((MyModel)root.child.get(1)).child.get(0)});
63
				v.editElement(path, 0);
64
				// v.editElement(root.child.get(0), 0);
65
			}
66
			
67
		});
68
		
69
		 
70
		TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));
71
		ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
72
			protected boolean isEditorActivationEvent(
73
					ColumnViewerEditorActivationEvent event) {
74
				return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
75
						|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
76
						|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
77
						|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
78
			}
79
		};
80
		
81
		TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
82
				| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
83
				| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
84
		
85
		final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
86
87
		TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
88
		column.getColumn().setWidth(200);
89
		column.getColumn().setText("Column 1");
90
		column.setLabelProvider(new ColumnLabelProvider() {
91
92
			public String getText(Object element) {
93
				return "Column 1 => " + element.toString();
94
			}
95
96
		});
97
		column.setEditingSupport(new EditingSupport(v) {
98
			protected boolean canEdit(Object element) {
99
				return true;
100
			}
101
102
			protected CellEditor getCellEditor(Object element) {
103
				return textCellEditor;
104
			}
105
106
			protected Object getValue(Object element) {
107
				return ((MyModel) element).counter + "";
108
			}
109
110
			protected void setValue(Object element, Object value) {
111
				((MyModel) element).counter = Integer
112
						.parseInt(value.toString());
113
				v.update(element, null);
114
			}
115
		});
116
117
		column = new TreeViewerColumn(v, SWT.NONE);
118
		column.getColumn().setWidth(200);
119
		column.getColumn().setText("Column 2");
120
		column.setLabelProvider(new ColumnLabelProvider() {
121
122
			public String getText(Object element) {
123
				return "Column 2 => " + element.toString();
124
			}
125
126
		});
127
		column.setEditingSupport(new EditingSupport(v) {
128
			protected boolean canEdit(Object element) {
129
				return true;
130
			}
131
132
			protected CellEditor getCellEditor(Object element) {
133
				return textCellEditor;
134
			}
135
136
			protected Object getValue(Object element) {
137
				return ((MyModel) element).counter + "";
138
			}
139
140
			protected void setValue(Object element, Object value) {
141
				((MyModel) element).counter = Integer
142
						.parseInt(value.toString());
143
				v.update(element, null);
144
			}
145
		});
146
		
147
		v.setContentProvider(new MyContentProvider());
148
149
		v.setInput(createModel());
150
	}
151
152
	private MyModel createModel() {
153
154
		MyModel root = new MyModel(0, null);
155
		root.counter = 0;
156
157
		MyModel tmp;
158
		MyModel subItem;
159
		for (int i = 1; i < 10; i++) {
160
			tmp = new MyModel(i, root);
161
			root.child.add(tmp);
162
			for (int j = 1; j < i; j++) {
163
				subItem = new MyModel(j, tmp);
164
				subItem.child.add(new MyModel(j * 100, subItem));
165
				tmp.child.add(subItem);
166
			}
167
		}
168
169
		return root;
170
	}
171
172
	public static void main(String[] args) {
173
		Display display = new Display();
174
		Shell shell = new Shell(display);
175
		shell.setLayout(new FillLayout());
176
		new Snippet026TreeViewerTabEditing(shell);
177
		shell.open();
178
179
		while (!shell.isDisposed()) {
180
			if (!display.readAndDispatch())
181
				display.sleep();
182
		}
183
184
		display.dispose();
185
	}
186
187
	private class MyContentProvider implements ITreeContentProvider {
188
189
		public Object[] getElements(Object inputElement) {
190
			return ((MyModel) inputElement).child.toArray();
191
		}
192
193
		public void dispose() {
194
		}
195
196
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
197
		}
198
199
		public Object[] getChildren(Object parentElement) {
200
			return getElements(parentElement);
201
		}
202
203
		public Object getParent(Object element) {
204
			if (element == null) {
205
				return null;
206
			}
207
			return ((MyModel) element).parent;
208
		}
209
210
		public boolean hasChildren(Object element) {
211
			return ((MyModel) element).child.size() > 0;
212
		}
213
214
	}
215
216
	public class MyModel {
217
		public MyModel parent;
218
219
		public ArrayList child = new ArrayList();
220
221
		public int counter;
222
223
		public MyModel(int counter, MyModel parent) {
224
			this.parent = parent;
225
			this.counter = counter;
226
		}
227
228
		public String toString() {
229
			String rv = "Item ";
230
			if (parent != null) {
231
				rv = parent.toString() + ".";
232
			}
233
234
			rv += counter;
235
236
			return rv;
237
		}
238
	}
239
240
}
(-)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 (-154 / +226 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.AbstractViewerEditor;
14
import org.eclipse.jface.viewers.AbstractTableViewer;
15
import org.eclipse.jface.viewers.BaseTableViewer;
15
import org.eclipse.jface.viewers.ColumnViewerEditor;
16
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.jface.viewers.ViewerCell;
17
import org.eclipse.jface.viewers.ViewerRow;
19
import org.eclipse.jface.viewers.ViewerRow;
18
import org.eclipse.jface.viewers.CellEditor.LayoutData;
20
import org.eclipse.jface.viewers.CellEditor.LayoutData;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.nebula.widgets.grid.Grid;
24
import org.eclipse.swt.nebula.widgets.grid.Grid;
22
import org.eclipse.swt.nebula.widgets.grid.GridEditor;
25
import org.eclipse.swt.nebula.widgets.grid.GridEditor;
Lines 24-210 Link Here
24
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Item;
29
import org.eclipse.swt.widgets.Item;
30
import org.eclipse.swt.widgets.TableItem;
27
import org.eclipse.swt.widgets.Widget;
31
import org.eclipse.swt.widgets.Widget;
28
32
29
public class GridViewer extends BaseTableViewer {
33
/**
30
	private static final int DEFAULT_STYLE = SWT.MULTI | SWT.H_SCROLL
34
 * A concrete viewer based on an Grid control.
31
			| SWT.V_SCROLL | SWT.BORDER;
35
 * <p>
32
36
 * This class is not intended to be subclassed outside the viewer framework. It
33
	private Grid grid;
37
 * is designed to be instantiated with a pre-existing Grid control and
34
38
 * configured with a domain-specific content provider, label provider, element
35
	private GridEditor gridEditor;
39
 * filter (optional), and element sorter (optional).
36
40
 * <p>
37
	public GridViewer(Composite parent) {
41
 * Content providers for grid viewers must not implement the
38
		this(parent, DEFAULT_STYLE);
42
 * {@code ITreeContentProvider} interface.
39
	}
43
 * <p>
44
 * 
45
 * @author rmcamara@us.ibm.com
46
 * @since
47
 * @3.3
48
 */
49
public class GridViewer extends AbstractTableViewer
50
{
51
    /** This viewer's grid control. */
52
    private Grid grid;
53
54
    /**
55
     * Creates a grid viewer on a newly-created grid control under the given
56
     * parent. The grid control is created using the SWT style bits
57
     * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
58
     * viewer has no input, no content provider, a default label provider, no
59
     * sorter, and no filters.
60
     * 
61
     * @param parent the parent control
62
     */
63
    public GridViewer(Composite parent)
64
    {
65
        this(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
66
    }
40
67
41
	public GridViewer(Composite parent, int style) {
68
    /**
42
		this(new Grid(parent, style));
69
     * Creates a grid viewer on a newly-created grid control under the given
43
	}
70
     * parent. The grid control is created using the given SWT style bits. The
71
     * viewer has no input, no content provider, a default label provider, no
72
     * sorter, and no filters.
73
     * 
74
     * @param parent the parent control
75
     * @param style the SWT style bits used to create the grid.
76
     */
77
    public GridViewer(Composite parent, int style)
78
    {
79
        this(new Grid(parent, style));
80
    }
44
81
45
	public GridViewer(Grid gridControl) {
82
    /**
46
		super();
83
     * Creates a grid viewer on the given grid control. The viewer has no
47
        grid = gridControl;
84
     * input, no content provider, a default label provider, no sorter, and no
48
		gridEditor = new GridEditor(gridControl);
85
     * filters.
86
     * 
87
     * @param grid the grid control
88
     */
89
    public GridViewer(Grid grid)
90
    {
91
        this.grid = grid;
49
        hookControl(grid);
92
        hookControl(grid);
50
	}
93
    }
51
94
    
52
	public Grid getGrid() {
95
    /**
53
		return grid;
96
     * Returns the underlying Grid Control. 
54
	}
97
     * 
55
98
     * @return grid control.
56
	protected ViewerRow createNewRowPart(int style, int rowIndex) {
99
     */
57
		GridItem item;
100
    public Grid getGrid()
58
101
    {
59
		if (rowIndex >= 0) {
102
        return grid;
60
			item = new GridItem(grid, style, rowIndex);
103
    }
61
		} else {
62
			item = new GridItem(grid, style);
63
		}
64
65
		return getViewerRowFromItem(item);
66
	}
67
104
68
    protected ViewerRow getViewerRowFromItem(Widget item) {
105
    /** {@inheritDoc} */
69
        ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);
106
    protected ViewerRow internalCreateNewRowPart(int style, int rowIndex)
107
    {
108
        GridItem item;
70
109
71
        if (part == null) {
110
        if (rowIndex >= 0) 
72
            part = new GridViewerRow(((GridItem) item));
111
        {
112
            item = new GridItem(grid, style, rowIndex);
113
        } 
114
        else 
115
        {
116
            item = new GridItem(grid, style);
73
        }
117
        }
74
118
75
        return part;
119
        return getViewerRowFromItem(item);
76
    }
120
    }
77
121
78
	protected AbstractViewerEditor createViewerEditor() {
122
    /** {@inheritDoc} */
79
        return new AbstractViewerEditor(this) {
123
    protected ColumnViewerEditor createViewerEditor() 
80
124
    {
81
            protected StructuredSelection createSelection(Object element) {
125
        return new GridViewerEditor(this,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT);
82
                return new StructuredSelection(element);
126
    }
83
            }
84
85
            protected Item[] getSelection() {
86
                return getGrid().getSelection();
87
            }
88
89
            protected void setEditor(Control w, Item item, int fColumnNumber) {
90
                gridEditor.setEditor(w, (GridItem) item, fColumnNumber);
91
            }
92
93
            protected void setLayoutData(LayoutData layoutData) {
94
                gridEditor.grabHorizontal = layoutData.grabHorizontal;
95
                gridEditor.horizontalAlignment = layoutData.horizontalAlignment;
96
                gridEditor.minimumWidth = layoutData.minimumWidth;
97
            }
98
99
            protected void showSelection() {
100
                getGrid().showSelection();
101
            }
102
103
        };
104
	}
105
106
	protected void internalClear(int index) {
107
		// TODO NEEDS IMP
108
	}
109
110
	protected void internalClearAll() {
111
		// TODO NEEDS IMP
112
	}
113
114
	protected void internalDeselectAll() {
115
		grid.deselectAll();
116
	}
117
118
	protected Widget internalGetColumn(int index) {
119
		return grid.getColumn(index);
120
	}
121
122
	protected int internalGetColumnCount() {
123
		return grid.getColumnCount();
124
	}
125
126
	protected Widget[] internalGetColumns() {
127
		return grid.getColumns();
128
	}
129
127
130
	protected Item internalGetItem(int index) {
128
    /** {@inheritDoc} */
131
		return grid.getItem(index);
129
    protected void doClear(int index)
132
	}
130
    {
131
        // TODO Fix when grid supports virtual
132
    }
133
133
134
	protected Item internalGetItem(Point point) {
134
    /** {@inheritDoc} */
135
		return grid.getItem(point);
135
    protected void doClearAll()
136
	}
136
    {
137
        //TODO Fix when grid supports virtual
138
    }
139
    
140
    /** {@inheritDoc} */
141
    protected void doSetItemCount(int count)
142
    {
143
        //TODO Once grid supports virtual
144
    }
137
145
138
	protected int internalGetItemCount() {
146
    /** {@inheritDoc} */
139
		return grid.getItemCount();
147
    protected void doDeselectAll()
140
	}
148
    {
149
        grid.deselectAll();
150
    }
141
151
142
	protected Item[] internalGetItems() {
152
    /** {@inheritDoc} */
143
		return grid.getItems();
153
    protected Widget doGetColumn(int index)
144
	}
154
    {
155
        return grid.getColumn(index);
156
    }
145
157
146
	protected Widget[] internalGetSelection() {
158
    /** {@inheritDoc} */
147
		return grid.getSelection();
159
    protected int doGetColumnCount()
148
	}
160
    {
161
        return grid.getColumnCount();
162
    }
149
163
150
	protected int[] internalGetSelectionIndices() {
164
    /** {@inheritDoc} */
151
		return grid.getSelectionIndices();
165
    protected Item doGetItem(int index)
152
	}
166
    {
167
        return grid.getItem(index);
168
    }
153
169
154
	protected int internalIndexOf(Item item) {
170
    /** {@inheritDoc} */
155
		return grid.indexOf((GridItem) item);
171
    protected int doGetItemCount()
156
	}
172
    {
173
        return grid.getItemCount();
174
    }
157
175
158
	protected void internalRemove(int start, int end) {
176
    /** {@inheritDoc} */
159
		grid.remove(start, end);
177
    protected Item[] doGetItems()
160
	}
178
    {
179
        return grid.getItems();
180
    }
161
181
162
	protected void internalRemove(int[] indices) {
182
    /** {@inheritDoc} */
163
		grid.remove(indices);
183
    protected Item[] doGetSelection()
164
	}
184
    {
185
        return grid.getSelection();
186
    }
165
187
166
	protected void internalRemoveAll() {
188
    /** {@inheritDoc} */
167
		grid.removeAll();
189
    protected int[] doGetSelectionIndices()
168
	}
190
    {
191
        return grid.getSelectionIndices();
192
    }
169
193
170
	protected void internalSetItemCount(int count) {
194
    /** {@inheritDoc} */
171
		// TODO NEEDS IMP
195
    protected int doIndexOf(Item item)
172
	}
196
    {
197
        return grid.indexOf((GridItem) item);
198
    }
173
199
174
	protected void internalSetSelection(Item[] items) {
200
    /** {@inheritDoc} */
175
		if (items != null) {
201
    protected void doRemove(int[] indices)
176
			grid.setSelection(new GridItem[0]);
202
    {
177
		} else {
203
        grid.remove(indices);
178
			GridItem[] tmp = new GridItem[items.length];
204
    }
179
			System.arraycopy(items, 0, tmp, 0, items.length);
180
			grid.setSelection(tmp);
181
		}
182
205
183
	}
206
    /** {@inheritDoc} */
207
    protected void doRemove(int start, int end)
208
    {
209
        grid.remove(start, end);
210
    }
184
211
185
	protected void internalSetSelection(int[] indices) {
212
    /** {@inheritDoc} */
186
		grid.setSelection(indices);
213
    protected void doRemoveAll()
187
	}
214
    {
215
        grid.removeAll();
216
    }
188
217
189
	protected void internalShowItem(Item item) {
218
    /** {@inheritDoc} */
190
		grid.showItem((GridItem) item);
219
    protected void doSetSelection(Item[] items)
191
	}
220
    {
221
        GridItem[] items2 = new GridItem[items.length];
222
        for (int i = 0; i < items.length; i++)
223
        {
224
            items2[i] = (GridItem) items[i];
225
        }
226
        grid.setSelection(items2);
227
    }
192
228
193
	protected void internalShowSelection() {
229
    /** {@inheritDoc} */
194
		grid.showSelection();
230
    protected void doSetSelection(int[] indices)
195
	}
231
    {
232
        grid.setSelection(indices);
233
    }
196
234
197
	protected void internalSetControl(Control table) {
235
    /** {@inheritDoc} */
198
		grid = (Grid) table;
236
    protected void doShowItem(Item item)
199
	}
237
    {
238
        grid.showItem((GridItem)item);
239
    }
200
240
201
	public Control getControl() {
241
    /** {@inheritDoc} */
202
		return grid;
242
    protected void doShowSelection()
203
	}
243
    {
244
        grid.showSelection();
245
    }
204
246
247
    /** {@inheritDoc} */
205
    protected Item getItemAt(Point point)
248
    protected Item getItemAt(Point point)
206
    {
249
    {
207
        return grid.getItem(point);
250
        return grid.getItem(point);
208
    }
251
    }
209
252
253
    /** {@inheritDoc} */
254
    public Control getControl()
255
    {
256
        return grid;
257
    }
258
    
259
    /** {@inheritDoc} */
260
    protected ViewerRow getViewerRowFromItem(Widget item) 
261
    {
262
        ViewerRow part = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);
263
264
        if (part == null) 
265
        {
266
            part = new GridViewerRow(((GridItem) item));
267
        }
268
269
        return part;
270
    }
271
272
    
273
    
274
    protected void doResetItem(Item item) {
275
		GridItem gridItem = (GridItem) item;
276
		int columnCount = Math.max(1, grid.getColumnCount());
277
		for (int i = 0; i < columnCount; i++) {
278
			gridItem.setText(i, ""); //$NON-NLS-1$
279
			gridItem.setImage(null);
280
		}
281
	}
210
}
282
}
(-)src/org/eclipse/swt/nebula/nebface/viewers/GridViewerRow.java (-74 / +148 lines)
Lines 1-16 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.TreePath;
14
import org.eclipse.jface.viewers.ViewerRow;
15
import org.eclipse.jface.viewers.ViewerRow;
15
import org.eclipse.swt.graphics.Color;
16
import org.eclipse.swt.graphics.Color;
16
import org.eclipse.swt.graphics.Font;
17
import org.eclipse.swt.graphics.Font;
Lines 20-101 Link Here
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Item;
22
import org.eclipse.swt.widgets.Item;
22
23
23
public class GridViewerRow extends ViewerRow {
24
/**
24
	private GridItem item;
25
 * GridViewerRow is the concrete implementation of the part that represents items in a
25
26
 * Grid.
26
	public GridViewerRow(GridItem item) {
27
 *
27
		super(item);
28
 * @author rmcamara@us.ibm.com
28
		this.item = item;
29
 * @since 3.3
29
	}
30
 */
30
31
public class GridViewerRow extends ViewerRow
31
	public void clear() {
32
{
32
		item.setText("");
33
    private GridItem item;
33
		if (getColumnCount() == 0) {
34
34
			item.setImage(null);
35
    /**
36
     * Create a new instance of the receiver.
37
     * 
38
     * @param item GridItem source.
39
     */
40
    public GridViewerRow(Item item)
41
    {
42
        super(item);
43
        this.item = (GridItem)item;
44
    }
45
46
    /** {@inheritDoc} */
47
    public Rectangle getBounds(int columnIndex)
48
    {
49
        return item.getBounds(columnIndex);
50
    }
51
52
    /** {@inheritDoc} */
53
    public Rectangle getBounds()
54
    {
55
        // TODO This is not correct. Update once item returns the correct information.
56
        return item.getBounds(0);
57
    }
58
59
    /** {@inheritDoc} */
60
    public Item getItem()
61
    {
62
        return item;
63
    }
64
65
    /** {@inheritDoc} */
66
    public int getColumnCount()
67
    {
68
        return item.getParent().getColumnCount();
69
    }
70
71
    /** {@inheritDoc} */
72
    public Color getBackground(int columnIndex)
73
    {
74
        return item.getBackground(columnIndex);
75
    }
76
77
    /** {@inheritDoc} */
78
    public Font getFont(int columnIndex)
79
    {
80
        return item.getFont(columnIndex);
81
    }
82
83
    /** {@inheritDoc} */
84
    public Color getForeground(int columnIndex)
85
    {
86
        return item.getForeground(columnIndex);
87
    }
88
89
    /** {@inheritDoc} */
90
    public Image getImage(int columnIndex)
91
    {
92
        return item.getImage(columnIndex);
93
    }
94
95
    /** {@inheritDoc} */
96
    public String getText(int columnIndex)
97
    {
98
        return item.getText(columnIndex);
99
    }
100
101
    /** {@inheritDoc} */
102
    public void setBackground(int columnIndex, Color color)
103
    {
104
        item.setBackground(columnIndex, color);
105
    }
106
107
    /** {@inheritDoc} */
108
    public void setFont(int columnIndex, Font font)
109
    {
110
        item.setFont(columnIndex, font);
111
    }
112
113
    /** {@inheritDoc} */
114
    public void setForeground(int columnIndex, Color color)
115
    {
116
        item.setForeground(columnIndex, color);
117
    }
118
119
    /** {@inheritDoc} */
120
    public void setImage(int columnIndex, Image image)
121
    {
122
        item.setImage(columnIndex, image);
123
    }
124
125
    /** {@inheritDoc} */
126
    public void setText(int columnIndex, String text)
127
    {
128
        item.setText(columnIndex, text == null ? "" : text); //$NON-NLS-1$
129
    }
130
131
    /** {@inheritDoc} */
132
    public Control getControl()
133
    {
134
        return item.getParent();
135
    }
136
137
    public ViewerRow getNeighbor(int direction, boolean sameLevel) {
138
		if( direction == ViewerRow.ABOVE ) {
139
			return getRowAbove();
140
		} else if( direction == ViewerRow.BELOW ) {
141
			return getRowBelow();
35
		} else {
142
		} else {
36
			for (int i = 0; i < getColumnCount(); i++) {
143
			throw new IllegalArgumentException("Illegal value of direction argument."); //$NON-NLS-1$
37
				item.setImage(i, null);
38
			}
39
		}
144
		}
40
	}
145
	}
41
146
42
	public Color getBackground(int columnIndex) {
147
	
43
		return item.getBackground(columnIndex);
148
	private ViewerRow getRowAbove() {
44
	}
149
		int index = item.getParent().indexOf(item) - 1;
45
150
		
46
	public Rectangle getBounds(int columnIndex) {
151
		if( index >= 0 ) {
47
		return item.getBounds(columnIndex);
152
			return (ViewerRow)item.getParent().getItem(index).getData(ViewerRow.ROWPART_KEY); 
48
	}
153
		}
49
154
		
50
	public Rectangle getBounds() {
155
		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
	}
156
	}
93
157
94
	public void setText(int columnIndex, String text) {
158
	private ViewerRow getRowBelow() {
95
		item.setText(columnIndex, text);
159
		int index = item.getParent().indexOf(item) + 1;
160
		
161
		if( index < item.getParent().getItemCount() ) {
162
			GridItem tmp = item.getParent().getItem(index);
163
			//TODO NULL can happen in case of VIRTUAL => How do we deal with that
164
			if( tmp != null ) {
165
				return (ViewerRow)tmp.getData(ViewerRow.ROWPART_KEY);
166
			}
167
		}
168
		
169
		return null;
96
	}
170
	}
97
171
98
	public Control getControl() {
172
	public TreePath getTreePath() {
99
		return item.getParent();
173
		return null;
100
	}
174
	}
101
}
175
}
(-)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.ColumnViewerEditor;
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 ColumnViewerEditor createViewerEditor()
208
    {
209
        return new ColumnViewerEditor(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/nebface/viewers/GridViewerEditor.java (+70 lines)
Added Link Here
1
package org.eclipse.swt.nebula.nebface.viewers;
2
3
import org.eclipse.jface.viewers.ColumnViewerEditor;
4
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
5
import org.eclipse.jface.viewers.StructuredSelection;
6
import org.eclipse.jface.viewers.ViewerCell;
7
import org.eclipse.jface.viewers.ViewerRow;
8
import org.eclipse.jface.viewers.CellEditor.LayoutData;
9
import org.eclipse.swt.graphics.Point;
10
import org.eclipse.swt.nebula.widgets.grid.Grid;
11
import org.eclipse.swt.nebula.widgets.grid.GridEditor;
12
import org.eclipse.swt.nebula.widgets.grid.GridItem;
13
import org.eclipse.swt.widgets.Control;
14
import org.eclipse.swt.widgets.Item;
15
16
public class GridViewerEditor extends ColumnViewerEditor {
17
	/** Editor support for tables. */
18
    private GridEditor gridEditor;
19
    
20
	public GridViewerEditor(GridViewer viewer,
21
			ColumnViewerEditorActivationStrategy editorActivationStrategy,
22
			int feature) {
23
		super(viewer, editorActivationStrategy, feature);
24
		this.gridEditor = new GridEditor(viewer.getGrid());
25
	}
26
27
	protected StructuredSelection createSelection(Object element) 
28
    {
29
        return new StructuredSelection(element);
30
    }
31
32
    protected void setEditor(Control w, Item item, int fColumnNumber) 
33
    {
34
        gridEditor.setEditor(w, (GridItem) item, fColumnNumber);
35
    }
36
37
    protected void setLayoutData(LayoutData layoutData) 
38
    {
39
        gridEditor.grabHorizontal = layoutData.grabHorizontal;
40
        gridEditor.horizontalAlignment = layoutData.horizontalAlignment;
41
        gridEditor.minimumWidth = layoutData.minimumWidth;
42
    }
43
44
	public ViewerCell getFocusCell() {
45
		Grid grid = ((GridViewer)getViewer()).getGrid();
46
		
47
		if( grid.getCellSelectionEnabled() ) {
48
			Point p = grid.getFocusCell();
49
			
50
			if( p.x >= 0 && p.y >= 0 ) {
51
				GridItem item = grid.getItem(p.y);
52
				if( item != null ) {
53
					ViewerRow row = (ViewerRow) item.getData(ViewerRow.ROWPART_KEY);
54
					return row.getCell(p.x);
55
				}
56
			}
57
		}
58
		
59
		return null;
60
	}
61
62
	protected void updateFocusCell(ViewerCell focusCell) {
63
		Grid grid = ((GridViewer)getViewer()).getGrid();
64
		
65
		if( grid.getCellSelectionEnabled() ) {
66
			//TODO CHRIS WE NEED SOMETHING LIKE
67
			// grid.setFocusCell();
68
		}
69
	}
70
}
(-)src/org/eclipse/jface/viewers/TableViewer.java (-33 / +1 lines)
Lines 16-24 Link Here
16
16
17
17
18
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.jface.viewers.CellEditor.LayoutData;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.custom.TableEditor;
22
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Composite;
Lines 67-77 Link Here
67
	private Table table;
65
	private Table table;
68
66
69
	/**
67
	/**
70
	 * This viewer's table editor.
71
	 */
72
	private TableEditor tableEditor;
73
74
	/**
75
	 * Creates a table viewer on a newly-created table control under the given
68
	 * Creates a table viewer on a newly-created table control under the given
76
	 * parent. The table control is created using the SWT style bits
69
	 * parent. The table control is created using the SWT style bits
77
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
70
	 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
Lines 110-116 Link Here
110
	 */
103
	 */
111
	public TableViewer(Table table) {
104
	public TableViewer(Table table) {
112
		this.table = table;
105
		this.table = table;
113
		tableEditor = new TableEditor(table);
114
		hookControl(table);
106
		hookControl(table);
115
	}
107
	}
116
108
Lines 128-158 Link Here
128
	}
120
	}
129
	
121
	
130
	protected ColumnViewerEditor createViewerEditor() {
122
	protected ColumnViewerEditor createViewerEditor() {
131
		return new ColumnViewerEditor(this) {
123
		return new TableViewerEditor(this,null,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT);
132
133
			protected StructuredSelection createSelection(Object element) {
134
				return new StructuredSelection(element);
135
			}
136
137
			protected Item[] getSelection() {
138
				return table.getSelection();
139
			}
140
141
			protected void setEditor(Control w, Item item, int fColumnNumber) {
142
				tableEditor.setEditor(w, (TableItem) item, fColumnNumber);
143
			}
144
145
			protected void setLayoutData(LayoutData layoutData) {
146
				tableEditor.grabHorizontal = layoutData.grabHorizontal;
147
				tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
148
				tableEditor.minimumWidth = layoutData.minimumWidth;
149
			}
150
151
			protected void showSelection() {
152
				table.showSelection();
153
			}
154
155
		};
156
	}
124
	}
157
	
125
	
158
	/**
126
	/**
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-37 / +23 lines)
Lines 16-24 Link Here
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.jface.util.Policy;
18
import org.eclipse.jface.util.Policy;
19
import org.eclipse.jface.viewers.CellEditor.LayoutData;
20
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.custom.TreeEditor;
22
import org.eclipse.swt.events.DisposeEvent;
20
import org.eclipse.swt.events.DisposeEvent;
23
import org.eclipse.swt.events.DisposeListener;
21
import org.eclipse.swt.events.DisposeListener;
24
import org.eclipse.swt.events.TreeEvent;
22
import org.eclipse.swt.events.TreeEvent;
Lines 63-73 Link Here
63
	private Tree tree;
61
	private Tree tree;
64
62
65
	/**
63
	/**
66
	 * This viewer's tree editor.
67
	 */
68
	private TreeEditor treeEditor;
69
70
	/**
71
	 * Flag for whether the tree has been disposed of.
64
	 * Flag for whether the tree has been disposed of.
72
	 */
65
	 */
73
	private boolean treeIsDisposed = false;
66
	private boolean treeIsDisposed = false;
Lines 116-122 Link Here
116
		super();
109
		super();
117
		this.tree = tree;
110
		this.tree = tree;
118
		hookControl(tree);
111
		hookControl(tree);
119
		treeEditor = new TreeEditor(tree);
120
	}
112
	}
121
113
122
	/*
114
	/*
Lines 274-308 Link Here
274
	}
266
	}
275
267
276
	protected ColumnViewerEditor createViewerEditor() {
268
	protected ColumnViewerEditor createViewerEditor() {
277
		return new ColumnViewerEditor(this) {
269
		return new TreeViewerEditor(this,null,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT);
278
279
			protected StructuredSelection createSelection(Object element) {
280
				if (element instanceof TreePath) {
281
					return new TreeSelection((TreePath) element, getComparer());
282
				}
283
284
				return new StructuredSelection(element);
285
			}
286
287
			protected Item[] getSelection() {
288
				return tree.getSelection();
289
			}
290
291
			protected void setEditor(Control w, Item item, int fColumnNumber) {
292
				treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
293
			}
294
295
			protected void setLayoutData(LayoutData layoutData) {
296
				treeEditor.grabHorizontal = layoutData.grabHorizontal;
297
				treeEditor.horizontalAlignment = layoutData.horizontalAlignment;
298
				treeEditor.minimumWidth = layoutData.minimumWidth;
299
			}
300
301
			protected void showSelection() {
302
				getTree().showSelection();
303
			}
304
305
		};
306
	}
270
	}
307
271
308
	/*
272
	/*
Lines 931-934 Link Here
931
	public void setSelection(ISelection selection, boolean reveal) {
895
	public void setSelection(ISelection selection, boolean reveal) {
932
		super.setSelection(selection, reveal);
896
		super.setSelection(selection, reveal);
933
	}
897
	}
898
	
899
	public void editElement(Object element, int column) {
900
		if( element instanceof TreePath ) {
901
			setSelection(new TreeSelection((TreePath) element));
902
			TreeItem[] items = tree.getSelection();
903
			
904
			if( items.length == 1 ) {
905
				ViewerRow row = getViewerRowFromItem(items[0]);
906
				
907
				if (row != null) {
908
					ViewerCell cell = row.getCell(column);
909
					if (cell != null) {
910
						getControl().setRedraw(false);
911
						triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
912
						getControl().setRedraw(true);
913
					}
914
				}
915
			}
916
		} else {
917
			super.editElement(element, column);
918
		}
919
	}
934
}
920
}
(-)src/org/eclipse/jface/viewers/EditingSupport.java (-191 / +27 lines)
Lines 14-21 Link Here
14
package org.eclipse.jface.viewers;
14
package org.eclipse.jface.viewers;
15
15
16
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.TraverseEvent;
19
17
20
/**
18
/**
21
 * EditingSupport is the abstract superclass of the support for cell editing.
19
 * EditingSupport is the abstract superclass of the support for cell editing.
Lines 27-58 Link Here
27
 * 
25
 * 
28
 */
26
 */
29
public abstract class EditingSupport {
27
public abstract class EditingSupport {
30
	/**
31
	 * Tabing from cell to cell is turned off
32
	 */
33
	public static final int TABBING_NONE = 1;
34
35
	/**
36
	 * Should if the end of the row is reach started from the start/end of the
37
	 * row below/above
38
	 */
39
	public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1;
40
41
	/**
42
	 * Should if the end of the row is reach started from the beginning in the
43
	 * same row
44
	 */
45
	public static final int TABBING_CYCLE_IN_ROW = 1 << 2;
46
47
	/**
48
	 * Support tabing to Cell above/below the current cell
49
	 */
50
	public static final int TABBING_VERTICAL = 1 << 3;
51
52
	/**
53
	 * Should tabing from column to column with in one row be supported
54
	 */
55
	public static final int TABBING_HORIZONTAL = 1 << 4;
56
28
57
	private ColumnViewer viewer;
29
	private ColumnViewer viewer;
58
30
Lines 61-67 Link Here
61
	 *            a new viewer
33
	 *            a new viewer
62
	 */
34
	 */
63
	public EditingSupport(ColumnViewer viewer) {
35
	public EditingSupport(ColumnViewer viewer) {
64
		Assert.isNotNull(viewer,"Viewer is not allowed to be null"); //$NON-NLS-1$
36
		Assert.isNotNull(viewer, "Viewer is not allowed to be null"); //$NON-NLS-1$
65
		this.viewer = viewer;
37
		this.viewer = viewer;
66
	}
38
	}
67
39
Lines 95-101 Link Here
95
	/**
67
	/**
96
	 * Restore the value from the CellEditor
68
	 * Restore the value from the CellEditor
97
	 * 
69
	 * 
98
	 * <p><b>Subclasses should overwrite!</b></p>
70
	 * <p>
71
	 * <b>Subclasses should overwrite!</b>
72
	 * </p>
99
	 * 
73
	 * 
100
	 * @param element
74
	 * @param element
101
	 *            the model element
75
	 *            the model element
Lines 105-278 Link Here
105
	protected abstract void setValue(Object element, Object value);
79
	protected abstract void setValue(Object element, Object value);
106
80
107
	/**
81
	/**
108
	 * @return <code>true</code> if tabing supported
82
	 * @return the viewer this editing support works for
109
	 */
110
	protected boolean isTabingSupported() {
111
		return (TABBING_NONE & getTabingStyle()) != TABBING_NONE;
112
	}
113
114
	/**
115
	 * @return the bit mask representing the tabing style
116
	 */
83
	 */
117
	int getTabingStyle() {
84
	public ColumnViewer getViewer() {
118
		return viewer.getTabEditingStyle();
85
		return viewer;
119
	}
86
	}
120
87
121
	/**
88
	/**
122
	 * Process the travers event and opens the next available editor depending
89
	 * Initialize the editor. Frameworks like Databinding can hook in here and provide
123
	 * of the implemented strategy. The default implementation uses the style
90
	 * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #getValue(Object)}</b></p>
124
	 * constants
125
	 * <ul>
126
	 * <li>{@link #TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
127
	 * <li>{@link #TABBING_CYCLE_IN_ROW}</li>
128
	 * <li>{@link #TABBING_VERTICAL}</li>
129
	 * <li>{@link #TABBING_HORIZONTAL}</li>
130
	 * </ul>
131
	 * 
132
	 * <p>
133
	 * Subclasses may overwrite to implement their custom logic to edit the next
134
	 * cell
135
	 * </p>
136
	 * 
91
	 * 
137
	 * @param columnIndex
92
	 * @param cellEditor
138
	 *            the index of the current column
93
	 *            the cell editor
139
	 * @param row
94
	 * @param cell
140
	 *            the current row
95
	 *            the cell the editor is working for
141
	 * @param event
96
	 */
142
	 *            the travers event
97
	protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
143
	 */
98
		Object value = getValue(cell.getElement());
144
	protected void processTraversEvent(int columnIndex,
99
		cellEditor.setValue(value);
145
			ViewerRow row, TraverseEvent event) {
146
		
147
		ViewerCell cell2edit = null;
148
149
		if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
150
			event.doit = false;
151
152
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
153
					&& (getTabingStyle() & TABBING_VERTICAL) == TABBING_VERTICAL) {
154
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true);
155
			} else if ((getTabingStyle() & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
156
				cell2edit = searchPreviousCell(row, viewer, columnIndex,
157
						columnIndex);
158
			}
159
		} else if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
160
			event.doit = false;
161
162
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
163
					&& (getTabingStyle() & TABBING_VERTICAL) == TABBING_VERTICAL) {
164
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex,
165
						false);
166
			} else if ((getTabingStyle() & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
167
				cell2edit = searchNextCell(row, viewer, columnIndex,
168
						columnIndex);
169
			}
170
		}
171
172
		if (cell2edit != null) {
173
			viewer.editElement(cell2edit.getElement(), cell2edit
174
					.getColumnIndex());
175
		}
176
	}
177
178
	private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer,
179
			int columnIndex, boolean above) {
180
		ViewerCell rv = null;
181
182
		ViewerRow newRow = null;
183
184
		if (above) {
185
			newRow = row.getNeighbor(ViewerRow.ABOVE, false);
186
		} else {
187
			newRow = row.getNeighbor(ViewerRow.BELOW,false);
188
		}
189
190
		if (newRow != null) {
191
			ViewerColumn column = viewer.getViewerColumn(columnIndex);
192
			if (column != null
193
					&& column.getEditingSupport().canEdit(
194
							newRow.getItem().getData())) {
195
				rv = newRow.getCell(columnIndex);
196
			} else {
197
				rv = searchCellAboveBelow(newRow, viewer, columnIndex, above);
198
			}
199
		}
200
201
		return rv;
202
	}
203
204
	private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer,
205
			int columnIndex, int startIndex) {
206
		ViewerCell rv = null;
207
208
		if (columnIndex - 1 >= 0) {
209
			ViewerColumn column = viewer.getViewerColumn(columnIndex - 1);
210
			if (column != null
211
					&& column.getEditingSupport().canEdit(
212
							row.getItem().getData())) {
213
				rv = row.getCell(columnIndex - 1);
214
			} else {
215
				rv = searchPreviousCell(row, viewer, columnIndex - 1,
216
						startIndex);
217
			}
218
		} else {
219
			if ((getTabingStyle() & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
220
				// Check that we don't get into endless loop
221
				if (columnIndex - 1 != startIndex) {
222
					// Don't subtract -1 from getColumnCount() we need to
223
					// start in the virtual column
224
					// next to it
225
					rv = searchPreviousCell(row, viewer, row.getColumnCount(),
226
							startIndex);
227
				}
228
			} else if ((getTabingStyle() & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
229
				ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE,false);
230
				if (rowAbove != null) {
231
					rv = searchPreviousCell(rowAbove, viewer, rowAbove
232
							.getColumnCount(), startIndex);
233
				}
234
			}
235
		}
236
237
		return rv;
238
	}
100
	}
239
101
240
	private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer,
241
			int columnIndex, int startIndex) {
242
		ViewerCell rv = null;
243
244
		if (columnIndex + 1 < row.getColumnCount()) {
245
			ViewerColumn column = viewer.getViewerColumn(columnIndex + 1);
246
			if (column != null
247
					&& column.getEditingSupport().canEdit(
248
							row.getItem().getData())) {
249
				rv = row.getCell(columnIndex + 1);
250
			} else {
251
				rv = searchNextCell(row, viewer, columnIndex + 1, startIndex);
252
			}
253
		} else {
254
			if ((getTabingStyle() & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
255
				// Check that we don't get into endless loop
256
				if (columnIndex + 1 != startIndex) {
257
					// Start from -1 from the virtual column before the
258
					// first one
259
					rv = searchNextCell(row, viewer, -1, startIndex);
260
				}
261
			} else if ((getTabingStyle() & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
262
				ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW,false);
263
				if (rowBelow != null) {
264
					rv = searchNextCell(rowBelow, viewer, -1, startIndex);
265
				}
266
			}
267
		}
268
269
		return rv;
270
	}
271
	
272
	/**
102
	/**
273
	 * @return the viewer this editing support works for
103
	 * Save the value of the cell editor back to the model. Frameworks like Databinding can hook in here and provide
274
	 */
104
	 * a customized implementation. <p><b>Standard customers should not overwrite this method but {@link #setValue(Object, Object)} </b></p>
275
	public ColumnViewer getViewer() {
105
	 * @param cellEditor
276
		return viewer;
106
	 *            the cell-editor
107
	 * @param cell 
108
	 * 			  the cell the editor is working for
109
	 */
110
	protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
111
		Object value = cellEditor.getValue();
112
		setValue(cell.getElement(), value);
277
	}
113
	}
278
}
114
}
(-)src/org/eclipse/jface/viewers/ColumnViewer.java (-75 / +113 lines)
Lines 14-19 Link Here
14
14
15
package org.eclipse.jface.viewers;
15
package org.eclipse.jface.viewers;
16
16
17
17
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.swt.events.MouseAdapter;
19
import org.eclipse.swt.events.MouseAdapter;
19
import org.eclipse.swt.events.MouseEvent;
20
import org.eclipse.swt.events.MouseEvent;
Lines 38-43 Link Here
38
 * 
39
 * 
39
 */
40
 */
40
public abstract class ColumnViewer extends StructuredViewer {
41
public abstract class ColumnViewer extends StructuredViewer {
42
	private CellEditor[] cellEditors;
43
44
	private ICellModifier cellModifier;
45
46
	private String[] columnProperties;
41
47
42
	/**
48
	/**
43
	 * The cell is a cached viewer cell used for refreshing.
49
	 * The cell is a cached viewer cell used for refreshing.
Lines 46-62 Link Here
46
52
47
	private ColumnViewerEditor viewerEditor;
53
	private ColumnViewerEditor viewerEditor;
48
54
49
	private int tabEditingStyle = EditingSupport.TABBING_NONE;
50
	
51
	/**
55
	/**
52
	 * Create a new instance of the receiver.
56
	 * Create a new instance of the receiver.
53
	 */
57
	 */
54
	public ColumnViewer() {
58
	public ColumnViewer() {
55
		viewerEditor = createViewerEditor();
59
56
	}
60
	}
57
61
58
	protected void hookControl(Control control) {
62
	protected void hookControl(Control control) {
59
		super.hookControl(control);
63
		super.hookControl(control);
64
		viewerEditor = createViewerEditor();
60
		hookEditingSupport(control);
65
		hookEditingSupport(control);
61
	}
66
	}
62
67
Lines 74-89 Link Here
74
		if (viewerEditor != null) {
79
		if (viewerEditor != null) {
75
			control.addMouseListener(new MouseAdapter() {
80
			control.addMouseListener(new MouseAdapter() {
76
				public void mouseDown(MouseEvent e) {
81
				public void mouseDown(MouseEvent e) {
77
					viewerEditor.handleMouseDown(e);
82
					handleMouseDown(e);
78
				}
83
				}
79
			});
84
			});
80
		}
85
		}
81
	}
86
	}
82
87
83
	/**
88
	/**
84
	 * Creates the viewer editor used for editing cell contents. To be implemented by subclasses.
89
	 * Creates the viewer editor used for editing cell contents. To be
90
	 * implemented by subclasses.
85
	 * 
91
	 * 
86
	 * @return the editor, or <code>null</code> if this viewer does not support editing cell contents.
92
	 * @return the editor, or <code>null</code> if this viewer does not
93
	 *         support editing cell contents.
87
	 */
94
	 */
88
	protected abstract ColumnViewerEditor createViewerEditor();
95
	protected abstract ColumnViewerEditor createViewerEditor();
89
96
Lines 93-99 Link Here
93
	 * 
100
	 * 
94
	 * @param point
101
	 * @param point
95
	 *            the widget-relative coordinates
102
	 *            the widget-relative coordinates
96
	 * @return the cell or <code>null</code> if no cell is found at the given point
103
	 * @return the cell or <code>null</code> if no cell is found at the given
104
	 *         point
97
	 */
105
	 */
98
	ViewerCell getCell(Point point) {
106
	ViewerCell getCell(Point point) {
99
		ViewerRow row = getViewerRow(point);
107
		ViewerRow row = getViewerRow(point);
Lines 125-131 Link Here
125
	/**
133
	/**
126
	 * Returns the viewer row associated with the given row widget.
134
	 * Returns the viewer row associated with the given row widget.
127
	 * 
135
	 * 
128
	 * @param item the row widget
136
	 * @param item
137
	 *            the row widget
129
	 * @return ViewerRow the associated viewer row
138
	 * @return ViewerRow the associated viewer row
130
	 */
139
	 */
131
	protected ViewerRow getViewerRowFromItem(Widget item) {
140
	protected ViewerRow getViewerRowFromItem(Widget item) {
Lines 135-141 Link Here
135
	/**
144
	/**
136
	 * Returns the column widget at the given column index.
145
	 * Returns the column widget at the given column index.
137
	 * 
146
	 * 
138
	 * @param columnIndex the column index
147
	 * @param columnIndex
148
	 *            the column index
139
	 * @return Widget the column widget
149
	 * @return Widget the column widget
140
	 */
150
	 */
141
	protected abstract Widget getColumnViewerOwner(int columnIndex);
151
	protected abstract Widget getColumnViewerOwner(int columnIndex);
Lines 148-154 Link Here
148
	 * @return the viewer column at the given index, or <code>null</code> if
158
	 * @return the viewer column at the given index, or <code>null</code> if
149
	 *         there is none for the given index
159
	 *         there is none for the given index
150
	 */
160
	 */
151
	/* package */ ViewerColumn getViewerColumn(final int columnIndex) {
161
	/* package */ViewerColumn getViewerColumn(final int columnIndex) {
152
162
153
		ViewerColumn viewer;
163
		ViewerColumn viewer;
154
		Widget columnOwner = getColumnViewerOwner(columnIndex);
164
		Widget columnOwner = getColumnViewerOwner(columnIndex);
Lines 174-180 Link Here
174
	}
184
	}
175
185
176
	/**
186
	/**
177
	 * Sets up editing support for the given column based on the "old" cell editor API.
187
	 * Sets up editing support for the given column based on the "old" cell
188
	 * editor API.
178
	 * 
189
	 * 
179
	 * @param columnIndex
190
	 * @param columnIndex
180
	 * @param viewer
191
	 * @param viewer
Lines 227-241 Link Here
227
	}
238
	}
228
239
229
	/**
240
	/**
230
	 * Creates a generic viewer column for the given column widget, based on the given label provider.
241
	 * Creates a generic viewer column for the given column widget, based on the
242
	 * given label provider.
231
	 * 
243
	 * 
232
	 * @param columnOwner the column widget
244
	 * @param columnOwner
233
	 * @param labelProvider the label provider to use for the column
245
	 *            the column widget
246
	 * @param labelProvider
247
	 *            the label provider to use for the column
234
	 * @return ViewerColumn the viewer column
248
	 * @return ViewerColumn the viewer column
235
	 */
249
	 */
236
	private ViewerColumn createViewerColumn(Widget columnOwner,
250
	private ViewerColumn createViewerColumn(Widget columnOwner,
237
			CellLabelProvider labelProvider) {
251
			CellLabelProvider labelProvider) {
238
		ViewerColumn column = new ViewerColumn(this,columnOwner) {};
252
		ViewerColumn column = new ViewerColumn(this, columnOwner) {
253
		};
239
		column.setLabelProvider(labelProvider, false);
254
		column.setLabelProvider(labelProvider, false);
240
		return column;
255
		return column;
241
	}
256
	}
Lines 247-265 Link Here
247
	 * @param column
262
	 * @param column
248
	 * @return ViewerCell
263
	 * @return ViewerCell
249
	 */
264
	 */
250
	/* package */ ViewerCell updateCell(ViewerRow rowItem, int column) {
265
	/* package */ViewerCell updateCell(ViewerRow rowItem, int column) {
251
		cell.update(rowItem, column);
266
		cell.update(rowItem, column);
252
		return cell;
267
		return cell;
253
	}
268
	}
254
269
255
	/**
270
	/**
256
	 * Returns the {@link Item} at the given widget-relative coordinates, or
271
	 * Returns the {@link Item} at the given widget-relative coordinates, or
257
     * <code>null</code> if there is no item at the given coordinates.
272
	 * <code>null</code> if there is no item at the given coordinates.
258
	 * 
273
	 * 
259
	 * @param point
274
	 * @param point
260
	 *            the widget-relative coordinates
275
	 *            the widget-relative coordinates
261
	 * @return the {@link Item} at the coordinates or <code>null</code> if there
276
	 * @return the {@link Item} at the coordinates or <code>null</code> if
262
	 *         is no item at the given coordinates
277
	 *         there is no item at the given coordinates
263
	 */
278
	 */
264
	protected abstract Item getItemAt(Point point);
279
	protected abstract Item getItemAt(Point point);
265
280
Lines 317-323 Link Here
317
332
318
	/**
333
	/**
319
	 * Cancels a currently active cell editor if one is active. All changes
334
	 * Cancels a currently active cell editor if one is active. All changes
320
     * already done in the cell editor are lost.
335
	 * already done in the cell editor are lost.
321
	 * 
336
	 * 
322
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
337
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
323
	 */
338
	 */
Lines 342-365 Link Here
342
	 * Starts editing the given element at the given column index.
357
	 * Starts editing the given element at the given column index.
343
	 * 
358
	 * 
344
	 * @param element
359
	 * @param element
345
	 *            the element
360
	 *            the model element
346
	 * @param column
361
	 * @param column
347
	 *            the column index
362
	 *            the column index
348
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
363
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
349
	 */
364
	 */
350
	public void editElement(Object element, int column) {
365
	public void editElement(Object element, int column) {
351
		if (viewerEditor != null) {
366
		if (viewerEditor != null) {
352
			viewerEditor.editElement(element, column);
367
			Widget item = findItem(element);
368
			if (item != null) {
369
				ViewerRow row = getViewerRowFromItem(item);
370
				if (row != null) {
371
					ViewerCell cell = row.getCell(column);
372
					if (cell != null) {
373
						getControl().setRedraw(false);
374
						setSelection(new StructuredSelection(cell.getElement()));
375
						triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
376
								cell));
377
						getControl().setRedraw(true);
378
					}
379
				}
380
			}
353
		}
381
		}
354
	}
382
	}
355
383
356
	/**
384
	/**
357
	 * Return the CellEditors for the receiver, or <code>null</code> if no
385
	 * Return the CellEditors for the receiver, or <code>null</code> if no
358
     * cell editors are set.
386
	 * cell editors are set.
359
	 * <p>
387
	 * <p>
360
	 * Since 3.3, an alternative API is available, see
388
	 * Since 3.3, an alternative API is available, see
361
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
389
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
362
	 * way of editing values in a column viewer.
390
	 * flexible way of editing values in a column viewer.
363
	 * </p>
391
	 * </p>
364
	 * 
392
	 * 
365
	 * @return CellEditor[]
393
	 * @return CellEditor[]
Lines 368-387 Link Here
368
	 * @see EditingSupport
396
	 * @see EditingSupport
369
	 */
397
	 */
370
	public CellEditor[] getCellEditors() {
398
	public CellEditor[] getCellEditors() {
371
		if (viewerEditor != null) {
399
		return cellEditors;
372
			return viewerEditor.getCellEditors();
373
		}
374
		return null;
375
	}
400
	}
376
401
377
	/**
402
	/**
378
	 * Returns the cell modifier of this viewer, or <code>null</code> if none
403
	 * Returns the cell modifier of this viewer, or <code>null</code> if none
379
     * has been set.
404
	 * has been set.
380
	 * 
405
	 * 
381
	 * <p>
406
	 * <p>
382
	 * Since 3.3, an alternative API is available, see
407
	 * Since 3.3, an alternative API is available, see
383
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
408
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
384
	 * way of editing values in a column viewer.
409
	 * flexible way of editing values in a column viewer.
385
	 * </p>
410
	 * </p>
386
	 * 
411
	 * 
387
	 * @return the cell modifier, or <code>null</code>
412
	 * @return the cell modifier, or <code>null</code>
Lines 390-399 Link Here
390
	 * @see EditingSupport
415
	 * @see EditingSupport
391
	 */
416
	 */
392
	public ICellModifier getCellModifier() {
417
	public ICellModifier getCellModifier() {
393
		if (viewerEditor != null) {
418
		return cellModifier;
394
			return viewerEditor.getCellModifier();
395
		}
396
		return null;
397
	}
419
	}
398
420
399
	/**
421
	/**
Lines 403-410 Link Here
403
	 * 
425
	 * 
404
	 * <p>
426
	 * <p>
405
	 * Since 3.3, an alternative API is available, see
427
	 * Since 3.3, an alternative API is available, see
406
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
428
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
407
	 * way of editing values in a column viewer.
429
	 * flexible way of editing values in a column viewer.
408
	 * </p>
430
	 * </p>
409
	 * 
431
	 * 
410
	 * @return the list of column properties
432
	 * @return the list of column properties
Lines 413-422 Link Here
413
	 * @see EditingSupport
435
	 * @see EditingSupport
414
	 */
436
	 */
415
	public Object[] getColumnProperties() {
437
	public Object[] getColumnProperties() {
416
		if (viewerEditor != null) {
438
		return columnProperties;
417
			return viewerEditor.getColumnProperties();
418
		}
419
		return null;
420
	}
439
	}
421
440
422
	/**
441
	/**
Lines 424-431 Link Here
424
	 * 
443
	 * 
425
	 * <p>
444
	 * <p>
426
	 * Since 3.3, an alternative API is available, see
445
	 * Since 3.3, an alternative API is available, see
427
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
446
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
428
	 * way of editing values in a column viewer.
447
	 * flexible way of editing values in a column viewer.
429
	 * </p>
448
	 * </p>
430
	 * 
449
	 * 
431
	 * @return <code>true</code> if there is an active cell editor, and
450
	 * @return <code>true</code> if there is an active cell editor, and
Lines 447-454 Link Here
447
	 * 
466
	 * 
448
	 * <p>
467
	 * <p>
449
	 * Since 3.3, an alternative API is available, see
468
	 * Since 3.3, an alternative API is available, see
450
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
469
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
451
	 * way of editing values in a column viewer.
470
	 * flexible way of editing values in a column viewer.
452
	 * </p>
471
	 * </p>
453
	 * 
472
	 * 
454
	 * @param editors
473
	 * @param editors
Lines 458-476 Link Here
458
	 * @see EditingSupport
477
	 * @see EditingSupport
459
	 */
478
	 */
460
	public void setCellEditors(CellEditor[] editors) {
479
	public void setCellEditors(CellEditor[] editors) {
461
		if (viewerEditor != null) {
480
		this.cellEditors = editors;
462
			viewerEditor.setCellEditors(editors);
463
		}
464
	}
481
	}
465
482
466
	/**
483
	/**
467
	 * Sets the cell modifier for this column viewer. This method does nothing if editing
484
	 * Sets the cell modifier for this column viewer. This method does nothing
468
	 * is not supported by this viewer.
485
	 * if editing is not supported by this viewer.
469
	 * 
486
	 * 
470
	 * <p>
487
	 * <p>
471
	 * Since 3.3, an alternative API is available, see
488
	 * Since 3.3, an alternative API is available, see
472
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
489
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
473
	 * way of editing values in a column viewer.
490
	 * flexible way of editing values in a column viewer.
474
	 * </p>
491
	 * </p>
475
	 * 
492
	 * 
476
	 * @param modifier
493
	 * @param modifier
Lines 480-488 Link Here
480
	 * @see EditingSupport
497
	 * @see EditingSupport
481
	 */
498
	 */
482
	public void setCellModifier(ICellModifier modifier) {
499
	public void setCellModifier(ICellModifier modifier) {
483
		if (viewerEditor != null) {
500
		this.cellModifier = modifier;
484
			viewerEditor.setCellModifier(modifier);
485
		}
486
	}
501
	}
487
502
488
	/**
503
	/**
Lines 493-500 Link Here
493
	 * 
508
	 * 
494
	 * <p>
509
	 * <p>
495
	 * Since 3.3, an alternative API is available, see
510
	 * Since 3.3, an alternative API is available, see
496
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible
511
	 * {@link ViewerColumn#setEditingSupport(EditingSupport)} for a more
497
	 * way of editing values in a column viewer.
512
	 * flexible way of editing values in a column viewer.
498
	 * </p>
513
	 * </p>
499
	 * 
514
	 * 
500
	 * @param columnProperties
515
	 * @param columnProperties
Lines 504-528 Link Here
504
	 * @see EditingSupport
519
	 * @see EditingSupport
505
	 */
520
	 */
506
	public void setColumnProperties(String[] columnProperties) {
521
	public void setColumnProperties(String[] columnProperties) {
507
		if (viewerEditor != null) {
522
		this.columnProperties = columnProperties;
508
			viewerEditor.setColumnProperties(columnProperties);
509
		}
510
	}
511
	
512
	/**
513
	 * The tab-editing style used if the default implementation is used
514
	 * 
515
	 * @param tabEditingStyle
516
	 *            bit mask for the tab editing style
517
	 */
518
	public void setTabEditingStyle(int tabEditingStyle) {
519
		this.tabEditingStyle = tabEditingStyle;
520
	}
523
	}
521
524
522
	int getTabEditingStyle() {
523
		return this.tabEditingStyle;
524
	}
525
	
526
	/**
525
	/**
527
	 * Returns the number of columns contained in the receiver. If no columns
526
	 * Returns the number of columns contained in the receiver. If no columns
528
	 * were created by the programmer, this value is zero, despite the fact that
527
	 * were created by the programmer, this value is zero, despite the fact that
Lines 554-557 Link Here
554
		}
553
		}
555
		return null;
554
		return null;
556
	}
555
	}
556
557
	private void handleMouseDown(MouseEvent e) {
558
		ViewerCell cell = getCell(new Point(e.x, e.y));
559
560
		if (cell != null) {
561
			triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
562
					cell, e));
563
		}
564
	}
565
566
	/**
567
	 * Invoking this method fires an editor activation event which tries to
568
	 * enable the editor but before this event is passed to
569
	 * {@link ColumnViewerEditorActivationStrategy} to see if this event should
570
	 * really trigger editor activation
571
	 * 
572
	 * @param event
573
	 *            the activation event
574
	 */
575
	protected void triggerEditorActivationEvent(
576
			ColumnViewerEditorActivationEvent event) {
577
		viewerEditor.handleEditorActivationEvent(event);
578
	}
579
580
	/**
581
	 * @param columnViewerEditor
582
	 *            the new column viewer editor
583
	 */
584
	public void setColumnViewerEditor(ColumnViewerEditor columnViewerEditor) {
585
		Assert.isNotNull(viewerEditor);
586
		this.viewerEditor = columnViewerEditor;
587
	}
588
589
	/**
590
	 * @return the currently attached viewer editor
591
	 */
592
	public ColumnViewerEditor getColumnViewerEditor() {
593
		return viewerEditor;
594
	}
557
}
595
}
(-)src/org/eclipse/jface/viewers/CellEditor.java (+10 lines)
Lines 853-856 Link Here
853
        dirty = true;
853
        dirty = true;
854
        fireEditorValueChanged(oldValidState, newValidState);
854
        fireEditorValueChanged(oldValidState, newValidState);
855
    }
855
    }
856
    
857
    /**
858
     * Activate the editor but also inform the editor which event triggered its activation.
859
     * <b>The default implementation simply calls {@link #activate()}</b>
860
     * 
861
     * @param activationEvent the editor activation event
862
     */
863
    public void activate(ColumnViewerEditorActivationEvent activationEvent) {
864
    	activate();
865
    }
856
}
866
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditor.java (-175 / +326 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;
19
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.FocusAdapter;
20
import org.eclipse.swt.events.FocusAdapter;
18
import org.eclipse.swt.events.FocusEvent;
21
import org.eclipse.swt.events.FocusEvent;
19
import org.eclipse.swt.events.FocusListener;
22
import org.eclipse.swt.events.FocusListener;
Lines 22-28 Link Here
22
import org.eclipse.swt.events.MouseListener;
25
import org.eclipse.swt.events.MouseListener;
23
import org.eclipse.swt.events.TraverseEvent;
26
import org.eclipse.swt.events.TraverseEvent;
24
import org.eclipse.swt.events.TraverseListener;
27
import org.eclipse.swt.events.TraverseListener;
25
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Display;
29
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Item;
30
import org.eclipse.swt.widgets.Item;
Lines 40-75 Link Here
40
public abstract class ColumnViewerEditor {
42
public abstract class ColumnViewerEditor {
41
	private CellEditor cellEditor;
43
	private CellEditor cellEditor;
42
44
43
	private CellEditor[] cellEditors;
45
	private ICellEditorListener cellEditorListener;
44
46
45
	private ICellModifier cellModifier;
47
	private FocusListener focusListener;
46
48
47
	private String[] columnProperties;
49
	private MouseListener mouseListener;
48
50
49
	private int columnNumber;
51
	private ColumnViewer viewer;
50
52
51
	private ICellEditorListener cellEditorListener;
53
	private TraverseListener tabeditingListener;
52
54
53
	private FocusListener focusListener;
55
	private int activationTime;
54
56
55
	private MouseListener mouseListener;
57
	private ViewerCell cell;
56
58
57
	private int doubleClickExpirationTime;
59
	private ColumnViewerEditorActivationEvent activationEvent;
58
60
59
	private ColumnViewer viewer;
61
	private ListenerList editorActivationListener;
60
62
61
	private Item item;
63
	private ColumnViewerEditorActivationStrategy editorActivationStrategy;
62
64
63
	private TraverseListener tabeditingListener;
65
	/**
66
	 * Tabing from cell to cell is turned off
67
	 */
68
	public static final int DEFAULT = 1;
69
70
	/**
71
	 * Should if the end of the row is reach started from the start/end of the
72
	 * row below/above
73
	 */
74
	public static final int TABBING_MOVE_TO_ROW_NEIGHBOR = 1 << 1;
75
76
	/**
77
	 * Should if the end of the row is reach started from the beginning in the
78
	 * same row
79
	 */
80
	public static final int TABBING_CYCLE_IN_ROW = 1 << 2;
81
82
	/**
83
	 * Support tabing to Cell above/below the current cell
84
	 */
85
	public static final int TABBING_VERTICAL = 1 << 3;
86
87
	/**
88
	 * Should tabing from column to column with in one row be supported
89
	 */
90
	public static final int TABBING_HORIZONTAL = 1 << 4;
64
91
65
	/**
92
	/**
66
	 * Create a new editor implementation for the viewer
67
	 * 
93
	 * 
94
	 */
95
	public static final int KEYBOARD_ACTIVATION = 1 << 5;
96
	
97
	private int feature;
98
99
	/**
68
	 * @param viewer
100
	 * @param viewer
69
	 *            the column viewer
101
	 * @param editorActivationStrategy
102
	 * @param feature
70
	 */
103
	 */
71
	public ColumnViewerEditor(ColumnViewer viewer) {
104
	protected ColumnViewerEditor(ColumnViewer viewer,
105
			ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) {
72
		this.viewer = viewer;
106
		this.viewer = viewer;
107
		this.editorActivationStrategy = editorActivationStrategy;
108
		if( (feature & KEYBOARD_ACTIVATION) == KEYBOARD_ACTIVATION ) {
109
			this.editorActivationStrategy.setEnableEditorActivationWithKeyboard(true);
110
		} 
111
		this.feature = feature;
73
		initCellEditorListener();
112
		initCellEditorListener();
74
	}
113
	}
75
114
Lines 92-119 Link Here
92
131
93
	void activateCellEditor() {
132
	void activateCellEditor() {
94
133
95
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
134
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
96
		Object element = item.getData();
135
		Object element = cell.getElement();
97
136
98
		if (part != null && part.getEditingSupport() != null
137
		if (part != null && part.getEditingSupport() != null
99
				&& part.getEditingSupport().canEdit(element)) {
138
				&& part.getEditingSupport().canEdit(element)) {
139
100
			cellEditor = part.getEditingSupport().getCellEditor(element);
140
			cellEditor = part.getEditingSupport().getCellEditor(element);
101
			if (cellEditor != null) {
141
			if (cellEditor != null) {
142
				if (editorActivationListener != null
143
						&& !editorActivationListener.isEmpty()) {
144
					Object[] ls = editorActivationListener.getListeners();
145
					for (int i = 0; i < ls.length; i++) {
146
147
						if (activationEvent.cancel) {
148
							return;
149
						}
150
151
						((ColumnViewerEditorActivationListener) ls[i])
152
								.beforeEditorActivated(activationEvent);
153
					}
154
				}
155
				
156
				// Update the focus cell when we activated the editor with these 2 events
157
				if( activationEvent.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC || activationEvent.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL ) {
158
					updateFocusCell(cell);
159
				}
160
				
161
				
102
				cellEditor.addListener(cellEditorListener);
162
				cellEditor.addListener(cellEditorListener);
103
				Object value = part.getEditingSupport().getValue(element);
163
				part.getEditingSupport().initializeCellEditorValue(cellEditor, cell);
104
				cellEditor.setValue(value);
164
				
105
				// Tricky flow of control here:
165
				// Tricky flow of control here:
106
				// activate() can trigger callback to cellEditorListener which
166
				// activate() can trigger callback to cellEditorListener which
107
				// will clear cellEditor
167
				// will clear cellEditor
108
				// so must get control first, but must still call activate()
168
				// so must get control first, but must still call activate()
109
				// even if there is no control.
169
				// even if there is no control.
110
				final Control control = cellEditor.getControl();
170
				final Control control = cellEditor.getControl();
111
				cellEditor.activate();
171
				cellEditor.activate(activationEvent);
112
				if (control == null) {
172
				if (control == null) {
113
					return;
173
					return;
114
				}
174
				}
115
				setLayoutData(cellEditor.getLayoutData());
175
				setLayoutData(cellEditor.getLayoutData());
116
				setEditor(control, item, columnNumber);
176
				setEditor(control, cell.getItem(), cell.getColumnIndex());
117
				cellEditor.setFocus();
177
				cellEditor.setFocus();
118
				if (focusListener == null) {
178
				if (focusListener == null) {
119
					focusListener = new FocusAdapter() {
179
					focusListener = new FocusAdapter() {
Lines 128-134 Link Here
128
					public void mouseDown(MouseEvent e) {
188
					public void mouseDown(MouseEvent e) {
129
						// time wrap?
189
						// time wrap?
130
						// check for expiration of doubleClickTime
190
						// check for expiration of doubleClickTime
131
						if (e.time <= doubleClickExpirationTime) {
191
						if (e.time <= activationTime) {
132
							control.removeMouseListener(mouseListener);
192
							control.removeMouseListener(mouseListener);
133
							cancelEditing();
193
							cancelEditing();
134
							handleDoubleClickEvent();
194
							handleDoubleClickEvent();
Lines 139-195 Link Here
139
				};
199
				};
140
				control.addMouseListener(mouseListener);
200
				control.addMouseListener(mouseListener);
141
201
142
				if( tabeditingListener == null ) {
202
				if (tabeditingListener == null) {
143
					tabeditingListener = new TraverseListener() {
203
					tabeditingListener = new TraverseListener() {
144
204
145
						public void keyTraversed(TraverseEvent e) {
205
						public void keyTraversed(TraverseEvent e) {
146
							ViewerColumn col = viewer.getViewerColumn(columnNumber);
206
							if ((feature & DEFAULT) != DEFAULT) {
147
							if ( col != null && col.getEditingSupport().isTabingSupported() ) {
207
								processTraverseEvent(cell.getColumnIndex(),
148
								col.getEditingSupport().processTraversEvent(
208
										viewer.getViewerRowFromItem(cell
149
										columnNumber,
209
												.getItem()), e);
150
										viewer.getViewerRowFromItem(item), e);
151
							}
210
							}
152
						}
211
						}
153
					};
212
					};
154
				}
213
				}
155
				
156
				control.addTraverseListener(tabeditingListener);
157
214
158
			}
215
				control.addTraverseListener(tabeditingListener);
159
		}
160
	}
161
216
162
	/**
217
				if (editorActivationListener != null
163
	 * Activate a cell editor for the given mouse position.
218
						&& !editorActivationListener.isEmpty()) {
164
	 */
219
					Object[] ls = editorActivationListener.getListeners();
165
	private void activateCellEditor(MouseEvent event) {
220
					for (int i = 0; i < ls.length; i++) {
166
		if (item == null || item.isDisposed()) {
221
						((ColumnViewerEditorActivationListener) ls[i])
167
			// item no longer exists
222
								.afterEditorActivated(activationEvent);
168
			return;
223
					}
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
				}
224
				}
185
			}
225
			}
186
			if (columnToEdit == -1) {
187
				return;
188
			}
189
		}
226
		}
190
191
		columnNumber = columnToEdit;
192
		activateCellEditor();
193
	}
227
	}
194
228
195
	/**
229
	/**
Lines 203-213 Link Here
203
			// in case save results in applyEditorValue being re-entered
237
			// in case save results in applyEditorValue being re-entered
204
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
238
			// see 1GAHI8Z: ITPUI:ALL - How to code event notification when
205
			// using cell editor ?
239
			// using cell editor ?
240
			ColumnViewerEditorDeactivationEvent tmp = new ColumnViewerEditorDeactivationEvent(cell);
241
			if (editorActivationListener != null
242
					&& !editorActivationListener.isEmpty()) {
243
				Object[] ls = editorActivationListener.getListeners();
244
				for (int i = 0; i < ls.length; i++) {
245
246
					((ColumnViewerEditorActivationListener) ls[i])
247
							.beforeEditorDeactivated(tmp);
248
				}
249
			}
250
206
			this.cellEditor = null;
251
			this.cellEditor = null;
207
			Item t = this.item;
252
			this.activationEvent = null;
253
			Item t = this.cell.getItem();
208
			// don't null out table item -- same item is still selected
254
			// don't null out table item -- same item is still selected
209
			if (t != null && !t.isDisposed()) {
255
			if (t != null && !t.isDisposed()) {
210
				saveEditorValue(c, t);
256
				saveEditorValue(c);
211
			}
257
			}
212
			setEditor(null, null, 0);
258
			setEditor(null, null, 0);
213
			c.removeListener(cellEditorListener);
259
			c.removeListener(cellEditorListener);
Lines 227-232 Link Here
227
				}
273
				}
228
			}
274
			}
229
			c.deactivate();
275
			c.deactivate();
276
277
			if (editorActivationListener != null
278
					&& !editorActivationListener.isEmpty()) {
279
				Object[] ls = editorActivationListener.getListeners();
280
				for (int i = 0; i < ls.length; i++) {
281
					((ColumnViewerEditorActivationListener) ls[i])
282
							.afterEditorDeactivated(tmp);
283
				}
284
			}
230
		}
285
		}
231
	}
286
	}
232
287
Lines 235-240 Link Here
235
	 */
290
	 */
236
	void cancelEditing() {
291
	void cancelEditing() {
237
		if (cellEditor != null) {
292
		if (cellEditor != null) {
293
			ColumnViewerEditorDeactivationEvent tmp = new ColumnViewerEditorDeactivationEvent(cell);
294
			if (editorActivationListener != null
295
					&& !editorActivationListener.isEmpty()) {
296
				Object[] ls = editorActivationListener.getListeners();
297
				for (int i = 0; i < ls.length; i++) {
298
					
299
					((ColumnViewerEditorActivationListener) ls[i])
300
							.beforeEditorDeactivated(tmp);
301
				}
302
			}
303
238
			setEditor(null, null, 0);
304
			setEditor(null, null, 0);
239
			cellEditor.removeListener(cellEditorListener);
305
			cellEditor.removeListener(cellEditorListener);
240
306
Lines 256-262 Link Here
256
322
257
			CellEditor oldEditor = cellEditor;
323
			CellEditor oldEditor = cellEditor;
258
			cellEditor = null;
324
			cellEditor = null;
325
			activationEvent = null;
259
			oldEditor.deactivate();
326
			oldEditor.deactivate();
327
328
			if (editorActivationListener != null
329
					&& !editorActivationListener.isEmpty()) {
330
				Object[] ls = editorActivationListener.getListeners();
331
				for (int i = 0; i < ls.length; i++) {
332
					((ColumnViewerEditorActivationListener) ls[i])
333
							.afterEditorDeactivated(tmp);
334
				}
335
			}
260
		}
336
		}
261
	}
337
	}
262
338
Lines 265-329 Link Here
265
	 * 
341
	 * 
266
	 * @param event
342
	 * @param event
267
	 */
343
	 */
268
	void handleMouseDown(MouseEvent event) {
344
	void handleEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
269
		if (event.button != 1) {
345
		if (editorActivationStrategy.isEditorActivationEvent(event)) {
270
			return;
346
			if (cellEditor != null) {
271
		}
347
				applyEditorValue();
272
348
			}
273
		if (cellEditor != null) {
274
			applyEditorValue();
275
		}
276
349
277
		// activate the cell editor immediately. If a second mouseDown
350
			this.cell = (ViewerCell) event.getSource();
278
		// is received prior to the expiration of the doubleClick time then
351
			
279
		// the cell editor will be deactivated and a doubleClick event will
352
			activationEvent = event;
280
		// be processed.
353
			activationTime = event.time
281
		//
354
					+ Display.getCurrent().getDoubleClickTime();
282
		doubleClickExpirationTime = event.time
283
				+ Display.getCurrent().getDoubleClickTime();
284
355
285
		Item[] items = getSelection();
356
			activateCellEditor();
286
		// Do not edit if more than one row is selected.
287
		if (items.length != 1) {
288
			item = null;
289
			return;
290
		}
357
		}
291
		item = items[0];
292
		activateCellEditor(event);
293
	}
358
	}
294
359
295
	/**
360
	private void saveEditorValue(CellEditor cellEditor) {
296
	 * Start editing the given element.
361
		ViewerColumn part = viewer.getViewerColumn(cell.getColumnIndex());
297
	 * 
298
	 * @param element
299
	 * @param column
300
	 */
301
	void editElement(Object element, int column) {
302
		if (cellEditor != null) {
303
			applyEditorValue();
304
		}
305
306
		setSelection(createSelection(element), true);
307
		Item[] selection = getSelection();
308
		if (selection.length != 1) {
309
			return;
310
		}
311
312
		item = selection[0];
313
314
		// Make sure selection is visible
315
		showSelection();
316
		columnNumber = column;
317
		activateCellEditor();
318
319
	}
320
321
	private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
322
		ViewerColumn part = viewer.getViewerColumn(columnNumber);
323
362
324
		if (part != null && part.getEditingSupport() != null) {
363
		if (part != null && part.getEditingSupport() != null) {
325
			part.getEditingSupport().setValue(tableItem.getData(),
364
			part.getEditingSupport().saveCellEditorValue(cellEditor, cell);
326
					cellEditor.getValue());
327
		}
365
		}
328
	}
366
	}
329
367
Lines 337-414 Link Here
337
		return cellEditor != null;
375
		return cellEditor != null;
338
	}
376
	}
339
377
340
	/**
378
	void handleDoubleClickEvent() {
341
	 * Set the cell editors
379
		viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer
342
	 * 
380
				.getSelection()));
343
	 * @param editors
381
		viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection()));
344
	 */
345
	void setCellEditors(CellEditor[] editors) {
346
		this.cellEditors = editors;
347
	}
382
	}
348
383
349
	/**
384
	void addEditorActivationListener(
350
	 * Set the cell modifier
385
			ColumnViewerEditorActivationListener listener) {
351
	 * 
386
		if (editorActivationListener == null) {
352
	 * @param modifier
387
			editorActivationListener = new ListenerList();
353
	 */
388
		}
354
	void setCellModifier(ICellModifier modifier) {
389
		editorActivationListener.add(listener);
355
		this.cellModifier = modifier;
356
	}
390
	}
357
391
358
	/**
392
	void removeEditorActivationListener(
359
	 * Set the column properties
393
			ColumnViewerEditorActivationListener listener) {
360
	 * 
394
		if (editorActivationListener != null) {
361
	 * @param columnProperties
395
			editorActivationListener.remove(listener);
362
	 */
396
		}
363
	void setColumnProperties(String[] columnProperties) {
364
		this.columnProperties = columnProperties;
365
	}
397
	}
366
398
367
	/**
399
	/**
368
	 * Return the properties for the column
400
	 * Process the travers event and opens the next available editor depending
401
	 * of the implemented strategy. The default implementation uses the style
402
	 * constants
403
	 * <ul>
404
	 * <li>{@link ColumnViewerEditor#TABBING_MOVE_TO_ROW_NEIGHBOR}</li>
405
	 * <li>{@link ColumnViewerEditor#TABBING_CYCLE_IN_ROW}</li>
406
	 * <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
407
	 * <li>{@link ColumnViewerEditor#TABBING_HORIZONTAL}</li>
408
	 * </ul>
369
	 * 
409
	 * 
370
	 * @return the array of column properties
410
	 * <p>
371
	 */
411
	 * Subclasses may overwrite to implement their custom logic to edit the next
372
	Object[] getColumnProperties() {
412
	 * cell
373
		return columnProperties;
413
	 * </p>
374
	}
375
376
	/**
377
	 * Get the cell modifier
378
	 * 
414
	 * 
379
	 * @return the cell modifier
415
	 * @param columnIndex
416
	 *            the index of the current column
417
	 * @param row
418
	 *            the current row
419
	 * @param event
420
	 *            the travers event
380
	 */
421
	 */
381
	ICellModifier getCellModifier() {
422
	protected void processTraverseEvent(int columnIndex, ViewerRow row,
382
		return cellModifier;
423
			TraverseEvent event) {
383
	}
384
424
385
	/**
425
		ViewerCell cell2edit = null;
386
	 * Return the array of CellEditors used in the viewer
426
387
	 * 
427
		if (event.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
388
	 * @return the cell editors
428
			event.doit = false;
389
	 */
429
390
	CellEditor[] getCellEditors() {
430
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
391
		return cellEditors;
431
					&& (feature & TABBING_VERTICAL) == TABBING_VERTICAL) {
432
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex, true);
433
			} else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
434
				cell2edit = searchPreviousCell(row, viewer, columnIndex,
435
						columnIndex);
436
			}
437
		} else if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
438
			event.doit = false;
439
440
			if ((event.stateMask & SWT.CTRL) == SWT.CTRL
441
					&& (feature & TABBING_VERTICAL) == TABBING_VERTICAL) {
442
				cell2edit = searchCellAboveBelow(row, viewer, columnIndex,
443
						false);
444
			} else if ((feature & TABBING_HORIZONTAL) == TABBING_HORIZONTAL) {
445
				cell2edit = searchNextCell(row, viewer, columnIndex,
446
						columnIndex);
447
			}
448
		}
449
450
		if (cell2edit != null) {
451
452
			viewer.getControl().setRedraw(false);
453
			ColumnViewerEditorActivationEvent acEvent = new ColumnViewerEditorActivationEvent(
454
					cell2edit, event);
455
			viewer.triggerEditorActivationEvent(acEvent);
456
			viewer.getControl().setRedraw(true);
457
		}
392
	}
458
	}
393
459
394
	void setSelection(StructuredSelection selection, boolean b) {
460
	private ViewerCell searchCellAboveBelow(ViewerRow row, ColumnViewer viewer,
395
		viewer.setSelection(selection, b);
461
			int columnIndex, boolean above) {
462
		ViewerCell rv = null;
463
464
		ViewerRow newRow = null;
465
466
		if (above) {
467
			newRow = row.getNeighbor(ViewerRow.ABOVE, false);
468
		} else {
469
			newRow = row.getNeighbor(ViewerRow.BELOW, false);
470
		}
471
472
		if (newRow != null) {
473
			ViewerColumn column = viewer.getViewerColumn(columnIndex);
474
			if (column != null && column.getEditingSupport() != null
475
					&& column.getEditingSupport().canEdit(
476
							newRow.getItem().getData())) {
477
				rv = newRow.getCell(columnIndex);
478
			} else {
479
				rv = searchCellAboveBelow(newRow, viewer, columnIndex, above);
480
			}
481
		}
482
483
		return rv;
396
	}
484
	}
397
485
398
	void handleDoubleClickEvent() {
486
	private ViewerCell searchPreviousCell(ViewerRow row, ColumnViewer viewer,
399
		viewer.fireDoubleClick(new DoubleClickEvent(viewer, viewer
487
			int columnIndex, int startIndex) {
400
				.getSelection()));
488
		ViewerCell rv = null;
401
		viewer.fireOpen(new OpenEvent(viewer, viewer.getSelection()));
489
490
		if (columnIndex - 1 >= 0) {
491
			ViewerColumn column = viewer.getViewerColumn(columnIndex - 1);
492
			if (column != null && column.getEditingSupport() != null
493
					&& column.getEditingSupport().canEdit(
494
							row.getItem().getData())) {
495
				rv = row.getCell(columnIndex - 1);
496
			} else {
497
				rv = searchPreviousCell(row, viewer, columnIndex - 1,
498
						startIndex);
499
			}
500
		} else {
501
			if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
502
				// Check that we don't get into endless loop
503
				if (columnIndex - 1 != startIndex) {
504
					// Don't subtract -1 from getColumnCount() we need to
505
					// start in the virtual column
506
					// next to it
507
					rv = searchPreviousCell(row, viewer, row.getColumnCount(),
508
							startIndex);
509
				}
510
			} else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
511
				ViewerRow rowAbove = row.getNeighbor(ViewerRow.ABOVE, false);
512
				if (rowAbove != null) {
513
					rv = searchPreviousCell(rowAbove, viewer, rowAbove
514
							.getColumnCount(), startIndex);
515
				}
516
			}
517
		}
518
519
		return rv;
402
	}
520
	}
403
521
404
	/**
522
	private ViewerCell searchNextCell(ViewerRow row, ColumnViewer viewer,
405
	 * Create a selection for this model element
523
			int columnIndex, int startIndex) {
406
	 * 
524
		ViewerCell rv = null;
407
	 * @param element
525
408
	 *            the element for which the selection is created
526
		if (columnIndex + 1 < row.getColumnCount()) {
409
	 * @return the selection created
527
			ViewerColumn column = viewer.getViewerColumn(columnIndex + 1);
410
	 */
528
			if (column != null && column.getEditingSupport() != null
411
	protected abstract StructuredSelection createSelection(Object element);
529
					&& column.getEditingSupport().canEdit(
530
							row.getItem().getData())) {
531
				rv = row.getCell(columnIndex + 1);
532
			} else {
533
				rv = searchNextCell(row, viewer, columnIndex + 1, startIndex);
534
			}
535
		} else {
536
			if ((feature & TABBING_CYCLE_IN_ROW) == TABBING_CYCLE_IN_ROW) {
537
				// Check that we don't get into endless loop
538
				if (columnIndex + 1 != startIndex) {
539
					// Start from -1 from the virtual column before the
540
					// first one
541
					rv = searchNextCell(row, viewer, -1, startIndex);
542
				}
543
			} else if ((feature & TABBING_MOVE_TO_ROW_NEIGHBOR) == TABBING_MOVE_TO_ROW_NEIGHBOR) {
544
				ViewerRow rowBelow = row.getNeighbor(ViewerRow.BELOW, false);
545
				if (rowBelow != null) {
546
					rv = searchNextCell(rowBelow, viewer, -1, startIndex);
547
				}
548
			}
549
		}
550
551
		return rv;
552
	}
412
553
413
	/**
554
	/**
414
	 * Position the editor inside the control
555
	 * Position the editor inside the control
Lines 431-442 Link Here
431
	protected abstract void setLayoutData(CellEditor.LayoutData layoutData);
572
	protected abstract void setLayoutData(CellEditor.LayoutData layoutData);
432
573
433
	/**
574
	/**
434
	 * Show up the current selection (scroll the selection into view)
575
	 * @param focusCell updates the cell with the current input focus
435
	 */
576
	 */
436
	protected abstract void showSelection();
577
	protected abstract void updateFocusCell(ViewerCell focusCell);
578
	
579
	/**
580
	 * @return the cell currently holding the focus
581
	 * 
582
	 */
583
	public ViewerCell getFocusCell() {
584
		return null;
585
	}
437
586
438
	/**
587
	/**
439
	 * @return the current selection
588
	 * @return the viewer working for
440
	 */
589
	 */
441
	protected abstract Item[] getSelection();
590
	protected ColumnViewer getViewer() {
442
}
591
		return viewer;
592
	}
593
}
(-)src/org/eclipse/jface/viewers/TableViewerEditor.java (+89 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.List;
15
16
import org.eclipse.jface.viewers.CellEditor.LayoutData;
17
import org.eclipse.swt.custom.TableEditor;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Item;
20
import org.eclipse.swt.widgets.TableItem;
21
22
/**
23
 * @since 3.3
24
 *
25
 */
26
public final class TableViewerEditor extends ColumnViewerEditor {
27
	/**
28
	 * This viewer's table editor.
29
	 */
30
	private TableEditor tableEditor;
31
	
32
	private SWTFocusCellManager focusCellManager;
33
	
34
	TableViewerEditor(TableViewer viewer, SWTFocusCellManager focusCellManager, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) {
35
		super(viewer,editorActivationStrategy,feature);
36
		tableEditor = new TableEditor(viewer.getTable());
37
		this.focusCellManager = focusCellManager; 
38
	}
39
	
40
	/**
41
	 * @param viewer
42
	 * @param focusCellManager
43
	 * @param editorActivationStrategy
44
	 * @param feature
45
	 */
46
	public static void create(TableViewer viewer, SWTFocusCellManager focusCellManager, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) {
47
		TableViewerEditor editor = new TableViewerEditor(viewer,focusCellManager,editorActivationStrategy,feature);
48
		viewer.setColumnViewerEditor(editor);
49
	}
50
	
51
	/**
52
	 * @param viewer
53
	 * @param editorActivationStrategy
54
	 * @param feature
55
	 */
56
	public static void create(TableViewer viewer, ColumnViewerEditorActivationStrategy editorActivationStrategy, int feature) {
57
		create(viewer, null, editorActivationStrategy, feature);
58
	}
59
	
60
	protected void setEditor(Control w, Item item, int columnNumber) {
61
		tableEditor.setEditor(w, (TableItem) item, columnNumber);
62
	}
63
64
	protected void setLayoutData(LayoutData layoutData) {
65
		tableEditor.grabHorizontal = layoutData.grabHorizontal;
66
		tableEditor.horizontalAlignment = layoutData.horizontalAlignment;
67
		tableEditor.minimumWidth = layoutData.minimumWidth;
68
	}
69
70
	public ViewerCell getFocusCell() {
71
		if( focusCellManager != null ) {
72
			return focusCellManager.getFocusCell();
73
		}
74
		
75
		return super.getFocusCell();
76
	}
77
78
	protected void updateFocusCell(ViewerCell focusCell) {
79
		List l = getViewer().getSelectionFromWidget();
80
81
		if( focusCellManager != null ) {
82
			focusCellManager.setFocusCell(focusCell);
83
		}
84
85
		if (!l.contains(focusCell.getElement())) {
86
			getViewer().setSelection(new StructuredSelection(focusCell.getElement()));
87
		}
88
	}
89
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditorActivationEvent.java (+164 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 ColumnViewerEditorActivationEvent 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 PROGRAMMATIC = 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
	 * Cancel the event (=> editor is not activated)
97
	 */
98
	public boolean cancel = false;
99
	
100
	/**
101
	 * This constructor can be used when no event exists. The type set is
102
	 * {@link #PROGRAMMATIC}
103
	 * 
104
	 * @param cell
105
	 *            the cell
106
	 */
107
	public ColumnViewerEditorActivationEvent(ViewerCell cell) {
108
		super(cell);
109
		eventType = PROGRAMMATIC;
110
	}
111
112
	/**
113
	 * This constructor is used for all types of mouse events. Currently the
114
	 * type is can be {@link #MOUSE_CLICK_SELECTION} and
115
	 * {@link #MOUSE_DOUBLE_CLICK_SELECTION}
116
	 * 
117
	 * @param cell
118
	 *            the cell source of the event
119
	 * @param event
120
	 *            the event
121
	 */
122
	public ColumnViewerEditorActivationEvent(ViewerCell cell, MouseEvent event) {
123
		super(cell);
124
125
		if (event.count >= 2) {
126
			eventType = MOUSE_DOUBLE_CLICK_SELECTION;
127
		} else {
128
			eventType = MOUSE_CLICK_SELECTION;
129
		}
130
131
		this.sourceEvent = event;
132
		this.time = event.time;
133
	}
134
135
	/**
136
	 * @param cell
137
	 *            the cell source of the event
138
	 * @param event
139
	 *            the event
140
	 */
141
	public ColumnViewerEditorActivationEvent(ViewerCell cell, KeyEvent event) {
142
		super(cell);
143
		this.eventType = KEY_PRESSED;
144
		this.sourceEvent = event;
145
		this.time = 0;
146
		this.keyCode = event.keyCode;
147
		this.character = event.character;
148
		this.stateMask = event.stateMask;
149
	}
150
151
	/**
152
	 * This constructur is used to mark the activation triggered by a traversal
153
	 * 
154
	 * @param cell
155
	 *            the cell source of the event
156
	 * @param event
157
	 *            the event
158
	 */
159
	public ColumnViewerEditorActivationEvent(ViewerCell cell, TraverseEvent event) {
160
		super(cell);
161
		this.eventType = TRAVERSAL;
162
		this.sourceEvent = event;
163
	}
164
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditorDeactivationEvent.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 ColumnViewerEditorDeactivationEvent extends EventObject {
23
24
	/**
25
	 * 
26
	 */
27
	private static final long serialVersionUID = 1L;
28
29
	/**
30
	 * @param source
31
	 */
32
	public ColumnViewerEditorDeactivationEvent(Object source) {
33
		super(source);
34
	}
35
36
}
(-)src/org/eclipse/jface/viewers/SWTFocusCellManager.java (+144 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 org.eclipse.core.runtime.Assert;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.swt.widgets.Event;
18
import org.eclipse.swt.widgets.Listener;
19
20
/**
21
 * @since 3.3
22
 * 
23
 */
24
abstract class SWTFocusCellManager {
25
	
26
	private CellNavigationStrategy navigationDelegate;
27
28
	private ColumnViewer viewer;
29
30
	private ViewerCell focusCell;
31
32
	/**
33
	 * @param viewer
34
	 * @param focusDrawingDelegate
35
	 * @param navigationDelegate
36
	 */
37
	public SWTFocusCellManager(ColumnViewer viewer,
38
			FocusCellHighlighter focusDrawingDelegate,
39
			CellNavigationStrategy navigationDelegate) {
40
		this.viewer = viewer;
41
		this.navigationDelegate = navigationDelegate;
42
		hookListener(viewer);
43
	}
44
45
	private void handleMouseDown(Event event) {
46
		ViewerCell cell = viewer.getCell(new Point(event.x, event.y));
47
		if (cell != null) {
48
49
			if (!cell.equals(focusCell)) {
50
				this.focusCell = cell;
51
				viewer.getControl().redraw();
52
			}
53
		}
54
	}
55
56
	private void handleKeyDown(Event event) {
57
		ViewerCell tmp = null;
58
59
		if (navigationDelegate.isCollapseEvent(viewer, focusCell, event)) {
60
			navigationDelegate.collapse(viewer, focusCell, event);
61
		} else if (navigationDelegate.isExpandEvent(viewer, focusCell, event)) {
62
			navigationDelegate.expand(viewer, focusCell, event);
63
		} else if (navigationDelegate.isNavigationEvent(viewer, event)) {
64
			tmp = navigationDelegate.findSelectedCell(viewer, focusCell, event);
65
66
			if (tmp != null) {
67
				if (!tmp.equals(focusCell)) {
68
					this.focusCell = tmp;
69
					viewer.getControl().redraw();
70
				}
71
			}
72
		}
73
74
		if (navigationDelegate.shouldCancelEvent(viewer, event)) {
75
			event.doit = false;
76
		}
77
	}
78
79
	private void handleSelection(Event event) {
80
		if (focusCell != null && focusCell.getItem() != event.item
81
				&& event.item != null) {
82
			ViewerRow row = viewer.getViewerRowFromItem(event.item);
83
			Assert
84
					.isNotNull(row,
85
							"Internal Structure invalid. Row item has no row ViewerRow assigned"); //$NON-NLS-1$
86
			ViewerCell tmp = row.getCell(focusCell.getColumnIndex());
87
			if (!focusCell.equals(tmp)) {
88
				this.focusCell = tmp;
89
				viewer.getControl().redraw();
90
			}
91
		}
92
	}
93
94
	private void handleFocusIn(Event event) {
95
		if( focusCell == null ) {
96
			focusCell = getInitialFocusCell();
97
		}
98
	}
99
	
100
	abstract ViewerCell getInitialFocusCell();
101
	
102
	private void hookListener(ColumnViewer viewer) {
103
		Listener listener = new Listener() {
104
105
			public void handleEvent(Event event) {
106
				switch (event.type) {
107
				case SWT.MouseDown:
108
					handleMouseDown(event);
109
					break;
110
				case SWT.KeyDown:
111
					handleKeyDown(event);
112
					break;
113
				case SWT.Selection:
114
					handleSelection(event);
115
					break;
116
				case SWT.FocusIn:
117
					handleFocusIn(event);
118
					break;
119
				}
120
			}
121
		};
122
123
		viewer.getControl().addListener(SWT.MouseDown, listener);
124
		viewer.getControl().addListener(SWT.KeyDown, listener);
125
		viewer.getControl().addListener(SWT.Selection, listener);
126
		viewer.getControl().addListener(SWT.FocusIn, listener);
127
	}
128
	
129
	/**
130
	 * @return the cell with the focus
131
	 * 
132
	 */
133
	public ViewerCell getFocusCell() {
134
		return focusCell;
135
	}
136
	
137
	void setFocusCell(ViewerCell focusCell) {
138
		this.focusCell = focusCell;
139
	}
140
	
141
	ColumnViewer getViewer() {
142
		return viewer;
143
	}
144
}
(-)src/org/eclipse/jface/viewers/TreeViewerEditor.java (+104 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.List;
15
16
import org.eclipse.jface.viewers.CellEditor.LayoutData;
17
import org.eclipse.swt.custom.TreeEditor;
18
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Item;
20
import org.eclipse.swt.widgets.TreeItem;
21
22
/**
23
 * @since 3.3
24
 * 
25
 */
26
public class TreeViewerEditor extends ColumnViewerEditor {
27
	/**
28
	 * This viewer's tree editor.
29
	 */
30
	private TreeEditor treeEditor;
31
32
	private SWTFocusCellManager focusCellManager;
33
34
	/**
35
	 * @param viewer
36
	 * @param focusCellManager
37
	 * @param editorActivationStrategy
38
	 * @param feature
39
	 */
40
	TreeViewerEditor(TreeViewer viewer, SWTFocusCellManager focusCellManager,
41
			ColumnViewerEditorActivationStrategy editorActivationStrategy,
42
			int feature) {
43
		super(viewer, editorActivationStrategy, feature);
44
		treeEditor = new TreeEditor(viewer.getTree());
45
		this.focusCellManager = focusCellManager;
46
	}
47
48
	/**
49
	 * @param viewer
50
	 * @param focusCellManager
51
	 * @param editorActivationStrategy
52
	 * @param feature
53
	 */
54
	public static void create(TreeViewer viewer,
55
			SWTFocusCellManager focusCellManager,
56
			ColumnViewerEditorActivationStrategy editorActivationStrategy,
57
			int feature) {
58
		TreeViewerEditor editor = new TreeViewerEditor(viewer,
59
				focusCellManager, editorActivationStrategy, feature);
60
		viewer.setColumnViewerEditor(editor);
61
	}
62
63
	/**
64
	 * @param viewer
65
	 * @param editorActivationStrategy
66
	 * @param feature
67
	 */
68
	public static void create(TreeViewer viewer,
69
			ColumnViewerEditorActivationStrategy editorActivationStrategy,
70
			int feature) {
71
		create(viewer, null, editorActivationStrategy, feature);
72
	}
73
74
	protected void setEditor(Control w, Item item, int fColumnNumber) {
75
		treeEditor.setEditor(w, (TreeItem) item, fColumnNumber);
76
	}
77
78
	protected void setLayoutData(LayoutData layoutData) {
79
		treeEditor.grabHorizontal = layoutData.grabHorizontal;
80
		treeEditor.horizontalAlignment = layoutData.horizontalAlignment;
81
		treeEditor.minimumWidth = layoutData.minimumWidth;
82
	}
83
84
	public ViewerCell getFocusCell() {
85
		if (focusCellManager != null) {
86
			return focusCellManager.getFocusCell();
87
		}
88
89
		return super.getFocusCell();
90
	}
91
92
	protected void updateFocusCell(ViewerCell focusCell) {
93
		List l = getViewer().getSelectionFromWidget();
94
95
		if (focusCellManager != null) {
96
			focusCellManager.setFocusCell(focusCell);
97
		}
98
99
		if (!l.contains(focusCell.getElement())) {
100
			getViewer().setSelection(new StructuredSelection(focusCell.getElement()));
101
		}
102
103
	}
104
}
(-)src/org/eclipse/jface/viewers/TableViewerFocusCellManager.java (+42 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 org.eclipse.swt.widgets.Table;
15
16
/**
17
 * @since 3.3
18
 *
19
 */
20
public class TableViewerFocusCellManager extends SWTFocusCellManager {
21
	private static final CellNavigationStrategy TABLE_NAVIGATE = new CellNavigationStrategy();
22
	
23
	/**
24
	 * @param viewer
25
	 * @param focusDrawingDelegate
26
	 */
27
	public TableViewerFocusCellManager(TableViewer viewer,
28
			FocusCellHighlighter focusDrawingDelegate) {
29
		super(viewer, focusDrawingDelegate, TABLE_NAVIGATE);
30
	}
31
32
	ViewerCell getInitialFocusCell() {
33
		Table table = (Table) getViewer().getControl();
34
		
35
		if( table.getItemCount() > 0 ) {
36
			return getViewer().getViewerRowFromItem(table.getItem(0)).getCell(0);
37
		}
38
		
39
		return null;
40
	}
41
42
}
(-)src/org/eclipse/jface/viewers/FocusCellHighlighter.java (+34 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
 * @since 3.3
16
 * 
17
 */
18
public abstract class FocusCellHighlighter {
19
	private ColumnViewer viewer;
20
21
	/**
22
	 * @param viewer
23
	 */
24
	public FocusCellHighlighter(ColumnViewer viewer) {
25
		this.viewer = viewer;
26
	}
27
28
	/**
29
	 * @return the focus cell
30
	 */
31
	public ViewerCell getFocusCell() {
32
		return viewer.getColumnViewerEditor().getFocusCell();
33
	}
34
}
(-)src/org/eclipse/jface/viewers/FocusCellOwnerDrawHighlighter.java (+119 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 org.eclipse.core.runtime.Assert;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.swt.widgets.Listener;
20
21
/**
22
 * @since 3.3
23
 * 
24
 */
25
public class FocusCellOwnerDrawHighlighter extends FocusCellHighlighter {
26
27
	/**
28
	 * @param viewer
29
	 *            the viewer
30
	 */
31
	public FocusCellOwnerDrawHighlighter(ColumnViewer viewer) {
32
		super(viewer);
33
		hookListener(viewer);
34
	}
35
36
	private void markFocusedCell(Event event, ViewerCell cell) {
37
		Color background = getSelectedCellBackgroundColor(cell);
38
		Color foreground = getSelectedCellForegroundColor(cell);
39
40
		if (foreground != null || background != null) {
41
			GC gc = event.gc;
42
43
			if (background == null) {
44
				background = cell.getItem().getDisplay().getSystemColor(
45
						SWT.COLOR_LIST_SELECTION);
46
			}
47
48
			if (foreground == null) {
49
				foreground = cell.getItem().getDisplay().getSystemColor(
50
						SWT.COLOR_LIST_SELECTION_TEXT);
51
			}
52
53
			gc.setBackground(background);
54
			gc.setForeground(foreground);
55
			gc.fillRectangle(event.getBounds());
56
57
			// This is a workaround for an SWT-Bug on WinXP bug 169517
58
			gc.drawText(" ", cell.getBounds().x, cell.getBounds().y, false); //$NON-NLS-1$
59
			event.detail &= ~SWT.SELECTED;
60
		}
61
	}
62
63
	private void removeSelectionInformation(Event event, ViewerCell cell) {
64
		GC gc = event.gc;
65
		gc.setBackground(cell.getViewerRow().getBackground(
66
				cell.getColumnIndex()));
67
		gc.setForeground(cell.getViewerRow().getForeground(
68
				cell.getColumnIndex()));
69
		gc.fillRectangle(cell.getBounds());
70
		// This is a workaround for an SWT-Bug on WinXP bug 169517
71
		gc.drawText(" ", cell.getBounds().x, cell.getBounds().y, false); //$NON-NLS-1$
72
		event.detail &= ~SWT.SELECTED;
73
	}
74
75
	private void hookListener(final ColumnViewer viewer) {
76
77
		Listener listener = new Listener() {
78
79
			public void handleEvent(Event event) {
80
				if ((event.detail & SWT.SELECTED) > 0) {
81
					ViewerCell focusCell = getFocusCell();
82
					ViewerRow row = viewer.getViewerRowFromItem(event.item);
83
84
					Assert
85
							.isNotNull(row,
86
									"Internal structure invalid. Item without associated row is not possible."); //$NON-NLS-1$
87
88
					ViewerCell cell = row.getCell(event.index);
89
90
					if (focusCell == null || !cell.equals(focusCell)) {
91
						removeSelectionInformation(event, cell);
92
					} else {
93
						markFocusedCell(event, cell);
94
					}
95
				}
96
			}
97
98
		};
99
		viewer.getControl().addListener(SWT.EraseItem, listener);
100
	}
101
102
	/**
103
	 * @param cell
104
	 *            the cell which is colored
105
	 * @return the color
106
	 */
107
	protected Color getSelectedCellBackgroundColor(ViewerCell cell) {
108
		return null;
109
	}
110
111
	/**
112
	 * @param cell
113
	 *            the cell which is colored
114
	 * @return the color
115
	 */
116
	protected Color getSelectedCellForegroundColor(ViewerCell cell) {
117
		return null;
118
	}
119
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditorActivationListener.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 ColumnViewerEditorActivationListener {
22
	/**
23
	 * Called before an editor is activated
24
	 * 
25
	 * @param event
26
	 *            the event
27
	 */
28
	public abstract void beforeEditorActivated(ColumnViewerEditorActivationEvent event);
29
30
	/**
31
	 * Called after an editor has been activated
32
	 * 
33
	 * @param event the event
34
	 */
35
	public abstract void afterEditorActivated(ColumnViewerEditorActivationEvent event);
36
37
	/**
38
	 * Called before an editor is deactivated
39
	 * 
40
	 * @param event
41
	 *            the event
42
	 */
43
	public abstract void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event);
44
45
	
46
	/**
47
	 * Called after an editor is deactivated
48
	 * 
49
	 * @param event the event
50
	 */
51
	public abstract void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event);
52
}
(-)src/org/eclipse/jface/viewers/TreeViewerFocusCellManager.java (+77 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 org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.Event;
16
import org.eclipse.swt.widgets.Tree;
17
import org.eclipse.swt.widgets.TreeItem;
18
19
/**
20
 * @since 3.3
21
 *
22
 */
23
public class TreeViewerFocusCellManager extends SWTFocusCellManager {
24
	private static final CellNavigationStrategy TREE_NAVIGATE = new CellNavigationStrategy() {
25
		public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse,
26
				Event event) {
27
			if (cellToCollapse != null) {
28
				((TreeItem) cellToCollapse.getItem()).setExpanded(false);
29
			}
30
		}
31
32
		public void expand(ColumnViewer viewer, ViewerCell cellToExpand,
33
				Event event) {
34
			if (cellToExpand != null) {
35
				TreeViewer v = (TreeViewer) viewer;
36
				v.setExpandedState(v
37
						.getTreePathFromItem(cellToExpand.getItem()), true);
38
			}
39
		}
40
41
		public boolean isCollapseEvent(ColumnViewer viewer,
42
				ViewerCell cellToCollapse, Event event) {
43
			return cellToCollapse != null
44
					&& ((TreeItem) cellToCollapse.getItem()).getExpanded()
45
					&& cellToCollapse.getColumnIndex() == 0
46
					&& event.keyCode == SWT.ARROW_LEFT;
47
		}
48
49
		public boolean isExpandEvent(ColumnViewer viewer,
50
				ViewerCell cellToExpand, Event event) {
51
			return cellToExpand != null
52
					&& ((TreeItem) cellToExpand.getItem()).getItemCount() > 0
53
					&& !((TreeItem) cellToExpand.getItem()).getExpanded()
54
					&& cellToExpand.getColumnIndex() == 0
55
					&& event.keyCode == SWT.ARROW_RIGHT;
56
		}
57
	};
58
	
59
	/**
60
	 * @param viewer
61
	 * @param focusDrawingDelegate
62
	 */
63
	public TreeViewerFocusCellManager(TreeViewer viewer,
64
			FocusCellHighlighter focusDrawingDelegate) {
65
		super(viewer, focusDrawingDelegate,TREE_NAVIGATE);
66
	}
67
68
	ViewerCell getInitialFocusCell() {
69
		Tree tree = (Tree) getViewer().getControl();
70
		
71
		if( tree.getItemCount() > 0 ) {
72
			return getViewer().getViewerRowFromItem(tree.getItem(0)).getCell(0);
73
		}
74
		
75
		return null;
76
	}
77
}
(-)src/org/eclipse/jface/viewers/CellNavigationStrategy.java (+151 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 org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.Event;
16
17
/**
18
 * @since 3.3
19
 * 
20
 */
21
public class CellNavigationStrategy {
22
	/**
23
	 * is the given event an event which moves the selection to another cell
24
	 * 
25
	 * @param viewer
26
	 *            the viewer we are working for
27
	 * 
28
	 * @param event
29
	 *            the key event
30
	 * @return <code>true</code> if a new cell is searched
31
	 */
32
	public boolean isNavigationEvent(ColumnViewer viewer, Event event) {
33
		switch (event.keyCode) {
34
		case SWT.ARROW_UP:
35
		case SWT.ARROW_DOWN:
36
		case SWT.ARROW_LEFT:
37
		case SWT.ARROW_RIGHT:
38
		case SWT.HOME:
39
		case SWT.PAGE_DOWN:
40
		case SWT.PAGE_UP:
41
		case SWT.END:
42
			return true;
43
		default:
44
			return false;
45
		}
46
	}
47
48
	/**
49
	 * @param viewer
50
	 *            the viewer we are working for
51
	 * @param cellToCollapse the cell to collapse
52
	 * @param event
53
	 *            the key event
54
	 * @return <code>true</code> if this event triggers collapsing of a node
55
	 */
56
	public boolean isCollapseEvent(ColumnViewer viewer, ViewerCell cellToCollapse, Event event) {
57
		return false;
58
	}
59
60
	/**
61
	 * @param viewer
62
	 *            the viewer we are working for
63
	 * @param cellToExpand the cell to expand
64
	 * @param event
65
	 *            the key event
66
	 * @return <code>true</code> if this event triggers expanding of a node
67
	 */
68
	public boolean isExpandEvent(ColumnViewer viewer, ViewerCell cellToExpand, Event event) {
69
		return false;
70
	}
71
72
	/**
73
	 * @param viewer
74
	 *            the viewer working for
75
	 * @param cellToExpand
76
	 *            the cell the user wants to expand
77
	 * @param event
78
	 *            the event triggering the exansion
79
	 */
80
	public void expand(ColumnViewer viewer, ViewerCell cellToExpand, Event event) {
81
82
	}
83
84
	/**
85
	 * @param viewer
86
	 *            the viewer working for
87
	 * @param cellToCollapse
88
	 *            the cell the user wants to collapse
89
	 * @param event
90
	 *            the event triggering the exansion
91
	 */
92
	public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse,
93
			Event event) {
94
95
	}
96
97
	/**
98
	 * @param viewer
99
	 *            the viewer we are working for
100
	 * @param currentSelectedCell
101
	 *            the cell currently selected
102
	 * @param event
103
	 *            the key event
104
	 * @return the cell which is highlighted next or <code>null</code> if the
105
	 *         default implementation is taken. E.g. it's fairly impossible to
106
	 *         react on PAGE_DOWN requests
107
	 */
108
	public ViewerCell findSelectedCell(ColumnViewer viewer,
109
			ViewerCell currentSelectedCell, Event event) {
110
111
		switch (event.keyCode) {
112
		case SWT.ARROW_UP:
113
			if (currentSelectedCell != null) {
114
				return currentSelectedCell.getNeighbor(ViewerCell.ABOVE, false);
115
			}
116
			break;
117
		case SWT.ARROW_DOWN:
118
			if (currentSelectedCell != null) {
119
				return currentSelectedCell.getNeighbor(ViewerCell.BELOW, false);
120
			}
121
			break;
122
		case SWT.ARROW_LEFT:
123
			if (currentSelectedCell != null) {
124
				return currentSelectedCell.getNeighbor(ViewerCell.LEFT, true);
125
			}
126
			break;
127
		case SWT.ARROW_RIGHT:
128
			if (currentSelectedCell != null) {
129
				return currentSelectedCell.getNeighbor(ViewerCell.RIGHT, true);
130
			}
131
			break;
132
		}
133
134
		return null;
135
	}
136
137
	/**
138
	 * This method is consulted to decide whether an event has to be cancled or
139
	 * not. By default events who collapse/expand tree-nodes are cancled
140
	 * 
141
	 * @param viewer
142
	 *            the viewer working for
143
	 * @param event
144
	 *            the event
145
	 * @return <code>true</code> if the event has to be cancled
146
	 */
147
	public boolean shouldCancelEvent(ColumnViewer viewer, Event event) {
148
		return event.keyCode == SWT.ARROW_LEFT
149
				|| event.keyCode == SWT.ARROW_RIGHT;
150
	}
151
}
(-)src/org/eclipse/jface/viewers/ColumnViewerEditorActivationStrategy.java (+91 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
import org.eclipse.swt.events.KeyEvent;
15
import org.eclipse.swt.events.KeyListener;
16
17
/**
18
 * This class is responsible to determin if a cell selection event is triggers
19
 * an editor activation
20
 * 
21
 * @since 3.3
22
 */
23
public class ColumnViewerEditorActivationStrategy {
24
	private ColumnViewer viewer;
25
	
26
	private KeyListener keyboardActivationListener;
27
	
28
	/**
29
	 * @param viewer the viewer the editor support is attached to
30
	 */
31
	public ColumnViewerEditorActivationStrategy(ColumnViewer viewer) {
32
		this.viewer = viewer;
33
	}
34
	
35
	/**
36
	 * @param event
37
	 * @return bla bl
38
	 */
39
	protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
40
		return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
41
			|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC
42
			|| event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL;
43
		}
44
45
	/**
46
	 * @return the cell holding the current focus
47
	 */
48
	private ViewerCell getFocusCell() {
49
		return viewer.getColumnViewerEditor().getFocusCell();
50
	}
51
	
52
	/**
53
	 * @return the viewer
54
	 */
55
	public ColumnViewer getViewer() {
56
		return viewer;
57
	}
58
	
59
	/**
60
	 * Enable activation of cell editors by keyboard
61
	 * @param enable <code>true</code> to enable
62
	 */
63
	public void setEnableEditorActivationWithKeyboard(boolean enable) {
64
		if( enable ) {
65
			if( keyboardActivationListener == null ) {
66
				keyboardActivationListener = new KeyListener() {
67
68
					public void keyPressed(KeyEvent e) {
69
						ViewerCell cell = getFocusCell();
70
						
71
						if( cell != null ) {
72
							viewer.triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell,e));
73
						}
74
					}
75
76
					public void keyReleased(KeyEvent e) {
77
						
78
					}
79
					
80
				};
81
				viewer.getControl().addKeyListener(keyboardActivationListener);
82
			}
83
		} else {
84
			if( keyboardActivationListener != null ) {
85
				viewer.getControl().removeKeyListener(keyboardActivationListener);
86
				keyboardActivationListener = null;
87
			}
88
		}
89
	}
90
91
}

Return to bug 172646