KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > decorators > DecorationReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.decorators;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.jface.viewers.IDecorationContext;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.ui.internal.WorkbenchMessages;
17
18 /**
19  * A DecorationReference is a class that holds onto the starting
20  * text and image of a decoration.
21  */

22 class DecorationReference {
23     Object JavaDoc element;
24
25     Object JavaDoc adaptedElement;
26
27     String JavaDoc undecoratedText;
28
29     boolean forceUpdate = false;
30
31     IDecorationContext[] contexts;
32
33     DecorationReference(Object JavaDoc object, Object JavaDoc adaptedObject, IDecorationContext context) {
34         this.contexts = new IDecorationContext[] { context} ;
35         Assert.isNotNull(object);
36         element = object;
37         this.adaptedElement = adaptedObject;
38     }
39
40     /**
41      * Returns the adaptedElement.
42      * @return Object
43      */

44     Object JavaDoc getAdaptedElement() {
45         return adaptedElement;
46     }
47
48     /**
49      * Returns the element.
50      * @return Object
51      */

52     Object JavaDoc getElement() {
53         return element;
54     }
55
56     /**
57      * Return true if an update should occur whether or
58      * not there is a result.
59      * @return boolean
60      */

61     boolean shouldForceUpdate() {
62         return forceUpdate;
63     }
64
65     /**
66      * Sets the forceUpdate flag. If true an update
67      * occurs whether or not a decoration has resulted.
68      * @param forceUpdate The forceUpdate to set
69      */

70     void setForceUpdate(boolean forceUpdate) {
71         this.forceUpdate = forceUpdate;
72     }
73
74     /**
75      * Set the text that will be used to label the decoration
76      * calculation.
77      * @param text
78      */

79     void setUndecoratedText(String JavaDoc text) {
80         undecoratedText = text;
81     }
82
83     /**
84      * Return the string for the subtask for this element.
85      * @return String
86      */

87     String JavaDoc getSubTask() {
88         if (undecoratedText == null) {
89             return WorkbenchMessages.DecorationReference_EmptyReference;
90         }
91     return NLS.bind(WorkbenchMessages.DecorationScheduler_DecoratingSubtask, undecoratedText );
92     }
93
94     /**
95      * Returns the decoration context associated with the element
96      * being decorated
97      * @return the decoration context
98      */

99     IDecorationContext[] getContexts() {
100         return contexts;
101     }
102
103     void addContext(IDecorationContext context) {
104         IDecorationContext[] newContexts = new IDecorationContext[contexts.length + 1];
105         System.arraycopy(contexts, 0, newContexts, 0, contexts.length);
106         newContexts[contexts.length] = context;
107         contexts = newContexts;
108     }
109 }
110
Popular Tags