001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.forms.examples.internal.rcp;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.layout.*;
014: import org.eclipse.swt.widgets.*;
015: import org.eclipse.ui.forms.IManagedForm;
016: import org.eclipse.ui.forms.editor.*;
017: import org.eclipse.ui.forms.events.*;
018: import org.eclipse.ui.forms.widgets.*;
019:
020: /**
021: * @author dejan
022: *
023: * To change the template for this generated type comment go to Window -
024: * Preferences - Java - Code Generation - Code and Comments
025: */
026: public class ThirdPage extends FormPage {
027: /**
028: * @param id
029: * @param title
030: */
031: public ThirdPage(FormEditor editor) {
032: super (editor, "third", "Flow Page");
033: }
034:
035: protected void createFormContent(IManagedForm managedForm) {
036: ScrolledForm form = managedForm.getForm();
037: //FormToolkit toolkit = managedForm.getToolkit();
038: form.setText("Form with wrapped controls");
039: ColumnLayout layout = new ColumnLayout();
040: layout.topMargin = 0;
041: layout.bottomMargin = 5;
042: layout.leftMargin = 10;
043: layout.rightMargin = 10;
044: layout.horizontalSpacing = 10;
045: layout.verticalSpacing = 10;
046: layout.maxNumColumns = 4;
047: layout.minNumColumns = 1;
048: form.getBody().setLayout(layout);
049: //form.getBody().setBackground(
050: // form.getBody().getDisplay().getSystemColor(SWT.COLOR_GREEN));
051: createSectionWithLinks(managedForm, "Link Section",
052: "An example of a section with links", 2);
053: createSectionWithLinks(managedForm, "Link Section",
054: "An example of a section with links", 2);
055: createMixedSection(managedForm, "Mixed Section",
056: "An example of a section with both links and form controls");
057: createSectionWithLinks(managedForm, "Link Section",
058: "An example of a section with links", 4);
059: createSectionWithControls(managedForm, "Control Section",
060: "An example of a section with form controls");
061: createSectionWithLinks(managedForm, "Sample Section",
062: "An example of a section with links", 3);
063: createSectionWithLinks(managedForm, "Sample Section",
064: "An example of a section with links", 5);
065: createMixedSection(managedForm, "Mixed Section",
066: "An example of a section with both links and form controls");
067: createSectionWithLinks(managedForm, "Sample Section",
068: "An example of a section with links", 2);
069: createSectionWithControls(managedForm, "Control Section",
070: "An example of a section with links");
071: createSectionWithLinks(managedForm, "Sample Section",
072: "An example of a section with links", 4);
073: createSectionWithLinks(managedForm, "Sample Section",
074: "An example of a section with links", 2);
075: createMixedSection(managedForm, "Mixed Section",
076: "An example of a section with both links and form controls");
077: createSectionWithLinks(managedForm, "Sample Section",
078: "An example of a section with links", 2);
079: createSectionWithControls(managedForm, "Control Section",
080: "An example of a section with form controls");
081: }
082:
083: private void createSectionWithLinks(IManagedForm mform,
084: String title, String desc, int nlinks) {
085: Composite client = createSection(mform, title, desc, 1);
086: FormToolkit toolkit = mform.getToolkit();
087: for (int i = 1; i <= nlinks; i++)
088: toolkit.createHyperlink(client, "Hyperlink text " + i,
089: SWT.WRAP);
090: }
091:
092: private void createSectionWithControls(IManagedForm mform,
093: String title, String desc) {
094: Composite client = createSection(mform, title, desc, 1);
095: FormToolkit toolkit = mform.getToolkit();
096: toolkit.createButton(client, "A radio button 1", SWT.RADIO);
097: toolkit.createButton(client, "A radio button 2", SWT.RADIO);
098: toolkit.createButton(client,
099: "A radio button with a longer text", SWT.RADIO);
100: toolkit.createButton(client, "A checkbox button", SWT.CHECK);
101: }
102:
103: private void createMixedSection(IManagedForm mform, String title,
104: String desc) {
105: Composite client = createSection(mform, title, desc, 2);
106: FormToolkit toolkit = mform.getToolkit();
107: Hyperlink link = toolkit.createHyperlink(client,
108: "A longer hyperlink text example", SWT.WRAP);
109: GridData gd = new GridData();
110: gd.horizontalSpan = 2;
111: link.setLayoutData(gd);
112: link = toolkit.createHyperlink(client,
113: "Another hyperlink text", SWT.WRAP);
114: gd = new GridData();
115: gd.horizontalSpan = 2;
116: link.setLayoutData(gd);
117: toolkit.createLabel(client, "A text label:");
118: Text text = toolkit.createText(client, "", SWT.SINGLE);
119: text.setText("Sample text");
120: text.setEnabled(false);
121: gd = new GridData();
122: gd.widthHint = 150;
123: text.setLayoutData(gd);
124: toolkit.paintBordersFor(client);
125: }
126:
127: private Composite createSection(IManagedForm mform, String title,
128: String desc, int numColumns) {
129: final ScrolledForm form = mform.getForm();
130: FormToolkit toolkit = mform.getToolkit();
131: Section section = toolkit.createSection(form.getBody(),
132: Section.TWISTIE | Section.SHORT_TITLE_BAR
133: | Section.DESCRIPTION | Section.EXPANDED);
134: section.setText(title);
135: section.setDescription(desc);
136: Composite client = toolkit.createComposite(section);
137: GridLayout layout = new GridLayout();
138: layout.marginWidth = layout.marginHeight = 0;
139: layout.numColumns = numColumns;
140: client.setLayout(layout);
141: section.setClient(client);
142: section.addExpansionListener(new ExpansionAdapter() {
143: public void expansionStateChanged(ExpansionEvent e) {
144: form.reflow(false);
145: }
146: });
147: return client;
148: }
149: }
|