KickJava   Java API By Example, From Geeks To Geeks.

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


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.entryeditor;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.ViewFormWidget;
25 import org.eclipse.jface.viewers.CellEditor;
26 import org.eclipse.jface.viewers.TreeViewer;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.ControlAdapter;
29 import org.eclipse.swt.events.ControlEvent;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Tree;
34 import org.eclipse.swt.widgets.TreeColumn;
35
36
37 /**
38  * The EntryEditorWidget is a reusable widget to display and edit the attributes of an entry.
39  * It is used by
40  * {@link org.apache.directory.ldapstudio.browser.ui.editors.entry.EntryEditor},
41  * {@link org.apache.directory.ldapstudio.browser.common.dialogs.MultivaluedDialog},
42  * {@link org.apache.directory.ldapstudio.browser.common.dialogs.LdifEntryEditorDialog} and
43  * {@link org.apache.directory.ldapstudio.browser.common.wizards.NewEntryAttributesWizardPage}.
44  *
45  * It provides a context menu and a local toolbar with actions to
46  * manage attributes. Further there is an instant search feature to filter
47  * the visible attributes.
48  *
49  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
50  * @version $Rev$, $Date$
51  */

52 public class EntryEditorWidget extends ViewFormWidget
53 {
54
55     /** The configuration. */
56     private EntryEditorWidgetConfiguration configuration;
57
58     /** The quick filter widget. */
59     private EntryEditorWidgetQuickFilterWidget quickFilterWidget;
60
61     /** The tree. */
62     private Tree tree;
63
64     /** The viewer. */
65     private TreeViewer viewer;
66
67
68     /**
69      * Creates a new instance of EntryEditorWidget.
70      *
71      * @param configuration the configuration
72      */

73     public EntryEditorWidget( EntryEditorWidgetConfiguration configuration )
74     {
75         this.configuration = configuration;
76     }
77
78
79     /**
80      * {@inheritDoc}
81      */

82     protected Control createContent( Composite parent )
83     {
84         quickFilterWidget = new EntryEditorWidgetQuickFilterWidget( configuration.getFilter(), this );
85         quickFilterWidget.createComposite( parent );
86
87         // create tree widget and viewer
88
tree = new Tree( parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
89             | SWT.HIDE_SELECTION );
90         GridData data = new GridData( GridData.FILL_BOTH );
91         data.widthHint = 450;
92         data.heightHint = 250;
93         tree.setLayoutData( data );
94         tree.setHeaderVisible( true );
95         tree.setLinesVisible( true );
96         viewer = new TreeViewer( tree );
97         viewer.setUseHashlookup( true );
98
99         // set tree columns
100
for ( int i = 0; i < EntryEditorWidgetTableMetadata.COLUM_NAMES.length; i++ )
101         {
102             TreeColumn column = new TreeColumn( tree, SWT.LEFT, i );
103             column.setText( EntryEditorWidgetTableMetadata.COLUM_NAMES[i] );
104             column.setWidth( 200 );
105             column.setResizable( true );
106
107         }
108         viewer.setColumnProperties( EntryEditorWidgetTableMetadata.COLUM_NAMES );
109         tree.addControlListener( new ControlAdapter()
110         {
111             public void controlResized( ControlEvent e )
112             {
113                 if ( tree.getClientArea().width > 0 )
114                 {
115                     int width = tree.getClientArea().width - 2 * tree.getBorderWidth();
116                     if ( tree.getVerticalBar().isVisible() )
117                     {
118                         width -= tree.getVerticalBar().getSize().x;
119                     }
120                     tree.getColumn( EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ).setWidth(
121                         width - tree.getColumn( EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ).getWidth() );
122                 }
123             }
124         } );
125
126         // setup sorter, filter and layout
127
configuration.getSorter().connect( viewer );
128         configuration.getFilter().connect( viewer );
129         configuration.getPreferences().connect( viewer );
130
131         // setup providers
132
viewer.setContentProvider( configuration.getContentProvider( this ) );
133         viewer.setLabelProvider( configuration.getLabelProvider( viewer ) );
134
135         // set table cell editors
136
viewer.setCellModifier( configuration.getCellModifier( viewer ) );
137         CellEditor[] editors = new CellEditor[EntryEditorWidgetTableMetadata.COLUM_NAMES.length];
138         viewer.setCellEditors( editors );
139
140         return tree;
141
142     }
143
144
145     /**
146      * Sets the focus to the tree viewer.
147      */

148     public void setFocus()
149     {
150         viewer.getTree().setFocus();
151     }
152
153
154     /**
155      * {@inheritDoc}
156      */

157     public void dispose()
158     {
159         if ( viewer != null )
160         {
161             configuration.dispose();
162             configuration = null;
163
164             if ( quickFilterWidget != null )
165             {
166                 quickFilterWidget.dispose();
167                 quickFilterWidget = null;
168             }
169
170             tree.dispose();
171             tree = null;
172             viewer = null;
173         }
174
175         super.dispose();
176     }
177
178
179     /**
180      * Gets the viewer.
181      *
182      * @return the viewer
183      */

184     public TreeViewer getViewer()
185     {
186         return viewer;
187     }
188
189
190     /**
191      * Gets the quick filter widget.
192      *
193      * @return the quick filter widget
194      */

195     public EntryEditorWidgetQuickFilterWidget getQuickFilterWidget()
196     {
197         return quickFilterWidget;
198     }
199
200
201     /**
202      * Enables or disables this widget.
203      *
204      * @param enabled true to enable this widget, false to disable this widget
205      */

206     public void setEnabled( boolean enabled )
207     {
208         tree.setEnabled( enabled );
209     }
210
211 }
212
Popular Tags