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.ITreeContentProvider; 25 import org.eclipse.jface.viewers.Viewer; 26 import org.fosstrak.llrp.commander.util.LLRPTreeMaintainer; 27 28 /** 29 * Content Provider for the message tree. 30 * 31 * @author Ulrich Etter, ETHZ 32 * 33 */ 34 class LLRPTreeContentProvider implements ITreeContentProvider { 35 36 private LLRPTreeMaintainer treeMaintainer; 37 38 public LLRPTreeContentProvider(LLRPTreeMaintainer treeMaintainer){ 39 this.treeMaintainer = treeMaintainer; 40 } 41 42 /* (non-Javadoc) 43 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) 44 */ 45 public void inputChanged(Viewer v, Object oldInput, Object newInput) { 46 } 47 48 /* (non-Javadoc) 49 * @see org.eclipse.jface.viewers.IContentProvider#dispose() 50 */ 51 public void dispose() { 52 } 53 54 /* (non-Javadoc) 55 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) 56 */ 57 public Object[] getElements(Object inputElement) { 58 return new Object[]{((LLRPTreeMaintainer) inputElement).getRoot()}; 59 } 60 61 /* (non-Javadoc) 62 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) 63 */ 64 public Object getParent(Object child) { 65 return treeMaintainer.getParent(child); 66 } 67 68 /* (non-Javadoc) 69 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) 70 */ 71 public Object[] getChildren(Object parent) { 72 java.util.List<Object> children = treeMaintainer.getNonNullChildren(parent); 73 return children.toArray(new Object[0]); 74 } 75 76 /* (non-Javadoc) 77 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) 78 */ 79 public boolean hasChildren(Object parent) { 80 if (getChildren(parent).length > 0){ 81 return true; 82 } 83 else{ 84 return false; 85 } 86 } 87 }