1 20 21 package org.apache.directory.ldapstudio.schemas.view.views; 22 23 24 import org.apache.directory.ldapstudio.schemas.Activator; 25 import org.apache.directory.ldapstudio.schemas.controller.SchemaElementsController; 26 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ITreeNode; 27 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.SchemaElementsViewRoot; 28 import org.eclipse.jface.viewers.DecoratingLabelProvider; 29 import org.eclipse.jface.viewers.TreeViewer; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.ui.part.ViewPart; 33 34 35 41 public class SchemaElementsView extends ViewPart 42 { 43 44 public static final String ID = Activator.PLUGIN_ID + ".view.SchemaElementsView"; 46 47 private TreeViewer viewer; 48 49 50 private SchemaElementsViewContentProvider contentProvider; 51 52 53 56 public void createPartControl( Composite parent ) 57 { 58 initViewer( parent ); 59 60 getSite().setSelectionProvider( viewer ); 62 63 new SchemaElementsController( this ); 65 } 66 67 68 74 private void initViewer( Composite parent ) 75 { 76 viewer = new TreeViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); 77 contentProvider = new SchemaElementsViewContentProvider( viewer ); 78 viewer.setContentProvider( contentProvider ); 79 viewer.setLabelProvider( new DecoratingLabelProvider( new SchemaElementsViewLabelProvider(), Activator 80 .getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) ); 81 viewer.setInput( new SchemaElementsViewRoot() ); 82 } 83 84 85 88 public void setFocus() 89 { 90 viewer.getControl().setFocus(); 91 } 92 93 94 97 public void refresh() 98 { 99 viewer.refresh(); 100 } 101 102 103 106 public void update() 107 { 108 viewer.update( viewer.getInput(), null ); 109 } 110 111 112 120 public ITreeNode findElementInTree( ITreeNode element ) 121 { 122 Object [] children = contentProvider.getChildren( ( ITreeNode ) getViewer().getInput() ); 123 124 for ( Object child : children ) 125 { 126 ITreeNode item = ( ITreeNode ) child; 127 if ( item.equals( element ) ) 128 { 129 return item; 130 } 131 } 132 133 return null; 134 } 135 136 137 143 public TreeViewer getViewer() 144 { 145 return viewer; 146 } 147 } | Popular Tags |