| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2005, 2012 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.linuxtools.tmf.ui.views.uml2sd.dialogs; |
| 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; |
| 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; |
| 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 | /** |
| 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 | protected SDWidget fSdView; |
| 44 | /** |
| 45 | * Sequence dialog print dialog UI |
| 46 | */ |
| 47 | protected SDPrintDialogUI fDialogUI; |
| 48 | /** |
| 49 | * Error message to display. |
| 50 | */ |
| 51 | protected String fErrorMessage = null; |
| 52 | /** |
| 53 | * A message label. |
| 54 | */ |
| 55 | protected Label fMessageLabel = null; |
| 56 | /** |
| 57 | * Flag whether the page is complete or not |
| 58 | */ |
| 59 | protected 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 | * (non-Javadoc) |
| 83 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
| 84 | */ |
| 85 | @Override |
| 86 | protected Control createDialogArea(Composite p) { |
| 87 | p.getShell().setText(SDMessages._114); |
| 88 | Composite parent = (Composite) super.createDialogArea(p); |
| 89 | |
| 90 | fDialogUI.createDialogArea(parent); |
| 91 | |
| 92 | fMessageLabel = new Label(parent, SWT.NONE); |
| 93 | GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); |
| 94 | gridData.horizontalSpan = 6; |
| 95 | fMessageLabel.setLayoutData(gridData); |
| 96 | setErrorMessage(fErrorMessage); |
| 97 | |
| 98 | return parent; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * (non-Javadoc) |
| 103 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() |
| 104 | */ |
| 105 | @Override |
| 106 | protected void okPressed() { |
| 107 | |
| 108 | if (fDialogUI.okPressed()) { |
| 109 | super.okPressed(); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * (non-Javadoc) |
| 115 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
| 116 | */ |
| 117 | @Override |
| 118 | protected void createButtonsForButtonBar(Composite parent) { |
| 119 | |
| 120 | super.createButtonsForButtonBar(parent); |
| 121 | createButton(parent, IDialogConstants.CLIENT_ID, SDMessages._115, false); |
| 122 | |
| 123 | getButton(IDialogConstants.CLIENT_ID).addSelectionListener(new SelectionListener() { |
| 124 | /* |
| 125 | * (non-Javadoc) |
| 126 | * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 127 | */ |
| 128 | @Override |
| 129 | public void widgetSelected(SelectionEvent e) { |
| 130 | |
| 131 | fDialogUI.printButtonSelected(); |
| 132 | } |
| 133 | /* |
| 134 | * (non-Javadoc) |
| 135 | * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
| 136 | */ |
| 137 | @Override |
| 138 | public void widgetDefaultSelected(SelectionEvent e) { |
| 139 | } |
| 140 | }); |
| 141 | |
| 142 | updateButtons(); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @return the dialog UI |
| 147 | */ |
| 148 | public SDPrintDialogUI getDialogUI() { |
| 149 | return fDialogUI; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets the error message. |
| 154 | * |
| 155 | * @param message error message to set |
| 156 | */ |
| 157 | public void setErrorMessage(String message) { |
| 158 | fErrorMessage = message; |
| 159 | if (fMessageLabel != null) { |
| 160 | if (fErrorMessage == null) { |
| 161 | fMessageLabel.setText(""); //$NON-NLS-1$ |
| 162 | } else { |
| 163 | fMessageLabel.setText(fErrorMessage); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Sets the page complete flag. |
| 170 | * @param complete whether page is complete or not |
| 171 | */ |
| 172 | public void setPageComplete(boolean complete) { |
| 173 | fIsPageComplete = complete; |
| 174 | updateButtons(); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Udates the button enable state. |
| 179 | */ |
| 180 | public void updateButtons() { |
| 181 | Button okButton = getButton(IDialogConstants.OK_ID); |
| 182 | if (fIsPageComplete) { |
| 183 | if (okButton != null) { |
| 184 | okButton.setEnabled(true); |
| 185 | } |
| 186 | } else { |
| 187 | if (okButton != null) { |
| 188 | okButton.setEnabled(false); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | } |