KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > ReusableViewerLabel


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

9
10 package org.eclipse.ui.internal.navigator;
11
12 import org.eclipse.jface.viewers.ViewerLabel;
13
14 /**
15  * Provides a subclass of ViewerLabel that can be re-used for multiple viewer updates.
16  *
17  * @since 3.2
18  *
19  */

20 public class ReusableViewerLabel extends ViewerLabel {
21
22     private ViewerLabel original = null;
23     /**
24      * Creates a ViewerLabel with null text and image.
25      *
26      */

27     public ReusableViewerLabel() {
28         super(null, null);
29     }
30
31
32     /**
33      * Updates the Background, Foreground, and Font to the given ViewerLabel. The
34      * Text and Image are reset to <b>null</b>.
35      *
36      * @param theOriginal The ViewerLabel to represent.
37      */

38     public void reset(ViewerLabel theOriginal) {
39         original = theOriginal;
40         setBackground(original.getBackground());
41         setFont(original.getFont());
42         setForeground(original.getForeground());
43         setImage(null);
44         setText(null);
45     }
46     
47     /**
48      *
49      * @param theOriginal The ViewerLabel to fill with my values.
50      */

51     public void fill(ViewerLabel theOriginal) {
52
53         theOriginal.setBackground(getBackground());
54         theOriginal.setFont(getFont());
55         theOriginal.setForeground(getForeground());
56         theOriginal.setImage(getImage());
57         theOriginal.setText(getText() != null ? getText() : ""); //$NON-NLS-1$
58
}
59
60     /**
61      *
62      * @return True if the ReusableViewerLabel has different text or image than the original
63      * ViewerLabel.
64      */

65     public boolean hasChanged() {
66         
67         boolean changed = false;
68         if(original != null) {
69             if(original.getText() == null ^ getText() != null)
70                 changed |= getText() != null;
71             if(original.getText() != null && getImage() != null)
72                 changed |= !getImage().equals(original.getImage());
73         }
74         return changed;
75     }
76
77     /**
78      * @return True if the text is non-null and non-zero in length.
79      */

80     public boolean isValid() {
81         return getText() != null && getText().length() > 0 && getImage() != null;
82
83     }
84
85 }
86
Popular Tags