1 11 package org.eclipse.ui.part; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.ui.IEditorInput; 17 import org.eclipse.ui.IEditorPart; 18 import org.eclipse.ui.IEditorSite; 19 import org.eclipse.ui.IPropertyListener; 20 import org.eclipse.ui.IWorkbenchPartConstants; 21 import org.eclipse.ui.IWorkbenchPartSite; 22 import org.eclipse.ui.PartInitException; 23 24 70 public abstract class EditorPart extends WorkbenchPart implements IEditorPart { 71 72 75 private IEditorInput editorInput = null; 76 77 82 private IPropertyListener compatibilityTitleListener = new IPropertyListener() { 83 86 public void propertyChanged(Object source, int propId) { 87 if (propId == IWorkbenchPartConstants.PROP_TITLE) { 88 setDefaultPartName(); 89 } 90 } 91 }; 92 93 96 protected EditorPart() { 97 super(); 98 99 addPropertyListener(compatibilityTitleListener); 100 } 101 102 111 public abstract void doSave(IProgressMonitor monitor); 112 113 122 public abstract void doSaveAs(); 123 124 127 public IEditorInput getEditorInput() { 128 return editorInput; 129 } 130 131 134 public IEditorSite getEditorSite() { 135 return (IEditorSite) getSite(); 136 } 137 138 143 public String getTitleToolTip() { 144 if (editorInput == null) { 145 return super.getTitleToolTip(); 146 } else { 147 return editorInput.getToolTipText(); 148 } 149 } 150 151 165 public abstract void init(IEditorSite site, IEditorInput input) 166 throws PartInitException; 167 168 178 public abstract boolean isDirty(); 179 180 189 public abstract boolean isSaveAsAllowed(); 190 191 199 public boolean isSaveOnCloseNeeded() { 200 return isDirty(); 201 } 202 203 223 protected void setInput(IEditorInput input) { 224 editorInput = input; 225 } 226 227 240 protected void setInputWithNotify(IEditorInput input) { 241 if (input != editorInput) { 242 editorInput = input; 243 firePropertyChange(PROP_INPUT); 244 } 245 } 246 247 250 protected void setContentDescription(String description) { 251 if (compatibilityTitleListener != null) { 252 removePropertyListener(compatibilityTitleListener); 253 compatibilityTitleListener = null; 254 } 255 256 super.setContentDescription(description); 257 } 258 259 262 protected void setPartName(String partName) { 263 if (compatibilityTitleListener != null) { 264 removePropertyListener(compatibilityTitleListener); 265 compatibilityTitleListener = null; 266 } 267 268 super.setPartName(partName); 269 } 270 271 274 public void setInitializationData(IConfigurationElement cfig, 275 String propertyName, Object data) { 276 super.setInitializationData(cfig, propertyName, data); 277 278 setDefaultPartName(); 279 } 280 281 282 private void setDefaultPartName() { 283 if (compatibilityTitleListener == null) { 284 return; 285 } 286 287 internalSetPartName(getTitle()); 288 } 289 290 293 void setDefaultTitle() { 294 setTitle(getPartName()); 295 } 296 297 304 protected final void checkSite(IWorkbenchPartSite site) { 305 super.checkSite(site); 306 Assert.isTrue(site instanceof IEditorSite, "The site for an editor must be an IEditorSite"); } 308 309 } 310 | Popular Tags |