Commit | Line | Data |
---|---|---|
c8422608 | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
c8422608 AM |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM - Initial API and implementation | |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 BH |
11 | **********************************************************************/ |
12 | ||
df0b8ff4 | 13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs; |
73005152 BH |
14 | |
15 | import org.eclipse.jface.dialogs.Dialog; | |
16 | import org.eclipse.jface.dialogs.IDialogConstants; | |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget; | |
df0b8ff4 | 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; |
73005152 BH |
19 | import org.eclipse.swt.SWT; |
20 | import org.eclipse.swt.events.SelectionEvent; | |
21 | import org.eclipse.swt.events.SelectionListener; | |
22 | import org.eclipse.swt.layout.GridData; | |
23 | import org.eclipse.swt.widgets.Button; | |
24 | import org.eclipse.swt.widgets.Composite; | |
25 | import org.eclipse.swt.widgets.Control; | |
26 | import org.eclipse.swt.widgets.Label; | |
27 | import org.eclipse.swt.widgets.Shell; | |
28 | ||
29 | /** | |
df0b8ff4 | 30 | * This class implements a dialog box for collecting printing information. |
c8422608 | 31 | * |
df0b8ff4 | 32 | * @version 1.0 |
73005152 BH |
33 | * @author sveyrier |
34 | */ | |
35 | public class SDPrintDialog extends Dialog { | |
36 | ||
df0b8ff4 BH |
37 | // ------------------------------------------------------------------------ |
38 | // Attributes | |
39 | // ------------------------------------------------------------------------ | |
40 | /** | |
41 | * The sequence dialog widget reference. | |
42 | */ | |
eb63f5ff | 43 | protected SDWidget fSdView; |
df0b8ff4 BH |
44 | /** |
45 | * Sequence dialog print dialog UI | |
46 | */ | |
eb63f5ff | 47 | protected SDPrintDialogUI fDialogUI; |
df0b8ff4 BH |
48 | /** |
49 | * Error message to display. | |
50 | */ | |
eb63f5ff | 51 | protected String fErrorMessage = null; |
df0b8ff4 BH |
52 | /** |
53 | * A message label. | |
54 | */ | |
eb63f5ff | 55 | protected Label fMessageLabel = null; |
df0b8ff4 BH |
56 | /** |
57 | * Flag whether the page is complete or not | |
58 | */ | |
eb63f5ff | 59 | protected boolean fIsPageComplete = true; |
73005152 | 60 | |
df0b8ff4 BH |
61 | // ------------------------------------------------------------------------ |
62 | // Constructors | |
63 | // ------------------------------------------------------------------------ | |
64 | /** | |
65 | * Standard constructor | |
c8422608 | 66 | * |
df0b8ff4 BH |
67 | * @param shell Shell reference |
68 | * @param viewer Sequence diagram widget reference | |
69 | */ | |
70 | public SDPrintDialog(Shell shell, SDWidget viewer) { | |
71 | super(shell); | |
eb63f5ff | 72 | fSdView = viewer; |
df0b8ff4 | 73 | |
eb63f5ff BH |
74 | fDialogUI = new SDPrintDialogUI(shell, fSdView); |
75 | fDialogUI.setParentDialog(this); | |
73005152 BH |
76 | } |
77 | ||
df0b8ff4 BH |
78 | // ------------------------------------------------------------------------ |
79 | // Methods | |
80 | // ------------------------------------------------------------------------ | |
11252342 | 81 | |
73005152 BH |
82 | @Override |
83 | protected Control createDialogArea(Composite p) { | |
84 | p.getShell().setText(SDMessages._114); | |
85 | Composite parent = (Composite) super.createDialogArea(p); | |
86 | ||
eb63f5ff | 87 | fDialogUI.createDialogArea(parent); |
73005152 | 88 | |
eb63f5ff | 89 | fMessageLabel = new Label(parent, SWT.NONE); |
73005152 BH |
90 | GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
91 | gridData.horizontalSpan = 6; | |
eb63f5ff BH |
92 | fMessageLabel.setLayoutData(gridData); |
93 | setErrorMessage(fErrorMessage); | |
73005152 BH |
94 | |
95 | return parent; | |
96 | } | |
c8422608 | 97 | |
73005152 BH |
98 | @Override |
99 | protected void okPressed() { | |
100 | ||
c8422608 | 101 | if (fDialogUI.okPressed()) { |
73005152 | 102 | super.okPressed(); |
c8422608 | 103 | } |
73005152 BH |
104 | } |
105 | ||
106 | @Override | |
107 | protected void createButtonsForButtonBar(Composite parent) { | |
108 | ||
109 | super.createButtonsForButtonBar(parent); | |
110 | createButton(parent, IDialogConstants.CLIENT_ID, SDMessages._115, false); | |
111 | ||
112 | getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() { | |
73005152 BH |
113 | @Override |
114 | public void widgetSelected(SelectionEvent e) { | |
eb63f5ff | 115 | fDialogUI.printButtonSelected(); |
73005152 | 116 | } |
11252342 | 117 | |
73005152 BH |
118 | @Override |
119 | public void widgetDefaultSelected(SelectionEvent e) { | |
120 | } | |
73005152 BH |
121 | }); |
122 | ||
123 | updateButtons(); | |
124 | } | |
125 | ||
df0b8ff4 BH |
126 | /** |
127 | * @return the dialog UI | |
128 | */ | |
73005152 | 129 | public SDPrintDialogUI getDialogUI() { |
eb63f5ff | 130 | return fDialogUI; |
73005152 BH |
131 | } |
132 | ||
df0b8ff4 BH |
133 | /** |
134 | * Sets the error message. | |
c8422608 | 135 | * |
df0b8ff4 BH |
136 | * @param message error message to set |
137 | */ | |
73005152 | 138 | public void setErrorMessage(String message) { |
eb63f5ff BH |
139 | fErrorMessage = message; |
140 | if (fMessageLabel != null) { | |
141 | if (fErrorMessage == null) { | |
142 | fMessageLabel.setText(""); //$NON-NLS-1$ | |
73005152 | 143 | } else { |
eb63f5ff | 144 | fMessageLabel.setText(fErrorMessage); |
73005152 BH |
145 | } |
146 | } | |
147 | } | |
148 | ||
df0b8ff4 BH |
149 | /** |
150 | * Sets the page complete flag. | |
151 | * @param complete whether page is complete or not | |
152 | */ | |
73005152 | 153 | public void setPageComplete(boolean complete) { |
eb63f5ff | 154 | fIsPageComplete = complete; |
73005152 BH |
155 | updateButtons(); |
156 | } | |
157 | ||
df0b8ff4 BH |
158 | /** |
159 | * Udates the button enable state. | |
160 | */ | |
73005152 BH |
161 | public void updateButtons() { |
162 | Button okButton = getButton(IDialogConstants.OK_ID); | |
eb63f5ff | 163 | if (fIsPageComplete) { |
73005152 BH |
164 | if (okButton != null) { |
165 | okButton.setEnabled(true); | |
166 | } | |
167 | } else { | |
168 | if (okButton != null) { | |
169 | okButton.setEnabled(false); | |
170 | } | |
171 | } | |
172 | } | |
173 | ||
174 | } |