1. mirror
  2. Apache Directory Studio

Commits

Pierre-Arnaud Marcelot  committed 96fde51

Added an Action Helper class to help other plugins create a connection from an LDAP Server.

git-svn-id: https://svn.apache.org/repos/asf/directory/studio/trunk@98665513f79535-47bb-0310-9956-ffa450edef68

  • Participants
  • Parent commits e726215
  • Branches trunk

Comments (0)

Files changed (6)

File plugins/ldapservers/plugin.properties

View file
 
 Ctx_ServersView_id=org.apache.directory.studio.ldapservers.contexts.serversView
 Ctx_ServersView_name=In LDAP Servers View
-Ctx_ServersView_description=In LDAP Servers View
+Ctx_ServersView_description=In LDAP Servers View
+
+Perspective_LdapBrowserPerspective_id=org.apache.directory.studio.ldapbrowser.ui.perspective.BrowserPerspective

File plugins/ldapservers/pom.xml

View file
  org.apache.commons.io;bundle-version="${org.apache.commons.io.version}",
  org.apache.directory.studio.common.core,
  org.apache.directory.studio.common.ui,
+ org.apache.directory.studio.connection.core,
  org.apache.mina.core;bundle-version="${org.apache.mina.core.validversion}",
  org.dom4j.dom4j;bundle-version="${org.dom4j.version}",
  org.eclipse.core.resources,
       <artifactId>common.ui</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.directory.studio</groupId>
+      <artifactId>connection.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
     
 	<!-- Eclipse plugins dependencies -->
     <dependency>

File plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/CreateConnectionActionHelper.java

View file
+/*
+ *  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.ldapservers.actions;
+
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.ldapservers.LdapServersPlugin;
+import org.apache.directory.studio.ldapservers.model.LdapServer;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements a helper class of the create connection action for a server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CreateConnectionActionHelper
+{
+    public static void createLdapBrowserConnection( LdapServer server, Connection connection )
+    {
+        // Adding the connection to the connection manager
+        ConnectionCorePlugin.getDefault().getConnectionManager().addConnection( connection );
+
+        // Adding the connection to the root connection folder
+        ConnectionCorePlugin.getDefault().getConnectionFolderManager().getRootConnectionFolder()
+            .addConnectionId( connection.getId() );
+
+        // Getting the window, LDAP perspective and current perspective
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        IPerspectiveDescriptor ldapPerspective = getLdapPerspective();
+        IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
+
+        // Checking if we are already in the LDAP perspective
+        if ( ( ldapPerspective != null ) && ( ldapPerspective.equals( currentPerspective ) ) )
+        {
+            // As we're already in the LDAP perspective, we only indicate to the user 
+            // the name of the connection that has been created
+            MessageDialog dialog = new MessageDialog(
+                window.getShell(),
+                Messages.getString( "CreateConnectionActionHelper.ConnectionCreated" ), null, //$NON-NLS-1$
+                NLS.bind(
+                    Messages.getString( "CreateConnectionActionHelper.ConnectionCalledCreated" ), new String[] { connection.getName() } ), MessageDialog.INFORMATION, //$NON-NLS-1$
+                new String[]
+                    { IDialogConstants.OK_LABEL }, MessageDialog.OK );
+            dialog.open();
+        }
+        else
+        {
+            // We're not already in the LDAP perspective, we indicate to the user
+            // the name of the connection that has been created and we ask him
+            // if we wants to switch to the LDAP perspective
+            MessageDialog dialog = new MessageDialog(
+                window.getShell(),
+                Messages.getString( "CreateConnectionActionHelper.ConnectionCreated" ), null, //$NON-NLS-1$
+                NLS.bind(
+                    Messages.getString( "CreateConnectionActionHelper.ConnectionCalledCreatedSwitch" ), new String[] { connection.getName() } ), //$NON-NLS-1$
+                MessageDialog.INFORMATION, new String[]
+                    { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, MessageDialog.OK );
+            if ( dialog.open() == MessageDialog.OK )
+            {
+                // Switching to the LDAP perspective
+                window.getActivePage().setPerspective( ldapPerspective );
+            }
+        }
+    }
+
+
+    /**
+     * Get the LDAP perspective.
+     *
+     * @return
+     *      the LDAP perspective
+     */
+    private static IPerspectiveDescriptor getLdapPerspective()
+    {
+        for ( IPerspectiveDescriptor perspective : PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives() )
+        {
+            if ( LdapServersPlugin.getDefault().getPluginProperties()
+                .getString( "Perspective_LdapBrowserPerspective_id" ) //$NON-NLS-1$
+                .equalsIgnoreCase( perspective.getId() ) )
+            {
+                return perspective;
+            }
+        }
+
+        return null;
+    }
+}

File plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/messages.properties

View file
 #  specific language governing permissions and limitations
 #  under the License.
 
+CreateConnectionActionHelper.ConnectionCalledCreated=A connection called "{0}" has been created.
+CreateConnectionActionHelper.ConnectionCalledCreatedSwitch=A connection called "{0}" has been created.\n\nDo you want to switch to the LDAP perspective ?
+CreateConnectionActionHelper.ConnectionCreated=Connection created
+
 DeleteAction.Delete=&Delete
 DeleteAction.DeleteToolTip=Delete
 DeleteAction.ErrorWhileStopping=An error occurred when stopping the server.\n\n

File plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/messages_de.properties

View file
 #  specific language governing permissions and limitations
 #  under the License.
 
+CreateConnectionActionHelper.ConnectionCalledCreated=Eine Verbindung mit Namen "{0}" ist erstellt worden.
+CreateConnectionActionHelper.ConnectionCalledCreatedSwitch=Eine Verbindung mit Namen "{0}" ist erstellt worden.\n\nM\u00F6chten Sie zur LDAP Perspektive wechseln?
+CreateConnectionActionHelper.ConnectionCreated=Verbindung erstellt
+
 DeleteAction.Delete=&L\u00F6schen
 DeleteAction.DeleteToolTip=L\u00F6schen
 DeleteAction.ErrorWhileStopping=Beim Stoppen des Servers ist ein Fehler aufgetreten.\n\n

File plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/actions/messages_fr.properties

View file
 # ^P : Propri\u00E9t\u00E9s
 # ^R : Renommer
 # ^S : Supprimer
+
+CreateConnectionActionHelper.ConnectionCalledCreated=Une connexion nomm\u00E9e "{0}" a \u00E9t\u00E9 cr\u00E9\u00E9e.
+CreateConnectionActionHelper.ConnectionCalledCreatedSwitch=Une connexion nomm\u00E9e "{0}" a \u00E9t\u00E9 cr\u00E9\u00E9e.\n\nSouhaitez-vous basculer vers la perspective LDAP ?
+CreateConnectionActionHelper.ConnectionCreated=Connexion cr\u00E9\u00E9e
+
 DeleteAction.Delete=&Supprimer
 DeleteAction.DeleteToolTip=Supprimer
 DeleteAction.ErrorWhileStopping=Une erreur est survenue lors de l'arr\u00EAt du serveur.\n\n