| /******************************************************************************* |
| * Copyright (c) 2002 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v0.5 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v05.html |
| * |
| * Contributors: |
| * IBM - Initial implementation |
| ******************************************************************************/ |
| package org.eclipse.team.internal.ccvs.ui; |
| |
| import org.eclipse.jface.dialogs.Dialog; |
| import org.eclipse.jface.dialogs.IDialogConstants; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.graphics.Color; |
| import org.eclipse.swt.graphics.Point; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Shell; |
| |
| /** |
| * A simple superclass for detail button dialogs. |
| */ |
| abstract public class DetailsDialog extends Dialog { |
| /** |
| * The Details button. |
| */ |
| private Button detailsButton; |
| |
| /** |
| * The Ok button. |
| */ |
| private Button okButton; |
| |
| /** |
| * The title of the dialog. |
| */ |
| private String title; |
| |
| /** |
| * The error message |
| */ |
| private Label errorMessageLabel; |
| |
| /** |
| * The SWT list control that displays the error details. |
| */ |
| private Composite detailsComposite; |
| |
| /** |
| * Indicates whether the error details viewer is currently created. |
| */ |
| private boolean detailsCreated = false; |
| |
| /** |
| * Creates a details pane dialog. |
| * Note that the dialog will have no visual representation (no widgets) |
| * until it is told to open. |
| * |
| * @param parentShell the shell under which to create this dialog |
| * @param dialogTitle the title to use for this dialog |
| * @param message the message to show in this dialog |
| * @param status the error to show to the user |
| * @param displayMask the mask to use to filter the displaying of child items, |
| * as per <code>IStatus.matches</code> |
| * @see org.eclipse.core.runtime.IStatus#matches |
| */ |
| public DetailsDialog(Shell parentShell, String dialogTitle) { |
| super(parentShell); |
| this.title = dialogTitle; |
| setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); |
| } |
| |
| /* (non-Javadoc) |
| * Method declared on Dialog. |
| * Handles the pressing of the Ok or Details button in this dialog. |
| * If the Ok button was pressed then close this dialog. If the Details |
| * button was pressed then toggle the displaying of the error details area. |
| * Note that the Details button will only be visible if the error being |
| * displayed specifies child details. |
| */ |
| protected void buttonPressed(int id) { |
| if (id == IDialogConstants.DETAILS_ID) { // was the details button pressed? |
| toggleDetailsArea(); |
| } else { |
| super.buttonPressed(id); |
| } |
| } |
| |
| /* (non-Javadoc) |
| * Method declared in Window. |
| */ |
| protected void configureShell(Shell shell) { |
| super.configureShell(shell); |
| shell.setText(title); |
| } |
| |
| /* (non-Javadoc) |
| * Method declared on Dialog. |
| */ |
| protected void createButtonsForButtonBar(Composite parent) { |
| // create OK and Details buttons |
| okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); |
| createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); |
| detailsButton = createButton(parent, IDialogConstants.DETAILS_ID, IDialogConstants.SHOW_DETAILS_LABEL, false); |
| updateEnablements(); |
| } |
| |
| /* (non-Javadoc) |
| * Method declared on Dialog. |
| * Creates and returns the contents of the upper part |
| * of the dialog (above the button bar). |
| */ |
| final protected Control createDialogArea(Composite parent) { |
| // create composite |
| Composite composite = (Composite)super.createDialogArea(parent); |
| |
| createMainDialogArea(composite); |
| |
| errorMessageLabel = new Label(composite, SWT.NONE); |
| errorMessageLabel.setLayoutData(new GridData( |
| GridData.GRAB_HORIZONTAL | |
| GridData.HORIZONTAL_ALIGN_FILL)); |
| errorMessageLabel.setFont(parent.getFont()); |
| errorMessageLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED)); |
| |
| return composite; |
| } |
| |
| /** |
| * Creates the dialog's top composite |
| * |
| * @param parent the parent composite |
| */ |
| abstract protected void createMainDialogArea(Composite parent); |
| |
| /** |
| * Create this dialog's drop-down list component. |
| * |
| * @param parent the parent composite |
| * @return the drop-down list component |
| */ |
| abstract protected Composite createDropDownDialogArea(Composite parent); |
| |
| /** |
| * Toggles the unfolding of the details area. This is triggered by |
| * the user pressing the details button. |
| */ |
| private void toggleDetailsArea() { |
| Point windowSize = getShell().getSize(); |
| Point oldSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); |
| |
| if (detailsCreated) { |
| detailsComposite.dispose(); |
| detailsCreated = false; |
| detailsButton.setText(IDialogConstants.SHOW_DETAILS_LABEL); |
| } else { |
| detailsComposite = createDropDownDialogArea((Composite)getContents()); |
| detailsCreated = true; |
| detailsButton.setText(IDialogConstants.HIDE_DETAILS_LABEL); |
| } |
| |
| Point newSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); |
| |
| getShell().setSize(new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y))); |
| } |
| |
| final protected void setErrorMessage(String error) { |
| if(errorMessageLabel != null) { |
| if(error == null || error.length() == 0) { |
| errorMessageLabel.setText(""); //$NON-NLS-1$ |
| } else { |
| errorMessageLabel.setText(error); |
| } |
| errorMessageLabel.update(); |
| } |
| } |
| |
| final protected void setPageComplete(boolean complete) { |
| if(okButton != null ) { |
| okButton.setEnabled(complete); |
| } |
| } |
| |
| abstract protected void updateEnablements(); |
| } |