1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.dialogs.IDialogConstants; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.ui.internal.MessageLine; 25 26 33 public abstract class StatusDialog extends Dialog { 34 35 private Button fOkButton; 36 private MessageLine fStatusLine; 37 private IStatus fLastStatus; 38 private String fTitle; 39 private Image fImage; 40 41 44 public StatusDialog(Shell parent) { 45 super(parent); 46 fLastStatus = new StatusInfo(); 47 } 48 49 53 protected void updateStatus(IStatus status) { 54 fLastStatus = status; 55 if (fStatusLine != null && !fStatusLine.isDisposed()) { 56 updateButtonsEnableState(status); 57 fStatusLine.setErrorStatus(status); 58 } 59 } 60 61 64 public IStatus getStatus() { 65 return fLastStatus; 66 } 67 68 73 protected void updateButtonsEnableState(IStatus status) { 74 if (fOkButton != null && !fOkButton.isDisposed()) 75 fOkButton.setEnabled(!status.matches(IStatus.ERROR)); 76 } 77 78 81 protected void configureShell(Shell shell) { 82 super.configureShell(shell); 83 if (fTitle != null) 84 shell.setText(fTitle); 85 } 86 87 90 public void create() { 91 super.create(); 92 if (fLastStatus != null) { 93 if (fLastStatus.matches(IStatus.ERROR)) { 95 StatusInfo status = new StatusInfo(); 96 status.setError(""); fLastStatus = status; 98 } 99 updateStatus(fLastStatus); 100 } 101 } 102 103 106 protected void createButtonsForButtonBar(Composite parent) { 107 fOkButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 108 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 109 } 110 111 114 protected Control createButtonBar(Composite parent) { 115 Composite composite = new Composite(parent, SWT.NULL); 116 GridLayout layout = new GridLayout(); 117 layout.numColumns = 1; 118 layout.marginHeight = 0; 119 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 120 composite.setLayout(layout); 121 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 122 123 fStatusLine = new MessageLine(composite); 124 fStatusLine.setAlignment(SWT.LEFT); 125 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 126 fStatusLine.setErrorStatus(null); applyDialogFont(composite); 128 super.createButtonBar(composite); 129 return composite; 130 } 131 132 136 public void setTitle(String title) { 137 fTitle = title != null ? title : ""; Shell shell = getShell(); 139 if ((shell != null) && !shell.isDisposed()) 140 shell.setText(fTitle); 141 } 142 143 147 public void setImage(Image image) { 148 fImage = image; 149 Shell shell = getShell(); 150 if ((shell != null) && !shell.isDisposed()) 151 shell.setImage(fImage); 152 } 153 } 154 | Popular Tags |