Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorOverviewPage.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorOverviewPage.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorOverviewPage.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorOverviewPage.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,1087 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.directory.shared.asn1.primitives.OID; +import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum; +import org.apache.directory.studio.apacheds.schemaeditor.Activator; +import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler; +import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl; +import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.apacheds.schemaeditor.view.ViewUtils; +import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.AttributeTypeSelectionDialog; +import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.EditAliasesDialog; +import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.ObjectClassSelectionDialog; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.NonExistingAttributeType; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.NonExistingObjectClass; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditor; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema.SchemaEditor; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema.SchemaEditorInput; +import org.apache.log4j.Logger; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; + + +/** + * This class is the Overview Page of the Object Class Editor + */ +public class ObjectClassEditorOverviewPage extends FormPage +{ + /** The page ID */ + public static final String ID = ObjectClassEditor.ID + "overviewPage"; //$NON-NLS-1$ + + /** The page title*/ + public static final String TITLE = "Overview"; + + /** The original object class */ + private ObjectClassImpl originalObjectClass; + + /** The modified object class */ + private ObjectClassImpl modifiedObjectClass; + + /** The SchemaHandler */ + private SchemaHandler schemaHandler; + + // UI fields + private Label aliasesLabel; + private Button aliasesButton; + private Text oidText; + private Hyperlink schemaLink; + private Label schemaLabel; + private Text descriptionText; + private Table superiorsTable; + private TableViewer superiorsTableViewer; + private Button addButtonSuperiorsTable; + private Button removeButtonSuperiorsTable; + private Combo classTypeCombo; + private Button obsoleteCheckbox; + private Table mandatoryAttributesTable; + private TableViewer mandatoryAttributesTableViewer; + private Button addButtonMandatoryTable; + private Button removeButtonMandatoryTable; + private Table optionalAttributesTable; + private TableViewer optionalAttributesTableViewer; + private Button addButtonOptionalTable; + private Button removeButtonOptionalTable; + + // Listeners + /** The listener for Aliases Button Widget */ + private SelectionAdapter aliasesButtonListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + EditAliasesDialog editDialog = new EditAliasesDialog( modifiedObjectClass.getNames() ); + if ( editDialog.open() != Window.OK ) + { + return; + } + if ( editDialog.isDirty() ) + { + modifiedObjectClass.setNames( editDialog.getAliases() ); + if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().length != 0 ) ) + { + aliasesLabel.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) ); + } + else + { + aliasesLabel.setText( "(None)" ); + } + setEditorDirty(); + } + } + }; + + /** The Modify listener for the OID Text Widget */ + private ModifyListener oidTextModifyListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + oidText.setForeground( ViewUtils.COLOR_BLACK ); + oidText.setToolTipText( "" ); //$NON-NLS-1$ + + String oid = oidText.getText(); + + if ( OID.isOID( oid ) ) + { + if ( ( originalObjectClass.getOid().equals( oid ) ) + || !( schemaHandler.isAliasOrOidAlreadyTaken( oid ) ) ) + { + modifiedObjectClass.setOid( oid ); + setEditorDirty(); + } + else + { + oidText.setForeground( ViewUtils.COLOR_RED ); + oidText.setToolTipText( "An element with same oid already exists." ); + } + } + else + { + oidText.setForeground( ViewUtils.COLOR_RED ); + oidText.setToolTipText( "Malformed_OID." ); + } + } + }; + + /** The Verify listener for the OID Text Widget */ + private VerifyListener oidTextVerifyListener = new VerifyListener() + { + public void verifyText( VerifyEvent e ) + { + if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$ + { + e.doit = false; + } + } + }; + + /** The listener for the Schema Hyperlink Widget*/ + private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter() + { + public void linkActivated( HyperlinkEvent e ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + + SchemaEditorInput input = new SchemaEditorInput( schemaHandler.getSchema( modifiedObjectClass.getSchema() ) ); + String editorId = SchemaEditor.ID; + try + { + page.openEditor( input, editorId ); + } + catch ( PartInitException exception ) + { + Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$ + } + } + }; + + /** The listener for Description Text Widget */ + private ModifyListener descriptionTextListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + int caretPosition = descriptionText.getCaretPosition(); + modifiedObjectClass.setDescription( descriptionText.getText() ); + descriptionText.setSelection( caretPosition ); + setEditorDirty(); + } + }; + + /** The listener for Class Type Widget */ + private ModifyListener classTypeListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + if ( classTypeCombo.getSelectionIndex() == 0 ) + { + modifiedObjectClass.setType( ObjectClassTypeEnum.ABSTRACT ); + } + else if ( classTypeCombo.getSelectionIndex() == 1 ) + { + modifiedObjectClass.setType( ObjectClassTypeEnum.AUXILIARY ); + } + else if ( classTypeCombo.getSelectionIndex() == 2 ) + { + modifiedObjectClass.setType( ObjectClassTypeEnum.STRUCTURAL ); + } + setEditorDirty(); + } + }; + + /** The listener for Obsolete Widget */ + private SelectionAdapter obsoleteListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + modifiedObjectClass.setObsolete( obsoleteCheckbox.getSelection() ); + setEditorDirty(); + } + }; + + /** The listener for Mandatory Attributes Table Widget */ + private MouseListener mandatoryAttributesTableListener = new MouseListener() + { + public void mouseDoubleClick( MouseEvent e ) + { + StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection(); + if ( selection.isEmpty() ) + { + return; + } + + Object selectedElement = selection.getFirstElement(); + if ( selectedElement != null ) + { + if ( selectedElement instanceof AttributeTypeImpl ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try + { + page.openEditor( new AttributeTypeEditorInput( ( AttributeTypeImpl ) selectedElement ), + AttributeTypeEditor.ID ); + } + catch ( PartInitException exception ) + { + Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$ + } + } + } + } + + + public void mouseDown( MouseEvent e ) + { + } + + + public void mouseUp( MouseEvent e ) + { + removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 ); + } + }; + + /** The listener for Add Button Widget of the Mandatory Attributes section */ + private SelectionAdapter addButtonMandatoryTableListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); + List hiddenATs = new ArrayList(); + for ( String must : modifiedObjectClass.getMustNamesList() ) + { + AttributeTypeImpl at = schemaHandler.getAttributeType( must ); + if ( at != null ) + { + hiddenATs.add( at ); + } + } + for ( String may : modifiedObjectClass.getMayNamesList() ) + { + AttributeTypeImpl at = schemaHandler.getAttributeType( may ); + if ( at != null ) + { + hiddenATs.add( at ); + } + } + dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeTypeImpl[0] ) ); + + if ( dialog.open() != Window.OK ) + { + return; + } + + AttributeTypeImpl at = dialog.getSelectedAttributeType(); + if ( at == null ) + { + return; + } + + List newMusts = new ArrayList(); + String[] musts = modifiedObjectClass.getMustNamesList(); + for ( String must : musts ) + { + newMusts.add( must ); + } + newMusts.add( at.getNames()[0] ); + modifiedObjectClass.setMustNamesList( newMusts.toArray( new String[0] ) ); + + fillInMandatoryAttributesTable(); + setEditorDirty(); + } + }; + + /** The listener for Remove Button Widget of the Mandatory Attributes section */ + private SelectionAdapter removeButtonMandatoryTableListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection(); + if ( selection.isEmpty() ) + { + return; + } + + Object selectedElement = selection.getFirstElement(); + if ( selectedElement != null ) + { + List newMusts = new ArrayList(); + String[] musts = modifiedObjectClass.getMustNamesList(); + for ( String must : musts ) + { + newMusts.add( must ); + } + + if ( selectedElement instanceof AttributeTypeImpl ) + { + for ( String name : ( ( AttributeTypeImpl ) selectedElement ).getNames() ) + { + newMusts.remove( name ); + } + } + else if ( selectedElement instanceof NonExistingAttributeType ) + { + newMusts.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() ); + } + + modifiedObjectClass.setMustNamesList( newMusts.toArray( new String[0] ) ); + + fillInMandatoryAttributesTable(); + addButtonMandatoryTable.setFocus(); + removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 ); + setEditorDirty(); + } + } + }; + + /** The listener for Optional Attributes Table Widget */ + private MouseListener optionalAttributesTableListener = new MouseAdapter() + { + public void mouseDoubleClick( MouseEvent e ) + { + StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection(); + if ( selection.isEmpty() ) + { + return; + } + + Object selectedElement = selection.getFirstElement(); + if ( selectedElement != null ) + { + if ( selectedElement instanceof AttributeTypeImpl ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try + { + page.openEditor( new AttributeTypeEditorInput( ( AttributeTypeImpl ) selectedElement ), + AttributeTypeEditor.ID ); + } + catch ( PartInitException exception ) + { + Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$ + } + } + } + } + + + public void mouseUp( MouseEvent e ) + { + removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 ); + } + }; + + /** The listener for Add Button Widget of the Optional Attributes section */ + private SelectionAdapter addButtonOptionalTableListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog(); + List hiddenATs = new ArrayList(); + for ( String must : modifiedObjectClass.getMustNamesList() ) + { + AttributeTypeImpl at = schemaHandler.getAttributeType( must ); + if ( at != null ) + { + hiddenATs.add( at ); + } + } + for ( String may : modifiedObjectClass.getMayNamesList() ) + { + AttributeTypeImpl at = schemaHandler.getAttributeType( may ); + if ( at != null ) + { + hiddenATs.add( at ); + } + } + dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeTypeImpl[0] ) ); + + if ( dialog.open() != Window.OK ) + { + return; + } + + AttributeTypeImpl at = dialog.getSelectedAttributeType(); + if ( at == null ) + { + return; + } + + List newMays = new ArrayList(); + String[] mays = modifiedObjectClass.getMayNamesList(); + for ( String may : mays ) + { + newMays.add( may ); + } + newMays.add( at.getNames()[0] ); + modifiedObjectClass.setMayNamesList( newMays.toArray( new String[0] ) ); + + fillInOptionalAttributesTable(); + setEditorDirty(); + } + }; + + /** The listener for Remove Button Widget of the Optional Attributes section */ + private SelectionAdapter removeButtonOptionalTableListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection(); + if ( selection.isEmpty() ) + { + return; + } + + Object selectedElement = selection.getFirstElement(); + if ( selectedElement != null ) + { + List newMays = new ArrayList(); + String[] mays = modifiedObjectClass.getMayNamesList(); + for ( String may : mays ) + { + newMays.add( may ); + } + + if ( selectedElement instanceof AttributeTypeImpl ) + { + for ( String name : ( ( AttributeTypeImpl ) selectedElement ).getNames() ) + { + newMays.remove( name ); + } + } + else if ( selectedElement instanceof NonExistingAttributeType ) + { + newMays.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() ); + } + + modifiedObjectClass.setMayNamesList( newMays.toArray( new String[0] ) ); + + fillInOptionalAttributesTable(); + addButtonOptionalTable.setFocus(); + removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 ); + setEditorDirty(); + } + } + }; + + /** The listener for Superiors Table Widget */ + private MouseListener superiorsTableListener = new MouseAdapter() + { + public void mouseDoubleClick( MouseEvent e ) + { + StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); + if ( selection.isEmpty() ) + { + return; + } + + Object selectedElement = selection.getFirstElement(); + if ( selectedElement != null ) + { + if ( selectedElement instanceof ObjectClassImpl ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try + { + page.openEditor( new ObjectClassEditorInput( ( ObjectClassImpl ) selectedElement ), + ObjectClassEditor.ID ); + } + catch ( PartInitException exception ) + { + Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$ + } + } + } + } + + + public void mouseUp( MouseEvent e ) + { + removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 ); + } + }; + + /** The listener for Add Button Widget of the Superiors Table */ + private SelectionAdapter addButtonSuperiorsTableListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + ObjectClassSelectionDialog dialog = new ObjectClassSelectionDialog(); + List hiddenOCs = new ArrayList(); + for ( String sup : modifiedObjectClass.getSuperClassesNames() ) + { + ObjectClassImpl oc = schemaHandler.getObjectClass( sup ); + if ( oc != null ) + { + hiddenOCs.add( oc ); + } + } + hiddenOCs.add( originalObjectClass ); + dialog.setHiddenObjectClasses( hiddenOCs.toArray( new ObjectClassImpl[0] ) ); + + if ( dialog.open() != Window.OK ) + { + return; + } + + ObjectClassImpl oc = dialog.getSelectedObjectClass(); + if ( oc == null ) + { + return; + } + + List superiors = new ArrayList(); + String[] sups = modifiedObjectClass.getSuperClassesNames(); + for ( String sup : sups ) + { + superiors.add( sup ); + } + superiors.add( oc.getNames()[0] ); + modifiedObjectClass.setSuperClassesNames( superiors.toArray( new String[0] ) ); + + fillInSuperiorsTable(); + setEditorDirty(); + } + }; + + /** The listener for Remove Button Widget of the Superiors Table */ + private SelectionAdapter removeButtonSuperiorsTableListener = new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection(); + if ( selection.isEmpty() ) + { + return; + } + + Object selectedElement = selection.getFirstElement(); + if ( selectedElement != null ) + { + List superiors = new ArrayList(); + String[] sups = modifiedObjectClass.getSuperClassesNames(); + for ( String sup : sups ) + { + superiors.add( sup ); + } + + if ( selectedElement instanceof ObjectClassImpl ) + { + for ( String name : ( ( ObjectClassImpl ) selectedElement ).getNames() ) + { + superiors.remove( name ); + } + } + else if ( selectedElement instanceof NonExistingObjectClass ) + { + superiors.remove( ( ( NonExistingObjectClass ) selectedElement ).getName() ); + } + + modifiedObjectClass.setSuperClassesNames( superiors.toArray( new String[0] ) ); + + fillInSuperiorsTable(); + addButtonSuperiorsTable.setFocus(); + removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 ); + setEditorDirty(); + } + } + }; + + + /** + * Default constructor + * @param editor + * the associated editor + */ + public ObjectClassEditorOverviewPage( FormEditor editor ) + { + super( editor, ID, TITLE ); + schemaHandler = Activator.getDefault().getSchemaHandler(); + // schemaHandler.addListener( this ); // TODO + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm) + */ + protected void createFormContent( IManagedForm managedForm ) + { + // Getting the original and modified object classes + modifiedObjectClass = ( ( ObjectClassEditor ) getEditor() ).getModifiedObjectClass(); + originalObjectClass = ( ( ObjectClassEditor ) getEditor() ).getOriginalObjectClass(); + + // Creating the base UI + ScrolledForm form = managedForm.getForm(); + FormToolkit toolkit = managedForm.getToolkit(); + form.getBody().setLayout( new GridLayout() ); + + // General Information Section + createGeneralInformationSection( form.getBody(), toolkit ); + + Composite bottomComposite = toolkit.createComposite( form.getBody() ); + bottomComposite.setLayout( new GridLayout( 2, true ) ); + bottomComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); + + // Mandatory Attributes Section + createMandatoryAttributesSection( bottomComposite, toolkit ); + + // Optionnal Attributes Section + createOptionalAttributesSection( bottomComposite, toolkit ); + + // Enabling or disabling the fields + // setFieldsEditableState(); + + // Filling the UI with values from the object class + fillInUiFields(); + + // Listeners initialization + addListeners(); + } + + + /** + * Creates the General Information Section. + * + * @param parent + * the parent composite + * @param toolkit + * the FormToolKit to use + */ + private void createGeneralInformationSection( Composite parent, FormToolkit toolkit ) + { + // General Information Section + Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); + section_general_information.setDescription( "General_Information_Section_Description" ); //TODO + section_general_information.setText( "General_Information_Section_Text" ); //TODO + section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, true ) ); + + // Creating the layout of the section + Composite client_general_information = toolkit.createComposite( section_general_information ); + client_general_information.setLayout( new GridLayout( 3, false ) ); + toolkit.paintBordersFor( client_general_information ); + section_general_information.setClient( client_general_information ); + + // ALIASES Button + toolkit.createLabel( client_general_information, "Aliases" ); + aliasesLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$ + aliasesLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); + toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$ + aliasesButton = toolkit.createButton( client_general_information, "Edit_Aliases", SWT.PUSH ); + aliasesButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) ); + + // OID Field + toolkit.createLabel( client_general_information, "OID" ); + oidText = toolkit.createText( client_general_information, "" ); //$NON-NLS-1$ + oidText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); + + // SCHEMA Field + schemaLink = toolkit.createHyperlink( client_general_information, "Schema", SWT.WRAP ); + schemaLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$ + schemaLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); + + // DESCRIPTION Field + toolkit.createLabel( client_general_information, "Description" ); + descriptionText = toolkit.createText( client_general_information, "", SWT.MULTI | SWT.V_SCROLL ); //$NON-NLS-1$ + GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ); + descriptionGridData.heightHint = 42; + descriptionText.setLayoutData( descriptionGridData ); + + // SUPERIORS Table + toolkit.createLabel( client_general_information, "Superior classes" ); + superiorsTable = toolkit.createTable( client_general_information, SWT.SINGLE | SWT.V_SCROLL ); + GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false ); + gridData.heightHint = 45; + gridData.minimumHeight = 45; + superiorsTable.setLayoutData( gridData ); + superiorsTableViewer = new TableViewer( superiorsTable ); + superiorsTableViewer.setContentProvider( new ObjectClassEditorSuperiorsTableContentProvider() ); + superiorsTableViewer.setLabelProvider( new ObjectClassEditorSuperiorsTableLabelProvider() ); + Composite superiorsButtonComposite = toolkit.createComposite( client_general_information ); + superiorsButtonComposite.setLayout( new GridLayout() ); + addButtonSuperiorsTable = toolkit.createButton( superiorsButtonComposite, "Add...", SWT.PUSH ); + addButtonSuperiorsTable.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); + removeButtonSuperiorsTable = toolkit.createButton( superiorsButtonComposite, "Remove", SWT.PUSH ); + removeButtonSuperiorsTable.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) ); + + // CLASS TYPE Combo + toolkit.createLabel( client_general_information, "Class type:" ); + classTypeCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE ); + classTypeCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); + initClassTypeCombo(); + + // OBSOLETE Checkbox + toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$ + obsoleteCheckbox = toolkit.createButton( client_general_information, "Obsolete", SWT.CHECK ); + obsoleteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) ); + } + + + /** + * Creates the Mandatory Attributes Section. + * + * @param parent + * the parent composite + * @param toolkit + * the FormToolKit to use + */ + private void createMandatoryAttributesSection( Composite parent, FormToolkit toolkit ) + { + // MANDATORY ATTRIBUTES Section + Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); + section.setText( "Mandatory_Attribute_Section_Text" ); //TODO + section.setDescription( "Mandatory_Attribute_Section_Description" ); //TODO + section.setExpanded( true ); + Composite client = toolkit.createComposite( section ); + section.setClient( client ); + GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); + section.setLayoutData( gd ); + toolkit.paintBordersFor( client ); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + client.setLayout( layout ); + + mandatoryAttributesTable = toolkit.createTable( client, SWT.NULL ); + gd = new GridData( SWT.FILL, SWT.NONE, true, false ); + gd.verticalSpan = 2; + gd.heightHint = 108; + mandatoryAttributesTable.setLayoutData( gd ); + mandatoryAttributesTableViewer = new TableViewer( mandatoryAttributesTable ); + mandatoryAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() ); + mandatoryAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() ); + + addButtonMandatoryTable = toolkit.createButton( client, "Add...", SWT.PUSH ); + removeButtonMandatoryTable = toolkit.createButton( client, "Remove", SWT.PUSH ); + gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING ); + addButtonMandatoryTable.setLayoutData( gd ); + removeButtonMandatoryTable.setLayoutData( gd ); + + // By default, no element is selected + removeButtonMandatoryTable.setEnabled( false ); + } + + + /** + * Creates the Optional Attributes Section. + * + * @param parent + * the parent composite + * @param toolkit + * the FormToolKit to use + */ + private void createOptionalAttributesSection( Composite parent, FormToolkit toolkit ) + { + // OPTIONAL ATTRIBUTES Section + Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR ); + section.setText( "Optionnal_Attributes_Section_Text" ); //TODO + section.setDescription( "Optionnal_Attributes_Section_Description" ); //TODO + section.setExpanded( true ); + Composite client = toolkit.createComposite( section ); + section.setClient( client ); + GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false ); + section.setLayoutData( gd ); + toolkit.paintBordersFor( client ); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + client.setLayout( layout ); + + optionalAttributesTable = toolkit.createTable( client, SWT.SINGLE | SWT.V_SCROLL ); + gd = new GridData( SWT.FILL, SWT.NONE, true, false ); + gd.verticalSpan = 2; + gd.heightHint = 108; + optionalAttributesTable.setLayoutData( gd ); + optionalAttributesTableViewer = new TableViewer( optionalAttributesTable ); + optionalAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() ); + optionalAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() ); + + addButtonOptionalTable = toolkit.createButton( client, "Add...", SWT.PUSH ); + removeButtonOptionalTable = toolkit.createButton( client, "Remove", SWT.PUSH ); + gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING ); + addButtonOptionalTable.setLayoutData( gd ); + removeButtonOptionalTable.setLayoutData( gd ); + + // By default, no element is selected + removeButtonOptionalTable.setEnabled( false ); + } + + + /** + * Initializes the UI fields from the input. + */ + private void fillInUiFields() + { + // ALIASES Label + if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().length != 0 ) ) + { + aliasesLabel.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) ); + } + else + { + aliasesLabel.setText( "(None)" ); + } + + // OID Field + if ( modifiedObjectClass.getOid() != null ) + { + oidText.setText( modifiedObjectClass.getOid() ); + } + + schemaLabel.setText( modifiedObjectClass.getSchema() ); + + // DESCRIPTION Field + if ( modifiedObjectClass.getDescription() != null ) + { + descriptionText.setText( modifiedObjectClass.getDescription() ); + } + + // SUPERIORS Table + fillInSuperiorsTable(); + + // CLASS TYPE Combo + fillInClassType(); + + // OBSOLETE Checkbox + obsoleteCheckbox.setSelection( modifiedObjectClass.isObsolete() ); + + // MANDATORY ATTRIBUTES Table + fillInMandatoryAttributesTable(); + + // OPTIONNAL ATTRIBUTES Table + fillInOptionalAttributesTable(); + } + + + /** + * Fills in the Superiors Table. + */ + private void fillInSuperiorsTable() + { + superiorsTableViewer.setInput( modifiedObjectClass.getSuperClassesNames() ); + } + + + /** + * Initializes the Class Type Combo + */ + private void initClassTypeCombo() + { + classTypeCombo.add( "Abstract", 0 ); + classTypeCombo.add( "Auxiliary", 1 ); + classTypeCombo.add( "Structural", 2 ); + } + + + /** + * Fills in the Class Type Combo + */ + private void fillInClassType() + { + if ( modifiedObjectClass.getType() == ObjectClassTypeEnum.ABSTRACT ) + { + classTypeCombo.select( 0 ); + } + else if ( modifiedObjectClass.getType() == ObjectClassTypeEnum.AUXILIARY ) + { + classTypeCombo.select( 1 ); + } + else if ( modifiedObjectClass.getType() == ObjectClassTypeEnum.STRUCTURAL ) + { + classTypeCombo.select( 2 ); + } + } + + + /** + * Initializes the Mandatory Attributes Table + */ + private void fillInMandatoryAttributesTable() + { + mandatoryAttributesTableViewer.setInput( modifiedObjectClass.getMustNamesList() ); + } + + + /** + * Initializes the Optional Attributes Table + */ + private void fillInOptionalAttributesTable() + { + optionalAttributesTableViewer.setInput( modifiedObjectClass.getMayNamesList() ); + } + + + // /** + // * Enalbes/Disables the UI fields + // */ + // private void setFieldsEditableState() + // { + // if ( modifiedObjectClass.getOriginatingSchema().type == Schema.SchemaType.coreSchema ) + // { + // // If the object class is in a core-schema file, we disable editing + // aliasesButton.setEnabled( false ); + // oidText.setEditable( false ); + // descriptionText.setEditable( false ); + // addButtonSuperiorsTable.setEnabled( false ); + // removeButtonSuperiorsTable.setEnabled( false ); + // classTypeCombo.setEnabled( false ); + // obsoleteCheckbox.setEnabled( false ); + // addButtonMandatoryTable.setEnabled( false ); + // removeButtonMandatoryTable.setEnabled( false ); + // addButtonOptionalTable.setEnabled( false ); + // removeButtonOptionalTable.setEnabled( false ); + // } + // else + // { + // removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelectionIndex() != -1 ); + // removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelectionIndex() != -1 ); + // removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelectionIndex() != -1 ); + // } + // } + + /** + * Adds listeners to UI fields + */ + private void addListeners() + { + aliasesButton.addSelectionListener( aliasesButtonListener ); + oidText.addModifyListener( oidTextModifyListener ); + oidText.addVerifyListener( oidTextVerifyListener ); + descriptionText.addModifyListener( descriptionTextListener ); + addButtonSuperiorsTable.addSelectionListener( addButtonSuperiorsTableListener ); + removeButtonSuperiorsTable.addSelectionListener( removeButtonSuperiorsTableListener ); + classTypeCombo.addModifyListener( classTypeListener ); + obsoleteCheckbox.addSelectionListener( obsoleteListener ); + addButtonMandatoryTable.addSelectionListener( addButtonMandatoryTableListener ); + removeButtonMandatoryTable.addSelectionListener( removeButtonMandatoryTableListener ); + addButtonOptionalTable.addSelectionListener( addButtonOptionalTableListener ); + removeButtonOptionalTable.addSelectionListener( removeButtonOptionalTableListener ); + schemaLink.addHyperlinkListener( schemaLinkListener ); + superiorsTable.addMouseListener( superiorsTableListener ); + mandatoryAttributesTable.addMouseListener( mandatoryAttributesTableListener ); + optionalAttributesTable.addMouseListener( optionalAttributesTableListener ); + } + + + /** + * Removes listeners from UI fields + */ + private void removeListeners() + { + aliasesButton.removeSelectionListener( aliasesButtonListener ); + oidText.removeModifyListener( oidTextModifyListener ); + oidText.removeVerifyListener( oidTextVerifyListener ); + schemaLink.removeHyperlinkListener( schemaLinkListener ); + descriptionText.removeModifyListener( descriptionTextListener ); + superiorsTable.removeMouseListener( superiorsTableListener ); + addButtonSuperiorsTable.removeSelectionListener( addButtonSuperiorsTableListener ); + removeButtonSuperiorsTable.removeSelectionListener( removeButtonSuperiorsTableListener ); + classTypeCombo.removeModifyListener( classTypeListener ); + obsoleteCheckbox.removeSelectionListener( obsoleteListener ); + mandatoryAttributesTable.removeMouseListener( mandatoryAttributesTableListener ); + addButtonMandatoryTable.removeSelectionListener( addButtonMandatoryTableListener ); + removeButtonMandatoryTable.removeSelectionListener( removeButtonMandatoryTableListener ); + optionalAttributesTable.removeMouseListener( optionalAttributesTableListener ); + addButtonOptionalTable.removeSelectionListener( addButtonOptionalTableListener ); + removeButtonOptionalTable.removeSelectionListener( removeButtonOptionalTableListener ); + } + + + /** + * Sets the editor as dirty + */ + private void setEditorDirty() + { + ( ( ObjectClassEditor ) getEditor() ).setDirty( true ); + } + + + /** + * Refreshes the UI. + */ + public void refreshUI() + { + removeListeners(); + fillInUiFields(); + addListeners(); +// setFieldsEditableState(); + } + + +// /* (non-Javadoc) +// * @see org.apache.directory.studio.schemas.model.PoolListener#poolChanged(org.apache.directory.studio.schemas.model.SchemaPool, org.apache.directory.studio.schemas.model.LDAPModelEvent) +// */ +// public void poolChanged( SchemaPool p, LDAPModelEvent e ) +// { +// removeListeners(); +// fillInSuperiorsTable(); +// fillInMandatoryAttributesTable(); +// fillInOptionalAttributesTable(); +// addListeners(); +// setFieldsEditableState(); +// } + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormPage#dispose() + */ + public void dispose() + { +// schemaPool.removeListener( this ); + removeListeners(); + + super.dispose(); + } +} Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass; + + +import java.io.IOException; +import java.text.ParseException; +import java.util.List; + +import org.apache.directory.server.core.tools.schema.ObjectClassLiteral; +import org.apache.directory.server.core.tools.schema.OpenLdapSchemaParser; +import org.apache.directory.studio.apacheds.schemaeditor.PluginUtils; +import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaSourceViewer; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; + + +/** + * This class is the Source Code Page of the Object Class Editor + */ +public class ObjectClassEditorSourceCodePage extends FormPage +{ + /** The page ID */ + public static final String ID = ObjectClassEditor.ID + "sourceCodePage"; //$NON-NLS-1$ + + /** The page title*/ + public static final String TITLE = "Source Code"; //$NON-NLS-1$ + + /** The modified object class */ + private ObjectClassImpl modifiedObjectClass; + + /** The Schema Source Viewer */ + private SchemaSourceViewer schemaSourceViewer; + + /** The flag to indicate if the user can leave the Source Code page */ + private boolean canLeaveThePage = true; + + /** The listener of the Schema Source Viewer Widget */ + private ModifyListener schemaSourceViewerListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + canLeaveThePage = true; + try + { + ( ( ObjectClassEditor ) getEditor() ).setDirty( true ); + OpenLdapSchemaParser parser = new OpenLdapSchemaParser(); + parser.parse( schemaSourceViewer.getTextWidget().getText() ); + + List objectclasses = parser.getObjectClassTypes(); + if ( objectclasses.size() != 1 ) + { + // TODO Throw an exception and return + } + else + { + updateObjectClass( ( ObjectClassLiteral ) objectclasses.get( 0 ) ); + } + } + catch ( IOException e1 ) + { + canLeaveThePage = false; + } + catch ( ParseException exception ) + { + canLeaveThePage = false; + } + } + }; + + + /** + * Default constructor + * @param editor + * the associated editor + */ + public ObjectClassEditorSourceCodePage( FormEditor editor ) + { + super( editor, ID, TITLE ); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm) + */ + protected void createFormContent( IManagedForm managedForm ) + { + ScrolledForm form = managedForm.getForm(); + FormToolkit toolkit = managedForm.getToolkit(); + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + form.getBody().setLayout( layout ); + toolkit.paintBordersFor( form.getBody() ); + + modifiedObjectClass = ( ( ObjectClassEditor ) getEditor() ).getModifiedObjectClass(); + + // SOURCE CODE Field + schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER | SWT.H_SCROLL + | SWT.V_SCROLL ); + GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true ); + gd.heightHint = 10; + schemaSourceViewer.getTextWidget().setLayoutData( gd ); + + // set text font + Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); + schemaSourceViewer.getTextWidget().setFont( font ); + + IDocument document = new Document(); + schemaSourceViewer.setDocument( document ); + + // Initialization from the "input" object class + fillInUiFields(); + + schemaSourceViewer.getTextWidget().addModifyListener( schemaSourceViewerListener ); + } + + + /** + * Fills in the User Interface. + */ + private void fillInUiFields() + { + // SOURCE CODE Field + schemaSourceViewer.getDocument().set( PluginUtils.toSourceCode( modifiedObjectClass ) ); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormPage#canLeaveThePage() + */ + public boolean canLeaveThePage() + { + return canLeaveThePage; + } + + + /** + * Updates the Modified Object Class from the given Object Class Literal. + * + * @param ocl + * the Object Class Literal + */ + private void updateObjectClass( ObjectClassLiteral ocl ) + { + modifiedObjectClass.setDescription( ocl.getDescription() ); + modifiedObjectClass.setMayNamesList( ocl.getMay() ); + modifiedObjectClass.setMustNamesList( ocl.getMust() ); + modifiedObjectClass.setNames( ocl.getNames() ); + modifiedObjectClass.setObsolete( ocl.isObsolete() ); + modifiedObjectClass.setOid( ocl.getOid() ); + modifiedObjectClass.setSuperClassesNames( ocl.getSuperiors() ); + modifiedObjectClass.setType( ocl.getClassType() ); + } + + + /** + * Refreshes the UI. + */ + public void refreshUI() + { + fillInUiFields(); + } +} Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableContentProvider.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableContentProvider.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableContentProvider.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableContentProvider.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.directory.studio.apacheds.schemaeditor.Activator; +import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler; +import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.NonExistingObjectClass; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + + +/** + * This class is the Content Provider for the Superiors Table of the Object Class Editor. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ObjectClassEditorSuperiorsTableContentProvider implements IStructuredContentProvider +{ + /** The SchemaHandler */ + private SchemaHandler schemaHandler; + + + /** + * Creates a new instance of ObjectClassFormEditorSuperiorsTableContentProvider. + */ + public ObjectClassEditorSuperiorsTableContentProvider() + { + schemaHandler = Activator.getDefault().getSchemaHandler(); + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements( Object inputElement ) + { + if ( inputElement instanceof String[] ) + { + List results = new ArrayList(); + + String[] superiors = ( String[] ) inputElement; + for ( String superior : superiors ) + { + ObjectClassImpl oc = schemaHandler.getObjectClass( superior ); + if ( oc != null ) + { + results.add( oc ); + } + else + { + results.add( new NonExistingObjectClass( superior ) ); + } + } + + // Sorting Elements + Collections.sort( results, new Comparator() + { + public int compare( Object o1, Object o2 ) + { + if ( o1 instanceof ObjectClassImpl && o2 instanceof ObjectClassImpl ) + { + return ( ( ObjectClassImpl ) o1 ).getNames()[0].compareToIgnoreCase( ( ( ObjectClassImpl ) o2 ) + .getNames()[0] ); + } + else if ( o1 instanceof ObjectClassImpl && o2 instanceof NonExistingObjectClass ) + { + return ( ( ObjectClassImpl ) o1 ).getNames()[0] + .compareToIgnoreCase( ( ( NonExistingObjectClass ) o2 ).getName() ); + } + else if ( o1 instanceof NonExistingObjectClass && o2 instanceof ObjectClassImpl ) + { + return ( ( NonExistingObjectClass ) o1 ).getName().compareToIgnoreCase( + ( ( ObjectClassImpl ) o2 ).getNames()[0] ); + } + else if ( o1 instanceof NonExistingObjectClass && o2 instanceof NonExistingObjectClass ) + { + return ( ( NonExistingObjectClass ) o1 ).getName().compareToIgnoreCase( + ( ( NonExistingObjectClass ) o2 ).getName() ); + } + + return 0; + } + } ); + + return results.toArray(); + } + + // Default + return null; + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() + { + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) + { + } +} Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableLabelProvider.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableLabelProvider.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableLabelProvider.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSuperiorsTableLabelProvider.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass; + + +import org.apache.directory.studio.apacheds.schemaeditor.Activator; +import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants; +import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.apacheds.schemaeditor.view.ViewUtils; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.NonExistingObjectClass; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; + + +/** + * This class is the Label Provider for the Superiors Table of the Object Class Editor. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ObjectClassEditorSuperiorsTableLabelProvider extends LabelProvider implements ITableLabelProvider +{ + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) + */ + public Image getColumnImage( Object element, int columnIndex ) + { + if ( ( element instanceof ObjectClassImpl ) || ( element instanceof NonExistingObjectClass ) ) + { + return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_OBJECT_CLASS ) + .createImage(); + } + + // Default + return null; + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) + */ + public String getColumnText( Object element, int columnIndex ) + { + if ( element instanceof ObjectClassImpl ) + { + return ViewUtils.concateAliases( ( ( ObjectClassImpl ) element ).getNames() ); + } + else if ( element instanceof NonExistingObjectClass ) + { + return ( ( NonExistingObjectClass ) element ).getDisplayName(); + } + + // Default + return null; + } +} Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditor.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditor.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditor.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditor.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema; + + +import org.apache.directory.studio.apacheds.schemaeditor.Activator; +import org.apache.directory.studio.apacheds.schemaeditor.model.Schema; +import org.apache.log4j.Logger; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.forms.editor.FormEditor; + + +/** + * This class is the Schema Editor main class. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class SchemaEditor extends FormEditor +{ + /** The logger */ + private static Logger logger = Logger.getLogger( SchemaEditor.class ); + + /** The ID of the Editor */ + public static final String ID = Activator.PLUGIN_ID + ".view.schemaformeditor"; //$NON-NLS-1$ + + /** The Overview Page */ + private SchemaEditorOverviewPage overview; + + /** The Source Code page */ + private SchemaEditorSourceCodePage sourceCode; + + /** The associated schema */ + private Schema schema; + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) + */ + public void init( IEditorSite site, IEditorInput input ) throws PartInitException + { + setSite( site ); + setInput( input ); + setPartName( input.getName() ); + + schema = ( ( SchemaEditorInput ) getEditorInput() ).getSchema(); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormEditor#addPages() + */ + protected void addPages() + { + try + { + overview = new SchemaEditorOverviewPage( this ); + addPage( overview ); + sourceCode = new SchemaEditorSourceCodePage( this ); + addPage( sourceCode ); + } + catch ( PartInitException e ) + { + logger.debug( "error when adding pages" ); //$NON-NLS-1$ + } + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) + */ + public void doSave( IProgressMonitor monitor ) + { + // There's nothing to save + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.part.EditorPart#doSaveAs() + */ + public void doSaveAs() + { + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() + */ + public boolean isSaveAsAllowed() + { + return false; + } + + + /** + * Gets the associated schema. + * + * @return + * the associated schema + */ + public Schema getSchema() + { + return schema; + } +} Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorInput.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorInput.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorInput.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorInput.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema; + + +import org.apache.directory.studio.apacheds.schemaeditor.model.Schema; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPersistableElement; + + +/** + * This class is the Input class for the Schema Editor + */ +public class SchemaEditorInput implements IEditorInput +{ + private Schema schema; + + + /** + * Default constructor + * @param schema + */ + public SchemaEditorInput( Schema schema ) + { + super(); + this.schema = schema; + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#exists() + */ + public boolean exists() + { + return ( this.schema == null ); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getImageDescriptor() + */ + public ImageDescriptor getImageDescriptor() + { + return null; + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getName() + */ + public String getName() + { + return this.schema.getName(); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getPersistable() + */ + public IPersistableElement getPersistable() + { + return null; + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getToolTipText() + */ + public String getToolTipText() + { + return getName(); + } + + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter( Class adapter ) + { + return null; + } + + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals( Object obj ) + { + if ( this == obj ) + return true; + if ( !( obj instanceof SchemaEditorInput ) ) + return false; + SchemaEditorInput other = ( SchemaEditorInput ) obj; + return other.getSchema().getName().equals( this.schema.getName() ); + } + + + /** + * Returns the input schema + * @return the input schema + */ + public Schema getSchema() + { + return this.schema; + } +} Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorOverviewPage.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorOverviewPage.java?view=auto&rev=553196 ============================================================================== --- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorOverviewPage.java (added) +++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorOverviewPage.java Wed Jul 4 06:05:16 2007 @@ -0,0 +1,368 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.apacheds.schemaeditor.view.editors.schema; + + +import org.apache.directory.studio.apacheds.schemaeditor.Activator; +import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants; +import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler; +import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener; +import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl; +import org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl; +import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl; +import org.apache.directory.studio.apacheds.schemaeditor.model.Schema; +import org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditor; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype.AttributeTypeEditorInput; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass.ObjectClassEditor; +import org.apache.directory.studio.apacheds.schemaeditor.view.editors.objectclass.ObjectClassEditorInput; +import org.apache.log4j.Logger; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.plugin.AbstractUIPlugin; + + +/** + * This class is the Overview Page of the Schema Editore. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class SchemaEditorOverviewPage extends FormPage +{ + /** The page ID */ + public static final String ID = SchemaEditor.ID + "overviewPage"; //$NON-NLS-1$ + + /** The page title */ + public static final String TITLE = "Overview"; + + /** The SchemaHandler */ + private SchemaHandler schemaHandler; + + /** The associated schema */ + private Schema schema; + + private SchemaListener schemaListener = new SchemaListener() + { + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#attributeTypeAdded(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl) + */ + public void attributeTypeAdded( AttributeTypeImpl at ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#attributeTypeModified(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl) + */ + public void attributeTypeModified( AttributeTypeImpl at ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#attributeTypeRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl) + */ + public void attributeTypeRemoved( AttributeTypeImpl at ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#matchingRuleAdded(org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl) + */ + public void matchingRuleAdded( MatchingRuleImpl mr ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#matchingRuleModified(org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl) + */ + public void matchingRuleModified( MatchingRuleImpl mr ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#matchingRuleRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl) + */ + public void matchingRuleRemoved( MatchingRuleImpl mr ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#objectClassAdded(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl) + */ + public void objectClassAdded( ObjectClassImpl oc ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#objectClassModified(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl) + */ + public void objectClassModified( ObjectClassImpl oc ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#objectClassRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl) + */ + public void objectClassRemoved( ObjectClassImpl oc ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#syntaxAdded(org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl) + */ + public void syntaxAdded( SyntaxImpl syntax ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#syntaxModified(org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl) + */ + public void syntaxModified( SyntaxImpl syntax ) + { + fillInUiFields(); + } + + + /* (non-Javadoc) + * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#syntaxRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl) + */ + public void syntaxRemoved( SyntaxImpl syntax ) + { + fillInUiFields(); + } + }; + + // UI Fields + private Table attributeTypesTable; + private Table objectClassesTable; + + // Listeners + /** The listener of the Attribute Types Table*/ + private MouseAdapter attributeTypesTableListener = new MouseAdapter() + { + public void mouseDoubleClick( MouseEvent e ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + + AttributeTypeEditorInput input = new AttributeTypeEditorInput( schemaHandler + .getAttributeType( attributeTypesTable.getSelection()[0].getText() ) ); + String editorId = AttributeTypeEditor.ID; + try + { + page.openEditor( input, editorId ); + } + catch ( PartInitException exception ) + { + Logger.getLogger( SchemaEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$ + } + } + }; + /** The listener of the Object Classes Table*/ + private MouseAdapter objectClassesTableListener = new MouseAdapter() + { + public void mouseDoubleClick( MouseEvent e ) + { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + + ObjectClassEditorInput input = new ObjectClassEditorInput( schemaHandler.getObjectClass( objectClassesTable + .getSelection()[0].getText() ) ); + String editorId = ObjectClassEditor.ID; + try + { + page.openEditor( input, editorId ); + } + catch ( PartInitException exception ) + { + Logger.getLogger( SchemaEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$ + } + } + }; + + + /** + * Creates a new instance of SchemaFormEditorOverviewPage. + * + * @param editor + * the associated editor + */ + public SchemaEditorOverviewPage( FormEditor editor ) + { + super( editor, ID, TITLE ); + schemaHandler = Activator.getDefault().getSchemaHandler(); + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm) + */ + protected void createFormContent( IManagedForm managedForm ) + { + // Getting the associated schema + schema = ( ( SchemaEditor ) getEditor() ).getSchema(); + schemaHandler.addListener( schema, schemaListener ); + + // Creating the base UI + ScrolledForm form = managedForm.getForm(); + FormToolkit toolkit = managedForm.getToolkit(); + GridLayout layout = new GridLayout( 2, true ); + form.getBody().setLayout( layout ); + + createAttributeTypesSection( form.getBody(), toolkit ); + + createObjectClassesSection( form.getBody(), toolkit ); + + // Initializes the UI from the schema + fillInUiFields(); + + // Listeners initialization + addListeners(); + } + + + /** + * Create the Attribute Types Section. + * + * @param parent + * the parent composite + * @param toolkit + * the FormToolKit to use + */ + private void createAttributeTypesSection( Composite parent, FormToolkit toolkit ) + { + // Attribute Types Section + Section attributeTypesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED + | Section.TITLE_BAR ); + attributeTypesSection.setDescription( "The schema" + schema.getName() + + "contains the following attribute types." ); + attributeTypesSection.setText( "Attribute Types" ); + + // Creating the layout of the section + Composite attributeTypesSectionClient = toolkit.createComposite( attributeTypesSection ); + attributeTypesSectionClient.setLayout( new GridLayout() ); + toolkit.paintBordersFor( attributeTypesSectionClient ); + attributeTypesSection.setClient( attributeTypesSectionClient ); + attributeTypesSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); + + attributeTypesTable = toolkit.createTable( attributeTypesSectionClient, SWT.NONE ); + GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true ); + gridData.heightHint = 1; + attributeTypesTable.setLayoutData( gridData ); + } + + + /** + * Create the Object Classes Section. + * + * @param parent + * the parent composite + * @param toolkit + * the FormToolKit to use + */ + private void createObjectClassesSection( Composite parent, FormToolkit toolkit ) + { + // Attribute Types Section + Section objectClassesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED + | Section.TITLE_BAR ); + objectClassesSection + .setDescription( "The_schema" + schema.getName() + "contains the following object classes." ); + objectClassesSection.setText( "Object Classes" ); + + // Creating the layout of the section + Composite objectClassesSectionClient = toolkit.createComposite( objectClassesSection ); + objectClassesSectionClient.setLayout( new GridLayout() ); + toolkit.paintBordersFor( objectClassesSectionClient ); + objectClassesSection.setClient( objectClassesSectionClient ); + objectClassesSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); + + objectClassesTable = toolkit.createTable( objectClassesSectionClient, SWT.NONE ); + GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true ); + gridData.heightHint = 1; + objectClassesTable.setLayoutData( gridData ); + } + + + /** + * Fills in the fields of the User Interface. + */ + private void fillInUiFields() + { + for ( AttributeTypeImpl at : schema.getAttributeTypes() ) + { + TableItem item = new TableItem( attributeTypesTable, SWT.NONE ); + item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, + PluginConstants.IMG_ATTRIBUTE_TYPE ).createImage() ); + item.setText( at.getNames()[0] ); + } + + for ( ObjectClassImpl oc : schema.getObjectClasses() ) + { + TableItem item = new TableItem( objectClassesTable, SWT.NONE ); + item.setImage( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, + PluginConstants.IMG_OBJECT_CLASS ).createImage() ); + item.setText( oc.getNames()[0] ); + } + } + + + /** + * Initializes and adds the listners. + */ + private void addListeners() + { + attributeTypesTable.addMouseListener( attributeTypesTableListener ); + objectClassesTable.addMouseListener( objectClassesTableListener ); + } +}