directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r553196 [3/5] - in /directory/studio/trunk/studio-apacheds-schemaeditor: ./ META-INF/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ src/main/java...
Date Wed, 04 Jul 2007 13:05:20 GMT
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java?view=auto&rev=553196
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
Wed Jul  4 06:05:16 2007
@@ -0,0 +1,201 @@
+/*
+ *  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.attributetype;
+
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.List;
+
+import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
+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.AttributeTypeImpl;
+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 Attribute Type Editor
+ */
+public class AttributeTypeEditorSourceCodePage extends FormPage
+{
+    /** The page ID*/
+    public static final String ID = AttributeTypeEditor.ID + "sourceCodePage"; //$NON-NLS-1$
+
+    /** The page title */
+    public static String TITLE = "Source Code";
+
+    /** The modified attribute type */
+    private AttributeTypeImpl modifiedAttributeType;
+
+    /** 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 Editor Widget */
+    private ModifyListener schemaSourceViewerListener = new ModifyListener()
+    {
+        public void modifyText( ModifyEvent e )
+        {
+            canLeaveThePage = true;
+            try
+            {
+                ( ( AttributeTypeEditor ) getEditor() ).setDirty( true );
+                OpenLdapSchemaParser parser = new OpenLdapSchemaParser();
+                parser.parse( schemaSourceViewer.getTextWidget().getText() );
+                List attributeTypes = parser.getAttributeTypes();
+                if ( attributeTypes.size() != 1 )
+                {
+                    // Throw an exception and return
+                }
+                else
+                {
+                    updateAttributeType( ( AttributeTypeLiteral ) attributeTypes.get( 0 )
);
+                }
+            }
+            catch ( IOException e1 )
+            {
+                canLeaveThePage = false;
+            }
+            catch ( ParseException exception )
+            {
+                canLeaveThePage = false;
+            }
+        }
+    };
+
+
+    /**
+     * Default constructor
+     * 
+     * @param editor
+     *      the associated editor
+     */
+    public AttributeTypeEditorSourceCodePage( 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() );
+
+        modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType();
+
+        // 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" attribute type
+        fillInUiFields();
+
+        schemaSourceViewer.getTextWidget().addModifyListener( schemaSourceViewerListener
);
+    }
+
+
+    /**
+     * Fills in the User Interface.
+     */
+    private void fillInUiFields()
+    {
+        // SOURCE CODE Field
+        schemaSourceViewer.getDocument().set( PluginUtils.toSourceCode( modifiedAttributeType
) );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormPage#canLeaveThePage()
+     */
+    public boolean canLeaveThePage()
+    {
+        return canLeaveThePage;
+    }
+
+
+    /**
+     * Updates the Modified Attribute Type from the given Attribute Type Literal.
+     *
+     * @param atl
+     *      the Attribute Type Literal
+     */
+    private void updateAttributeType( AttributeTypeLiteral atl )
+    {
+        modifiedAttributeType.setCanUserModify( !atl.isNoUserModification() );
+        modifiedAttributeType.setCollective( atl.isCollective() );
+        modifiedAttributeType.setDescription( atl.getDescription() );
+        modifiedAttributeType.setEqualityName( atl.getEquality() );
+        modifiedAttributeType.setLength( atl.getLength() );
+        modifiedAttributeType.setNames( atl.getNames() );
+        modifiedAttributeType.setObsolete( atl.isObsolete() );
+        modifiedAttributeType.setOid( atl.getOid() );
+        modifiedAttributeType.setOrderingName( atl.getOrdering() );
+        modifiedAttributeType.setSingleValue( atl.isSingleValue() );
+        modifiedAttributeType.setSubstrName( atl.getSubstr() );
+        modifiedAttributeType.setSuperiorName( atl.getSuperior() );
+        modifiedAttributeType.setSyntaxOid( atl.getOid() );
+        modifiedAttributeType.setUsage( atl.getUsage() );
+    }
+
+
+    /**
+     * 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/attributetype/AttributeTypeEditorUsedByPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorUsedByPage.java?view=auto&rev=553196
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorUsedByPage.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorUsedByPage.java
Wed Jul  4 06:05:16 2007
@@ -0,0 +1,356 @@
+/*
+ *  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.attributetype;
+
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerAdapter;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener;
+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.model.Schema;
+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.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+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.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;
+
+
+/**
+ * This class is the Used By Page of the Attribute Type Editor
+ */
+public class AttributeTypeEditorUsedByPage extends FormPage
+{
+    /** The page ID */
+    public static final String ID = AttributeTypeEditor.ID + "usedByPage"; //$NON-NLS-1$
+
+    /** The page title */
+    public static String TITLE = "Used By";
+
+    /** The modified attribute type */
+    private AttributeTypeImpl modifiedAttributeType;
+
+    /** The original attribute type */
+    private AttributeTypeImpl originalAttributeType;
+
+    /** The Schema Handler */
+    private SchemaHandler schemaHandler;
+
+    /** The Schema listener */
+    private SchemaHandlerListener schemaHandlerListener = new SchemaHandlerAdapter()
+    {
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#attributeTypeAdded(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
+         */
+        public void attributeTypeAdded( AttributeTypeImpl at )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#attributeTypeModified(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
+         */
+        public void attributeTypeModified( AttributeTypeImpl at )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#attributeTypeRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
+         */
+        public void attributeTypeRemoved( AttributeTypeImpl at )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#objectClassAdded(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
+         */
+        public void objectClassAdded( ObjectClassImpl oc )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#objectClassModified(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
+         */
+        public void objectClassModified( ObjectClassImpl oc )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#objectClassRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
+         */
+        public void objectClassRemoved( ObjectClassImpl oc )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#schemaAdded(org.apache.directory.studio.apacheds.schemaeditor.model.Schema)
+         */
+        public void schemaAdded( Schema schema )
+        {
+            refreshTableViewers();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandlerListener#schemaRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.Schema)
+         */
+        public void schemaRemoved( Schema schema )
+        {
+            refreshTableViewers();
+        }
+    };
+
+    // UI Widgets
+    private Table mandatoryAttributeTable;
+    private TableViewer mandatoryAttributeTableViewer;
+    private Table optionalAttibuteTable;
+    private TableViewer optionalAttibuteTableViewer;
+
+    // Listeners
+    /** The listener of the Mandatory Attribute Type Table*/
+    private MouseAdapter mandatoryAttributeTableListener = new MouseAdapter()
+    {
+        public void mouseDoubleClick( MouseEvent e )
+        {
+            Object selectedItem = ( ( StructuredSelection ) mandatoryAttributeTableViewer.getSelection()
)
+                .getFirstElement();
+
+            if ( selectedItem instanceof ObjectClassImpl )
+            {
+                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+                try
+                {
+                    page.openEditor( new ObjectClassEditorInput( ( ObjectClassImpl ) selectedItem
),
+                        ObjectClassEditor.ID );
+                }
+                catch ( PartInitException exception )
+                {
+                    Logger.getLogger( AttributeTypeEditorUsedByPage.class ).debug( "error
when opening the editor" ); //$NON-NLS-1$
+                }
+            }
+        }
+    };
+
+    /** The listener of the Optional Attribute Type Table*/
+    private MouseAdapter optionalAttibuteTableListener = new MouseAdapter()
+    {
+        public void mouseDoubleClick( MouseEvent e )
+        {
+            Object selectedItem = ( ( StructuredSelection ) optionalAttibuteTableViewer.getSelection()
)
+                .getFirstElement();
+
+            if ( selectedItem instanceof ObjectClassImpl )
+            {
+                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+                try
+                {
+                    page.openEditor( new ObjectClassEditorInput( ( ObjectClassImpl ) selectedItem
),
+                        ObjectClassEditor.ID );
+                }
+                catch ( PartInitException exception )
+                {
+                    Logger.getLogger( AttributeTypeEditorUsedByPage.class ).debug( "error
when opening the editor" ); //$NON-NLS-1$
+                }
+            }
+        }
+    };
+
+
+    /**
+     * Default constructor.
+     * 
+     * @param editor
+     *      the associated editor
+     */
+    public AttributeTypeEditorUsedByPage( FormEditor editor )
+    {
+        super( editor, ID, TITLE );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+        schemaHandler.addListener( schemaHandlerListener );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
+     */
+    protected void createFormContent( IManagedForm managedForm )
+    {
+        // Getting the modified and original attribute types
+        modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType();
+        originalAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getOriginalAttributeType();
+
+        // Creating the base UI
+        ScrolledForm form = managedForm.getForm();
+        FormToolkit toolkit = managedForm.getToolkit();
+        GridLayout layout = new GridLayout( 2, true );
+        form.getBody().setLayout( layout );
+
+        // As Mandatory Attribute Section
+        createAsMandatoryAttributeSection( form.getBody(), toolkit );
+
+        // As Optional Attribute Section
+        createAsOptionalAttributeSection( form.getBody(), toolkit );
+
+        // Filling the UI with values from the attribute type
+        fillInUiFields();
+
+        // Listeners initialization
+        addListeners();
+    }
+
+
+    /**
+     * Creates the As Mandatory Attribute Section.
+     *
+     * @param parent
+     *      the parent composite
+     * @param toolkit
+     *      the FormToolKit to use
+     */
+    private void createAsMandatoryAttributeSection( Composite parent, FormToolkit toolkit
)
+    {
+        // As Mandatory Attribute Section
+        Section mandatoryAttributeSection = toolkit.createSection( parent, Section.DESCRIPTION
| Section.EXPANDED
+            | Section.TITLE_BAR );
+        mandatoryAttributeSection.setDescription( "The attribute type" + " '" + modifiedAttributeType.getNames()[0]
+            + "' " + "is used as a mandatory attribute in the following object classes."
);
+        mandatoryAttributeSection.setText( "As Mandatory Attribute" );
+
+        // Creating the layout of the section
+        Composite mandatoryAttributeSectionClient = toolkit.createComposite( mandatoryAttributeSection
);
+        mandatoryAttributeSectionClient.setLayout( new GridLayout() );
+        toolkit.paintBordersFor( mandatoryAttributeSectionClient );
+        mandatoryAttributeSection.setClient( mandatoryAttributeSectionClient );
+        mandatoryAttributeSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL,
true, true ) );
+
+        mandatoryAttributeTable = toolkit.createTable( mandatoryAttributeSectionClient, SWT.NONE
);
+        GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
+        gridData.heightHint = 1;
+        mandatoryAttributeTable.setLayoutData( gridData );
+        mandatoryAttributeTableViewer = new TableViewer( mandatoryAttributeTable );
+        mandatoryAttributeTableViewer.setContentProvider( new ATEUsedByMandatoryTableContentProvider()
);
+        mandatoryAttributeTableViewer.setLabelProvider( new ATEUsedByTablesLabelProvider()
);
+    }
+
+
+    /**
+     * Creates the As Optional Attribute Section.
+     *
+     * @param parent
+     *      the parent composite
+     * @param toolkit
+     *      the FormToolKit to use
+     */
+    private void createAsOptionalAttributeSection( Composite parent, FormToolkit toolkit
)
+    {
+        // Matching Rules Section
+        Section optionalAttributeSection = toolkit.createSection( parent, Section.DESCRIPTION
| Section.EXPANDED
+            | Section.TITLE_BAR );
+        optionalAttributeSection.setDescription( "The attribute type" + " '" + modifiedAttributeType.getNames()[0]
+            + "' " + "is used as an optional attribute in the following object classes."
);
+        optionalAttributeSection.setText( "As Optional Attribute" );
+
+        // Creating the layout of the section
+        Composite optionalAttributeSectionClient = toolkit.createComposite( optionalAttributeSection
);
+        optionalAttributeSectionClient.setLayout( new GridLayout() );
+        toolkit.paintBordersFor( optionalAttributeSectionClient );
+        optionalAttributeSection.setClient( optionalAttributeSectionClient );
+        optionalAttributeSection.setLayoutData( new GridData( GridData.FILL, GridData.FILL,
true, true ) );
+
+        optionalAttibuteTable = toolkit.createTable( optionalAttributeSectionClient, SWT.NONE
);
+        GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
+        gridData.heightHint = 1;
+        optionalAttibuteTable.setLayoutData( gridData );
+        optionalAttibuteTableViewer = new TableViewer( optionalAttibuteTable );
+        optionalAttibuteTableViewer.setContentProvider( new ATEUsedByOptionalTableContentProvider()
);
+        optionalAttibuteTableViewer.setLabelProvider( new ATEUsedByTablesLabelProvider()
);
+    }
+
+
+    /**
+     * Fills in the User Iterface.
+     */
+    private void fillInUiFields()
+    {
+        mandatoryAttributeTableViewer.setInput( originalAttributeType );
+        optionalAttibuteTableViewer.setInput( originalAttributeType );
+    }
+
+
+    /**
+     * Adds listeners to UI fields
+     */
+    private void addListeners()
+    {
+        mandatoryAttributeTable.addMouseListener( mandatoryAttributeTableListener );
+        optionalAttibuteTable.addMouseListener( optionalAttibuteTableListener );
+    }
+
+
+    /**
+     * Refreshes the Table Viewers
+     */
+    public void refreshTableViewers()
+    {
+        mandatoryAttributeTableViewer.refresh();
+        optionalAttibuteTableViewer.refresh();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormPage#dispose()
+     */
+    public void dispose()
+    {
+        schemaHandler.removeListener( schemaHandlerListener );
+
+        super.dispose();
+    }
+
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditor.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/ObjectClassEditor.java?view=auto&rev=553196
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditor.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditor.java
Wed Jul  4 06:05:16 2007
@@ -0,0 +1,261 @@
+/*
+ *  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.PluginUtils;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.IPageChangedListener;
+import org.eclipse.jface.dialogs.PageChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.editor.FormEditor;
+
+
+/**
+ * This class is the ObjectClass Editor main class
+ */
+public class ObjectClassEditor extends FormEditor
+{
+    /** The logger */
+    private static Logger logger = Logger.getLogger( ObjectClassEditor.class );
+
+    /** The ID of the Editor */
+    public static final String ID = Activator.PLUGIN_ID + ".view.objectClassEditor"; //$NON-NLS-1$
+
+    /** The Overview page */
+    private ObjectClassEditorOverviewPage overview;
+
+    /** The Source Code page */
+    private ObjectClassEditorSourceCodePage sourceCode;
+
+    /** The dirty state flag */
+    private boolean dirty = false;
+
+    /** The original object class */
+    private ObjectClassImpl originalObjectClass;
+
+    /** The object class used to save modifications */
+    private ObjectClassImpl modifiedObjectClass;
+
+    /** The listener for page changed */
+    private IPageChangedListener pageChangedListener = new IPageChangedListener()
+    {
+        public void pageChanged( PageChangedEvent event )
+        {
+            Object selectedPage = event.getSelectedPage();
+
+            if ( selectedPage instanceof ObjectClassEditorOverviewPage )
+            {
+                if ( !sourceCode.canLeaveThePage() )
+                {
+                    notifyError( "Source_Code_Error_cannot_return_to_Overview_page" ); //TODO
+                    return;
+                }
+
+                overview.refreshUI();
+            }
+            else if ( selectedPage instanceof ObjectClassEditorSourceCodePage )
+            {
+                if ( sourceCode.canLeaveThePage() )
+                {
+                    sourceCode.refreshUI();
+                }
+            }
+        }
+    };
+
+
+    /**
+     * Default constructor
+     */
+    public ObjectClassEditor()
+    {
+        super();
+    }
+
+
+    /* (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() );
+
+        originalObjectClass = ( ( ObjectClassEditorInput ) getEditorInput() ).getObjectClass();
+        //        originalObjectClass.setEditor( this );
+
+        modifiedObjectClass = PluginUtils.getClone( originalObjectClass );
+
+        addPageChangedListener( pageChangedListener );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormEditor#dispose()
+     */
+    public void dispose()
+    {
+        //        originalObjectClass.removeEditor( this ); //TODO
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
+     */
+    @Override
+    protected void addPages()
+    {
+        try
+        {
+            overview = new ObjectClassEditorOverviewPage( this ); //$NON-NLS-1$ //$NON-NLS-2$
+            addPage( overview );
+            sourceCode = new ObjectClassEditorSourceCodePage( this ); //$NON-NLS-1$ //$NON-NLS-2$
+            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 )
+    {
+        // Verifying if there is an error on the source code page
+        if ( !sourceCode.canLeaveThePage() )
+        {
+            notifyError( "Source_Code_Error_cannot_save_object_class" ); //TODO
+            monitor.setCanceled( true );
+            return;
+        }
+
+        Activator.getDefault().getSchemaHandler().modifyObjectClass( originalObjectClass,
modifiedObjectClass );
+
+        setPartName( getEditorInput().getName() );
+        if ( !monitor.isCanceled() )
+        {
+            setDirty( false );
+        }
+    }
+
+
+    /* (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;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
+     */
+    public boolean isDirty()
+    {
+        return dirty;
+    }
+
+
+    /**
+     * Sets the dirty state of the editor
+     * 
+     * @param dirty
+     *            the dirty state
+     */
+    public void setDirty( boolean dirty )
+    {
+        this.dirty = dirty;
+        editorDirtyStateChanged();
+    }
+
+
+    /**
+     * Gets the original object class.
+     *
+     * @return
+     *      the original object class
+     */
+    public ObjectClassImpl getOriginalObjectClass()
+    {
+        return originalObjectClass;
+    }
+
+
+    /**
+     * Gets the modified object class.
+     *
+     * @return
+     *      the modified object class
+     */
+    public ObjectClassImpl getModifiedObjectClass()
+    {
+        return modifiedObjectClass;
+    }
+
+
+    /**
+     * Sets the modified object class.
+     *
+     * @param modifiedObjectClass
+     *      the modified object class to set.
+     */
+    public void setModifiedObjectClass( ObjectClassImpl modifiedObjectClass )
+    {
+        this.modifiedObjectClass = modifiedObjectClass;
+    }
+
+
+    /**
+     * Opens an error dialog displaying the given message.
+     *  
+     * @param message
+     *      the message to display
+     */
+    private void notifyError( String message )
+    {
+        MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.OK
+            | SWT.ICON_ERROR );
+        messageBox.setMessage( message );
+        messageBox.open();
+    }
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableContentProvider.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/ObjectClassEditorAttributesTableContentProvider.java?view=auto&rev=553196
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableContentProvider.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableContentProvider.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.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.view.editors.NonExistingAttributeType;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class is the Content Provider for the Attributes Table of the Object Class Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassEditorAttributesTableContentProvider implements IStructuredContentProvider
+{
+    /** The Schema Pool */
+    private SchemaHandler schemaHandler;
+
+
+    /**
+     * Creates a new instance of ObjectClassEditorAttributesTableContentProvider.
+     */
+    public ObjectClassEditorAttributesTableContentProvider()
+    {
+        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<Object> results = new ArrayList<Object>();
+
+            String[] attributes = ( String[] ) inputElement;
+            for ( String attribute : attributes )
+            {
+                AttributeTypeImpl at = schemaHandler.getAttributeType( attribute );
+                if ( at != null )
+                {
+                    results.add( at );
+                }
+                else
+                {
+                    results.add( new NonExistingAttributeType( attribute ) );
+                }
+            }
+
+            // Sorting Elements
+            Collections.sort( results, new Comparator<Object>()
+            {
+                public int compare( Object o1, Object o2 )
+                {
+                    if ( o1 instanceof AttributeTypeImpl && o2 instanceof AttributeTypeImpl
)
+                    {
+                        return ( ( AttributeTypeImpl ) o1 ).getNames()[0]
+                            .compareToIgnoreCase( ( ( AttributeTypeImpl ) o2 ).getNames()[0]
);
+                    }
+                    else if ( o1 instanceof AttributeTypeImpl && o2 instanceof NonExistingAttributeType
)
+                    {
+                        return ( ( AttributeTypeImpl ) o1 ).getNames()[0]
+                            .compareToIgnoreCase( ( ( NonExistingAttributeType ) o2 ).getName()
);
+                    }
+                    else if ( o1 instanceof NonExistingAttributeType && o2 instanceof
AttributeTypeImpl )
+                    {
+                        return ( ( NonExistingAttributeType ) o1 ).getName().compareToIgnoreCase(
+                            ( ( AttributeTypeImpl ) o2 ).getNames()[0] );
+                    }
+                    else if ( o1 instanceof NonExistingAttributeType && o2 instanceof
NonExistingAttributeType )
+                    {
+                        return ( ( NonExistingAttributeType ) o1 ).getName().compareToIgnoreCase(
+                            ( ( NonExistingAttributeType ) 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/ObjectClassEditorAttributesTableLabelProvider.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/ObjectClassEditorAttributesTableLabelProvider.java?view=auto&rev=553196
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableLabelProvider.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorAttributesTableLabelProvider.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.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.view.ViewUtils;
+import org.apache.directory.studio.apacheds.schemaeditor.view.editors.NonExistingAttributeType;
+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 Attributes Table of the Object Class Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassEditorAttributesTableLabelProvider 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 AttributeTypeImpl ) || ( element instanceof NonExistingAttributeType
) )
+        {
+            return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_ATTRIBUTE_TYPE
)
+                .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 AttributeTypeImpl )
+        {
+            return ViewUtils.concateAliases( ( ( AttributeTypeImpl ) element ).getNames()
);
+        }
+        else if ( element instanceof NonExistingAttributeType )
+        {
+            return ( ( NonExistingAttributeType ) element ).getDisplayName();
+        }
+
+        // Default
+        return null;
+    }
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorInput.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/ObjectClassEditorInput.java?view=auto&rev=553196
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorInput.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorInput.java
Wed Jul  4 06:05:16 2007
@@ -0,0 +1,137 @@
+/*
+ *  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.model.ObjectClassImpl;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+
+/**
+ * This class is the Input class for the Object Class Editor
+ */
+public class ObjectClassEditorInput implements IEditorInput
+{
+    private ObjectClassImpl objectClass;
+
+
+    /**
+     * Default constructor.
+     * 
+     * @param obj
+     *      the object class
+     */
+    public ObjectClassEditorInput( ObjectClassImpl obj )
+    {
+        super();
+        objectClass = obj;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IEditorInput#exists()
+     */
+    public boolean exists()
+    {
+        return ( objectClass == null );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
+     */
+    public ImageDescriptor getImageDescriptor()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IEditorInput#getName()
+     */
+    public String getName()
+    {
+        if ( objectClass.getNames().length != 0 )
+        {
+            return objectClass.getNames()[0];
+        }
+        else
+        {
+            return objectClass.getOid();
+        }
+    }
+
+
+    /* (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() + " from the" + objectClass.getSchema() + " schema";
+    }
+
+
+    /* (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 ObjectClassEditorInput ) )
+            return false;
+        ObjectClassEditorInput other = ( ObjectClassEditorInput ) obj;
+        return other.getObjectClass().getOid().equals( this.objectClass.getOid() );
+    }
+
+
+    /**
+     * Returns the input object class
+     * 
+     * @return
+     *      the input object class
+     */
+    public ObjectClassImpl getObjectClass()
+    {
+        return this.objectClass;
+    }
+}



Mime
View raw message