KickJava   Java API By Example, From Geeks To Geeks.

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


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.ExtendedOperation;
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 Extended Operation type
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

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

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

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

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

141     private void addListeners()
142     {
143         classTypeText.addModifyListener( textModifyListener );
144     }
145
146
147     /**
148      * Removes listeners to UI fields.
149      */

150     private void removeListeners()
151     {
152         classTypeText.removeModifyListener( textModifyListener );
153     }
154
155
156     /* (non-Javadoc)
157      * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
158      */

159     public void selectionChanged( IFormPart part, ISelection selection )
160     {
161         IStructuredSelection ssel = ( IStructuredSelection ) selection;
162         if ( ssel.size() == 1 )
163         {
164             input = ( ExtendedOperation ) ssel.getFirstElement();
165         }
166         else
167         {
168             input = null;
169         }
170         refresh();
171     }
172
173
174     /* (non-Javadoc)
175      * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
176      */

177     public void commit( boolean onSave )
178     {
179         if ( input != null )
180         {
181             input.setClassType( classTypeText.getText() );
182         }
183     }
184
185
186     /* (non-Javadoc)
187      * @see org.eclipse.ui.forms.IFormPart#dispose()
188      */

189     public void dispose()
190     {
191     }
192
193
194     /* (non-Javadoc)
195      * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
196      */

197     public void initialize( IManagedForm form )
198     {
199         this.mform = form;
200     }
201
202
203     /* (non-Javadoc)
204      * @see org.eclipse.ui.forms.IFormPart#isDirty()
205      */

206     public boolean isDirty()
207     {
208         return dirty;
209     }
210
211
212     /* (non-Javadoc)
213      * @see org.eclipse.ui.forms.IFormPart#isStale()
214      */

215     public boolean isStale()
216     {
217         return false;
218     }
219
220
221     /* (non-Javadoc)
222      * @see org.eclipse.ui.forms.IFormPart#refresh()
223      */

224     public void refresh()
225     {
226         removeListeners();
227
228         classTypeText.setText( input.getClassType() );
229
230         addListeners();
231     }
232
233
234     /* (non-Javadoc)
235      * @see org.eclipse.ui.forms.IFormPart#setFocus()
236      */

237     public void setFocus()
238     {
239         classTypeText.setFocus();
240     }
241
242
243     /* (non-Javadoc)
244      * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
245      */

246     public boolean setFormInput( Object JavaDoc input )
247     {
248         return false;
249     }
250 }
251
Popular Tags