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