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