1 11 package org.eclipse.pde.internal.ui.parts; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.jface.dialogs.*; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.layout.*; 19 import org.eclipse.swt.widgets.*; 20 import org.eclipse.ui.internal.MessageLine; 21 import org.eclipse.jface.dialogs.Dialog; 22 23 29 public abstract class StatusDialog extends Dialog { 30 31 private Button fOkButton; 32 private MessageLine fStatusLine; 33 private IStatus fLastStatus; 34 private String fTitle; 35 private Image fImage; 36 37 40 public StatusDialog(Shell parent) { 41 super(parent); 42 fLastStatus= new StatusInfo(); 43 } 44 45 52 55 56 60 protected void updateStatus(IStatus status) { 61 fLastStatus= status; 62 if (fStatusLine != null && !fStatusLine.isDisposed()) { 63 updateButtonsEnableState(status); 64 fStatusLine.setErrorStatus(status); 65 } 66 } 67 68 71 public IStatus getStatus() { 72 return fLastStatus; 73 } 74 75 80 protected void updateButtonsEnableState(IStatus status) { 81 if (fOkButton != null && !fOkButton.isDisposed()) 82 fOkButton.setEnabled(!status.matches(IStatus.ERROR)); 83 } 84 85 88 protected void configureShell(Shell shell) { 89 super.configureShell(shell); 90 if (fTitle != null) 91 shell.setText(fTitle); 92 } 93 94 97 public void create() { 98 super.create(); 99 if (fLastStatus != null) { 100 if (fLastStatus.matches(IStatus.ERROR)) { 102 StatusInfo status= new StatusInfo(); 103 status.setError(""); fLastStatus= status; 105 } 106 updateStatus(fLastStatus); 107 } 108 } 109 110 113 protected void createButtonsForButtonBar(Composite parent) { 114 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 115 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 116 } 117 118 121 protected Control createButtonBar(Composite parent) { 122 Composite composite= new Composite(parent, SWT.NULL); 123 GridLayout layout= new GridLayout(); 124 layout.numColumns= 1; 125 layout.marginHeight= 0; 126 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 127 composite.setLayout(layout); 128 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 129 130 fStatusLine= new MessageLine(composite); 131 fStatusLine.setAlignment(SWT.LEFT); 132 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 133 fStatusLine.setErrorStatus(null); 135 super.createButtonBar(composite); 136 return composite; 137 } 138 139 143 public void setTitle(String title) { 144 fTitle= title != null ? title : ""; Shell shell= getShell(); 146 if ((shell != null) && !shell.isDisposed()) 147 shell.setText(fTitle); 148 } 149 150 154 public void setImage(Image image) { 155 fImage= image; 156 Shell shell= getShell(); 157 if ((shell != null) && !shell.isDisposed()) 158 shell.setImage(fImage); 159 } 160 161 } | Popular Tags |