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;
23  
24  import org.eclipse.jface.viewers.*;
25  
26  /**
27   * Provides the content of an LLRP message for a tree viewer. This content 
28   * provider returns the content encoded as an array of BinarySingleValue.
29   * @author Haoning Zhang
30   * @author sawielan
31   *
32   */
33  public class LLRPBinaryContentProvider implements ITreeContentProvider {
34  
35  	private BinaryMessage message;
36  	
37  	public void inputChanged (Viewer aViewer, Object aOldInput, Object aNewInput) {
38  		message = (BinaryMessage) aNewInput;
39  	}
40  	
41  	public Object[] getElements(Object aElement) {
42  		return getChildren(aElement);
43  	}
44  	
45  	/**
46  	 * @return an array encoding the content of the LLRP message for the 
47  	 * binary editor. The important values are encoded as {@link BinarySingleValue}.
48  	 */
49  	public Object[] getChildren(Object aElement) {
50  		if (aElement instanceof BinaryMessage) {
51  			BinaryMessage msg = (BinaryMessage) aElement;
52  			
53  			// to achieve a nicer presentation in the binary view, we 
54  			// use the split parameters instead of one huge binary string.
55  			
56  			BinarySingleValue[] arr = msg.getSplitParameters();
57  			int len = 5 + arr.length;
58  			BinarySingleValue[] values = new BinarySingleValue[len];
59  			values[0] = msg.getReserved();
60  			values[1] = msg.getVersion();
61  			values[2] = msg.getMsgType();
62  			values[3] = msg.getMsgID();
63  			values[4] = msg.getMsgLength();
64  			//values[5] = msg.getParameters();
65  			
66  			for (int i=5; i<len; i++) {
67  				values[i] = arr[i-5];
68  			}
69  			
70  			return values;
71  		}
72  		
73  		return null;
74  	}
75  	
76  	public Object getParent(Object aElement) {
77  		if (aElement instanceof BinarySingleValue) {
78  			BinarySingleValue value = (BinarySingleValue) aElement;
79  			return value.getParent();
80  		}
81  		return null;
82  	}
83  	
84  	public boolean hasChildren(Object aElement) {
85  		if (aElement instanceof BinaryMessage) {
86  			return true;
87  		}
88  		
89  		return false;
90  	}
91  	
92  	public void dispose() {
93  		
94  	}
95  }