001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.examples.components.views.context;
011:
012: import org.eclipse.jface.resource.ImageDescriptor;
013: import org.eclipse.ui.internal.part.components.services.INameable;
014:
015: /**
016: * Multiplexed version of the INameable interface.
017: *
018: * @since 3.1
019: */
020: public class HardcodedChildNameable implements INameable {
021:
022: private String currentName = ""; //$NON-NLS-1$
023: private String descr = ""; //$NON-NLS-1$
024: private ImageDescriptor image = ImageDescriptor
025: .getMissingImageDescriptor();
026: private String tooltip = ""; //$NON-NLS-1$
027: private INameable parent;
028: private boolean isActive = false;
029:
030: /**
031: * Component constructor. Do not invoke directly.
032: */
033: public HardcodedChildNameable(INameable parent,
034: String initialLabel, ImageDescriptor initialImage) {
035: currentName = initialLabel;
036: image = initialImage;
037: this .parent = parent;
038: }
039:
040: /* (non-Javadoc)
041: * @see org.eclipse.ui.workbench.services.INameable#setName(java.lang.String)
042: */
043: public void setName(String newName) {
044: if (!newName.equals(currentName)) {
045: currentName = newName;
046: if (isActive) {
047: parent.setName(newName);
048: }
049: }
050: }
051:
052: /* (non-Javadoc)
053: * @see org.eclipse.ui.workbench.services.INameable#setContentDescription(java.lang.String)
054: */
055: public void setContentDescription(String contentDescription) {
056: if (!descr.equals(contentDescription)) {
057: descr = contentDescription;
058: if (isActive) {
059: parent.setContentDescription(contentDescription);
060: }
061: }
062: }
063:
064: /* (non-Javadoc)
065: * @see org.eclipse.ui.workbench.services.INameable#setImage(org.eclipse.jface.resource.ImageDescriptor)
066: */
067: public void setImage(ImageDescriptor theImage) {
068: if (theImage != image) {
069: image = theImage;
070: if (isActive) {
071: parent.setImage(theImage);
072: }
073: }
074: }
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.ui.workbench.services.INameable#setTooltip(java.lang.String)
078: */
079: public void setTooltip(String toolTip) {
080: if (!toolTip.equals(this .tooltip)) {
081: this .tooltip = toolTip;
082: if (isActive) {
083: parent.setTooltip(toolTip);
084: }
085: }
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.ui.part.serviceimplementation.multiplexer.INestedComponent#activate()
090: */
091: public void activate() {
092: if (isActive) {
093: return;
094: }
095:
096: if (parent != null) {
097: parent.setName(currentName);
098: parent.setImage(image);
099: parent.setTooltip(tooltip);
100: parent.setContentDescription(descr);
101: }
102:
103: isActive = true;
104: }
105:
106: public void deactivate() {
107: isActive = false;
108: }
109: }
|