1 11 12 package org.eclipse.ui.texteditor; 13 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.custom.StackLayout; 17 import org.eclipse.swt.layout.FillLayout; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IStatus; 23 24 import org.eclipse.ui.IEditorInput; 25 26 27 31 public class StatusTextEditor extends AbstractTextEditor { 32 33 34 private Composite fParent; 35 36 private StackLayout fStackLayout; 37 38 private Composite fDefaultComposite; 39 40 private Control fStatusControl; 41 42 45 public void createPartControl(Composite parent) { 46 47 fParent= new Composite(parent, SWT.NONE); 48 fStackLayout= new StackLayout(); 49 fParent.setLayout(fStackLayout); 50 51 fDefaultComposite= new Composite(fParent, SWT.NONE); 52 fDefaultComposite.setLayout(new FillLayout()); 53 super.createPartControl(fDefaultComposite); 54 55 updatePartControl(getEditorInput()); 56 } 57 58 64 public void updatePartControl(IEditorInput input) { 65 66 if (fStatusControl != null) { 67 fStatusControl.dispose(); 68 fStatusControl= null; 69 } 70 71 Control front= null; 72 if (fParent != null && input != null) { 73 if (getDocumentProvider() instanceof IDocumentProviderExtension) { 74 IDocumentProviderExtension extension= (IDocumentProviderExtension) getDocumentProvider(); 75 IStatus status= extension.getStatus(input); 76 if (!isErrorStatus(status)) { 77 front= fDefaultComposite; 78 } else { 79 fStatusControl= createStatusControl(fParent, status); 80 front= fStatusControl; 81 } 82 } 83 } 84 85 if (fStackLayout.topControl != front) { 86 fStackLayout.topControl= front; 87 fParent.layout(); 88 updateStatusFields(); 89 } 90 } 91 92 96 public boolean validateEditorInputState() { 97 if (!super.validateEditorInputState()) 98 return false; 99 100 if (getDocumentProvider() instanceof IDocumentProviderExtension) { 101 IDocumentProviderExtension extension= (IDocumentProviderExtension)getDocumentProvider(); 102 IStatus status= extension.getStatus(getEditorInput()); 103 return !isErrorStatus(status) && status.getSeverity() != IStatus.CANCEL; 104 } 105 106 return true; 107 } 108 109 116 protected boolean isErrorStatus(IStatus status) { 117 return status != null && status.getSeverity() == IStatus.ERROR; 118 } 119 120 128 protected Control createStatusControl(Composite parent, IStatus status) { 129 InfoForm infoForm= new InfoForm(parent); 130 infoForm.setHeaderText(getStatusHeader(status)); 131 infoForm.setBannerText(getStatusBanner(status)); 132 infoForm.setInfo(getStatusMessage(status)); 133 return infoForm.getControl(); 134 } 135 136 142 protected String getStatusHeader(IStatus status) { 143 return ""; } 145 146 152 protected String getStatusBanner(IStatus status) { 153 return ""; } 155 156 162 protected String getStatusMessage(IStatus status) { 163 return status.getMessage(); 164 } 165 166 169 protected void updateStatusField(String category) { 170 IDocumentProvider provider= getDocumentProvider(); 171 if (provider instanceof IDocumentProviderExtension) { 172 IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; 173 IStatus status= extension.getStatus(getEditorInput()); 174 if (isErrorStatus(status)) { 175 IStatusField field= getStatusField(category); 176 if (field != null) { 177 field.setText(fErrorLabel); 178 return; 179 } 180 } 181 } 182 183 super.updateStatusField(category); 184 } 185 186 189 protected void doSetInput(IEditorInput input) throws CoreException { 190 super.doSetInput(input); 191 if (fParent != null && !fParent.isDisposed()) 192 updatePartControl(getEditorInput()); 193 } 194 195 198 public void doRevertToSaved() { 199 super.doRevertToSaved(); 201 if (fParent != null && !fParent.isDisposed()) 202 updatePartControl(getEditorInput()); 203 } 204 205 208 protected void sanityCheckState(IEditorInput input) { 209 super.sanityCheckState(input); 211 if (fParent != null && !fParent.isDisposed()) 212 updatePartControl(getEditorInput()); 213 } 214 215 219 protected void handleEditorInputChanged() { 220 super.handleEditorInputChanged(); 221 if (fParent != null && !fParent.isDisposed()) 222 updatePartControl(getEditorInput()); 223 } 224 225 229 protected void handleElementContentReplaced() { 230 super.handleElementContentReplaced(); 231 if (fParent != null && !fParent.isDisposed()) 232 updatePartControl(getEditorInput()); 233 } 234 } 235 | Popular Tags |