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 262615
Collapse All | Expand All

(-)Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java (+1 lines)
Lines 55-59 Link Here
55
        addTest(new TestSuite(ReopenMenuTest.class));
55
        addTest(new TestSuite(ReopenMenuTest.class));
56
        addTest(new TestSuite(UtilTest.class));
56
        addTest(new TestSuite(UtilTest.class));
57
		addTest(new TestSuite(MarkerTesterTest.class));
57
		addTest(new TestSuite(MarkerTesterTest.class));
58
		addTest(new TestSuite(TextHandlerTest.class));
58
    }
59
    }
59
}
60
}
(-)plugin.xml (+6 lines)
Lines 465-470 Link Here
465
            name="NonRestorableView"
465
            name="NonRestorableView"
466
            restorable="false">
466
            restorable="false">
467
      </view>
467
      </view>
468
      <view
469
            class="org.eclipse.ui.tests.internal.TextControlView"
470
            id="org.eclipse.ui.tests.textHandlerView"
471
            name="Text Control view"
472
            restorable="true">
473
      </view>
468
474
469
   </extension>
475
   </extension>
470
   <extension
476
   <extension
(-)Eclipse (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.ui.tests.internal;
13
14
import java.lang.reflect.Field;
15
import java.lang.reflect.Method;
16
17
import org.eclipse.jface.action.Action;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Text;
23
import org.eclipse.ui.actions.TextActionHandler;
24
import org.eclipse.ui.part.ViewPart;
25
26
/**
27
 * @since 3.5
28
 * 
29
 */
30
public class TextControlView extends ViewPart {
31
	public static final String ID = "org.eclipse.ui.tests.textHandlerView";
32
	public Action cutAction;
33
	public Action copyAction;
34
	public Action selectAllAction;
35
	public Action pasteAction;
36
	public Action cutDummyAction;
37
	public Action copyDummyAction;
38
	public Action selectDummyAllAction;
39
	public Action pasteDummyAction;
40
	public Text editableText;
41
	public Text nonEditableText;
42
	private TextActionHandler delegator;
43
44
	public TextControlView() {
45
		cutDummyAction = new Action("Cut") {
46
		};
47
		copyDummyAction = new Action("Copy") {
48
		};
49
		selectDummyAllAction = new Action("Select All") {
50
		};
51
		pasteDummyAction = new Action("Paste") {
52
		};
53
	}
54
55
	/*
56
	 * (non-Javadoc)
57
	 * 
58
	 * @see
59
	 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
60
	 * .Composite)
61
	 */
62
	public void createPartControl(Composite parent) {
63
		Composite c = new Composite(parent, SWT.NONE);
64
		c.setLayout(new GridLayout(3, true));
65
		editableText = new Text(c, SWT.MULTI);
66
		editableText.setLayoutData(new GridData());
67
		nonEditableText = new Text(c, SWT.MULTI | SWT.READ_ONLY);
68
		nonEditableText.setLayoutData(new GridData());
69
		delegator = new TextActionHandler(getViewSite().getActionBars());
70
		delegator.addText(editableText);
71
		delegator.addText(nonEditableText);
72
		delegator.setCutAction(cutDummyAction);
73
		delegator.setCopyAction(copyDummyAction);
74
		delegator.setSelectAllAction(selectDummyAllAction);
75
		delegator.setPasteAction(pasteDummyAction);
76
	}
77
78
	/*
79
	 * (non-Javadoc)
80
	 * 
81
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
82
	 */
83
	public void setFocus() {
84
		editableText.setFocus();
85
	}
86
87
	public Action getPasteAction() throws Exception {
88
		return getAction("textPasteAction");
89
	}
90
91
	public Action getCopyAction() throws Exception {
92
		return getAction("textCopyAction");
93
	}
94
95
	public Action getCutAction() throws Exception {
96
		return getAction("textCutAction");
97
	}
98
99
	public Action getSelectAllAction() throws Exception {
100
		return getAction("textSelectAllAction");
101
	}
102
103
	public void updateEnabledState() throws Exception {
104
		Method method = TextActionHandler.class.getDeclaredMethod(
105
				"updateActionsEnableState", null);
106
		method.setAccessible(true);
107
		method.invoke(delegator, null);
108
	}
109
110
	private Action getAction(String fieldName) throws Exception {
111
		Field field = TextActionHandler.class.getDeclaredField(fieldName);
112
		field.setAccessible(true);
113
		return (Action) field.get(delegator);
114
	}
115
}
(-)Eclipse (+126 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.ui.tests.internal;
13
14
import org.eclipse.swt.dnd.Clipboard;
15
import org.eclipse.swt.dnd.TextTransfer;
16
import org.eclipse.swt.dnd.Transfer;
17
import org.eclipse.swt.dnd.URLTransfer;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.tests.harness.util.UITestCase;
20
21
/**
22
 * @since 3.5
23
 * 
24
 */
25
public class TextHandlerTest extends UITestCase {
26
27
	public TextHandlerTest(String testName) {
28
		super(testName);
29
	}
30
31
	public void testEditableText() throws Exception {
32
		IWorkbenchWindow window = openTestWindow();
33
		TextControlView view = (TextControlView) window.getActivePage()
34
				.showView(TextControlView.ID);
35
36
		Clipboard clipboard = new Clipboard(window.getWorkbench().getDisplay());
37
		try {
38
			clipboard.setContents(new Object[] { "http://www.google.ca" },
39
					new Transfer[] { URLTransfer.getInstance() });
40
			processEvents();
41
			view.updateEnabledState();
42
43
			assertFalse(view.getCopyAction().isEnabled());
44
			assertFalse(view.getCutAction().isEnabled());
45
			assertFalse(view.getPasteAction().isEnabled());
46
			assertFalse(view.getSelectAllAction().isEnabled());
47
			
48
			view.editableText.setText("Hello");
49
			processEvents();
50
			view.updateEnabledState();
51
			assertFalse(view.getCopyAction().isEnabled());
52
			assertFalse(view.getCutAction().isEnabled());
53
			assertFalse(view.getPasteAction().isEnabled());
54
			assertTrue(view.getSelectAllAction().isEnabled());
55
			
56
			view.editableText.setSelection(0, 3);
57
			processEvents();
58
			view.updateEnabledState();
59
			assertTrue(view.getCopyAction().isEnabled());
60
			assertTrue(view.getCutAction().isEnabled());
61
			assertFalse(view.getPasteAction().isEnabled());
62
			assertTrue(view.getSelectAllAction().isEnabled());
63
			
64
			clipboard.setContents(new Object[] { "http://www.google.ca" },
65
					new Transfer[] { TextTransfer.getInstance() });
66
			processEvents();
67
			view.updateEnabledState();
68
			
69
			assertTrue(view.getCopyAction().isEnabled());
70
			assertTrue(view.getCutAction().isEnabled());
71
			assertTrue(view.getPasteAction().isEnabled());
72
			assertTrue(view.getSelectAllAction().isEnabled());
73
			
74
		} finally {
75
			clipboard.dispose();
76
		}
77
	}
78
	
79
	public void testNonEditableText() throws Exception {
80
		IWorkbenchWindow window = openTestWindow();
81
		TextControlView view = (TextControlView) window.getActivePage()
82
				.showView(TextControlView.ID);
83
84
		Clipboard clipboard = new Clipboard(window.getWorkbench().getDisplay());
85
		try {
86
			clipboard.setContents(new Object[] { "http://www.google.ca" },
87
					new Transfer[] { URLTransfer.getInstance() });
88
			view.nonEditableText.setFocus();
89
			processEvents();
90
			view.updateEnabledState();
91
92
			assertFalse(view.getCopyAction().isEnabled());
93
			assertFalse(view.getCutAction().isEnabled());
94
			assertFalse(view.getPasteAction().isEnabled());
95
			assertFalse(view.getSelectAllAction().isEnabled());
96
			
97
			view.nonEditableText.setText("Hello");
98
			processEvents();
99
			view.updateEnabledState();
100
			assertFalse(view.getCopyAction().isEnabled());
101
			assertFalse(view.getCutAction().isEnabled());
102
			assertFalse(view.getPasteAction().isEnabled());
103
			assertTrue(view.getSelectAllAction().isEnabled());
104
			
105
			view.nonEditableText.setSelection(0, 3);
106
			processEvents();
107
			view.updateEnabledState();
108
			assertTrue(view.getCopyAction().isEnabled());
109
			assertFalse(view.getCutAction().isEnabled());
110
			assertFalse(view.getPasteAction().isEnabled());
111
			assertTrue(view.getSelectAllAction().isEnabled());
112
113
			clipboard.setContents(new Object[] { "http://www.google.ca" },
114
					new Transfer[] { TextTransfer.getInstance() });
115
			processEvents();
116
			view.updateEnabledState();
117
			
118
			assertTrue(view.getCopyAction().isEnabled());
119
			assertFalse(view.getCutAction().isEnabled());
120
			assertFalse(view.getPasteAction().isEnabled());
121
			assertTrue(view.getSelectAllAction().isEnabled());
122
		} finally {
123
			clipboard.dispose();
124
		}
125
	}
126
}

Return to bug 262615