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 java.text.DateFormat;
25  import java.text.SimpleDateFormat;
26  
27  import org.apache.log4j.Logger;
28  import org.eclipse.jface.viewers.ITableLabelProvider;
29  import org.eclipse.jface.viewers.LabelProvider;
30  import org.eclipse.swt.graphics.Image;
31  import org.eclipse.ui.ISharedImages;
32  import org.eclipse.ui.PlatformUI;
33  import org.fosstrak.llrp.client.LLRPMessageItem;
34  import org.fosstrak.llrp.client.repository.sql.DerbyRepository;
35  import org.fosstrak.llrp.commander.ResourceCenter;
36  
37  
38  /**
39  * label provider for the message box view. Depending on the column the 
40  * provider returns the message id, the adaptor/reader name etc.
41  * @author zhanghao
42  * @author sawielan
43  *
44  */
45  public class MessageboxViewLabelProvider extends LabelProvider implements
46  		ITableLabelProvider {
47  	
48  	/**
49  	 * Log4j instance.
50  	 */
51  	private static Logger log = Logger.getLogger(DerbyRepository.class);
52  	
53  	private static final DateFormat DATE_FORMATTER = new SimpleDateFormat(
54  			"yyyy-MMM-dd HH:mm:ss.SSS");
55  
56  	public String getColumnText(Object aObj, int aIndex) {
57  		LLRPMessageItem msg = (LLRPMessageItem) aObj;
58  		
59  		switch (aIndex) {
60  			case MessageboxView.COL_MSG_ID:
61  				return msg.getId();
62  			case MessageboxView.COL_MSG_ADAPTER:
63  				return (msg.getAdapter()).trim();
64  			case MessageboxView.COL_MSG_READER:
65  				return (msg.getReader().trim());
66  			case MessageboxView.COL_MSG_TYPE:
67  				return msg.getMessageType();
68  			case MessageboxView.COL_STATUS_CODE:
69  				return msg.getStatusCode();
70  			case MessageboxView.COL_MSG_COMMENT:
71  				return msg.getComment();
72  			case MessageboxView.COL_MSG_TIME:
73  				return DATE_FORMATTER.format(msg.getTime());
74  		}
75  		
76  		return "";
77  	}
78  
79  	public Image getColumnImage(Object aObj, int aIndex) {
80  		
81  		LLRPMessageItem msg = (LLRPMessageItem) aObj;
82  		
83  		if (aIndex == MessageboxView.COL_MSG_MARK) {
84  			
85  			ISharedImages sharedImages =
86  		         PlatformUI.getWorkbench().getSharedImages();
87  			
88  			log.debug("Mark value is " + msg.getMark());
89  			
90  			if (msg.getMark() == LLRPMessageItem.MARK_INCOMING) {
91  				return ResourceCenter.getInstance().getImage("incomingMsg.gif");
92  			} else {
93  				return ResourceCenter.getInstance().getImage("outgoingMsg.gif");
94  			}
95  			
96  		}
97  		
98  		return null;
99  	}
100 }