1 11 package org.eclipse.ui.texteditor.templates; 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 35 abstract class StatusDialog extends Dialog { 36 37 private Button fOkButton; 38 private MessageLine fStatusLine; 39 private IStatus fLastStatus; 40 private String fTitle; 41 private Image fImage; 42 private boolean fStatusLineAboveButtons= true; 43 44 49 public StatusDialog(Shell parent) { 50 super(parent); 51 fLastStatus= new StatusInfo(); 52 } 53 54 61 public void setStatusLineAboveButtons(boolean aboveButtons) { 62 fStatusLineAboveButtons= aboveButtons; 63 } 64 65 71 protected void updateStatus(IStatus status) { 72 fLastStatus= status; 73 if (fStatusLine != null && !fStatusLine.isDisposed()) { 74 updateButtonsEnableState(status); 75 fStatusLine.setErrorStatus(status); 76 } 77 } 78 79 84 public IStatus getStatus() { 85 return fLastStatus; 86 } 87 88 93 protected void updateButtonsEnableState(IStatus status) { 94 if (fOkButton != null && !fOkButton.isDisposed()) 95 fOkButton.setEnabled(!status.matches(IStatus.ERROR)); 96 } 97 98 101 protected void configureShell(Shell shell) { 102 super.configureShell(shell); 103 if (fTitle != null) 104 shell.setText(fTitle); 105 } 106 107 110 public void create() { 111 super.create(); 112 if (fLastStatus != null) { 113 if (fLastStatus.matches(IStatus.ERROR)) { 115 StatusInfo status= new StatusInfo(); 116 status.setError(""); fLastStatus= status; 118 } 119 updateStatus(fLastStatus); 120 } 121 } 122 123 126 protected void createButtonsForButtonBar(Composite parent) { 127 fOkButton= createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 128 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 129 } 130 131 134 protected Control createButtonBar(Composite parent) { 135 Composite composite= new Composite(parent, SWT.NULL); 136 GridLayout layout= new GridLayout(); 137 138 if (fStatusLineAboveButtons) { 139 layout.numColumns= 1; 140 } else { 141 layout.numColumns= 2; 142 } 143 144 layout.marginHeight= 0; 145 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 146 composite.setLayout(layout); 147 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 148 149 fStatusLine= new MessageLine(composite); 150 fStatusLine.setAlignment(SWT.LEFT); 151 fStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 152 fStatusLine.setErrorStatus(null); 153 applyDialogFont(composite); 154 super.createButtonBar(composite); 155 return composite; 156 } 157 158 162 public void setTitle(String title) { 163 fTitle= title != null ? title : ""; Shell shell= getShell(); 165 if ((shell != null) && !shell.isDisposed()) 166 shell.setText(fTitle); 167 } 168 169 173 public void setImage(Image image) { 174 fImage= image; 175 Shell shell= getShell(); 176 if ((shell != null) && !shell.isDisposed()) 177 shell.setImage(fImage); 178 } 179 180 } 181 | Popular Tags |