1 11 package org.eclipse.jdt.internal.ui.dialogs; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.core.runtime.Status; 15 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 25 import org.eclipse.jface.dialogs.Dialog; 26 import org.eclipse.jface.dialogs.IDialogConstants; 27 28 import org.eclipse.ui.internal.MessageLine; 29 30 36 public abstract class StatusDialog extends Dialog { 37 38 private Button fOkButton; 39 private MessageLine fStatusLine; 40 private IStatus fLastStatus; 41 private String fTitle; 42 private Image fImage; 43 private boolean fStatusLineAboveButtons= true; 44 45 48 public StatusDialog(Shell parent) { 49 super(parent); 50 fLastStatus= new StatusInfo(); 51 } 52 53 60 public void setStatusLineAboveButtons(boolean aboveButtons) { 61 fStatusLineAboveButtons= aboveButtons; 62 } 63 64 68 protected void updateStatus(IStatus status) { 69 fLastStatus= status; 70 if (fStatusLine != null && !fStatusLine.isDisposed()) { 71 updateButtonsEnableState(status); 72 fStatusLine.setErrorStatus(status); 73 } 74 } 75 76 79 public IStatus getStatus() { 80 return fLastStatus; 81 } 82 83 88 protected void updateButtonsEnableState(IStatus status) { 89 if (fOkButton != null && !fOkButton.isDisposed()) 90 fOkButton.setEnabled(!status.matches(IStatus.ERROR)); 91 } 92 93 96 protected void configureShell(Shell shell) { 97 super.configureShell(shell); 98 if (fTitle != null) 99 shell.setText(fTitle); 100 } 101 102 105 public void create() { 106 super.create(); 107 if (fLastStatus != null) { 108 if (fLastStatus.matches(IStatus.ERROR)) { 110 fLastStatus= new Status(IStatus.ERROR, fLastStatus.getPlugin(), fLastStatus.getCode(), "", fLastStatus.getException()); } 113 updateStatus(fLastStatus); 114 } 115 } 116 117 120 protected void createButtonsForButtonBar(Composite parent) { 121 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 122 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 123 } 124 125 128 protected Control createButtonBar(Composite parent) { 129 Composite composite= new Composite(parent, SWT.NULL); 130 GridLayout layout= new GridLayout(); 131 132 if (fStatusLineAboveButtons) { 133 layout.numColumns= 1; 134 } else { 135 layout.numColumns= 2; 136 } 137 138 layout.marginHeight= 0; 139 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 140 composite.setLayout(layout); 141 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 142 143 fStatusLine= new MessageLine(composite); 144 fStatusLine.setAlignment(SWT.LEFT); 145 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 146 fStatusLine.setErrorStatus(null); 147 applyDialogFont(composite); 148 super.createButtonBar(composite); 149 return composite; 150 } 151 152 156 public void setTitle(String title) { 157 fTitle= title != null ? title : ""; Shell shell= getShell(); 159 if ((shell != null) && !shell.isDisposed()) 160 shell.setText(fTitle); 161 } 162 163 167 public void setImage(Image image) { 168 fImage= image; 169 Shell shell= getShell(); 170 if ((shell != null) && !shell.isDisposed()) 171 shell.setImage(fImage); 172 } 173 174 } 175 | Popular Tags |