1 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 51 public class SchemaEditorSourceCodePage extends FormPage 52 { 53 54 public static final String ID = SchemaEditor.ID + "sourceCode"; 56 57 public static final String TITLE = Messages.getString( "SchemaEditorSourceCodePage.Source_code" ); 59 60 private Schema schema; 61 62 private SchemaSourceViewer schemaSourceViewer; 64 65 private SchemaListener schemaListener = new SchemaListener() 67 { 68 public void schemaChanged( Schema originatingSchema, LDAPModelEvent e ) 69 { 70 fillInUiFields(); 71 } 72 }; 73 74 75 81 public SchemaEditorSourceCodePage( FormEditor editor ) 82 { 83 super( editor, ID, TITLE ); 84 } 85 86 87 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 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 Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); 111 schemaSourceViewer.getTextWidget().setFont( font ); 112 113 IDocument document = new Document(); 114 schemaSourceViewer.setDocument( document ); 115 116 fillInUiFields(); 118 } 119 120 121 124 private void fillInUiFields() 125 { 126 StringBuffer sb = new StringBuffer (); 127 128 AttributeType[] attributeTypes = schema.getAttributeTypesAsArray(); 129 for ( AttributeType at : attributeTypes ) 130 { 131 sb.append( at.write() ); 132 sb.append( "\n" ); } 134 135 ObjectClass[] objectClasses = schema.getObjectClassesAsArray(); 136 for ( ObjectClass oc : objectClasses ) 137 { 138 sb.append( oc.write() ); 139 sb.append( "\n" ); } 141 142 schemaSourceViewer.getDocument().set( sb.toString() ); 143 } 144 } 145 | Popular Tags |