01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.tests.views.properties.tabbed.text;
11:
12: import org.eclipse.jface.text.Document;
13: import org.eclipse.jface.text.TextViewer;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.layout.FormAttachment;
16: import org.eclipse.swt.layout.FormData;
17: import org.eclipse.swt.layout.FormLayout;
18: import org.eclipse.swt.widgets.Composite;
19: import org.eclipse.swt.widgets.Label;
20: import org.eclipse.ui.part.ViewPart;
21: import org.eclipse.ui.views.properties.IPropertySheetPage;
22: import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
23: import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
24: import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
25:
26: /**
27: * A text view to test dynamic contributions to the tabbed properties view.
28: *
29: * @author Anthony Hunter
30: */
31: public class TextTestsView extends ViewPart implements
32: ITabbedPropertySheetPageContributor {
33:
34: public static final String TEXT_TESTS_VIEW_ID = "org.eclipse.ui.tests.views.properties.tabbed.text.TextTestsView"; //$NON-NLS-1$
35:
36: private TabbedPropertySheetPage tabbedPropertySheetPage;
37:
38: private TextViewer viewer;
39:
40: public void createPartControl(Composite parent) {
41: Composite composite = new Composite(parent, SWT.NONE);
42: FormLayout layout = new FormLayout();
43: layout.marginWidth = ITabbedPropertyConstants.HSPACE;
44: layout.marginHeight = ITabbedPropertyConstants.VSPACE;
45: layout.spacing = ITabbedPropertyConstants.VMARGIN;
46: composite.setLayout(layout);
47:
48: Label label = new Label(composite, SWT.NONE);
49: label
50: .setText("Enter text, selected words becomes tabs and sections");
51: FormData data = new FormData();
52: data.left = new FormAttachment(0, 0);
53: data.right = new FormAttachment(100, 0);
54: data.top = new FormAttachment(0, 0);
55: label.setLayoutData(data);
56:
57: viewer = new TextViewer(composite, SWT.WRAP | SWT.H_SCROLL
58: | SWT.V_SCROLL | SWT.BORDER);
59: viewer.setDocument(new Document());
60: data = new FormData();
61: data.left = new FormAttachment(0, 0);
62: data.right = new FormAttachment(100, 0);
63: data.top = new FormAttachment(label, 0);
64: data.bottom = new FormAttachment(100, 0);
65: viewer.getControl().setLayoutData(data);
66:
67: getSite().setSelectionProvider(viewer);
68: }
69:
70: public Object getAdapter(Class adapter) {
71: if (adapter == IPropertySheetPage.class) {
72: if (tabbedPropertySheetPage == null) {
73: tabbedPropertySheetPage = new TabbedPropertySheetPage(
74: this );
75: }
76: return tabbedPropertySheetPage;
77: }
78: return super .getAdapter(adapter);
79: }
80:
81: public String getContributorId() {
82: return "org.eclipse.ui.tests.views.properties.tabbed.text"; //$NON-NLS-1$
83: }
84:
85: public TabbedPropertySheetPage getTabbedPropertySheetPage() {
86: return tabbedPropertySheetPage;
87: }
88:
89: public TextViewer getViewer() {
90: return viewer;
91: }
92:
93: public void setFocus() {
94: viewer.getControl().setFocus();
95: }
96:
97: }
|