1 package eu
.etaxonomy
.taxeditor
;
3 import org
.eclipse
.jface
.resource
.JFaceResources
;
4 import org
.eclipse
.swt
.SWT
;
5 import org
.eclipse
.swt
.layout
.FillLayout
;
6 import org
.eclipse
.swt
.layout
.GridData
;
7 import org
.eclipse
.swt
.layout
.GridLayout
;
8 import org
.eclipse
.swt
.widgets
.Button
;
9 import org
.eclipse
.swt
.widgets
.Composite
;
10 import org
.eclipse
.swt
.widgets
.Label
;
11 import org
.eclipse
.swt
.widgets
.Text
;
12 import org
.eclipse
.ui
.forms
.FormColors
;
13 import org
.eclipse
.ui
.forms
.ManagedForm
;
14 import org
.eclipse
.ui
.forms
.events
.ExpansionAdapter
;
15 import org
.eclipse
.ui
.forms
.events
.ExpansionEvent
;
16 import org
.eclipse
.ui
.forms
.events
.HyperlinkAdapter
;
17 import org
.eclipse
.ui
.forms
.events
.HyperlinkEvent
;
18 import org
.eclipse
.ui
.forms
.widgets
.ExpandableComposite
;
19 import org
.eclipse
.ui
.forms
.widgets
.Form
;
20 import org
.eclipse
.ui
.forms
.widgets
.FormText
;
21 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
22 import org
.eclipse
.ui
.forms
.widgets
.Hyperlink
;
23 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
24 import org
.eclipse
.ui
.forms
.widgets
.Section
;
25 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
26 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
27 import org
.eclipse
.ui
.part
.ViewPart
;
29 public class FormView
extends ViewPart
{
30 private FormToolkit toolkit
;
32 private ScrolledForm form
;
33 private ScrolledPropertiesBlock block
;
35 public static final String ID
= "eu.etaxonomy.taxeditor.formview";
41 /*block = new ScrolledPropertiesBlock();*/
45 * This is a callback that will allow us to create the viewer and initialize
48 public void createPartControl(Composite parent
) {
50 toolkit
= new FormToolkit(parent
.getDisplay());
51 Composite container
= toolkit
.createComposite(parent
, SWT
.NONE
);
52 container
.setLayout(new FillLayout());
53 toolkit
.paintBordersFor(container
);
55 ScrolledForm form
= toolkit
.createScrolledForm(container
);
56 form
.getBody().setLayout(new FillLayout());
57 form
.setText("MasterDetailsBlock example form");
59 ManagedForm mform
= new ManagedForm(toolkit
, form
) ;
61 /*ScrolledPropertiesBlock block = new ScrolledPropertiesBlock();
62 block.createContent(mform);*/
70 /*toolkit = new FormToolkit(parent.getDisplay());
71 form = toolkit.createScrolledForm(parent);*/
73 /* TableWrapData td = new TableWrapData();
74 Section section = toolkit.createSection(form.getBody(),
75 Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE
77 td = new TableWrapData(TableWrapData.FILL);
79 section.setLayoutData(td);
80 section.addExpansionListener(new ExpansionAdapter() {
81 public void expansionStateChanged(ExpansionEvent e) {
85 section.setText("Section title");
86 section.setDescription("This is the description that goes "
88 Composite sectionClient = toolkit.createComposite(section);
89 sectionClient.setLayout(new GridLayout());
90 section.setClient(sectionClient);
93 /*Label label = toolkit.createLabel(form.getBody(), "Text field label:");
94 final Text text = toolkit.createText(form.getBody(), "");
95 text.setText("value");*/
97 final String[] names = new String[6];
98 names[0] = "Pilosella piloselloides (Vill.) Soják subsp. piloselloides";
99 names[1] = "Pilosella piloselloides subsp. bauhinii (Schult.) S. Bräut. & Greuter";
100 names[2] = "Pilosella piloselloides subsp. floccosa (Nägeli & Peter) S. Bräut. & Greuter";
101 names[3] = "Pilosella piloselloides subsp. magyarica (Peter) S. Bräut. & Greuter";
102 names[4] = "Pilosella piloselloides subsp. praealta (Gochnat) S. Bräut. & Greuter";
103 names[5] = "Pilosella piloselloides subsp. rubrobauhinii (Schelk. & Zahn) S. Bräut. & Greuter";
105 TableWrapLayout layout = new TableWrapLayout();
106 form.getBody().setLayout(layout);
108 for (int i = 0; i < 5; i++) {
109 Hyperlink link = toolkit.createHyperlink(form.getBody(), names[i],
112 link.addHyperlinkListener(new HyperlinkAdapter() {
114 public void linkActivated(HyperlinkEvent e) {
115 text.setText(Integer.toString(j));
123 final Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
126 layout.numColumns = 2;
127 TableWrapData td = new TableWrapData();
129 link.setLayoutData(td);
130 Label label = toolkit.createLabel(form.getBody(), "Text field label:");
131 final Text text = toolkit.createText(form.getBody(), "");
132 text.setText("value");
134 final int tester = 2;
136 link.addHyperlinkListener(new HyperlinkAdapter() {
138 public void linkActivated(HyperlinkEvent e) {
139 text.setText(Integer.toString(tester));
144 toolkit = new FormToolkit(parent.getDisplay());
145 form = toolkit.createScrolledForm(parent); // .createForm(parent); //
147 // createScrolledForm
148 form.setText("Hello, Eclipse Forms");
149 TableWrapLayout layout = new TableWrapLayout();
150 // GridLayout layout = new GridLayout();
151 form.getBody().setLayout(layout);
152 Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
154 link.addHyperlinkListener(new HyperlinkAdapter() {
155 public void linkActivated(HyperlinkEvent e) {
156 System.out.println("Link activated!");
159 link.setText("This is an example of a form that is much longer "
160 + "and will need to wrap.");
162 layout.numColumns = 2;
163 TableWrapData td = new TableWrapData();
165 link.setLayoutData(td);
167 Label label = toolkit.createLabel(form.getBody(), "Text field label:");
168 Text text = toolkit.createText(form.getBody(), "");
170 td = new TableWrapData(TableWrapData.FILL_GRAB);
171 text.setLayoutData(td);
173 Button button = toolkit.createButton(form.getBody(),
174 "A checkbox in a form", SWT.CHECK);
175 td = new TableWrapData();
177 button.setLayoutData(td);
179 ExpandableComposite ec = toolkit.createExpandableComposite(form
180 .getBody(), ExpandableComposite.TREE_NODE
181 | ExpandableComposite.CLIENT_INDENT);
182 ec.setText("Expandable Composite title");
183 String ctext = "We will now create a somewhat long text so that "
184 + "we can use it as content for the expandable composite. "
185 + "Expandable composite is used to hide or show the text using the "
187 Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);
188 ec.setClient(client);
189 td = new TableWrapData();
191 ec.setLayoutData(td);
192 ec.addExpansionListener(new ExpansionAdapter() {
193 public void expansionStateChanged(ExpansionEvent e) {
198 Section section = toolkit.createSection(form.getBody(),
199 Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE
201 td = new TableWrapData(TableWrapData.FILL);
203 section.setLayoutData(td);
204 section.addExpansionListener(new ExpansionAdapter() {
205 public void expansionStateChanged(ExpansionEvent e) {
209 section.setText("Section title");
210 section.setDescription("This is the description that goes "
211 + "below the title");
212 Composite sectionClient = toolkit.createComposite(section);
213 sectionClient.setLayout(new GridLayout());
214 button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);
215 button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);
216 section.setClient(sectionClient);
218 StringBuffer buf = new StringBuffer();
219 buf.append("<form>");
221 buf.append("Here is some plain text for the text to render; ");
222 buf.append("this text is at <a href=\"http://www.eclipse.org\" "
223 + "nowrap=\"true\">http://www.eclipse.org</a> web site.");
226 buf.append("<span color=\"header\" font=\"header\">"
227 + "This text is in header font and color.</span>");
229 buf.append("<p>This line will contain some <b>bold</b> and "
230 + "some <span font=\"code\">source</span> text. ");
231 buf.append("We can also add <img href=\"image\"/> an image. ");
233 buf.append("<li>A default (bulleted) list item.</li>");
234 buf.append("<li>Another bullet list item.</li>");
236 .append("<li style=\"text\" value=\"1.\">A list item with text.</li>");
237 buf.append("<li style=\"text\" value=\"2.\">Another list "
238 + "item with text</li>");
239 buf.append("<li style=\"image\" value=\"image\">List item with "
240 + "an image bullet</li>");
242 .append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"3.\">"
243 + "A list item with text.</li>");
245 .append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"4.\">"
246 + "A list item with text.</li>");
247 buf.append("<p> leading blanks; more white \n\n new "
248 + "lines <br/> \n more <b> bb </b> white . </p>");
249 buf.append("</form>");
250 FormText formText = toolkit.createFormText(form.getBody(), true);
251 formText.setWhitespaceNormalized(true);
252 td = new TableWrapData(TableWrapData.FILL);
254 formText.setLayoutData(td);
256 formText.setColor("header", toolkit.getColors().getColor(
258 formText.setFont("header", JFaceResources.getHeaderFont());
259 formText.setFont("code", JFaceResources.getTextFont());
260 formText.setText(buf.toString(), true, false);
261 formText.addHyperlinkListener(new HyperlinkAdapter() {
262 public void linkActivated(HyperlinkEvent e) {
263 System.out.println("Link active: " + e.getHref());
268 /* colspan, rowspan demo */
270 * TableWrapLayout layout = new TableWrapLayout(); toolkit = new
271 * FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); //
272 * alternate: createScrolledForm form.getBody().setLayout(layout);
274 * layout.numColumns = 3; Label label; TableWrapData td;
276 * label = toolkit.createLabel(form.getBody(), "Some text to put in the
277 * first column", SWT.WRAP); label = toolkit.createLabel(form.getBody(),
278 * "Some text to put in the second column and make it a bit "+ "longer
279 * so that we can see what happens with column "+ "distribution. This
280 * text must be the longest so that it can "+ "get more space allocated
281 * to the columns it belongs to.", SWT.WRAP); td = new TableWrapData();
282 * td.colspan = 2; label.setLayoutData(td); label =
283 * toolkit.createLabel(form.getBody(), "This text will span two rows and
284 * should not grow the column.", SWT.WRAP); td = new TableWrapData();
285 * td.rowspan = 2; label.setLayoutData(td); label =
286 * toolkit.createLabel(form.getBody(), "This text goes into column 2 and
287 * consumes only one cell", SWT.WRAP); label.setLayoutData(new
288 * TableWrapData(TableWrapData.FILL_GRAB)); label =
289 * toolkit.createLabel(form.getBody(), "This text goes into column 3 and
290 * consumes only one cell too", SWT.WRAP); label.setLayoutData(new
291 * TableWrapData(TableWrapData.FILL)); label =
292 * toolkit.createLabel(form.getBody(), "This text goes into column 2 and
293 * consumes only one cell", SWT.WRAP); label.setLayoutData(new
294 * TableWrapData(TableWrapData.FILL_GRAB)); label =
295 * toolkit.createLabel(form.getBody(), "This text goes into column 3 and
296 * consumes only one cell too", SWT.WRAP); label.setLayoutData(new
297 * TableWrapData(TableWrapData.FILL));
298 * form.getBody().setBackground(form.getBody().getDisplay().
299 * getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
304 * Passing the focus request to the form.
306 public void setFocus() {
311 * Disposes the toolkit
313 public void dispose() {