Home | History | Annotate | Download | only in tree
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.uiautomator.tree;
     18 
     19 
     20 import org.eclipse.jface.viewers.ITreeContentProvider;
     21 import org.eclipse.jface.viewers.Viewer;
     22 
     23 public class BasicTreeNodeContentProvider implements ITreeContentProvider {
     24 
     25     private static final Object[] EMPTY_ARRAY = {};
     26 
     27     @Override
     28     public void dispose() {
     29     }
     30 
     31     @Override
     32     public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
     33     }
     34 
     35     @Override
     36     public Object[] getElements(Object inputElement) {
     37         return getChildren(inputElement);
     38     }
     39 
     40     @Override
     41     public Object[] getChildren(Object parentElement) {
     42         if (parentElement instanceof BasicTreeNode) {
     43             return ((BasicTreeNode)parentElement).getChildren();
     44         }
     45         return EMPTY_ARRAY;
     46     }
     47 
     48     @Override
     49     public Object getParent(Object element) {
     50         if (element instanceof BasicTreeNode) {
     51             return ((BasicTreeNode)element).getParent();
     52         }
     53         return null;
     54     }
     55 
     56     @Override
     57     public boolean hasChildren(Object element) {
     58         if (element instanceof BasicTreeNode) {
     59             return ((BasicTreeNode) element).hasChild();
     60         }
     61         return false;
     62     }
     63 }
     64