KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > services > ChildNameable


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
24  * Multiplexed version of the INameable interface.
25  *
26  * @since 3.1
27  */

28 public class ChildNameable implements INameable, INestedComponent {
29
30     private String JavaDoc currentName = ""; //$NON-NLS-1$
31
private String JavaDoc contentDescription = ""; //$NON-NLS-1$
32
private ImageDescriptor image = ImageDescriptor.getMissingImageDescriptor();
33     private String JavaDoc tooltip = ""; //$NON-NLS-1$
34
private INameable parent;
35     private boolean isActive = false;
36     
37     /**
38      * Component constructor. Do not invoke directly.
39      */

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     /* (non-Javadoc)
51      * @see org.eclipse.ui.workbench.services.INameable#setName(java.lang.String)
52      */

53     public void setName(String JavaDoc 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     /* (non-Javadoc)
64      * @see org.eclipse.ui.workbench.services.INameable#setContentDescription(java.lang.String)
65      */

66     public void setContentDescription(String JavaDoc contentDescription) {
67         if (!this.contentDescription.equals(contentDescription)) {
68             this.contentDescription = contentDescription;
69             if (isActive) {
70                 parent.setContentDescription(contentDescription);
71             }
72         }
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.ui.workbench.services.INameable#setImage(org.eclipse.jface.resource.ImageDescriptor)
77      */

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     /* (non-Javadoc)
88      * @see org.eclipse.ui.workbench.services.INameable#setTooltip(java.lang.String)
89      */

90     public void setTooltip(String JavaDoc toolTip) {
91         if (!toolTip.equals(this.tooltip)) {
92             this.tooltip = toolTip;
93             if (isActive) {
94                 parent.setTooltip(toolTip);
95             }
96         }
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.ui.internal.part.serviceimplementation.multiplexer.INestedComponent#activate()
101      */

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 JavaDoc newActive) {
118         isActive = false;
119     }
120 }
121
Popular Tags