aboutsummaryrefslogtreecommitdiffstats
blob: a0030e3017d0f57c3ee297686775e070d4a837d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.jface.tests.viewers;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeColumn;

/**
 * @since 3.3
 *
 */
public class Bug200558Test extends ViewerTestCase {

	private TreeViewer<Object,Object> treeViewer;

	/**
	 * @param name
	 */
	public Bug200558Test(String name) {
		super(name);
	}

	protected StructuredViewer createViewer(Composite parent) {
		treeViewer = new TreeViewer<Object,Object>(parent, SWT.FULL_SELECTION);
		treeViewer.setContentProvider(new ITreeContentProvider<Object,Object>() {

			public void dispose() {
			}

			public void inputChanged(Viewer<Object> viewer, Object oldInput,
					Object newInput) {
			}

			public Object[] getElements(Object inputElement) {
				return new Object[] { "item" };
			}

			public Object[] getChildren(Object parentElement) {
				return null;
			}

			public Object getParent(Object element) {
				return null;
			}

			public boolean hasChildren(Object element) {
				return false;
			}

		});
		treeViewer.setCellEditors(new CellEditor[] { new TextCellEditor(
				treeViewer.getTree()) });
		treeViewer.setColumnProperties(new String[] { "0" });
		treeViewer.setCellModifier(new ICellModifier() {
			public boolean canModify(Object element, String property) {
				return true;
			}

			public Object getValue(Object element, String property) {
				return "Test";
			}

			public void modify(Object element, String property, Object value) {
			}

		});

	    new TreeColumn(treeViewer.getTree(), SWT.NONE);
	    new TreeColumn(treeViewer.getTree(), SWT.NONE).setWidth(100);

		return treeViewer;
	}

	protected void setUpModel() {
		// don't do anything here - we are not using the normal fModel and
		// fRootElement
	}

	protected void setInput() {
		getTreeViewer().setInput(new Object());
		getTreeViewer().getTree().getColumn(0).dispose();
	}

	private TreeViewer<Object,Object> getTreeViewer() {
		return treeViewer;
	}

	public void testBug200558() {
		getTreeViewer().editElement(getTreeViewer().getTree().getItem(0).getData(), 0);
		assertEquals("Test", ((Text)getTreeViewer().getCellEditors()[0].getControl()).getText());
	}
}