001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.internal.decorators;
011:
012: import org.eclipse.core.runtime.Assert;
013: import org.eclipse.jface.viewers.IDecorationContext;
014: import org.eclipse.osgi.util.NLS;
015: import org.eclipse.ui.internal.WorkbenchMessages;
016:
017: /**
018: * A DecorationReference is a class that holds onto the starting
019: * text and image of a decoration.
020: */
021: class DecorationReference {
022: Object element;
023:
024: Object adaptedElement;
025:
026: String undecoratedText;
027:
028: boolean forceUpdate = false;
029:
030: IDecorationContext[] contexts;
031:
032: DecorationReference(Object object, Object adaptedObject,
033: IDecorationContext context) {
034: this .contexts = new IDecorationContext[] { context };
035: Assert.isNotNull(object);
036: element = object;
037: this .adaptedElement = adaptedObject;
038: }
039:
040: /**
041: * Returns the adaptedElement.
042: * @return Object
043: */
044: Object getAdaptedElement() {
045: return adaptedElement;
046: }
047:
048: /**
049: * Returns the element.
050: * @return Object
051: */
052: Object getElement() {
053: return element;
054: }
055:
056: /**
057: * Return true if an update should occur whether or
058: * not there is a result.
059: * @return boolean
060: */
061: boolean shouldForceUpdate() {
062: return forceUpdate;
063: }
064:
065: /**
066: * Sets the forceUpdate flag. If true an update
067: * occurs whether or not a decoration has resulted.
068: * @param forceUpdate The forceUpdate to set
069: */
070: void setForceUpdate(boolean forceUpdate) {
071: this .forceUpdate = forceUpdate;
072: }
073:
074: /**
075: * Set the text that will be used to label the decoration
076: * calculation.
077: * @param text
078: */
079: void setUndecoratedText(String text) {
080: undecoratedText = text;
081: }
082:
083: /**
084: * Return the string for the subtask for this element.
085: * @return String
086: */
087: String getSubTask() {
088: if (undecoratedText == null) {
089: return WorkbenchMessages.DecorationReference_EmptyReference;
090: }
091: return NLS
092: .bind(
093: WorkbenchMessages.DecorationScheduler_DecoratingSubtask,
094: undecoratedText);
095: }
096:
097: /**
098: * Returns the decoration context associated with the element
099: * being decorated
100: * @return the decoration context
101: */
102: IDecorationContext[] getContexts() {
103: return contexts;
104: }
105:
106: void addContext(IDecorationContext context) {
107: IDecorationContext[] newContexts = new IDecorationContext[contexts.length + 1];
108: System.arraycopy(contexts, 0, newContexts, 0, contexts.length);
109: newContexts[contexts.length] = context;
110: contexts = newContexts;
111: }
112: }
|