(no commit message)
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / FormView.java
1 package eu.etaxonomy.taxeditor;
2
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;
28
29 public class FormView extends ViewPart {
30 private FormToolkit toolkit;
31 // private Form form;
32 private ScrolledForm form;
33 private ScrolledPropertiesBlock block;
34
35 public static final String ID = "eu.etaxonomy.taxeditor.formview";
36
37 /**
38 * The constructor.
39 */
40 public FormView() {
41 /*block = new ScrolledPropertiesBlock();*/
42 }
43
44 /**
45 * This is a callback that will allow us to create the viewer and initialize
46 * it.
47 */
48 public void createPartControl(Composite parent) {
49
50 toolkit = new FormToolkit(parent.getDisplay());
51 Composite container = toolkit.createComposite(parent, SWT.NONE);
52 container.setLayout(new FillLayout());
53 toolkit.paintBordersFor(container);
54
55 ScrolledForm form = toolkit.createScrolledForm(container);
56 form.getBody().setLayout(new FillLayout());
57 form.setText("MasterDetailsBlock example form");
58
59 ManagedForm mform = new ManagedForm(toolkit, form) ;
60
61 /*ScrolledPropertiesBlock block = new ScrolledPropertiesBlock();
62 block.createContent(mform);*/
63
64 //
65 /*createActions();
66 initializeToolBar();
67 initializeMenu();*/
68
69
70 /*toolkit = new FormToolkit(parent.getDisplay());
71 form = toolkit.createScrolledForm(parent);*/
72
73 /* TableWrapData td = new TableWrapData();
74 Section section = toolkit.createSection(form.getBody(),
75 Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE
76 | Section.EXPANDED);
77 td = new TableWrapData(TableWrapData.FILL);
78 td.colspan = 2;
79 section.setLayoutData(td);
80 section.addExpansionListener(new ExpansionAdapter() {
81 public void expansionStateChanged(ExpansionEvent e) {
82 form.reflow(true);
83 }
84 });
85 section.setText("Section title");
86 section.setDescription("This is the description that goes "
87 + "below the title");
88 Composite sectionClient = toolkit.createComposite(section);
89 sectionClient.setLayout(new GridLayout());
90 section.setClient(sectionClient);
91 */
92
93 /*Label label = toolkit.createLabel(form.getBody(), "Text field label:");
94 final Text text = toolkit.createText(form.getBody(), "");
95 text.setText("value");*/
96 /*
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";
104
105 TableWrapLayout layout = new TableWrapLayout();
106 form.getBody().setLayout(layout);
107 final Integer j = 1;
108 for (int i = 0; i < 5; i++) {
109 Hyperlink link = toolkit.createHyperlink(form.getBody(), names[i],
110 SWT.WRAP);
111 /*j = (Integer)i;
112 link.addHyperlinkListener(new HyperlinkAdapter() {
113
114 public void linkActivated(HyperlinkEvent e) {
115 text.setText(Integer.toString(j));
116 }
117 });
118 }*/
119
120 /*
121
122
123 final Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
124 SWT.WRAP);
125
126 layout.numColumns = 2;
127 TableWrapData td = new TableWrapData();
128 td.colspan = 2;
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");
133
134 final int tester = 2;
135
136 link.addHyperlinkListener(new HyperlinkAdapter() {
137
138 public void linkActivated(HyperlinkEvent e) {
139 text.setText(Integer.toString(tester));
140 }
141 });
142 */
143 /*
144 toolkit = new FormToolkit(parent.getDisplay());
145 form = toolkit.createScrolledForm(parent); // .createForm(parent); //
146 // alternate:
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.",
153 SWT.WRAP);
154 link.addHyperlinkListener(new HyperlinkAdapter() {
155 public void linkActivated(HyperlinkEvent e) {
156 System.out.println("Link activated!");
157 }
158 });
159 link.setText("This is an example of a form that is much longer "
160 + "and will need to wrap.");
161
162 layout.numColumns = 2;
163 TableWrapData td = new TableWrapData();
164 td.colspan = 2;
165 link.setLayoutData(td);
166
167 Label label = toolkit.createLabel(form.getBody(), "Text field label:");
168 Text text = toolkit.createText(form.getBody(), "");
169
170 td = new TableWrapData(TableWrapData.FILL_GRAB);
171 text.setLayoutData(td);
172
173 Button button = toolkit.createButton(form.getBody(),
174 "A checkbox in a form", SWT.CHECK);
175 td = new TableWrapData();
176 td.colspan = 2;
177 button.setLayoutData(td);
178
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 "
186 + "toggle control";
187 Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);
188 ec.setClient(client);
189 td = new TableWrapData();
190 td.colspan = 2;
191 ec.setLayoutData(td);
192 ec.addExpansionListener(new ExpansionAdapter() {
193 public void expansionStateChanged(ExpansionEvent e) {
194 form.reflow(true);
195 }
196 });
197
198 Section section = toolkit.createSection(form.getBody(),
199 Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE
200 | Section.EXPANDED);
201 td = new TableWrapData(TableWrapData.FILL);
202 td.colspan = 2;
203 section.setLayoutData(td);
204 section.addExpansionListener(new ExpansionAdapter() {
205 public void expansionStateChanged(ExpansionEvent e) {
206 form.reflow(true);
207 }
208 });
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);
217
218 StringBuffer buf = new StringBuffer();
219 buf.append("<form>");
220 buf.append("<p>");
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.");
224 buf.append("</p>");
225 buf.append("<p>");
226 buf.append("<span color=\"header\" font=\"header\">"
227 + "This text is in header font and color.</span>");
228 buf.append("</p>");
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. ");
232 buf.append("</p>");
233 buf.append("<li>A default (bulleted) list item.</li>");
234 buf.append("<li>Another bullet list item.</li>");
235 buf
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>");
241 buf
242 .append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"3.\">"
243 + "A list item with text.</li>");
244 buf
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);
253 td.colspan = 2;
254 formText.setLayoutData(td);
255
256 formText.setColor("header", toolkit.getColors().getColor(
257 FormColors.TITLE));
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());
264 }
265 });
266 */
267
268 /* colspan, rowspan demo */
269 /*
270 * TableWrapLayout layout = new TableWrapLayout(); toolkit = new
271 * FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); //
272 * alternate: createScrolledForm form.getBody().setLayout(layout);
273 *
274 * layout.numColumns = 3; Label label; TableWrapData td;
275 *
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));
300 */
301 }
302
303 /**
304 * Passing the focus request to the form.
305 */
306 public void setFocus() {
307 form.setFocus();
308 }
309
310 /**
311 * Disposes the toolkit
312 */
313 public void dispose() {
314 toolkit.dispose();
315 super.dispose();
316 }
317 }