View Javadoc

1   /*
2    *  
3    *  Fosstrak LLRP Commander (www.fosstrak.org)
4    * 
5    *  Copyright (C) 2008 ETH Zurich
6    *
7    *  This program is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  This program is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with this program.  If not, see <http://www.gnu.org/licenses/> 
19   *
20   */
21  
22  package org.fosstrak.llrp.commander.views;
23  
24  import org.eclipse.jface.viewers.LabelProvider;
25  import org.eclipse.swt.graphics.Image;
26  import org.eclipse.ui.ISharedImages;
27  import org.eclipse.ui.PlatformUI;
28  import org.fosstrak.llrp.commander.ResourceCenter;
29  
30  
31  /**
32  * label provider for the reader explorer view. Essentially returns the 
33  * adaptor name (in case of an adaptor) or the reader name (together with the 
34  * status of the reader).
35  * @author zhanghao
36  * @author sawielan
37  *
38  */
39  public class ReaderExplorerViewLabelProvider extends LabelProvider {
40  	
41  	/**
42  	 * Get the string value of the object on the tree.
43  	 */
44  	public String getText(Object obj) {
45  		
46  		if (null == obj) {
47  			return "";
48  		} 
49  		
50  		if (obj instanceof ReaderTreeObject) {
51  			ReaderTreeObject rdr = (ReaderTreeObject) obj;
52  			
53  			String status = rdr.isConnected() ? "Connected" : "Disconnected";
54  			
55  			if (rdr.isReader()) {
56  				return rdr.toString() + "(" + status + ")";
57  			}
58  		}
59  		
60  		return obj.toString();
61  	}
62  
63  	/**
64  	 * Get the Image object of the object on the tree.
65  	 */
66  	public Image getImage(Object obj) {
67  		
68  		String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
69  		if (obj instanceof ReaderTreeObject) {
70  			//imageKey = ISharedImages.IMG_OBJ_FOLDER;
71  			ReaderTreeObject treeObj = (ReaderTreeObject) obj;
72  			
73  			if (treeObj.isReader()) {
74  				if (treeObj.isConnected()) {
75  					return ResourceCenter.getInstance().getImage("People_069.gif");
76  				} else {
77  					return ResourceCenter.getInstance().getImage("People_070.gif");
78  				}
79  			}
80  			
81  			return ResourceCenter.getInstance().getImage("adapter.gif");
82  		}
83  		return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
84  	}
85  
86  }