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.ui.IMemento; 16 import org.eclipse.ui.IPropertyListener; 17 import org.eclipse.ui.IViewPart; 18 import org.eclipse.ui.IViewSite; 19 import org.eclipse.ui.IWorkbenchPartConstants; 20 import org.eclipse.ui.IWorkbenchPartSite; 21 import org.eclipse.ui.PartInitException; 22 import org.eclipse.ui.internal.util.Util; 23 24 63 public abstract class ViewPart extends WorkbenchPart implements IViewPart { 64 65 70 private IPropertyListener compatibilityTitleListener = new IPropertyListener() { 71 74 public void propertyChanged(Object source, int propId) { 75 if (propId == IWorkbenchPartConstants.PROP_TITLE) { 76 setDefaultContentDescription(); 77 } 78 } 79 }; 80 81 84 protected ViewPart() { 85 super(); 86 87 addPropertyListener(compatibilityTitleListener); 88 } 89 90 93 public IViewSite getViewSite() { 94 return (IViewSite) getSite(); 95 } 96 97 98 101 public void init(IViewSite site) throws PartInitException { 102 setSite(site); 103 104 setDefaultContentDescription(); 105 } 106 107 111 public void init(IViewSite site, IMemento memento) throws PartInitException { 112 122 init(site); 123 } 124 125 126 129 public void saveState(IMemento memento) { 130 } 132 133 136 protected void setPartName(String partName) { 137 if (compatibilityTitleListener != null) { 138 removePropertyListener(compatibilityTitleListener); 139 compatibilityTitleListener = null; 140 } 141 142 super.setPartName(partName); 143 } 144 145 148 protected void setContentDescription(String description) { 149 if (compatibilityTitleListener != null) { 150 removePropertyListener(compatibilityTitleListener); 151 compatibilityTitleListener = null; 152 } 153 154 super.setContentDescription(description); 155 } 156 157 160 public void setInitializationData(IConfigurationElement cfig, 161 String propertyName, Object data) { 162 super.setInitializationData(cfig, propertyName, data); 163 164 setDefaultContentDescription(); 165 } 166 167 private void setDefaultContentDescription() { 168 if (compatibilityTitleListener == null) { 169 return; 170 } 171 172 String partName = getPartName(); 173 String title = getTitle(); 174 175 if (Util.equals(partName, title)) { 176 internalSetContentDescription(""); } else { 178 internalSetContentDescription(title); 179 } 180 } 181 182 189 protected final void checkSite(IWorkbenchPartSite site) { 190 super.checkSite(site); 191 Assert.isTrue(site instanceof IViewSite, "The site for a view must be an IViewSite"); } 193 } 194 | Popular Tags |