KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > views > SchemaElementsView


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

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 /**
36  * This class implements the Schema Elements View where all the object classes and attribute types are displayed.
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class SchemaElementsView extends ViewPart
42 {
43     /** The view's ID */
44     public static final String JavaDoc ID = Activator.PLUGIN_ID + ".view.SchemaElementsView"; //$NON-NLS-1$
45

46     /** The tree viewer */
47     private TreeViewer viewer;
48
49     /** The content provider */
50     private SchemaElementsViewContentProvider contentProvider;
51
52
53     /* (non-Javadoc)
54      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
55      */

56     public void createPartControl( Composite parent )
57     {
58         initViewer( parent );
59
60         // Registering the Viewer, so other views can be notified when the viewer selection changes
61
getSite().setSelectionProvider( viewer );
62
63         // Adding the controller
64
new SchemaElementsController( this );
65     }
66
67
68     /**
69      * Initializes the viewer.
70      *
71      * @param parent
72      * the parent element
73      */

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     /* (non-Javadoc)
86      * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
87      */

88     public void setFocus()
89     {
90         viewer.getControl().setFocus();
91     }
92
93
94     /**
95      * Refresh the viewer
96      */

97     public void refresh()
98     {
99         viewer.refresh();
100     }
101
102
103     /**
104      * Updates the viewer
105      */

106     public void update()
107     {
108         viewer.update( viewer.getInput(), null );
109     }
110
111
112     /**
113      * Search for the given element in the Tree and returns it if it has been found.
114      *
115      * @param element
116      * the element to find
117      * @return
118      * the element if it has been found, null if has not been found
119      */

120     public ITreeNode findElementInTree( ITreeNode element )
121     {
122         Object JavaDoc[] children = contentProvider.getChildren( ( ITreeNode ) getViewer().getInput() );
123
124         for ( Object JavaDoc 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     /**
138      * Gets the tree viewer.
139      *
140      * @return
141      * the tree viewer
142      */

143     public TreeViewer getViewer()
144     {
145         return viewer;
146     }
147 }
Popular Tags