001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.views.properties.tabbed.override.items;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.graphics.Image;
014: import org.eclipse.swt.layout.FillLayout;
015: import org.eclipse.swt.layout.FormAttachment;
016: import org.eclipse.swt.layout.FormData;
017: import org.eclipse.swt.layout.FormLayout;
018: import org.eclipse.swt.widgets.Button;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Label;
021: import org.eclipse.swt.widgets.Text;
022: import org.eclipse.ui.ISharedImages;
023: import org.eclipse.ui.PlatformUI;
024: import org.eclipse.ui.forms.widgets.FormToolkit;
025: import org.eclipse.ui.forms.widgets.ScrolledForm;
026: import org.eclipse.ui.forms.widgets.Section;
027: import org.eclipse.ui.forms.widgets.TableWrapData;
028: import org.eclipse.ui.forms.widgets.TableWrapLayout;
029: import org.eclipse.ui.tests.views.properties.tabbed.model.Information;
030:
031: /**
032: * An item for when the Information element is the selected element in the
033: * override tests view.
034: *
035: * @author Anthony Hunter
036: * @since 3.4
037: */
038: public class InformationItem implements IOverrideTestsItem {
039:
040: private Composite composite;
041:
042: /*
043: * (non-Javadoc)
044: *
045: * @see org.eclipse.ui.tests.views.properties.tabbed.override.items.IOverrideTestsItem#createControls(org.eclipse.swt.widgets.Composite)
046: */
047: public void createControls(Composite parent) {
048: FormToolkit toolkit = new FormToolkit(parent.getDisplay());
049: composite = toolkit.createComposite(parent);
050: composite.setLayout(new FillLayout());
051:
052: ScrolledForm form = toolkit.createScrolledForm(composite);
053: form.getBody().setLayout(new TableWrapLayout());
054:
055: Section section = toolkit.createSection(form.getBody(),
056: Section.DESCRIPTION);
057: TableWrapData td = new TableWrapData(TableWrapData.FILL,
058: TableWrapData.TOP);
059: td.grabHorizontal = true;
060: section.setLayoutData(td);
061: section.setText(getText() + " Properties"); //$NON-NLS-1$
062: toolkit.createCompositeSeparator(section);
063: section.setDescription("Set the properties of the selected " + //$NON-NLS-1$
064: getText() + " element.");//$NON-NLS-1$
065:
066: Composite sectionClient = toolkit.createComposite(section);
067: FormLayout layout = new FormLayout();
068: layout.marginWidth = 5;
069: layout.marginHeight = 5;
070: layout.spacing = 2;
071: sectionClient.setLayout(layout);
072: section.setClient(sectionClient);
073: toolkit.paintBordersFor(sectionClient);
074:
075: Button radioLeft = toolkit.createButton(sectionClient,
076: "Choice 1",//$NON-NLS-1$
077: SWT.RADIO);
078: FormData data = new FormData();
079: data.left = new FormAttachment(0, 0);
080: data.top = new FormAttachment(0, 5);
081: radioLeft.setLayoutData(data);
082:
083: Button radioRight = toolkit.createButton(sectionClient,
084: "Choice 2",//$NON-NLS-1$
085: SWT.RADIO);
086: data = new FormData();
087: data.left = new FormAttachment(radioLeft, 5);
088: data.top = new FormAttachment(0, 5);
089: radioRight.setLayoutData(data);
090:
091: Button radioRight2 = toolkit.createButton(sectionClient,
092: "Choice 3",//$NON-NLS-1$
093: SWT.RADIO);
094: data = new FormData();
095: data.left = new FormAttachment(radioRight, 5);
096: data.right = new FormAttachment(100, 0);
097: data.top = new FormAttachment(0, 5);
098: radioRight2.setLayoutData(data);
099:
100: Button flag = toolkit.createButton(sectionClient,
101: "Value of the flag property", SWT.CHECK);//$NON-NLS-1$
102: data = new FormData();
103: data.left = new FormAttachment(0, 0);
104: data.right = new FormAttachment(100, 0);
105: data.top = new FormAttachment(radioLeft, 5);
106: flag.setLayoutData(data);
107:
108: Label nameLabel = toolkit.createLabel(sectionClient,
109: "Text Property:"); //$NON-NLS-1$
110: data = new FormData();
111: data.left = new FormAttachment(0, 0);
112: data.top = new FormAttachment(flag, 5);
113: nameLabel.setLayoutData(data);
114:
115: Text nameText = toolkit.createText(sectionClient, ""); //$NON-NLS-1$
116: data = new FormData();
117: data.left = new FormAttachment(nameLabel, 5);
118: data.right = new FormAttachment(100, 0);
119: data.top = new FormAttachment(flag, 5);
120: nameText.setLayoutData(data);
121:
122: }
123:
124: /*
125: * (non-Javadoc)
126: *
127: * @see org.eclipse.ui.tests.views.properties.tabbed.override.items.IOverrideTestsItem#dispose()
128: */
129: public void dispose() {
130: if (composite != null && !composite.isDisposed()) {
131: composite.dispose();
132: composite = null;
133: }
134: }
135:
136: public Composite getComposite() {
137: return composite;
138: }
139:
140: /*
141: * (non-Javadoc)
142: *
143: * @see org.eclipse.ui.tests.views.properties.tabbed.override.items.IOverrideTestsItem#getElement()
144: */
145: public Class getElement() {
146: return Information.class;
147: }
148:
149: /*
150: * (non-Javadoc)
151: *
152: * @see org.eclipse.ui.tests.views.properties.tabbed.override.items.IOverrideTestsItem#getImage()
153: */
154: public Image getImage() {
155: return PlatformUI.getWorkbench().getSharedImages().getImage(
156: ISharedImages.IMG_OBJS_INFO_TSK);
157: }
158:
159: /*
160: * (non-Javadoc)
161: *
162: * @see org.eclipse.ui.tests.views.properties.tabbed.override.items.IOverrideTestsItem#getText()
163: */
164: public String getText() {
165: return "Information"; //$NON-NLS-1$
166: }
167: }
|