1 20 package org.apache.directory.ldapstudio.schemas.view.views; 21 22 23 import org.apache.directory.ldapstudio.schemas.Activator; 24 import org.apache.directory.ldapstudio.schemas.controller.HierarchyViewController; 25 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ITreeNode; 26 import org.eclipse.jface.viewers.DecoratingLabelProvider; 27 import org.eclipse.jface.viewers.TreeViewer; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.ui.part.ViewPart; 31 32 33 39 public class HierarchyView extends ViewPart 40 { 41 42 public static final String ID = Activator.PLUGIN_ID + ".view.HierarchyView"; 44 45 private TreeViewer viewer; 46 47 48 private HierarchyViewContentProvider contentProvider; 49 50 51 54 public void createPartControl( Composite parent ) 55 { 56 initViewer( parent ); 57 58 new HierarchyViewController( this ); 59 } 60 61 62 68 private void initViewer( Composite parent ) 69 { 70 viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); 71 contentProvider = new HierarchyViewContentProvider( viewer ); 72 viewer.setContentProvider( contentProvider ); 73 viewer.setLabelProvider( new DecoratingLabelProvider( new HierarchyViewLabelProvider(), Activator.getDefault() 74 .getWorkbench().getDecoratorManager().getLabelDecorator() ) ); 75 } 76 77 78 81 public void setFocus() 82 { 83 viewer.getControl().setFocus(); 84 } 85 86 87 93 public TreeViewer getViewer() 94 { 95 return viewer; 96 } 97 98 99 102 public void refresh() 103 { 104 viewer.refresh(); 105 viewer.expandAll(); 106 } 107 108 109 public void setInput( Object input ) 110 { 111 viewer.setInput( input ); 112 viewer.expandAll(); 113 } 114 115 116 124 public ITreeNode findElementInTree( ITreeNode element ) 125 { 126 if ( element == null ) 127 { 128 return null; 129 } 130 131 ITreeNode input = ( ITreeNode ) getViewer().getInput(); 132 133 return findElementInTree( element, input ); 134 } 135 136 137 146 public ITreeNode findElementInTree( ITreeNode element, ITreeNode node ) 147 { 148 if ( element.equals( node ) ) 149 { 150 return node; 151 } 152 else 153 { 154 Object [] children = contentProvider.getChildren( node ); 155 for ( Object child : children ) 156 { 157 ITreeNode foundElement = findElementInTree( element, ( ITreeNode ) child ); 158 if ( foundElement != null ) 159 { 160 return foundElement; 161 } 162 } 163 } 164 return null; 165 } 166 } 167 | Popular Tags |