KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.Schema;
29 import org.apache.directory.ldapstudio.schemas.model.SchemaListener;
30 import org.apache.directory.ldapstudio.schemas.view.views.SchemaSourceViewer;
31 import org.eclipse.jface.resource.JFaceResources;
32 import org.eclipse.jface.text.Document;
33 import org.eclipse.jface.text.IDocument;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.graphics.Font;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.ui.forms.IManagedForm;
39 import org.eclipse.ui.forms.editor.FormEditor;
40 import org.eclipse.ui.forms.editor.FormPage;
41 import org.eclipse.ui.forms.widgets.FormToolkit;
42 import org.eclipse.ui.forms.widgets.ScrolledForm;
43
44
45 /**
46  * This class is the Source Code Page of the Schema Editor.
47  *
48  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
49  * @version $Rev$, $Date$
50  */

51 public class SchemaEditorSourceCodePage extends FormPage
52 {
53     /** The page ID */
54     public static final String JavaDoc ID = SchemaEditor.ID + "sourceCode"; //$NON-NLS-1$
55

56     /** The page title */
57     public static final String JavaDoc TITLE = Messages.getString( "SchemaEditorSourceCodePage.Source_code" ); //$NON-NLS-1$
58

59     /** The associated schema */
60     private Schema schema;
61
62     // UI Field
63
private SchemaSourceViewer schemaSourceViewer;
64
65     // Listerner
66
private SchemaListener schemaListener = new SchemaListener()
67     {
68         public void schemaChanged( Schema originatingSchema, LDAPModelEvent e )
69         {
70             fillInUiFields();
71         }
72     };
73
74
75     /**
76      * Creates a new instance of SchemaFormEditorSourceCodePage.
77      *
78      * @param editor
79      * the associated editor
80      */

81     public SchemaEditorSourceCodePage( FormEditor editor )
82     {
83         super( editor, ID, TITLE );
84     }
85
86
87     /* (non-Javadoc)
88      * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
89      */

90     protected void createFormContent( IManagedForm managedForm )
91     {
92         schema = ( ( SchemaEditor ) getEditor() ).getSchema();
93         schema.addListener( schemaListener );
94
95         ScrolledForm form = managedForm.getForm();
96         FormToolkit toolkit = managedForm.getToolkit();
97         GridLayout layout = new GridLayout();
98         form.getBody().setLayout( layout );
99         toolkit.paintBordersFor( form.getBody() );
100
101         // SOURCE CODE Field
102
schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER | SWT.H_SCROLL
103             | SWT.V_SCROLL );
104         GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
105         gd.heightHint = 10;
106         schemaSourceViewer.getTextWidget().setLayoutData( gd );
107         schemaSourceViewer.getTextWidget().setEditable( false );
108
109         // set text font
110
Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
111         schemaSourceViewer.getTextWidget().setFont( font );
112
113         IDocument document = new Document();
114         schemaSourceViewer.setDocument( document );
115
116         // Initializes the UI from the schema
117
fillInUiFields();
118     }
119
120
121     /**
122      * Fills in the fields of the User Interface.
123      */

124     private void fillInUiFields()
125     {
126         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
127
128         AttributeType[] attributeTypes = schema.getAttributeTypesAsArray();
129         for ( AttributeType at : attributeTypes )
130         {
131             sb.append( at.write() );
132             sb.append( "\n" ); //$NON-NLS-1$
133
}
134
135         ObjectClass[] objectClasses = schema.getObjectClassesAsArray();
136         for ( ObjectClass oc : objectClasses )
137         {
138             sb.append( oc.write() );
139             sb.append( "\n" ); //$NON-NLS-1$
140
}
141
142         schemaSourceViewer.getDocument().set( sb.toString() );
143     }
144 }
145
Popular Tags