1 11 package org.eclipse.ui.part; 12 13 import org.eclipse.core.commands.common.EventManager; 14 import org.eclipse.core.runtime.Assert; 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.core.runtime.IExecutableExtension; 17 import org.eclipse.core.runtime.Platform; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.resource.JFaceResources; 20 import org.eclipse.jface.util.SafeRunnable; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.ui.IMemento; 24 import org.eclipse.ui.IPropertyListener; 25 import org.eclipse.ui.ISharedImages; 26 import org.eclipse.ui.PartInitException; 27 import org.eclipse.ui.PlatformUI; 28 import org.eclipse.ui.internal.intro.IntroMessages; 29 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 30 import org.eclipse.ui.internal.util.Util; 31 import org.eclipse.ui.intro.IIntroPart; 32 import org.eclipse.ui.intro.IIntroSite; 33 import org.eclipse.ui.plugin.AbstractUIPlugin; 34 35 60 public abstract class IntroPart extends EventManager implements IIntroPart, 61 IExecutableExtension { 62 63 private IConfigurationElement configElement; 64 65 private ImageDescriptor imageDescriptor; 66 67 private IIntroSite partSite; 68 69 private Image titleImage; 70 71 private String titleLabel; 72 73 76 protected IntroPart() { 77 super(); 78 } 79 80 83 public void addPropertyListener(IPropertyListener l) { 84 addListenerObject(l); 85 } 86 87 96 public abstract void createPartControl(Composite parent); 97 98 103 public void dispose() { 104 if (titleImage != null) { 105 JFaceResources.getResources().destroyImage(imageDescriptor); 106 titleImage = null; 107 } 108 109 clearListeners(); 113 } 114 115 121 protected void firePropertyChange(final int propertyId) { 122 Object [] array = getListeners(); 123 for (int nX = 0; nX < array.length; nX++) { 124 final IPropertyListener l = (IPropertyListener) array[nX]; 125 Platform.run(new SafeRunnable() { 126 127 public void run() { 128 l.propertyChanged(this, propertyId); 129 } 130 }); 131 } 132 } 133 134 142 public Object getAdapter(Class adapter) { 143 return Platform.getAdapterManager().getAdapter(this, adapter); 144 } 145 146 153 protected IConfigurationElement getConfigurationElement() { 154 return configElement; 155 } 156 157 162 protected Image getDefaultImage() { 163 return PlatformUI.getWorkbench().getSharedImages().getImage( 164 ISharedImages.IMG_DEF_VIEW); 165 } 166 167 172 public final IIntroSite getIntroSite() { 173 return partSite; 174 } 175 176 179 public Image getTitleImage() { 180 if (titleImage != null) { 181 return titleImage; 182 } 183 return getDefaultImage(); 184 } 185 186 189 public String getTitle() { 190 if (titleLabel != null) { 191 return titleLabel; 192 } 193 return getDefaultTitle(); 194 } 195 196 201 private String getDefaultTitle() { 202 return IntroMessages.Intro_default_title; 203 } 204 205 218 public void init(IIntroSite site, IMemento memento) 219 throws PartInitException { 220 setSite(site); 221 } 222 223 231 protected void setSite(IIntroSite site) { 232 this.partSite = site; 233 } 234 235 238 public void removePropertyListener(IPropertyListener l) { 239 removeListenerObject(l); 240 } 241 242 249 public void saveState(IMemento memento) { 250 } 252 253 262 public abstract void setFocus(); 263 264 274 public void setInitializationData(IConfigurationElement cfig, 275 String propertyName, Object data) { 276 277 configElement = cfig; 279 280 titleLabel = cfig.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL); 281 282 String strIcon = cfig.getAttribute(IWorkbenchRegistryConstants.ATT_ICON); 284 if (strIcon == null) { 285 return; 286 } 287 288 imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( 289 configElement.getNamespace(), strIcon); 290 291 if (imageDescriptor == null) { 292 return; 293 } 294 295 Image image = JFaceResources.getResources().createImageWithDefault(imageDescriptor); 296 titleImage = image; 297 } 298 299 305 protected void setTitleImage(Image titleImage) { 306 Assert.isTrue(titleImage == null || !titleImage.isDisposed()); 307 if (this.titleImage == titleImage) { 309 return; 310 } 311 this.titleImage = titleImage; 312 firePropertyChange(IIntroPart.PROP_TITLE); 313 } 314 315 321 protected void setTitle(String titleLabel) { 322 Assert.isNotNull(titleLabel); 323 if (Util.equals(this.titleLabel, titleLabel)) 324 return; 325 this.titleLabel = titleLabel; 326 firePropertyChange(IIntroPart.PROP_TITLE); 327 } 328 } 329 | Popular Tags |