1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import org.eclipse.ant.internal.ui.model.IAntUIHelpContextIds; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.layout.GridLayout; 22 import org.eclipse.swt.widgets.Button; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.ui.help.WorkbenchHelp; 27 28 34 public abstract class StatusDialog extends Dialog { 35 36 private Button fOkButton; 37 private MessageLine fStatusLine; 38 private IStatus fLastStatus; 39 private String fTitle; 40 private Image fImage; 41 42 45 public StatusDialog(Shell parent) { 46 super(parent); 47 fLastStatus= new StatusInfo(); 48 } 49 50 54 protected void updateStatus(IStatus status) { 55 fLastStatus= status; 56 if (fStatusLine != null && !fStatusLine.isDisposed()) { 57 updateButtonsEnableState(status); 58 fStatusLine.setErrorStatus(status); 59 } 60 } 61 62 65 public IStatus getStatus() { 66 return fLastStatus; 67 } 68 69 74 protected void updateButtonsEnableState(IStatus status) { 75 if (fOkButton != null && !fOkButton.isDisposed()) 76 fOkButton.setEnabled(!status.matches(IStatus.ERROR)); 77 } 78 79 82 protected void configureShell(Shell shell) { 83 super.configureShell(shell); 84 if (fTitle != null) { 85 shell.setText(fTitle); 86 } 87 WorkbenchHelp.setHelp(shell, IAntUIHelpContextIds.STATUS_DIALOG); 88 } 89 90 93 public void create() { 94 super.create(); 95 if (fLastStatus != null) { 96 if (fLastStatus.matches(IStatus.ERROR)) { 98 StatusInfo status= new StatusInfo(); 99 status.setError(""); fLastStatus= status; 101 } 102 updateStatus(fLastStatus); 103 } 104 } 105 106 109 protected void createButtonsForButtonBar(Composite parent) { 110 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 111 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 112 } 113 114 117 protected Control createButtonBar(Composite parent) { 118 Composite composite= new Composite(parent, SWT.NULL); 119 GridLayout layout= new GridLayout(); 120 layout.numColumns= 1; 121 layout.marginHeight= 0; 122 layout.marginWidth= 0; 123 composite.setLayout(layout); 124 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 125 126 fStatusLine= new MessageLine(composite); 127 fStatusLine.setAlignment(SWT.LEFT); 128 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 129 fStatusLine.setErrorStatus(null); 131 super.createButtonBar(composite); 132 return composite; 133 } 134 135 139 public void setTitle(String title) { 140 fTitle= title != null ? title : ""; Shell shell= getShell(); 142 if ((shell != null) && !shell.isDisposed()) 143 shell.setText(fTitle); 144 } 145 146 150 public void setImage(Image image) { 151 fImage= image; 152 Shell shell= getShell(); 153 if ((shell != null) && !shell.isDisposed()) 154 shell.setImage(fImage); 155 } 156 157 } 158 | Popular Tags |