01: /***************************************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others. All rights reserved. This program and the
03: * accompanying materials are made available under the terms of the Eclipse Public License v1.0
04: * which accompanies this distribution, and is available at
05: * http://www.eclipse.org/legal/epl-v10.html
06: *
07: * Contributors: IBM Corporation - initial API and implementation
08: **************************************************************************************************/package org.eclipse.ui.internal.navigator;
09:
10: import org.eclipse.jface.viewers.ViewerLabel;
11:
12: /**
13: * Provides a subclass of ViewerLabel that can be re-used for multiple viewer updates.
14: *
15: * @since 3.2
16: *
17: */
18: public class ReusableViewerLabel extends ViewerLabel {
19:
20: private ViewerLabel original = null;
21:
22: /**
23: * Creates a ViewerLabel with null text and image.
24: *
25: */
26: public ReusableViewerLabel() {
27: super (null, null);
28: }
29:
30: /**
31: * Updates the Background, Foreground, and Font to the given ViewerLabel. The
32: * Text and Image are reset to <b>null</b>.
33: *
34: * @param theOriginal The ViewerLabel to represent.
35: */
36: public void reset(ViewerLabel theOriginal) {
37: original = theOriginal;
38: setBackground(original.getBackground());
39: setFont(original.getFont());
40: setForeground(original.getForeground());
41: setImage(null);
42: setText(null);
43: }
44:
45: /**
46: *
47: * @param theOriginal The ViewerLabel to fill with my values.
48: */
49: public void fill(ViewerLabel theOriginal) {
50:
51: theOriginal.setBackground(getBackground());
52: theOriginal.setFont(getFont());
53: theOriginal.setForeground(getForeground());
54: theOriginal.setImage(getImage());
55: theOriginal.setText(getText() != null ? getText() : ""); //$NON-NLS-1$
56: }
57:
58: /**
59: *
60: * @return True if the ReusableViewerLabel has different text or image than the original
61: * ViewerLabel.
62: */
63: public boolean hasChanged() {
64:
65: boolean changed = false;
66: if (original != null) {
67: if (original.getText() == null ^ getText() != null)
68: changed |= getText() != null;
69: if (original.getText() != null && getImage() != null)
70: changed |= !getImage().equals(original.getImage());
71: }
72: return changed;
73: }
74:
75: /**
76: * @return True if the text is non-null and non-zero in length.
77: */
78: public boolean isValid() {
79: return getText() != null && getText().length() > 0
80: && getImage() != null;
81:
82: }
83:
84: }
|