1 package net.sourceforge.phpdt.externaltools.internal.ui;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
10 import org.eclipse.core.runtime.IStatus;
11 import org.eclipse.jface.dialogs.Dialog;
12 import org.eclipse.jface.dialogs.IDialogConstants;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Image;
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.Shell;
23 * An abstract base class for dialogs with a status bar and ok/cancel buttons.
24 * The status message must be passed over as StatusInfo object and can be
25 * an error, warning or ok. The OK button is enabled or disabled depending
28 public abstract class StatusDialog extends Dialog {
30 private Button fOkButton;
31 private MessageLine fStatusLine;
32 private IStatus fLastStatus;
33 private String fTitle;
36 private boolean fStatusLineAboveButtons;
39 * Creates an instane of a status dialog.
41 public StatusDialog(Shell parent) {
43 fStatusLineAboveButtons= false;
44 fLastStatus= new StatusInfo();
48 * Specifies whether status line appears to the left of the buttons (default)
51 * @param aboveButtons if <code>true</code> status line is placed above buttons; if
52 * <code>false</code> to the right
54 public void setStatusLineAboveButtons(boolean aboveButtons) {
55 fStatusLineAboveButtons= aboveButtons;
59 * Update the dialog's status line to reflect the given status.
60 * It is save to call this method before the dialog has been opened.
62 protected void updateStatus(IStatus status) {
64 if (fStatusLine != null && !fStatusLine.isDisposed()) {
65 updateButtonsEnableState(status);
66 fStatusLine.setErrorStatus(status);
71 * Returns the last status.
73 public IStatus getStatus() {
78 * Updates the status of the ok button to reflect the given status.
79 * Subclasses may override this method to update additional buttons.
80 * @param status the status.
82 protected void updateButtonsEnableState(IStatus status) {
83 if (fOkButton != null && !fOkButton.isDisposed())
84 fOkButton.setEnabled(!status.matches(IStatus.ERROR));
88 * @see Window#create(Shell)
90 protected void configureShell(Shell shell) {
91 super.configureShell(shell);
93 shell.setText(fTitle);
97 * @see Window#create()
99 public void create() {
101 if (fLastStatus != null) {
102 // policy: dialogs are not allowed to come up with an error message
103 if (fLastStatus.matches(IStatus.ERROR)) {
104 StatusInfo status= new StatusInfo();
105 status.setError(""); //$NON-NLS-1$
108 updateStatus(fLastStatus);
113 * @see Dialog#createButtonsForButtonBar(Composite)
115 protected void createButtonsForButtonBar(Composite parent) {
116 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
117 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
121 * @see Dialog#createButtonBar(Composite)
123 protected Control createButtonBar(Composite parent) {
124 Composite composite= new Composite(parent, SWT.NULL);
125 GridLayout layout= new GridLayout();
126 layout.numColumns= 1;
127 layout.marginHeight= 0;
128 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
129 composite.setLayout(layout);
130 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
132 fStatusLine= new MessageLine(composite);
133 fStatusLine.setAlignment(SWT.LEFT);
134 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
135 fStatusLine.setErrorStatus(null); //$NON-NLS-1$
137 super.createButtonBar(composite);
142 * Sets the title for this dialog.
143 * @param title the title.
145 public void setTitle(String title) {
146 fTitle= title != null ? title : ""; //$NON-NLS-1$
147 Shell shell= getShell();
148 if ((shell != null) && !shell.isDisposed())
149 shell.setText(fTitle);
153 * Sets the image for this dialog.
154 * @param image the image.
156 public void setImage(Image image) {
158 Shell shell= getShell();
159 if ((shell != null) && !shell.isDisposed())
160 shell.setImage(fImage);