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