]> git.argeo.org Git - lgpl/argeo-commons.git/blob - MultiSectionPage.java
7e12e85b81a0e368b397ac12c8c1c0f23cbd6bd6
[lgpl/argeo-commons.git] / MultiSectionPage.java
1 package org.argeo.demo.i18n.editors;
2
3 import org.argeo.demo.i18n.I18nDemoMessages;
4 import org.argeo.demo.i18n.I18nDemoPlugin;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.events.SelectionAdapter;
7 import org.eclipse.swt.events.SelectionEvent;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.widgets.Button;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.MessageBox;
13 import org.eclipse.swt.widgets.Text;
14 import org.eclipse.ui.forms.AbstractFormPart;
15 import org.eclipse.ui.forms.IManagedForm;
16 import org.eclipse.ui.forms.editor.FormEditor;
17 import org.eclipse.ui.forms.editor.FormPage;
18 import org.eclipse.ui.forms.widgets.FormToolkit;
19 import org.eclipse.ui.forms.widgets.ScrolledForm;
20 import org.eclipse.ui.forms.widgets.Section;
21 import org.eclipse.ui.forms.widgets.TableWrapData;
22
23 /**
24 * Offers two main sections : one to display a text area with a summary of all
25 * variations between a version and its predecessor and one tree view that
26 * enable browsing
27 * */
28 public class MultiSectionPage extends FormPage {
29 // private final static Log log = LogFactory.getLog(MultiSectionPage.class);
30
31 // this page UI components
32 private FormToolkit tk;
33
34 public MultiSectionPage(FormEditor editor, String title) {
35 super(editor, "MultiSectionPage", title);
36 }
37
38 protected void createFormContent(IManagedForm managedForm) {
39 ScrolledForm form = managedForm.getForm();
40 tk = managedForm.getToolkit();
41 GridLayout twt = new GridLayout(1, false);
42 twt.marginWidth = twt.marginHeight = 5;
43 Composite body = form.getBody();
44 body.setLayout(twt);
45
46 createDetailsSection(form.getBody());
47 createDescriptionSection(form.getBody());
48 }
49
50 protected void createDescriptionSection(Composite parent) {
51 // Section Layout & MetaData
52 Section section = tk.createSection(parent, Section.TWISTIE);
53 section.setLayoutData(new GridData(GridData.FILL_BOTH));
54 section.setText(I18nDemoMessages.get().MultiSectionPage_DescriptionSectionTitle);
55
56 // Section Body
57 Composite body = tk.createComposite(section, SWT.FILL);
58 // WARNING : 2 following lines are compulsory or body won't be
59 // displayed.
60 body.setLayout(new GridLayout());
61 section.setClient(body);
62
63 body.setLayoutData(new GridData(GridData.FILL_BOTH));
64 section.setExpanded(true);
65
66 // button line
67 Button b1 = new Button(body, SWT.PUSH | SWT.FILL);
68 b1.setText(I18nDemoMessages.get().MultiSectionPage_Btn1Lbl);
69 Button b2 = new Button(body, SWT.PUSH | SWT.FILL);
70 b2.setText(I18nDemoMessages.get().MultiSectionPage_Btn2Lbl);
71 Button b3 = new Button(body, SWT.PUSH | SWT.FILL);
72 b3.setText(I18nDemoMessages.get().MultiSectionPage_Btn3Lbl);
73
74 addAListener(b1);
75 addAListener(b2);
76 addAListener(b3);
77 }
78
79 private void addAListener(Button b) {
80 b.addSelectionListener(new SelectionAdapter() {
81 public void widgetSelected(SelectionEvent e) {
82 MessageBox mb = new MessageBox(I18nDemoPlugin.getDefault()
83 .getWorkbench().getActiveWorkbenchWindow().getShell(),
84 SWT.OK);
85 // Title
86 mb.setText(I18nDemoMessages.get().MultiSectionPage_PopupTitle);
87 // Message
88 mb.setMessage(I18nDemoMessages.get().MultiSectionPage_PopupText);
89 mb.open();
90 }
91 });
92 }
93
94 protected void createDetailsSection(Composite parent) {
95
96 // Section Layout
97 Section section = tk.createSection(parent, Section.TWISTIE);
98 section.setLayoutData(new GridData(TableWrapData.FILL_GRAB));
99 GridLayout gd = new GridLayout();
100 section.setLayout(gd);
101
102 // Set title of the section
103 section.setText(I18nDemoMessages.get().MultiSectionPage_DetailsSectionTitle);
104
105 final Text styledText = tk.createText(section, "", SWT.FULL_SELECTION
106 | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
107 styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
108 styledText.setEditable(false);
109 styledText
110 .setText(I18nDemoMessages.get().MultiSectionPage_DescriptionSectionTxt);
111 section.setExpanded(false);
112
113 section.setClient(styledText);
114
115 AbstractFormPart part = new AbstractFormPart() {
116 public void commit(boolean onSave) {
117 }
118
119 public void refresh() {
120 super.refresh();
121 }
122 };
123 getManagedForm().addPart(part);
124 }
125
126 @Override
127 public void setActive(boolean active) {
128 super.setActive(active);
129 }
130 }