2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.demo
.i18n
.editors
;
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
;
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
43 public class MultiSectionPage
extends FormPage
{
44 // private final static Log log = LogFactory.getLog(MultiSectionPage.class);
46 // this page UI components
47 private FormToolkit tk
;
49 public MultiSectionPage(FormEditor editor
, String title
) {
50 super(editor
, "MultiSectionPage", title
);
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();
61 createDetailsSection(form
.getBody());
62 createDescriptionSection(form
.getBody());
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
);
72 Composite body
= tk
.createComposite(section
, SWT
.FILL
);
73 // WARNING : 2 following lines are compulsory or body won't be
75 body
.setLayout(new GridLayout());
76 section
.setClient(body
);
78 body
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
79 section
.setExpanded(true);
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
);
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(),
101 mb
.setText(I18nDemoMessages
.get().MultiSectionPage_PopupTitle
);
103 mb
.setMessage(I18nDemoMessages
.get().MultiSectionPage_PopupText
);
109 protected void createDetailsSection(Composite parent
) {
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
);
117 // Set title of the section
118 section
.setText(I18nDemoMessages
.get().MultiSectionPage_DetailsSectionTitle
);
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);
125 .setText(I18nDemoMessages
.get().MultiSectionPage_DescriptionSectionTxt
);
126 section
.setExpanded(false);
128 section
.setClient(styledText
);
130 AbstractFormPart part
= new AbstractFormPart() {
131 public void commit(boolean onSave
) {
134 public void refresh() {
138 getManagedForm().addPart(part
);
142 public void setActive(boolean active
) {
143 super.setActive(active
);