directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r506058 [3/3] - in /directory/ldapstudio/trunk: ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/events/ ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/schema/ ldap...
Date Sun, 11 Feb 2007 16:01:39 GMT
Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserInput.java?view=diff&rev=506058&r1=506057&r2=506058
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserInput.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserInput.java
Sun Feb 11 08:01:38 2007
@@ -21,6 +21,8 @@
 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser;
 
 
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -28,51 +30,204 @@
 import org.eclipse.ui.IPersistableElement;
 
 
+/**
+ * The input for the schema browser.
+ * 
+ * There is a trick to provide a single instance of the schema browser:
+ * <ul>
+ * <li>If oneInstanceHackEnabled is true the equals method returns always 
+ *     true as long as the compared object is also of type SchemaBrowserInput. 
+ *     With this trick only one instance of the schema browser is opened
+ *     by the eclipse editor framework.
+ * <li>If oneInstanceHackEnabled is false the equals method returns 
+ *     true only if the wrapped objects (IConnection and SchemaPart) are equal. 
+ *     This is necessary for the history navigation because it must be able 
+ *     to distinguish the different input objects.
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class SchemaBrowserInput implements IEditorInput
 {
 
-    private static final SchemaBrowserInput instance = new SchemaBrowserInput();
-
-
-    public static SchemaBrowserInput getInstance()
-    {
-        return instance;
-    }
-
-
+    /** The connection */
+    private IConnection connection;
+    
+    /** The schema element */
+    private SchemaPart schemaElement;
+    
+    /** One instance hack flag */
+    private static boolean oneInstanceHackEnabled = true;
+
+
+    /**
+     * Creates a new instance of SchemaBrowserInput.
+     *
+     *@param connection the connection
+     * @param schemaElement the schema element input
+     */
+    public SchemaBrowserInput( IConnection connection, SchemaPart schemaElement )
+    {
+        this.connection = connection;
+        this.schemaElement = schemaElement;
+    }
+    
+
+    /**
+     * This implementation always return false because
+     * a schema element should not be visible in the 
+     * "File Most Recently Used" menu.
+     * 
+     * {@inheritDoc}
+     */
     public boolean exists()
     {
         return false;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public ImageDescriptor getImageDescriptor()
     {
         return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SCHEMABROWSEREDITOR
);
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getName()
     {
         return "Schema Browser";
     }
 
 
+    /**
+     * This implementation always return null.
+     * 
+     * {@inheritDoc}
+     */
     public IPersistableElement getPersistable()
     {
         return null;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public String getToolTipText()
     {
-        return "Schema Browser";
+        return "";
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public Object getAdapter( Class adapter )
     {
         return null;
+    }
+    
+
+    /**
+     * Gets the connection.
+     *
+     * @return the connection
+     */
+    public IConnection getConnection()
+    {
+        return connection;
+    }
+    
+    
+    /**
+    /**
+     * Gets the schema element, may be null.
+     *
+     * @return the schema element or null
+     */
+    public SchemaPart getSchemaElement()
+    {
+        return schemaElement;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int hashCode()
+    {
+        return getToolTipText().hashCode();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean equals( Object obj )
+    {
+
+        boolean equal;
+
+        if ( oneInstanceHackEnabled )
+        {
+            equal = ( obj instanceof SchemaBrowserInput );
+        }
+        else
+        {
+            if ( obj instanceof SchemaBrowserInput )
+            {
+                SchemaBrowserInput other = ( SchemaBrowserInput ) obj;
+                if ( this.connection == null && other.connection == null)
+                {
+                    return true;
+                }
+                else if ( this.connection == null || other.connection == null)
+                {
+                    return false;
+                }
+                else if ( !this.connection.equals( other.connection ))
+                {
+                    return false;
+                }
+                else if ( this.schemaElement == null && other.schemaElement == null
)
+                {
+                    return true;
+                }
+                else if ( this.schemaElement == null || other.schemaElement == null )
+                {
+                    return false;
+                }
+                else
+                {
+                    equal = other.schemaElement.equals( this.schemaElement );
+                }
+            }
+            else
+            {
+                equal = false;
+            }
+        }
+
+        return equal;
+    }
+
+
+    /**
+     * Enables or disabled the one instance hack.
+     *
+     * @param b 
+     *      true to enable the one instance hack,
+     *      false to disable the one instance hack
+     */
+    public static void enableOneInstanceHack( boolean b )
+    {
+        oneInstanceHackEnabled = b;
     }
 
 }

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserManager.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserManager.java?view=auto&rev=506058
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserManager.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserManager.java
Sun Feb 11 08:01:38 2007
@@ -0,0 +1,96 @@
+/*
+ *  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.ldapstudio.browser.ui.editors.schemabrowser;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The SchemaBrowserManager is used to set and get the the input
+ * of the single schema browser instance.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaBrowserManager
+{
+
+    /** The dummy input, to find the single schema browser instance */
+    private static SchemaBrowserInput DUMMY_INPUT = new SchemaBrowserInput( null, null );
+
+
+    /**
+     * Sets the input to the schema browser.
+     *
+     * @param connection the connection
+     * @param schemaElement the schema element
+     */
+    public static void setInput( IConnection connection, SchemaPart schemaElement )
+    {
+        SchemaBrowserInput input = new SchemaBrowserInput( connection, schemaElement );
+        setInput( input );
+    }
+
+
+    /**
+     * Sets the input to the schema browser. 
+     *
+     * @param input the input
+     */
+    private static void setInput( SchemaBrowserInput input )
+    {
+        SchemaBrowser editor = ( SchemaBrowser ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+            .findEditor( DUMMY_INPUT );
+        if ( editor == null && input != null )
+        {
+            // open new schema browser
+            try
+            {
+                editor = ( SchemaBrowser ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+                    .openEditor( input, SchemaBrowser.getId(), false );
+                editor.setInput( input );
+            }
+            catch ( PartInitException e )
+            {
+                e.printStackTrace();
+            }
+        }
+        else
+        {
+            // set the input to already opened schema browser
+            editor.setInput( input );
+
+            // bring schema browser to top only if schema element schould be displayed. 
+            if ( input.getSchemaElement() != null )
+            {
+                if ( !PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().isPartVisible(
editor ) )
+                {
+                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().bringToTop(
editor );
+                }
+            }
+        }
+    }
+
+}

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserNavigationLocation.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserNavigationLocation.java?view=auto&rev=506058
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserNavigationLocation.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaBrowserNavigationLocation.java
Sun Feb 11 08:01:38 2007
@@ -0,0 +1,260 @@
+/*
+ *  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.ldapstudio.browser.ui.editors.schemabrowser;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.INavigationLocation;
+import org.eclipse.ui.NavigationLocation;
+
+
+/**
+ * This class is used to mark the schema browser input to the navigation history.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaBrowserNavigationLocation extends NavigationLocation
+{
+
+    /**
+     * Creates a new instance of SchemaBrowserNavigationLocation.
+     *
+     * @param schemaBrowser the schema browser
+     */
+    SchemaBrowserNavigationLocation( SchemaBrowser schemaBrowser )
+    {
+        super( schemaBrowser );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getText()
+    {
+        SchemaPart schemaElement = getSchemElement();
+        if ( schemaElement != null )
+        {
+            if(schemaElement instanceof ObjectClassDescription)
+            {
+                return "Object Class " + schemaElement.toString();
+            }
+            else if(schemaElement instanceof AttributeTypeDescription )
+            {
+                return "Attribute Type " + schemaElement.toString();
+            }
+            else if(schemaElement instanceof LdapSyntaxDescription )
+            {
+                return "Syntax " + schemaElement.toString();
+            }
+            else if(schemaElement instanceof MatchingRuleDescription)
+            {
+                return "Matching Rule " + schemaElement.toString();
+            }
+            else if(schemaElement instanceof MatchingRuleUseDescription )
+            {
+                return "Matching Rule Use " + schemaElement.toString();
+            }
+            else
+            {
+                return schemaElement.getNumericOID();
+            }
+        }
+        else
+        {
+            return super.getText();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void saveState( IMemento memento )
+    {
+        IConnection connection = getConnection();
+        SchemaPart schemaElement = getSchemElement();
+        memento.putString( "CONNECTION", connection.getName() );
+        memento.putString( "SCHEMAELEMENTYPE", schemaElement.getClass().getName() );
+        memento.putString( "SCHEMAELEMENTOID", schemaElement.getNumericOID() );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void restoreState( IMemento memento )
+    {
+        IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+            memento.getString( "CONNECTION" ) );
+        String schemaElementType = memento.getString( "SCHEMAELEMENTYPE" );
+        String schemaElementOid = memento.getString( "SCHEMAELEMENTOID" );
+        SchemaPart schemaElement = null;
+        if(ObjectClassDescription.class.getName().equals( schemaElementType ) )
+        {
+            schemaElement = connection.getSchema().getObjectClassDescription( schemaElementOid
);
+        }
+        else if(AttributeTypeDescription.class.getName().equals( schemaElementType ) )
+        {
+            schemaElement = connection.getSchema().getAttributeTypeDescription( schemaElementOid
);
+        }
+        else if(LdapSyntaxDescription.class.getName().equals( schemaElementType ) )
+        {
+            schemaElement = connection.getSchema().getLdapSyntaxDescription( schemaElementOid
);
+        }
+        else if(MatchingRuleDescription.class.getName().equals( schemaElementType ) )
+        {
+            schemaElement = connection.getSchema().getMatchingRuleDescription( schemaElementOid
);
+        }
+        else if(MatchingRuleUseDescription.class.getName().equals( schemaElementType ) )
+        {
+            schemaElement = connection.getSchema().getMatchingRuleUseDescription( schemaElementOid
);
+        }
+        
+        super.setInput( new SchemaBrowserInput( connection, schemaElement  ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void restoreLocation()
+    {
+        IEditorPart editorPart = getEditorPart();
+        if ( editorPart != null && editorPart instanceof SchemaBrowser )
+        {
+            SchemaBrowser schemaBrowser = ( SchemaBrowser ) editorPart;
+            Object input = getInput();
+            if(input != null && input instanceof SchemaBrowserInput)
+            {
+                SchemaBrowserInput sbi = (SchemaBrowserInput)input;
+                if(sbi.getConnection() != null && sbi.getSchemaElement() != null)

+                {
+                    schemaBrowser.setInput( sbi );
+                }
+            }
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean mergeInto( INavigationLocation currentLocation )
+    {
+        if ( currentLocation == null )
+        {
+            return false;
+        }
+
+        if ( getClass() != currentLocation.getClass() )
+        {
+            return false;
+        }
+
+        SchemaBrowserNavigationLocation location = ( SchemaBrowserNavigationLocation ) currentLocation;
+        SchemaPart other = location.getSchemElement();
+        SchemaPart element = getSchemElement();
+
+        if ( other == null && element == null )
+        {
+            return true;
+        }
+        else if ( other == null || element == null )
+        {
+            return false;
+        }
+        else
+        {
+            return element.equals( other );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void update()
+    {
+    }
+
+
+    /**
+     * Gets the schema element.
+     *
+     * @return the schema element
+     */
+    private SchemaPart getSchemElement()
+    {
+
+        Object editorInput = getInput();
+        if ( editorInput != null && editorInput instanceof SchemaBrowserInput )
+        {
+            SchemaBrowserInput schemaBrowserInput = ( SchemaBrowserInput ) editorInput;
+            SchemaPart schemaElement = schemaBrowserInput.getSchemaElement();
+            if ( schemaElement != null )
+            {
+                return schemaElement;
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Gets the connection.
+     *
+     * @return the connection
+     */
+    private IConnection getConnection()
+    {
+        
+        Object editorInput = getInput();
+        if ( editorInput != null && editorInput instanceof SchemaBrowserInput )
+        {
+            SchemaBrowserInput schemaBrowserInput = ( SchemaBrowserInput ) editorInput;
+            return schemaBrowserInput.getConnection();
+        }
+        
+        return null;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public String toString()
+    {
+        return "" + getSchemElement();
+    }
+
+}

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaDetailsPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaDetailsPage.java?view=diff&rev=506058&r1=506057&r2=506058
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaDetailsPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaDetailsPage.java
Sun Feb 11 08:01:38 2007
@@ -21,15 +21,7 @@
 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser;
 
 
-import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
-import org.apache.directory.ldapstudio.browser.core.events.SchemaElementSelectionListener;
-import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
-import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription;
-import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription;
-import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription;
-import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
-
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -37,68 +29,109 @@
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.events.ExpansionAdapter;
 import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 import org.eclipse.ui.forms.widgets.Section;
 
 
-public abstract class SchemaDetailsPage implements SchemaElementSelectionListener
+/**
+ * A base implementation used from all schema detail pages.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class SchemaDetailsPage implements IHyperlinkListener
 {
 
+    /** The raw section, displays the schema attibute value */
     protected Section rawSection;
 
+    /** The text with the schema attribute value */
     protected Text rawText;
 
+    /** The toolkit used to create controls */
     protected FormToolkit toolkit;
 
-    protected SchemaBrowser schemaBrowser;
+    /** The master schema page */
+    protected SchemaPage schemaPage;
 
+    /** The detail page form */
     protected ScrolledForm detailForm;
 
 
-    protected SchemaDetailsPage( SchemaBrowser schemaBrowser, FormToolkit toolkit )
+    /**
+     * Creates a new instance of SchemaDetailsPage.
+     *
+     * @param schemaPage the master schema page
+     * @param toolkit the toolkit used to create controls
+     */
+    protected SchemaDetailsPage( SchemaPage schemaPage, FormToolkit toolkit )
     {
-        this.schemaBrowser = schemaBrowser;
+        this.schemaPage = schemaPage;
         this.toolkit = toolkit;
-        EventRegistry.addSchemaElementSelectionListener( this );
     }
 
 
+    /**
+     * Disposes this details page.
+     */
     public void dispose()
     {
-        EventRegistry.removeSchemaElementSelectionListener( this );
-    }
-
-
-    public void attributeTypeDescriptionSelected( AttributeTypeDescription atd )
-    {
     }
 
 
-    public void objectClassDescriptionSelected( ObjectClassDescription ocd )
+    /**
+     * {@inheritDoc}
+     */
+    public void linkActivated( HyperlinkEvent e )
     {
+        Object obj = e.getHref();
+        if ( obj instanceof SchemaPart )
+        {
+            schemaPage.getSchemaBrowser().setInput(
+                new SchemaBrowserInput( schemaPage.getConnection(), ( SchemaPart ) obj )
);
+        }
     }
 
 
-    public void matchingRuleDescriptionSelected( MatchingRuleDescription mrd )
+    /**
+     * {@inheritDoc}
+     */
+    public void linkEntered( HyperlinkEvent e )
     {
     }
 
 
-    public void ldapSyntacDescriptionSelected( LdapSyntaxDescription lsd )
+    /**
+     * {@inheritDoc}
+     */
+    public void linkExited( HyperlinkEvent e )
     {
     }
 
 
-    public void matchingRuleUseDescriptionSelected( MatchingRuleUseDescription mrud )
-    {
-    }
+    /**
+     * Sets the input of this details page.
+     *
+     * @param input the input
+     */
+    public abstract void setInput( Object input );
 
 
-    public abstract void createContents( final ScrolledForm detailForm );
+    /**
+     * Creates the contents of the details page.
+     *
+     * @param detailForm the parent
+     */
+    protected abstract void createContents( final ScrolledForm detailForm );
 
 
-    public void createRawSection()
+    /**
+     * Creates the raw content section.
+     */
+    protected void createRawSection()
     {
         rawSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
         rawSection.setText( "Raw Schema Definition" );
@@ -116,7 +149,12 @@
     }
 
 
-    public void createRawContents( SchemaPart schemaPart )
+    /**
+     * Creates the contents of the raw section.
+     *
+     * @param schemaPart the schema part to display
+     */
+    protected void createRawContents( SchemaPart schemaPart )
     {
 
         if ( rawSection.getClient() != null && !rawSection.getClient().isDisposed()
)
@@ -145,6 +183,12 @@
     }
 
 
+    /**
+     * Helper method, return a dash "-" if the given string is null. 
+     *
+     * @param s the string
+     * @return the given string or a dash "-" if the given string is null.
+     */
     protected String getNonNullString( String s )
     {
         return s == null ? "-" : s;

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaPage.java?view=diff&rev=506058&r1=506057&r2=506058
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/SchemaPage.java
Sun Feb 11 08:01:38 2007
@@ -21,126 +21,297 @@
 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser;
 
 
-import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
-import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateListener;
-import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
-import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
-import org.apache.directory.ldapstudio.browser.core.model.IEntry;
-import org.apache.directory.ldapstudio.browser.core.model.IValue;
-import org.apache.directory.ldapstudio.browser.ui.actions.SelectionUtils;
-import org.apache.directory.ldapstudio.browser.ui.views.connection.ConnectionView;
-
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.ViewerSorter;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.FormColors;
 import org.eclipse.ui.forms.widgets.Form;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
 
 
-public abstract class SchemaPage implements ISelectionListener, ConnectionUpdateListener
+/**
+ * A base implementation used from all schema master pages.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class SchemaPage
 {
 
-    protected IConnection selectedConnection;
+    /** The connection combo */
+    protected ConnectionComboContributionItem connectionCombo;
+
+    /** The show default schema action */
+    protected ShowDefaultSchemaAction showDefaultSchemaAction;
 
+    /** The reload schema action */
+    protected ReloadSchemaAction reloadSchemaAction;
+
+    /** The schema browser */
     protected SchemaBrowser schemaBrowser;
 
+    /** The toolkit used to create controls */
     protected FormToolkit toolkit;
 
+    /** The outer form */
     protected Form form;
 
+    /** The sash form, used to split the master and detail form */
     protected SashForm sashForm;
 
+    /** The master form, contains the schema element list */
     protected ScrolledForm masterForm;
 
+    /** The detail form, contains the schema details */
     protected ScrolledForm detailForm;
 
+    /** The schema details page */
     protected SchemaDetailsPage detailsPage;
 
+    /** The section of the master form */
+    protected Section section;
+
+    /** The filter field of the master form */
+    protected Text filterText;
 
+    /** The list with all schema elements */
+    protected TableViewer viewer;
+
+    /** Flag indicating if the viewer's selection is changed programatically */
+    protected boolean inChange;
+
+
+    /**
+     * Creates a new instance of SchemaPage.
+     *
+     * @param schemaBrowser the schema browser
+     */
     public SchemaPage( SchemaBrowser schemaBrowser )
     {
         this.schemaBrowser = schemaBrowser;
-
-        this.selectedConnection = null;
-        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addSelectionListener(
this );
-        EventRegistry.addConnectionUpdateListener( this );
+        this.inChange = false;
     }
 
 
-    protected abstract void refresh();
-
-
-    protected abstract void createMaster( Composite body );
+    /**
+     * Refreshes this schema page.
+     */
+    public void refresh()
+    {
+        Schema schema = null;
+        if ( showDefaultSchemaAction.isChecked() )
+        {
+            schema = Schema.DEFAULT_SCHEMA;
+        }
+        else if ( getConnection() != null )
+        {
+            schema = getConnection().getSchema();
+        }
 
+        if ( viewer.getInput() != schema )
+        {
+            viewer.setInput( schema );
+            viewer.setSelection( StructuredSelection.EMPTY );
+        }
 
-    protected abstract void createDetail( Composite body );
+        form.setText( getTitle() );
+        viewer.refresh();
+    }
 
 
-    public void selectionChanged( IWorkbenchPart part, ISelection selection )
+    /**
+     * Gets the title of this schema page.
+     *
+     * @return the title
+     */
+    protected abstract String getTitle();
+
+
+    /**
+     * Gets the filter description.
+     *
+     * @return the filter description
+     */
+    protected abstract String getFilterDescription();
+
+
+    /**
+     * Gets the content provider.
+     * 
+     * @return the content provider
+     */
+    protected abstract IStructuredContentProvider getContentProvider();
+
+
+    /**
+     * Gets the label provider.
+     * 
+     * @return the label provider
+     */
+    protected abstract ITableLabelProvider getLabelProvider();
+
+
+    /**
+     * Gets the sorter.
+     * 
+     * @return the sorter
+     */
+    protected abstract ViewerSorter getSorter();
+
+
+    /**
+     * Gets the filter.
+     * 
+     * @return the filter
+     */
+    protected abstract ViewerFilter getFilter();
+
+
+    /**
+     * Gets the details page.
+     * 
+     * @return the details page
+     */
+    protected abstract SchemaDetailsPage getDetailsPage();
+
+
+    /**
+     * Creates the master page.
+     *
+     * @param body the parent composite
+     */
+    //protected abstract void createMaster( Composite body );
+    private void createMaster( Composite parent )
     {
-        if ( part.getClass() == ConnectionView.class )
+        // create section
+        section = toolkit.createSection( parent, Section.DESCRIPTION );
+        section.marginWidth = 10;
+        section.marginHeight = 12;
+        section.setText( getTitle() );
+        section.setDescription( getFilterDescription() );
+        toolkit.createCompositeSeparator( section );
+
+        // create client
+        Composite client = toolkit.createComposite( section, SWT.WRAP );
+        GridLayout layout = new GridLayout( 2, false );
+        layout.marginWidth = 5;
+        layout.marginHeight = 5;
+        client.setLayout( layout );
+        section.setClient( client );
+
+        // create filter field
+        toolkit.createLabel( client, "Filter:" );
+        this.filterText = toolkit.createText( client, "", SWT.NONE );
+        this.filterText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+        this.filterText.setData( FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER );
+        this.filterText.addModifyListener( new ModifyListener()
         {
-            IConnection[] connections = SelectionUtils.getConnections( selection );
-            if ( connections.length == 1 )
-                this.connectionSelected( connections[0] );
-            else
-                this.connectionSelected( null );
-        }
+            public void modifyText( ModifyEvent e )
+            {
+                viewer.refresh();
+            }
+        } );
+
+        // create table
+        Table t = toolkit.createTable( client, SWT.NONE );
+        GridData gd = new GridData( GridData.FILL_BOTH );
+        gd.horizontalSpan = 2;
+        gd.heightHint = 20;
+        gd.widthHint = 100;
+        t.setLayoutData( gd );
+        toolkit.paintBordersFor( client );
+
+        // setup viewer
+        viewer = new TableViewer( t );
+        viewer.setContentProvider( getContentProvider() );
+        viewer.setLabelProvider( getLabelProvider() );
+        viewer.setSorter( getSorter() );
+        viewer.addFilter( getFilter() );
     }
 
 
-    void connectionSelected( IConnection connection )
+    /**
+     * Creates the detail page.
+     *
+     * @param body the parent composite
+     */
+    private void createDetail( Composite body )
     {
-        this.selectedConnection = connection;
-        if ( this.toolkit != null && this.form != null && !this.form.isDisposed()
)
-        {
-            this.refresh();
-        }
+        detailsPage = getDetailsPage();
+        detailsPage.createContents( this.detailForm );
     }
 
 
-    public final void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
+    /**
+     * Selects the given object in the list. Causes also an input
+     * change of the details page.
+     *
+     * @param obj the object to select
+     */
+    public void select( Object obj )
     {
-        if ( this.toolkit != null && this.form != null && !this.form.isDisposed()
)
+        ISelection newSelection = new StructuredSelection( obj );
+        ISelection oldSelection = this.viewer.getSelection();
+
+        if ( !newSelection.equals( oldSelection ) )
         {
-            this.refresh();
+            inChange = true;
+            this.viewer.setSelection( newSelection, true );
+            if ( this.viewer.getSelection().isEmpty() )
+            {
+                this.filterText.setText( "" );
+                this.viewer.setSelection( newSelection, true );
+            }
+            inChange = false;
         }
     }
 
 
+    /**
+     * Disposed this page and the details page.
+     */
     public void dispose()
     {
-        if ( this.selectedConnection != null )
-        {
-            this.selectedConnection = null;
-        }
-        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removeSelectionListener(
this );
-        EventRegistry.removeConnectionUpdateListener( this );
-
         this.detailsPage.dispose();
 
         this.schemaBrowser = null;
         this.toolkit.dispose();
         this.toolkit = null;
-
     }
 
 
-    public Control createControl( Composite parent )
+    /**
+     * Creates this schema page and details page. 
+     *
+     * @param parent the parent composite
+     * @return the created composite.
+     */
+    Control createControl( Composite parent )
     {
-
         this.toolkit = new FormToolkit( parent.getDisplay() );
         this.form = this.toolkit.createForm( parent );
         this.form.getBody().setLayout( new FillLayout() );
@@ -149,7 +320,6 @@
         this.sashForm.setLayout( new FillLayout() );
 
         this.masterForm = this.toolkit.createScrolledForm( this.sashForm );
-        // this.detailForm = this.toolkit.createScrolledForm(this.sashForm);
         this.detailForm = new ScrolledForm( this.sashForm, SWT.V_SCROLL | this.toolkit.getOrientation()
);
         this.detailForm.setExpandHorizontal( true );
         this.detailForm.setExpandVertical( true );
@@ -164,60 +334,102 @@
 
         this.detailForm.getBody().setLayout( new FillLayout() );
         this.createDetail( this.detailForm.getBody() );
+        viewer.addSelectionChangedListener( new ISelectionChangedListener()
+        {
+            public void selectionChanged( SelectionChangedEvent event )
+            {
+                ISelection selection = event.getSelection();
+                if ( selection.isEmpty() )
+                {
+                    detailsPage.setInput( null );
+                }
+                else
+                {
+                    Object obj = ( ( StructuredSelection ) selection ).getFirstElement();
+                    detailsPage.setInput( obj );
+
+                    // Do not set the input of the schema browser if 
+                    // the selection was changed programatically.
+                    if ( !inChange && obj instanceof SchemaPart )
+                    {
+                        schemaBrowser.setInput( new SchemaBrowserInput( getConnection(),
( SchemaPart ) obj ) );
+                    }
+                }
+            }
+        } );
 
-        this.form.getToolBarManager().add( schemaBrowser.getShowDefaultSchemaAction() );
+        connectionCombo = new ConnectionComboContributionItem( this );
+        this.form.getToolBarManager().add( connectionCombo );
         this.form.getToolBarManager().add( new Separator() );
-        this.form.getToolBarManager().add( schemaBrowser.getReloadSchemaAction() );
+        showDefaultSchemaAction = new ShowDefaultSchemaAction( schemaBrowser );
+        this.form.getToolBarManager().add( showDefaultSchemaAction );
         this.form.getToolBarManager().add( new Separator() );
-        this.form.getToolBarManager().add( schemaBrowser.getBackAction() );
-        this.form.getToolBarManager().add( schemaBrowser.getForwardAction() );
+        reloadSchemaAction = new ReloadSchemaAction( this );
+        this.form.getToolBarManager().add( reloadSchemaAction );
         this.form.updateToolBar();
 
-        if ( schemaBrowser.getEditorSite().getPage().getSelection() != null
-            && !schemaBrowser.getEditorSite().getPage().getSelection().isEmpty()
-            && schemaBrowser.getEditorSite().getPage().getSelection() instanceof
IStructuredSelection )
-        {
-
-            IConnection[] connections = SelectionUtils.getConnections( ( IStructuredSelection
) schemaBrowser
-                .getEditorSite().getPage().getSelection() );
-            IEntry[] entries = SelectionUtils.getEntries( ( IStructuredSelection ) schemaBrowser.getEditorSite()
-                .getPage().getSelection() );
-            IAttribute[] attributes = SelectionUtils.getAttributes( ( IStructuredSelection
) schemaBrowser
-                .getEditorSite().getPage().getSelection() );
-            IValue[] values = SelectionUtils.getValues( ( IStructuredSelection ) schemaBrowser.getEditorSite()
-                .getPage().getSelection() );
-            if ( connections != null && connections.length == 1 )
-            {
-                this.selectedConnection = connections[0];
-            }
-            else if ( entries != null && entries.length == 1 )
-            {
-                this.selectedConnection = entries[0].getConnection();
-            }
-            else if ( attributes != null && attributes.length == 1 )
-            {
-                this.selectedConnection = attributes[0].getEntry().getConnection();
-            }
-            else if ( values != null && values.length == 1 )
-            {
-                this.selectedConnection = values[0].getAttribute().getEntry().getConnection();
-            }
-
-            // Object obj =
-            // ((IStructuredSelection)schemaBrowser.getEditorSite().getPage().getSelection()).getFirstElement();
-            // if (obj instanceof IConnection) {
-            // this.selectedConnection = (IConnection) obj;
-            // }
-        }
         this.refresh();
 
         return this.form;
     }
 
 
-    public IConnection getSelectedConnection()
+    /**
+     * Gets the schema browser.
+     * 
+     * @return the schema browser
+     */
+    public SchemaBrowser getSchemaBrowser()
     {
-        return selectedConnection;
+        return schemaBrowser;
     }
 
+
+    /**
+     * Gets the connection.
+     * 
+     * @return the connection
+     */
+    public IConnection getConnection()
+    {
+        return connectionCombo.getConnection();
+    }
+
+
+    /**
+     * Sets the connection.
+     * 
+     * @param connection the connection
+     */
+    public void setConnection( IConnection connection )
+    {
+        connectionCombo.setConnection( connection );
+        reloadSchemaAction.updateEnabledState();
+        refresh();
+    }
+
+
+    /**
+     * Checks if is show default schema.
+     * 
+     * @return true, if is show default schema
+     */
+    public boolean isShowDefaultSchema()
+    {
+        return showDefaultSchemaAction.isChecked();
+    }
+
+
+    /**
+     * Sets the show default schema flag.
+     * 
+     * @param b the show default schema flag
+     */
+    public void setShowDefaultSchema( boolean b )
+    {
+        showDefaultSchemaAction.setChecked( b );
+        connectionCombo.updateEnabledState();
+        reloadSchemaAction.updateEnabledState();
+        refresh();
+    }
 }

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/ShowDefaultSchemaAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/ShowDefaultSchemaAction.java?view=diff&rev=506058&r1=506057&r2=506058
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/ShowDefaultSchemaAction.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/editors/schemabrowser/ShowDefaultSchemaAction.java
Sun Feb 11 08:01:38 2007
@@ -26,13 +26,24 @@
 import org.eclipse.jface.action.Action;
 
 
+/**
+ * This action toggles between connection specific schemas and the default schema.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class ShowDefaultSchemaAction extends Action
 {
-
+    /** The schema browser */
     private SchemaBrowser schemaBrowser;
 
 
-    public ShowDefaultSchemaAction( SchemaBrowser schemaBrowserView )
+    /**
+     * Creates a new instance of ShowDefaultSchemaAction.
+     *
+     * @param schemaBrowser the schema browser
+     */
+    public ShowDefaultSchemaAction( SchemaBrowser schemaBrowser )
     {
         super( "Show Default Schema", Action.AS_CHECK_BOX );
         super.setToolTipText( "Show Default Schema" );
@@ -40,16 +51,22 @@
             BrowserUIConstants.IMG_DEFAULT_SCHEMA ) );
         super.setEnabled( true );
 
-        this.schemaBrowser = schemaBrowserView;
+        this.schemaBrowser = schemaBrowser;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void run()
     {
-        this.schemaBrowser.refresh();
+        this.schemaBrowser.setShowDefaultSchema( isChecked() );
     }
 
 
+    /**
+     * Disposes this action.
+     */
     public void dispose()
     {
         this.schemaBrowser = null;



Mime
View raw message