1 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 64 public class SchemaEditorOverviewPage extends FormPage 65 { 66 67 public static final String ID = SchemaEditor.ID + "overviewPage"; 69 70 public static final String TITLE = Messages.getString( "SchemaEditorOverviewPage.Overview" ); 72 73 private SchemaPool schemaPool; 74 75 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 private Table attributeTypesTable; 88 private Table objectClassesTable; 89 90 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 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" ); } 109 } 110 }; 111 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 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" ); } 129 } 130 }; 131 132 133 139 public SchemaEditorOverviewPage( FormEditor editor ) 140 { 141 super( editor, ID, TITLE ); 142 schemaPool = SchemaPool.getInstance(); 143 } 144 145 146 149 protected void createFormContent( IManagedForm managedForm ) 150 { 151 schema = ( ( SchemaEditor ) getEditor() ).getSchema(); 153 schema.addListener( schemaListener ); 154 155 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 fillInUiFields(); 167 168 addListeners(); 170 } 171 172 173 181 private void createAttributeTypesSection( Composite parent, FormToolkit toolkit ) 182 { 183 Section attributeTypesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED 185 | Section.TITLE_BAR ); 186 attributeTypesSection 187 .setDescription( Messages.getString( "SchemaEditorOverviewPage.The_schema" ) + schema.getName() + Messages.getString( "SchemaEditorOverviewPage.contains_the_following_attribute_types." ) ); attributeTypesSection.setText( Messages.getString( "SchemaEditorOverviewPage.Attribute_types" ) ); 191 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 213 private void createObjectClassesSection( Composite parent, FormToolkit toolkit ) 214 { 215 Section objectClassesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED 217 | Section.TITLE_BAR ); 218 objectClassesSection 219 .setDescription( Messages.getString( "SchemaEditorOverviewPage.The_schema" ) + schema.getName() + Messages.getString( "SchemaEditorOverviewPage.contains_the_following_object_classes." ) ); objectClassesSection.setText( Messages.getString( "SchemaEditorOverviewPage.Object_classes" ) ); 223 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 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 265 private void addListeners() 266 { 267 attributeTypesTable.addMouseListener( attributeTypesTableListener ); 268 objectClassesTable.addMouseListener( objectClassesTableListener ); 269 } 270 } 271 | Popular Tags |