1 package org
.argeo
.cms
.ui
.dialogs
;
3 import java
.lang
.reflect
.InvocationTargetException
;
5 import org
.argeo
.cms
.CmsException
;
6 import org
.argeo
.cms
.util
.CmsUtils
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
8 import org
.argeo
.eclipse
.ui
.Selected
;
9 import org
.argeo
.eclipse
.ui
.dialogs
.LightweightDialog
;
10 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
11 import org
.eclipse
.jface
.wizard
.IWizard
;
12 import org
.eclipse
.jface
.wizard
.IWizardContainer2
;
13 import org
.eclipse
.jface
.wizard
.IWizardPage
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Button
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Label
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
23 public class CmsWizardDialog
extends LightweightDialog
implements IWizardContainer2
{
24 private static final long serialVersionUID
= -2123153353654812154L;
26 private IWizard wizard
;
27 private IWizardPage currentPage
;
29 private Label titleBar
;
30 private Label message
;
31 private Composite body
;
32 private Composite buttons
;
35 private Button finish
;
37 public CmsWizardDialog(Shell parentShell
, IWizard wizard
) {
40 wizard
.setContainer(this);
43 currentPage
= wizard
.getStartingPage();
44 if (currentPage
== null)
45 throw new CmsException("At least one wizard page is required");
49 protected Control
createDialogArea(Composite parent
) {
52 Composite messageArea
= new Composite(parent
, SWT
.NONE
);
53 messageArea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
55 messageArea
.setLayout(CmsUtils
.noSpaceGridLayout(new GridLayout(2, false)));
56 titleBar
= new Label(messageArea
, SWT
.WRAP
);
57 titleBar
.setFont(EclipseUiUtils
.getBoldFont(parent
));
58 titleBar
.setLayoutData(new GridData(SWT
.BEGINNING
, SWT
.FILL
, true, false));
60 Button cancelButton
= new Button(messageArea
, SWT
.FLAT
);
61 cancelButton
.setText("Cancel");
62 cancelButton
.setLayoutData(new GridData(SWT
.END
, SWT
.TOP
, false, false, 1, 3));
63 cancelButton
.addSelectionListener((Selected
) (e
) -> closeShell(CANCEL
));
64 message
= new Label(messageArea
, SWT
.WRAP
);
65 message
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 1, 2));
69 body
= new Composite(parent
, SWT
.BORDER
);
70 body
.setLayout(CmsUtils
.noSpaceGridLayout());
71 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
72 showPage(currentPage
);
74 buttons
= new Composite(parent
, SWT
.NONE
);
75 buttons
.setLayoutData(new GridData(SWT
.END
, SWT
.FILL
, true, false));
77 boolean singlePage
= wizard
.getPageCount() == 1;
78 // singlePage = false;// dev
79 GridLayout layout
= new GridLayout(singlePage ?
1 : 3, true);
80 layout
.marginWidth
= 0;
81 layout
.marginHeight
= 0;
82 buttons
.setLayout(layout
);
83 // TODO revert order for right-to-left languages
86 back
= new Button(buttons
, SWT
.PUSH
);
88 back
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
89 back
.addSelectionListener((Selected
) (e
) -> backPressed());
91 next
= new Button(buttons
, SWT
.PUSH
);
93 next
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
94 next
.addSelectionListener((Selected
) (e
) -> nextPressed());
96 finish
= new Button(buttons
, SWT
.PUSH
);
97 finish
.setText("Finish");
98 finish
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
99 finish
.addSelectionListener((Selected
) (e
) -> finishPressed());
107 public IWizardPage
getCurrentPage() {
112 public Shell
getShell() {
113 return getForegoundShell();
117 public void showPage(IWizardPage page
) {
119 for (Control c
: body
.getChildren())
121 page
.createControl(body
);
126 public void updateButtons() {
128 back
.setEnabled(wizard
.getPreviousPage(currentPage
) != null);
130 next
.setEnabled(wizard
.getNextPage(currentPage
) != null && currentPage
.canFlipToNextPage());
131 finish
.setEnabled(wizard
.canFinish());
135 public void updateMessage() {
136 if (currentPage
.getMessage() != null)
137 message
.setText(currentPage
.getMessage());
141 public void updateTitleBar() {
142 if (currentPage
.getTitle() != null)
143 titleBar
.setText(currentPage
.getTitle());
147 public void updateWindowTitle() {
148 setTitle(wizard
.getWindowTitle());
152 public void run(boolean fork
, boolean cancelable
, IRunnableWithProgress runnable
)
153 throws InvocationTargetException
, InterruptedException
{
158 public void updateSize() {
162 protected boolean onCancel() {
163 return wizard
.performCancel();
166 protected void nextPressed() {
167 IWizardPage page
= wizard
.getNextPage(currentPage
);
171 protected void backPressed() {
172 IWizardPage page
= wizard
.getPreviousPage(currentPage
);
176 protected void finishPressed() {
177 if (wizard
.performFinish())