1 11 package org.eclipse.ui.internal.part.services; 12 13 import org.eclipse.jface.resource.ImageDescriptor; 14 import org.eclipse.ui.internal.components.Assert; 15 import org.eclipse.ui.internal.components.framework.ComponentException; 16 import org.eclipse.ui.internal.components.framework.IServiceProvider; 17 import org.eclipse.ui.internal.part.Part; 18 import org.eclipse.ui.internal.part.components.services.INameable; 19 import org.eclipse.ui.internal.part.components.services.IPartDescriptor; 20 import org.eclipse.ui.internal.part.multiplexer.INestedComponent; 21 import org.eclipse.ui.internal.part.multiplexer.ISharedContext; 22 23 28 public class ChildNameable implements INameable, INestedComponent { 29 30 private String currentName = ""; private String contentDescription = ""; private ImageDescriptor image = ImageDescriptor.getMissingImageDescriptor(); 33 private String tooltip = ""; private INameable parent; 35 private boolean isActive = false; 36 37 40 public ChildNameable(IPartDescriptor descr, ISharedContext shared) throws ComponentException { 41 Assert.isNotNull(descr); 42 IServiceProvider sharedContainer = shared.getSharedComponents(); 43 44 currentName = descr.getLabel(); 45 Assert.isNotNull(currentName); 46 image = descr.getImage(); 47 this.parent = (INameable)sharedContainer.getService(INameable.class); 48 } 49 50 53 public void setName(String newName) { 54 Assert.isNotNull(newName); 55 if (!newName.equals(currentName)) { 56 currentName = newName; 57 if (isActive) { 58 parent.setName(newName); 59 } 60 } 61 } 62 63 66 public void setContentDescription(String contentDescription) { 67 if (!this.contentDescription.equals(contentDescription)) { 68 this.contentDescription = contentDescription; 69 if (isActive) { 70 parent.setContentDescription(contentDescription); 71 } 72 } 73 } 74 75 78 public void setImage(ImageDescriptor theImage) { 79 if (theImage != image) { 80 image = theImage; 81 if (isActive) { 82 parent.setImage(theImage); 83 } 84 } 85 } 86 87 90 public void setTooltip(String toolTip) { 91 if (!toolTip.equals(this.tooltip)) { 92 this.tooltip = toolTip; 93 if (isActive) { 94 parent.setTooltip(toolTip); 95 } 96 } 97 } 98 99 102 public void activate(Part newActivePart) { 103 if (isActive) { 104 return; 105 } 106 107 if (parent != null) { 108 parent.setName(currentName); 109 parent.setImage(image); 110 parent.setTooltip(tooltip); 111 parent.setContentDescription(contentDescription); 112 } 113 114 isActive = true; 115 } 116 117 public void deactivate(Object newActive) { 118 isActive = false; 119 } 120 } 121 | Popular Tags |