1 20 21 package org.apache.directory.ldapstudio.schemas.view.editors.objectClass; 22 23 24 import java.io.IOException ; 25 import java.text.ParseException ; 26 import java.util.List ; 27 28 import org.apache.directory.ldapstudio.schemas.Messages; 29 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 30 import org.apache.directory.ldapstudio.schemas.model.Schema.SchemaType; 31 import org.apache.directory.ldapstudio.schemas.view.views.SchemaSourceViewer; 32 import org.apache.directory.server.core.tools.schema.ObjectClassLiteral; 33 import org.apache.directory.server.core.tools.schema.OpenLdapSchemaParser; 34 import org.eclipse.jface.resource.JFaceResources; 35 import org.eclipse.jface.text.Document; 36 import org.eclipse.jface.text.IDocument; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.events.ModifyEvent; 39 import org.eclipse.swt.events.ModifyListener; 40 import org.eclipse.swt.graphics.Font; 41 import org.eclipse.swt.layout.GridData; 42 import org.eclipse.swt.layout.GridLayout; 43 import org.eclipse.ui.forms.IManagedForm; 44 import org.eclipse.ui.forms.editor.FormEditor; 45 import org.eclipse.ui.forms.editor.FormPage; 46 import org.eclipse.ui.forms.widgets.FormToolkit; 47 import org.eclipse.ui.forms.widgets.ScrolledForm; 48 49 50 53 public class ObjectClassEditorSourceCodePage extends FormPage 54 { 55 56 public static final String ID = ObjectClassEditor.ID + "sourceCodePage"; 58 59 public static final String TITLE = Messages.getString( "ObjectClassEditorSourceCodePage.Source_Code" ); 61 62 private ObjectClass modifiedObjectClass; 63 64 65 private SchemaSourceViewer schemaSourceViewer; 66 67 68 private boolean canLeaveThePage = true; 69 70 71 private ModifyListener schemaSourceViewerListener = new ModifyListener() 72 { 73 public void modifyText( ModifyEvent e ) 74 { 75 canLeaveThePage = true; 76 try 77 { 78 ( ( ObjectClassEditor ) getEditor() ).setDirty( true ); 79 OpenLdapSchemaParser parser = new OpenLdapSchemaParser(); 80 parser.parse( schemaSourceViewer.getTextWidget().getText() ); 81 82 List objectclasses = parser.getObjectClassTypes(); 83 if ( objectclasses.size() != 1 ) 84 { 85 } 87 else 88 { 89 updateObjectClass( ( ObjectClassLiteral ) objectclasses.get( 0 ) ); 90 } 91 } 92 catch ( IOException e1 ) 93 { 94 canLeaveThePage = false; 95 } 96 catch ( ParseException exception ) 97 { 98 canLeaveThePage = false; 99 } 100 } 101 }; 102 103 104 109 public ObjectClassEditorSourceCodePage( FormEditor editor ) 110 { 111 super( editor, ID, TITLE ); 112 } 113 114 115 118 protected void createFormContent( IManagedForm managedForm ) 119 { 120 ScrolledForm form = managedForm.getForm(); 121 FormToolkit toolkit = managedForm.getToolkit(); 122 GridLayout layout = new GridLayout(); 123 layout.marginWidth = 0; 124 layout.marginHeight = 0; 125 form.getBody().setLayout( layout ); 126 toolkit.paintBordersFor( form.getBody() ); 127 128 modifiedObjectClass = ( ( ObjectClassEditor ) getEditor() ).getModifiedObjectClass(); 129 130 schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER | SWT.H_SCROLL 132 | SWT.V_SCROLL ); 133 GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); 134 gd.heightHint = 10; 135 schemaSourceViewer.getTextWidget().setLayoutData( gd ); 136 if ( modifiedObjectClass.getOriginatingSchema().type == SchemaType.coreSchema ) 137 { 138 schemaSourceViewer.setEditable( false ); 139 } 140 141 Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); 143 schemaSourceViewer.getTextWidget().setFont( font ); 144 145 IDocument document = new Document(); 146 schemaSourceViewer.setDocument( document ); 147 148 fillInUiFields(); 150 151 schemaSourceViewer.getTextWidget().addModifyListener( schemaSourceViewerListener ); 152 } 153 154 155 158 private void fillInUiFields() 159 { 160 schemaSourceViewer.getDocument().set( modifiedObjectClass.write() ); 162 } 163 164 165 168 public boolean canLeaveThePage() 169 { 170 return canLeaveThePage; 171 } 172 173 174 180 private void updateObjectClass( ObjectClassLiteral ocl ) 181 { 182 modifiedObjectClass.setClassType( ocl.getClassType() ); 183 modifiedObjectClass.setDescription( ocl.getDescription() ); 184 modifiedObjectClass.setMay( ocl.getMay() ); 185 modifiedObjectClass.setMust( ocl.getMust() ); 186 modifiedObjectClass.setNames( ocl.getNames() ); 187 modifiedObjectClass.setObsolete( ocl.isObsolete() ); 188 modifiedObjectClass.setOid( ocl.getOid() ); 189 modifiedObjectClass.setSuperiors( ocl.getSuperiors() ); 190 } 191 192 193 196 public void refreshUI() 197 { 198 fillInUiFields(); 199 } 200 } 201 | Popular Tags |