KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > eclipse > mapper > views > FormView


1 package org.hibernate.eclipse.mapper.views;
2
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Button;
5 import org.eclipse.swt.widgets.Composite;
6 import org.eclipse.swt.widgets.Label;
7 import org.eclipse.swt.widgets.Text;
8 import org.eclipse.ui.forms.events.HyperlinkAdapter;
9 import org.eclipse.ui.forms.events.HyperlinkEvent;
10 import org.eclipse.ui.forms.widgets.FormToolkit;
11 import org.eclipse.ui.forms.widgets.Hyperlink;
12 import org.eclipse.ui.forms.widgets.ScrolledForm;
13 import org.eclipse.ui.forms.widgets.TableWrapData;
14 import org.eclipse.ui.forms.widgets.TableWrapLayout;
15 import org.eclipse.ui.part.ViewPart;
16
17 public class FormView extends ViewPart {
18     private FormToolkit toolkit;
19
20     private ScrolledForm form;
21
22     /**
23      * This is a callback that will allow us to create the viewer and initialize
24      * it.
25      */

26     public void createPartControl(Composite parent) {
27         toolkit = new FormToolkit(parent.getDisplay());
28         form = toolkit.createScrolledForm(parent);
29         // form.setAlwaysShowScrollBars(true);
30
form.setText("Hello, Eclipse Forms");
31         TableWrapLayout layout = new TableWrapLayout();
32         form.getBody().setLayout(layout);
33         Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
34                 SWT.WRAP);
35         link.addHyperlinkListener(new HyperlinkAdapter() {
36             public void linkActivated(HyperlinkEvent e) {
37                 System.out.println("Link activated!");
38             }
39         });
40         link
41                 .setText("This is an example of a form that is much longer and will need to wrap.");
42         layout.numColumns = 2;
43         TableWrapData td = new TableWrapData();
44         td.colspan = 2;
45         link.setLayoutData(td);
46         Label label = toolkit.createLabel(form.getBody(), "Text field label:");
47         Text text = toolkit.createText(form.getBody(), "");
48         td = new TableWrapData(TableWrapData.FILL_GRAB);
49         text.setLayoutData(td);
50         Button button = toolkit.createButton(form.getBody(),
51                 "An example of a checkbox in a form", SWT.CHECK);
52         td = new TableWrapData();
53         td.colspan = 2;
54         button.setLayoutData(td);
55
56         layout.numColumns = 3;
57
58         label = toolkit.createLabel(form.getBody(),
59                 "Some text to put in the first column", SWT.WRAP);
60         label = toolkit
61                 .createLabel(
62                         form.getBody(),
63                         "Some text to put in the second column and make it a bit longer so that we can see what happens with column distribution. This text must be the longest so that it can get more space allocated to the columns it belongs to.",
64                         SWT.WRAP);
65         td = new TableWrapData();
66         td.colspan = 2;
67         label.setLayoutData(td);
68         label = toolkit.createLabel(form.getBody(),
69                 "This text will span two rows and should not grow the column.",
70                 SWT.WRAP);
71         td = new TableWrapData();
72         td.rowspan = 2;
73         label.setLayoutData(td);
74         label = toolkit.createLabel(form.getBody(),
75                 "This text goes into column 2 and consumes only one cell",
76                 SWT.WRAP);
77         label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
78         label = toolkit.createLabel(form.getBody(),
79                 "This text goes into column 3 and consumes only one cell too",
80                 SWT.WRAP);
81         label.setLayoutData(new TableWrapData(TableWrapData.FILL));
82         label = toolkit.createLabel(form.getBody(),
83                 "This text goes into column 2 and consumes only one cell",
84                 SWT.WRAP);
85         label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
86         label = toolkit.createLabel(form.getBody(),
87                 "This text goes into column 3 and consumes only one cell too",
88                 SWT.WRAP);
89         label.setLayoutData(new TableWrapData(TableWrapData.FILL));
90         form.getBody().setBackground(
91                 form.getBody().getDisplay().getSystemColor(
92                         SWT.COLOR_WIDGET_BACKGROUND));
93     }
94
95     /**
96      * Passing the focus request to the form.
97      */

98     public void setFocus() {
99         form.setFocus();
100     }
101
102     /**
103      * Disposes the toolkit.
104      */

105     public void dispose() {
106         toolkit.dispose();
107         super.dispose();
108     }
109 }
Popular Tags