KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > apacheds > configuration > editor > InterceptorDetailsPage


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 package org.apache.directory.ldapstudio.apacheds.configuration.editor;
21
22
23 import org.apache.directory.ldapstudio.apacheds.configuration.model.Interceptor;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.ModifyEvent;
28 import org.eclipse.swt.events.ModifyListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Text;
33 import org.eclipse.ui.forms.IDetailsPage;
34 import org.eclipse.ui.forms.IFormPart;
35 import org.eclipse.ui.forms.IManagedForm;
36 import org.eclipse.ui.forms.widgets.FormToolkit;
37 import org.eclipse.ui.forms.widgets.Section;
38 import org.eclipse.ui.forms.widgets.TableWrapData;
39 import org.eclipse.ui.forms.widgets.TableWrapLayout;
40
41
42 /**
43  * This class represents the Details Page of the Server Configuration Editor for the Interceptor type
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class InterceptorDetailsPage implements IDetailsPage
49 {
50     /** The associated Master Details Block */
51     private InterceptorsMasterDetailsBlock masterDetailsBlock;
52
53     /** The Managed Form */
54     private IManagedForm mform;
55
56     /** The input Interceptor */
57     private Interceptor input;
58
59     /** The dirty flag */
60     private boolean dirty = false;
61
62     // UI fields
63
private Text nameText;
64     private Text classText;
65
66     // Listeners
67
/** The Modify Listener for Text Widgets */
68     private ModifyListener textModifyListener = new ModifyListener()
69     {
70         public void modifyText( ModifyEvent e )
71         {
72             masterDetailsBlock.setEditorDirty();
73             dirty = true;
74         }
75     };
76
77
78     /**
79      * Creates a new instance of InterceptorDetailsPage.
80      *
81      * @param imdb
82      * The associated Master Details Block
83      */

84     public InterceptorDetailsPage( InterceptorsMasterDetailsBlock imdb )
85     {
86         masterDetailsBlock = imdb;
87     }
88
89
90     /* (non-Javadoc)
91      * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
92      */

93     public void createContents( Composite parent )
94     {
95         FormToolkit toolkit = mform.getToolkit();
96         TableWrapLayout layout = new TableWrapLayout();
97         layout.topMargin = 5;
98         layout.leftMargin = 5;
99         layout.rightMargin = 2;
100         layout.bottomMargin = 2;
101         parent.setLayout( layout );
102
103         createDetailsSection( parent, toolkit );
104     }
105
106
107     /**
108      * Creates the Details Section
109      *
110      * @param parent
111      * the parent composite
112      * @param toolkit
113      * the toolkit to use
114      */

115     private void createDetailsSection( Composite parent, FormToolkit toolkit )
116     {
117         Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
118         section.marginWidth = 10;
119         section.setText( "Interceptor Details" ); //$NON-NLS-1$
120
section.setDescription( "Set the properties of the interceptor." ); //$NON-NLS-1$
121
TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP );
122         td.grabHorizontal = true;
123         section.setLayoutData( td );
124         Composite client = toolkit.createComposite( section );
125         toolkit.paintBordersFor( client );
126         GridLayout glayout = new GridLayout( 3, false );
127         client.setLayout( glayout );
128         section.setClient( client );
129
130         // Name
131
toolkit.createLabel( client, "Name:" );
132         nameText = toolkit.createText( client, "" );
133         nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
134
135         // Class
136
toolkit.createLabel( client, "Class:" );
137         classText = toolkit.createText( client, "" );
138         classText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
139     }
140
141
142     /**
143      * Adds listeners to UI fields.
144      */

145     private void addListeners()
146     {
147         nameText.addModifyListener( textModifyListener );
148         classText.addModifyListener( textModifyListener );
149     }
150
151
152     /**
153      * Removes listeners to UI fields.
154      */

155     private void removeListeners()
156     {
157         nameText.removeModifyListener( textModifyListener );
158         classText.removeModifyListener( textModifyListener );
159     }
160
161
162     /* (non-Javadoc)
163      * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
164      */

165     public void selectionChanged( IFormPart part, ISelection selection )
166     {
167         IStructuredSelection ssel = ( IStructuredSelection ) selection;
168         if ( ssel.size() == 1 )
169         {
170             input = ( Interceptor ) ssel.getFirstElement();
171         }
172         else
173         {
174             input = null;
175         }
176         refresh();
177     }
178
179
180     /* (non-Javadoc)
181      * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
182      */

183     public void commit( boolean onSave )
184     {
185         if ( input != null )
186         {
187             input.setName( nameText.getText() );
188             input.setClassType( classText.getText() );
189         }
190     }
191
192
193     /* (non-Javadoc)
194      * @see org.eclipse.ui.forms.IFormPart#dispose()
195      */

196     public void dispose()
197     {
198     }
199
200
201     /* (non-Javadoc)
202      * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
203      */

204     public void initialize( IManagedForm form )
205     {
206         this.mform = form;
207     }
208
209
210     /* (non-Javadoc)
211      * @see org.eclipse.ui.forms.IFormPart#isDirty()
212      */

213     public boolean isDirty()
214     {
215         return dirty;
216     }
217
218
219     /* (non-Javadoc)
220      * @see org.eclipse.ui.forms.IFormPart#isStale()
221      */

222     public boolean isStale()
223     {
224         return false;
225     }
226
227
228     /* (non-Javadoc)
229      * @see org.eclipse.ui.forms.IFormPart#refresh()
230      */

231     public void refresh()
232     {
233         removeListeners();
234
235         // Name
236
String JavaDoc name = input.getName();
237         nameText.setText( ( name == null ) ? "" : name );
238
239         // Class
240
String JavaDoc classType = input.getClassType();
241         classText.setText( ( classType == null ) ? "" : classType );
242
243         addListeners();
244     }
245
246
247     /* (non-Javadoc)
248      * @see org.eclipse.ui.forms.IFormPart#setFocus()
249      */

250     public void setFocus()
251     {
252         nameText.setFocus();
253     }
254
255
256     /* (non-Javadoc)
257      * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
258      */

259     public boolean setFormInput( Object JavaDoc input )
260     {
261         return false;
262     }
263 }
264
Popular Tags