KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > schema > SchemaEditorOverviewPage


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.schema;
22
23
24 import org.apache.directory.ldapstudio.schemas.Activator;
25 import org.apache.directory.ldapstudio.schemas.Messages;
26 import org.apache.directory.ldapstudio.schemas.PluginConstants;
27 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
28 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
29 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
30 import org.apache.directory.ldapstudio.schemas.model.Schema;
31 import org.apache.directory.ldapstudio.schemas.model.SchemaListener;
32 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
33 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor;
34 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput;
35 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditor;
36 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditorInput;
37 import org.apache.log4j.Logger;
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.events.MouseAdapter;
40 import org.eclipse.swt.events.MouseEvent;
41 import org.eclipse.swt.layout.GridData;
42 import org.eclipse.swt.layout.GridLayout;
43 import org.eclipse.swt.widgets.Composite;
44 import org.eclipse.swt.widgets.Table;
45 import org.eclipse.swt.widgets.TableItem;
46 import org.eclipse.ui.IWorkbenchPage;
47 import org.eclipse.ui.PartInitException;
48 import org.eclipse.ui.PlatformUI;
49 import org.eclipse.ui.forms.IManagedForm;
50 import org.eclipse.ui.forms.editor.FormEditor;
51 import org.eclipse.ui.forms.editor.FormPage;
52 import org.eclipse.ui.forms.widgets.FormToolkit;
53 import org.eclipse.ui.forms.widgets.ScrolledForm;
54 import org.eclipse.ui.forms.widgets.Section;
55 import org.eclipse.ui.plugin.AbstractUIPlugin;
56
57
58 /**
59  * This class is the Overview Page of the Schema Editore.
60  *
61  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
62  * @version $Rev$, $Date$
63  */

64 public class SchemaEditorOverviewPage extends FormPage
65 {
66     /** The page ID */
67     public static final String JavaDoc ID = SchemaEditor.ID + "overviewPage"; //$NON-NLS-1$
68

69     /** The page title */
70     public static final String JavaDoc TITLE = Messages.getString( "SchemaEditorOverviewPage.Overview" ); //$NON-NLS-1$
71

72     /** The Schema Pool */
73     private SchemaPool schemaPool;
74
75     /** The associated schema */
76     private Schema schema;
77
78     private SchemaListener schemaListener = new SchemaListener()
79     {
80         public void schemaChanged( Schema originatingSchema, LDAPModelEvent e )
81         {
82             fillInUiFields();
83         }
84     };
85
86     // UI Fields
87
private Table attributeTypesTable;
88     private Table objectClassesTable;
89
90     // Listeners
91
/** The listener of the Attribute Types Table*/
92     private MouseAdapter attributeTypesTableListener = new MouseAdapter()
93     {
94         public void mouseDoubleClick( MouseEvent e )
95         {
96             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
97
98             AttributeTypeEditorInput input = new AttributeTypeEditorInput( schemaPool
99                 .getAttributeType( attributeTypesTable.getSelection()[0].getText() ) );
100             String JavaDoc editorId = AttributeTypeEditor.ID;
101             try
102             {
103                 page.openEditor( input, editorId );
104             }
105             catch ( PartInitException exception )
106             {
107                 Logger.getLogger( SchemaEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
108
}
109         }
110     };
111     /** The listener of the Object Classes Table*/
112     private MouseAdapter objectClassesTableListener = new MouseAdapter()
113     {
114         public void mouseDoubleClick( MouseEvent e )
115         {
116             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
117
118             ObjectClassEditorInput input = new ObjectClassEditorInput( schemaPool.getObjectClass( objectClassesTable
119                 .getSelection()[0].getText() ) );
120             String JavaDoc editorId = ObjectClassEditor.ID;
121             try
122             {
123                 page.openEditor( input, editorId );
124             }
125             catch ( PartInitException exception )
126             {
127                 Logger.getLogger( SchemaEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
128
}
129         }
130     };
131
132
133     /**
134      * Creates a new instance of SchemaFormEditorOverviewPage.
135      *
136      * @param editor
137      * the associated editor
138      */

139     public SchemaEditorOverviewPage( FormEditor editor )
140     {
141         super( editor, ID, TITLE );
142         schemaPool = SchemaPool.getInstance();
143     }
144
145
146     /* (non-Javadoc)
147      * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
148      */

149     protected void createFormContent( IManagedForm managedForm )
150     {
151         // Getting the associated schema
152
schema = ( ( SchemaEditor ) getEditor() ).getSchema();
153         schema.addListener( schemaListener );
154
155         // Creating the base UI
156
ScrolledForm form = managedForm.getForm();
157         FormToolkit toolkit = managedForm.getToolkit();
158         GridLayout layout = new GridLayout( 2, true );
159         form.getBody().setLayout( layout );
160
161         createAttributeTypesSection( form.getBody(), toolkit );
162
163         createObjectClassesSection( form.getBody(), toolkit );
164
165         // Initializes the UI from the schema
166
fillInUiFields();
167
168         // Listeners initialization
169
addListeners();
170     }
171
172
173     /**
174      * Create the Attribute Types Section.
175      *
176      * @param parent
177      * the parent composite
178      * @param toolkit
179      * the FormToolKit to use
180      */

181     private void createAttributeTypesSection( Composite parent, FormToolkit toolkit )
182     {
183         // Attribute Types Section
184
Section attributeTypesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED
185             | Section.TITLE_BAR );
186         attributeTypesSection
187             .setDescription( Messages.getString( "SchemaEditorOverviewPage.The_schema" ) + schema.getName() //$NON-NLS-1$
188
+ Messages.getString( "SchemaEditorOverviewPage.contains_the_following_attribute_types." ) ); //$NON-NLS-1$
189
attributeTypesSection.setText( Messages.getString( "SchemaEditorOverviewPage.Attribute_types" ) ); //$NON-NLS-1$
190

191         // Creating the layout of the section
192
Composite attributeTypesSectionClient = toolkit.createComposite( attributeTypesSection );
193         attributeTypesSectionClient.setLayout( new GridLayout() );
194         toolkit.paintBordersFor( attributeTypesSectionClient );
195         attributeTypesSection.setClient( attributeTypesSectionClient );
196         attributeTypesSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
197
198         attributeTypesTable = toolkit.createTable( attributeTypesSectionClient, SWT.NONE );
199         GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
200         gridData.heightHint = 1;
201         attributeTypesTable.setLayoutData( gridData );
202     }
203
204
205     /**
206      * Create the Object Classes Section.
207      *
208      * @param parent
209      * the parent composite
210      * @param toolkit
211      * the FormToolKit to use
212      */

213     private void createObjectClassesSection( Composite parent, FormToolkit toolkit )
214     {
215         // Attribute Types Section
216
Section objectClassesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED
217             | Section.TITLE_BAR );
218         objectClassesSection
219             .setDescription( Messages.getString( "SchemaEditorOverviewPage.The_schema" ) + schema.getName() //$NON-NLS-1$
220
+ Messages.getString( "SchemaEditorOverviewPage.contains_the_following_object_classes." ) ); //$NON-NLS-1$
221
objectClassesSection.setText( Messages.getString( "SchemaEditorOverviewPage.Object_classes" ) ); //$NON-NLS-1$
222

223         // Creating the layout of the section
224
Composite objectClassesSectionClient = toolkit.createComposite( objectClassesSection );
225         objectClassesSectionClient.setLayout( new GridLayout() );
226         toolkit.paintBordersFor( objectClassesSectionClient );
227         objectClassesSection.setClient( objectClassesSectionClient );
228         objectClassesSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) );
229
230         objectClassesTable = toolkit.createTable( objectClassesSectionClient, SWT.NONE );
231         GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
232         gridData.heightHint = 1;
233         objectClassesTable.setLayoutData( gridData );
234     }
235
236
237     /**
238      * Fills in the fields of the User Interface.
239      */

240     private void fillInUiFields()
241     {
242         AttributeType[] attributeTypes = schema.getAttributeTypesAsArray();
243         for ( AttributeType at : attributeTypes )
244         {
245             TableItem item = new TableItem( attributeTypesTable, SWT.NONE );
246             item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
247                 PluginConstants.IMG_ATTRIBUTE_TYPE ).createImage() );
248             item.setText( at.getNames()[0] );
249         }
250
251         ObjectClass[] objectClasses = schema.getObjectClassesAsArray();
252         for ( ObjectClass oc : objectClasses )
253         {
254             TableItem item = new TableItem( objectClassesTable, SWT.NONE );
255             item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
256                 PluginConstants.IMG_OBJECT_CLASS ).createImage() );
257             item.setText( oc.getNames()[0] );
258         }
259     }
260
261
262     /**
263      * Initializes and adds the listners.
264      */

265     private void addListeners()
266     {
267         attributeTypesTable.addMouseListener( attributeTypesTableListener );
268         objectClassesTable.addMouseListener( objectClassesTableListener );
269     }
270 }
271
Popular Tags