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.editors.graphical;
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  import org.fosstrak.llrp.commander.util.LLRPTreeMaintainer;
30  import org.llrp.ltk.types.LLRPMessage;
31  import org.llrp.ltk.types.LLRPParameter;
32  
33  /**
34   * Label Provider for the message tree.
35   *
36   * @author Ulrich Etter, ETHZ
37   *
38   */
39  class LLRPTreeLabelProvider extends LabelProvider {
40  	
41  	private LLRPTreeMaintainer treeMaintainer;
42  
43  	public LLRPTreeLabelProvider(LLRPTreeMaintainer treeMaintainer){
44  		this.treeMaintainer = treeMaintainer;
45  	}
46  
47  	/* (non-Javadoc)
48  	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
49  	 */
50  	public String getText(Object object) {
51  		return treeMaintainer.getName(object);
52  	}
53  	
54  	/* (non-Javadoc)
55  	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
56  	 */
57  	public Image getImage(Object object) {
58  		String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
59  		if (treeMaintainer.isValid(object)){
60  			if (object instanceof LLRPMessage){
61  			   return ResourceCenter.getInstance().getImage("Message.gif");
62  			}
63  			else if (object instanceof LLRPParameter){
64  				imageKey = ISharedImages.IMG_OBJ_ELEMENT;
65  			}
66  			else if (object instanceof java.util.List){
67  				imageKey = ISharedImages.IMG_OBJ_FOLDER;
68  			}
69  		}
70  		else{
71  			imageKey = ISharedImages.IMG_OBJS_ERROR_TSK;
72  		}
73  		return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
74  	}
75  }