1 11 package org.eclipse.jdt.internal.debug.ui; 12 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; 21 22 import org.eclipse.jface.dialogs.Dialog; 23 import org.eclipse.jface.dialogs.IDialogConstants; 24 25 import org.eclipse.core.runtime.IStatus; 26 27 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 private boolean fStatusLineAboveButtons= true; 41 42 45 public StatusDialog(Shell parent) { 46 super(parent); 47 fLastStatus= new StatusInfo(); 48 } 49 50 57 public void setStatusLineAboveButtons(boolean aboveButtons) { 58 fStatusLineAboveButtons= aboveButtons; 59 } 60 61 65 protected void updateStatus(IStatus status) { 66 fLastStatus= status; 67 if (fStatusLine != null && !fStatusLine.isDisposed()) { 68 updateButtonsEnableState(status); 69 fStatusLine.setErrorStatus(status); 70 } 71 } 72 73 76 public IStatus getStatus() { 77 return fLastStatus; 78 } 79 80 85 protected void updateButtonsEnableState(IStatus status) { 86 if (fOkButton != null && !fOkButton.isDisposed()) 87 fOkButton.setEnabled(!status.matches(IStatus.ERROR)); 88 } 89 90 93 protected void configureShell(Shell shell) { 94 super.configureShell(shell); 95 if (fTitle != null) 96 shell.setText(fTitle); 97 } 98 99 102 public void create() { 103 super.create(); 104 if (fLastStatus != null) { 105 if (fLastStatus.matches(IStatus.ERROR)) { 107 StatusInfo status= new StatusInfo(); 108 status.setError(""); fLastStatus= status; 110 } 111 updateStatus(fLastStatus); 112 } 113 } 114 115 118 protected void createButtonsForButtonBar(Composite parent) { 119 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 120 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 121 } 122 123 126 protected Control createButtonBar(Composite parent) { 127 Composite composite= new Composite(parent, SWT.NULL); 128 GridLayout layout= new GridLayout(); 129 130 if (fStatusLineAboveButtons) { 131 layout.numColumns= 1; 132 } else { 133 layout.numColumns= 2; 134 } 135 136 layout.marginHeight= 0; 137 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 138 composite.setLayout(layout); 139 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 140 141 fStatusLine= new MessageLine(composite); 142 fStatusLine.setAlignment(SWT.LEFT); 143 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 144 fStatusLine.setErrorStatus(null); 145 applyDialogFont(composite); 146 super.createButtonBar(composite); 147 return composite; 148 } 149 150 154 public void setTitle(String title) { 155 fTitle= title != null ? title : ""; Shell shell= getShell(); 157 if ((shell != null) && !shell.isDisposed()) 158 shell.setText(fTitle); 159 } 160 161 165 public void setImage(Image image) { 166 fImage= image; 167 Shell shell= getShell(); 168 if ((shell != null) && !shell.isDisposed()) 169 shell.setImage(fImage); 170 } 171 172 } 173 | Popular Tags |