KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > browser > BrowserWidget


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.browser.common.widgets.browser;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget;
25 import org.eclipse.jface.action.IMenuManager;
26 import org.eclipse.jface.action.IToolBarManager;
27 import org.eclipse.jface.viewers.TreeViewer;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Tree;
33 import org.eclipse.ui.IActionBars;
34
35
36 /**
37  * The BrowserWidget is a reusable widget that displays the DIT, searches
38  * and bookmarks of a connection a tree viewer.
39  * It is used by {@link BrowserView} and {@link SelectEntryDialog}.
40  *
41  * It provides a context menu and a local toolbar with actions to
42  * manage entries, searches and bookmarks.
43  *
44  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
45  * @version $Rev$, $Date$
46  */

47 public class BrowserWidget extends ViewFormWidget
48 {
49
50     /** The widget's configuration with the content provider, label provider and menu manager */
51     private BrowserConfiguration configuration;
52
53     /** The action bars. */
54     private IActionBars actionBars;
55
56     /** The tree widget used by the tree viewer */
57     private Tree tree;
58
59     /** The tree viewer. */
60     private TreeViewer viewer;
61
62
63     /**
64      * Creates a new instance of BrowserWidget.
65      *
66      * @param configuration the configuration
67      * @param actionBars the action bars
68      */

69     public BrowserWidget( BrowserConfiguration configuration, IActionBars actionBars )
70     {
71         this.configuration = configuration;
72         this.actionBars = actionBars;
73     }
74
75
76     /**
77      * {@inheritDoc}
78      */

79     public void createWidget( Composite parent )
80     {
81         if ( actionBars == null )
82         {
83             super.createWidget( parent );
84         }
85         else
86         {
87             createContent( parent );
88         }
89     }
90
91
92     /**
93      * {@inheritDoc}
94      */

95     public IToolBarManager getToolBarManager()
96     {
97         if ( actionBars == null )
98         {
99             return super.getToolBarManager();
100         }
101         else
102         {
103             return actionBars.getToolBarManager();
104         }
105     }
106
107
108     /**
109      * {@inheritDoc}
110      */

111     public IMenuManager getMenuManager()
112     {
113         if ( actionBars == null )
114         {
115             return super.getMenuManager();
116         }
117         else
118         {
119             return actionBars.getMenuManager();
120         }
121     }
122
123
124     /**
125      * {@inheritDoc}
126      */

127     public IMenuManager getContextMenuManager()
128     {
129         if ( actionBars == null )
130         {
131             return super.getContextMenuManager();
132         }
133         else
134         {
135             return configuration.getContextMenuManager( viewer );
136         }
137     }
138
139
140     /**
141      * {@inheritDoc}
142      */

143     protected Control createContent( Composite parent )
144     {
145
146         // create tree widget and viewer
147
tree = new Tree( parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
148         GridData data = new GridData( GridData.FILL_BOTH );
149         data.widthHint = 450;
150         data.heightHint = 250;
151         tree.setLayoutData( data );
152         viewer = new TreeViewer( tree );
153         viewer.setUseHashlookup( true );
154
155         // setup sorter, filter and layout
156
configuration.getSorter().connect( viewer );
157         configuration.getPreferences().connect( viewer );
158
159         // setup providers
160
viewer.setContentProvider( configuration.getContentProvider( viewer ) );
161         viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
162
163         return tree;
164     }
165
166
167     /**
168      * Sets the input to the tree viewer.
169      *
170      * @param input the input
171      */

172     public void setInput( Object JavaDoc input )
173     {
174         viewer.setInput( input );
175     }
176
177
178     /**
179      * Sets focus to the table viewer.
180      */

181     public void setFocus()
182     {
183         viewer.getTree().setFocus();
184     }
185
186
187     /**
188      * {@inheritDoc}
189      */

190     public void dispose()
191     {
192         if ( this.viewer != null )
193         {
194             this.configuration.dispose();
195             this.configuration = null;
196
197             this.tree.dispose();
198             this.tree = null;
199             this.viewer = null;
200         }
201     }
202
203
204     /**
205      * Gets the tree viewer.
206      *
207      * @return the tree viewer
208      */

209     public TreeViewer getViewer()
210     {
211         return viewer;
212     }
213
214 }
215
Popular Tags