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.swt.SWT;
11 import org.eclipse.swt.graphics.Image;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Button;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.core.runtime.IStatus;
25 * An abstract base class for dialogs with a status bar and ok/cancel buttons.
26 * The status message must be passed over as StatusInfo object and can be
27 * an error, warning or ok. The OK button is enabled or disabled depending
30 public abstract class StatusDialog extends Dialog {
32 private Button fOkButton;
33 private MessageLine fStatusLine;
34 private IStatus fLastStatus;
35 private String fTitle;
38 private boolean fStatusLineAboveButtons;
41 * Creates an instane of a status dialog.
43 public StatusDialog(Shell parent) {
45 fStatusLineAboveButtons= false;
46 fLastStatus= new StatusInfo();
50 * Specifies whether status line appears to the left of the buttons (default)
53 * @param aboveButtons if <code>true</code> status line is placed above buttons; if
54 * <code>false</code> to the right
56 public void setStatusLineAboveButtons(boolean aboveButtons) {
57 fStatusLineAboveButtons= aboveButtons;
61 * Update the dialog's status line to reflect the given status.
62 * It is save to call this method before the dialog has been opened.
64 protected void updateStatus(IStatus status) {
66 if (fStatusLine != null && !fStatusLine.isDisposed()) {
67 updateButtonsEnableState(status);
68 fStatusLine.setErrorStatus(status);
73 * Returns the last status.
75 public IStatus getStatus() {
80 * Updates the status of the ok button to reflect the given status.
81 * Subclasses may override this method to update additional buttons.
82 * @param status the status.
84 protected void updateButtonsEnableState(IStatus status) {
85 if (fOkButton != null && !fOkButton.isDisposed())
86 fOkButton.setEnabled(!status.matches(IStatus.ERROR));
90 * @see Window#create(Shell)
92 protected void configureShell(Shell shell) {
93 super.configureShell(shell);
95 shell.setText(fTitle);
99 * @see Window#create()
101 public void create() {
103 if (fLastStatus != null) {
104 // policy: dialogs are not allowed to come up with an error message
105 if (fLastStatus.matches(IStatus.ERROR)) {
106 StatusInfo status= new StatusInfo();
107 status.setError(""); //$NON-NLS-1$
110 updateStatus(fLastStatus);
115 * @see Dialog#createButtonsForButtonBar(Composite)
117 protected void createButtonsForButtonBar(Composite parent) {
118 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
119 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
123 * @see Dialog#createButtonBar(Composite)
125 protected Control createButtonBar(Composite parent) {
126 Composite composite= new Composite(parent, SWT.NULL);
127 GridLayout layout= new GridLayout();
128 layout.numColumns= 1;
129 layout.marginHeight= 0;
130 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
131 composite.setLayout(layout);
132 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
134 fStatusLine= new MessageLine(composite);
135 fStatusLine.setAlignment(SWT.LEFT);
136 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
137 fStatusLine.setErrorStatus(null); //$NON-NLS-1$
139 super.createButtonBar(composite);
144 * Sets the title for this dialog.
145 * @param title the title.
147 public void setTitle(String title) {
148 fTitle= title != null ? title : ""; //$NON-NLS-1$
149 Shell shell= getShell();
150 if ((shell != null) && !shell.isDisposed())
151 shell.setText(fTitle);
155 * Sets the image for this dialog.
156 * @param image the image.
158 public void setImage(Image image) {
160 Shell shell= getShell();
161 if ((shell != null) && !shell.isDisposed())
162 shell.setImage(fImage);