KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > attributeType > AttributeTypeEditorUsedByPage


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.editors.attributeType;
22
23
24 import org.apache.directory.ldapstudio.schemas.Messages;
25 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
26 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
27 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
28 import org.apache.directory.ldapstudio.schemas.model.PoolListener;
29 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
30 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditor;
31 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditorInput;
32 import org.apache.log4j.Logger;
33 import org.eclipse.jface.viewers.StructuredSelection;
34 import org.eclipse.jface.viewers.TableViewer;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.swt.events.MouseAdapter;
37 import org.eclipse.swt.events.MouseEvent;
38 import org.eclipse.swt.layout.GridData;
39 import org.eclipse.swt.layout.GridLayout;
40 import org.eclipse.swt.widgets.Composite;
41 import org.eclipse.swt.widgets.Table;
42 import org.eclipse.ui.IWorkbenchPage;
43 import org.eclipse.ui.PartInitException;
44 import org.eclipse.ui.PlatformUI;
45 import org.eclipse.ui.forms.IManagedForm;
46 import org.eclipse.ui.forms.editor.FormEditor;
47 import org.eclipse.ui.forms.editor.FormPage;
48 import org.eclipse.ui.forms.widgets.FormToolkit;
49 import org.eclipse.ui.forms.widgets.ScrolledForm;
50 import org.eclipse.ui.forms.widgets.Section;
51
52
53 /**
54  * This class is the Used By Page of the Attribute Type Editor
55  */

56 public class AttributeTypeEditorUsedByPage extends FormPage implements PoolListener
57 {
58     /** The page ID */
59     public static final String JavaDoc ID = AttributeTypeEditor.ID + "usedByPage"; //$NON-NLS-1$
60

61     /** The page title */
62     public static String JavaDoc TITLE = Messages.getString( "AttributeTypeEditorUsedByPage.Used_By" ); //$NON-NLS-1$
63

64     /** The modified attribute type */
65     private AttributeType modifiedAttributeType;
66
67     /** The original attribute type */
68     private AttributeType originalAttributeType;
69
70     /** The Schema Pool */
71     private SchemaPool schemaPool;
72
73     // UI Widgets
74
private Table mandatoryAttributeTable;
75     private TableViewer mandatoryAttributeTableViewer;
76     private Table optionalAttibuteTable;
77     private TableViewer optionalAttibuteTableViewer;
78
79     // Listeners
80
/** The listener of the Mandatory Attribute Type Table*/
81     private MouseAdapter mandatoryAttributeTableListener = new MouseAdapter()
82     {
83         public void mouseDoubleClick( MouseEvent e )
84         {
85             Object JavaDoc selectedItem = ( ( StructuredSelection ) mandatoryAttributeTableViewer.getSelection() )
86                 .getFirstElement();
87
88             if ( selectedItem instanceof ObjectClass )
89             {
90                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
91                 try
92                 {
93                     page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedItem ), ObjectClassEditor.ID );
94                 }
95                 catch ( PartInitException exception )
96                 {
97                     Logger.getLogger( AttributeTypeEditorUsedByPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
98
}
99             }
100         }
101     };
102
103     /** The listener of the Optional Attribute Type Table*/
104     private MouseAdapter optionalAttibuteTableListener = new MouseAdapter()
105     {
106         public void mouseDoubleClick( MouseEvent e )
107         {
108             Object JavaDoc selectedItem = ( ( StructuredSelection ) optionalAttibuteTableViewer.getSelection() )
109                 .getFirstElement();
110
111             if ( selectedItem instanceof ObjectClass )
112             {
113                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
114                 try
115                 {
116                     page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedItem ), ObjectClassEditor.ID );
117                 }
118                 catch ( PartInitException exception )
119                 {
120                     Logger.getLogger( AttributeTypeEditorUsedByPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
121
}
122             }
123         }
124     };
125
126
127     /**
128      * Default constructor.
129      *
130      * @param editor
131      * the associated editor
132      */

133     public AttributeTypeEditorUsedByPage( FormEditor editor )
134     {
135         super( editor, ID, TITLE );
136         schemaPool = SchemaPool.getInstance();
137         schemaPool.addListener( this );
138     }
139
140
141     /* (non-Javadoc)
142      * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
143      */

144     protected void createFormContent( IManagedForm managedForm )
145     {
146         // Getting the modified and original attribute types
147
modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType();
148         originalAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getOriginalAttributeType();
149
150         // Creating the base UI
151
ScrolledForm form = managedForm.getForm();
152         FormToolkit toolkit = managedForm.getToolkit();
153         GridLayout layout = new GridLayout( 2, true );
154         form.getBody().setLayout( layout );
155
156         // As Mandatory Attribute Section
157
createAsMandatoryAttributeSection( form.getBody(), toolkit );
158
159         // As Optional Attribute Section
160
createAsOptionalAttributeSection( form.getBody(), toolkit );
161
162         // Filling the UI with values from the attribute type
163
fillInUiFields();
164
165         // Listeners initialization
166
addListeners();
167     }
168
169
170     /**
171      * Creates the As Mandatory Attribute Section.
172      *
173      * @param parent
174      * the parent composite
175      * @param toolkit
176      * the FormToolKit to use
177      */

178     private void createAsMandatoryAttributeSection( Composite parent, FormToolkit toolkit )
179     {
180         // As Mandatory Attribute Section
181
Section mandatoryAttributeSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED
182             | Section.TITLE_BAR );
183         mandatoryAttributeSection
184             .setDescription( Messages.getString( "AttributeTypeEditorUsedByPage.The_attribute_type" ) + " '" + modifiedAttributeType.getNames()[0] //$NON-NLS-1$ //$NON-NLS-2$
185
+ "' " + Messages.getString( "AttributeTypeEditorUsedByPage.is_used_as_a_mandatory_attribute_in_the_following_object_classes." ) ); //$NON-NLS-1$ //$NON-NLS-2$
186
mandatoryAttributeSection
187             .setText( Messages.getString( "AttributeTypeEditorUsedByPage.As_Mandatory_Attribute" ) ); //$NON-NLS-1$
188

189         // Creating the layout of the section
190
Composite mandatoryAttributeSectionClient = toolkit.createComposite( mandatoryAttributeSection );
191         mandatoryAttributeSectionClient.setLayout( new GridLayout() );
192         toolkit.paintBordersFor( mandatoryAttributeSectionClient );
193         mandatoryAttributeSection.setClient( mandatoryAttributeSectionClient );
194         mandatoryAttributeSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
195
196         mandatoryAttributeTable = toolkit.createTable( mandatoryAttributeSectionClient, SWT.NONE );
197         GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
198         gridData.heightHint = 1;
199         mandatoryAttributeTable.setLayoutData( gridData );
200         mandatoryAttributeTableViewer = new TableViewer( mandatoryAttributeTable );
201         mandatoryAttributeTableViewer.setContentProvider( new ATEUsedByMandatoryTableContentProvider() );
202         mandatoryAttributeTableViewer.setLabelProvider( new ATEUsedByTablesLabelProvider() );
203     }
204
205
206     /**
207      * Creates the As Optional Attribute Section.
208      *
209      * @param parent
210      * the parent composite
211      * @param toolkit
212      * the FormToolKit to use
213      */

214     private void createAsOptionalAttributeSection( Composite parent, FormToolkit toolkit )
215     {
216         // Matching Rules Section
217
Section optionalAttributeSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED
218             | Section.TITLE_BAR );
219         optionalAttributeSection
220             .setDescription( Messages.getString( "AttributeTypeEditorUsedByPage.The_attribute_type" ) + " '" + modifiedAttributeType.getNames()[0] //$NON-NLS-1$ //$NON-NLS-2$
221
+ "' " + Messages.getString( "AttributeTypeEditorUsedByPage.is_used_as_an_optional_attribute_in_the_following_object_classes." ) ); //$NON-NLS-1$ //$NON-NLS-2$
222
optionalAttributeSection.setText( Messages.getString( "AttributeTypeEditorUsedByPage.As_Optional_Attribute" ) ); //$NON-NLS-1$
223

224         // Creating the layout of the section
225
Composite optionalAttributeSectionClient = toolkit.createComposite( optionalAttributeSection );
226         optionalAttributeSectionClient.setLayout( new GridLayout() );
227         toolkit.paintBordersFor( optionalAttributeSectionClient );
228         optionalAttributeSection.setClient( optionalAttributeSectionClient );
229         optionalAttributeSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
230
231         optionalAttibuteTable = toolkit.createTable( optionalAttributeSectionClient, SWT.NONE );
232         GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
233         gridData.heightHint = 1;
234         optionalAttibuteTable.setLayoutData( gridData );
235         optionalAttibuteTableViewer = new TableViewer( optionalAttibuteTable );
236         optionalAttibuteTableViewer.setContentProvider( new ATEUsedByOptionalTableContentProvider() );
237         optionalAttibuteTableViewer.setLabelProvider( new ATEUsedByTablesLabelProvider() );
238     }
239
240
241     /**
242      * Fills in the User Iterface.
243      */

244     private void fillInUiFields()
245     {
246         mandatoryAttributeTableViewer.setInput( originalAttributeType );
247         optionalAttibuteTableViewer.setInput( originalAttributeType );
248     }
249
250
251     /**
252      * Adds listeners to UI fields
253      */

254     private void addListeners()
255     {
256         mandatoryAttributeTable.addMouseListener( mandatoryAttributeTableListener );
257         optionalAttibuteTable.addMouseListener( optionalAttibuteTableListener );
258     }
259
260
261     /* (non-Javadoc)
262      * @see org.apache.directory.ldapstudio.schemas.model.PoolListener#poolChanged(org.apache.directory.ldapstudio.schemas.model.SchemaPool, org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent)
263      */

264     public void poolChanged( SchemaPool p, LDAPModelEvent e )
265     {
266         mandatoryAttributeTableViewer.refresh();
267         optionalAttibuteTableViewer.refresh();
268     }
269
270
271     /* (non-Javadoc)
272      * @see org.eclipse.ui.forms.editor.FormPage#dispose()
273      */

274     public void dispose()
275     {
276         schemaPool.removeListener( this );
277
278         super.dispose();
279     }
280 }
281
Popular Tags