directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r639670 - in /directory/studio/trunk/ldapbrowser-ui: resources/icons/ src/main/java/org/apache/directory/studio/ldapbrowser/ui/ src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ src/main/java/org/apache/directory/studio/ldap...
Date Fri, 21 Mar 2008 15:34:44 GMT
Author: pamarcelot
Date: Fri Mar 21 08:34:38 2008
New Revision: 639670

URL: http://svn.apache.org/viewvc?rev=639670&view=rev
Log:
Part of a fix for DIRSTUDIO-46 (Add connections import/export).

Added:
    directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections.gif   (with props)
    directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections_wizard.gif  
(with props)
    directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections.gif   (with props)
    directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections_wizard.gif  
(with props)
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ExportConnectionsAction.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ImportConnectionsAction.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizard.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizardPage.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizard.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizardPage.java
Modified:
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/BrowserUIConstants.java
    directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionViewActionGroup.java

Added: directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections.gif?rev=639670&view=auto
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections_wizard.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections_wizard.gif?rev=639670&view=auto
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/ldapbrowser-ui/resources/icons/export_connections_wizard.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections.gif?rev=639670&view=auto
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections_wizard.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections_wizard.gif?rev=639670&view=auto
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/ldapbrowser-ui/resources/icons/import_connections_wizard.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/BrowserUIConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/BrowserUIConstants.java?rev=639670&r1=639669&r2=639670&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/BrowserUIConstants.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/BrowserUIConstants.java
Fri Mar 21 08:34:38 2008
@@ -71,6 +71,10 @@
 
     public static final String IMG_EXPORT_LDIF_WIZARD = "resources/icons/export_ldif_wizard.gif";
 
+    public static final String IMG_IMPORT_CONNECTIONS_WIZARD = "resources/icons/import_connections_wizard.gif";
+    
+    public static final String IMG_EXPORT_CONNECTIONS_WIZARD = "resources/icons/export_connections_wizard.gif";
+    
     public static final String IMG_IMPORT_CSV_WIZARD = "resources/icons/import_csv_wizard.gif";
 
     public static final String IMG_EXPORT_CSV_WIZARD = "resources/icons/export_csv_wizard.gif";
@@ -87,6 +91,10 @@
 
     public static final String IMG_EXPORT_LDIF = "resources/icons/export_ldif.gif";
 
+    public static final String IMG_IMPORT_CONNECTIONS = "resources/icons/import_connections.gif";
+
+    public static final String IMG_EXPORT_CONNECTIONS = "resources/icons/export_connections.gif";
+    
     public static final String IMG_IMPORT_CSV = "resources/icons/import_csv.gif";
 
     public static final String IMG_EXPORT_CSV = "resources/icons/export_csv.gif";

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ExportConnectionsAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ExportConnectionsAction.java?rev=639670&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ExportConnectionsAction.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ExportConnectionsAction.java
Fri Mar 21 08:34:38 2008
@@ -0,0 +1,108 @@
+/*
+ *  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.ldapbrowser.ui.actions;
+
+
+import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.ExportConnectionsWizard;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.NewBookmarkWizard;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
+import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.apache.directory.studio.connection.ui.dialogs.ConnectionFolderDialog;
+import org.apache.directory.studio.connection.ui.dialogs.CredentialsDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This Action launches the Export Connections Wizard.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportConnectionsAction extends BrowserAction
+{
+    /**
+     * Creates a new instance of NewConnectionFolderAction.
+     */
+    public ExportConnectionsAction()
+    {
+        super();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        ExportConnectionsWizard wizard = new ExportConnectionsWizard();
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        wizard.init( window.getWorkbench(), ( IStructuredSelection ) window.getSelectionService().getSelection()
);
+        WizardDialog dialog = new WizardDialog( getShell(), wizard );
+        dialog.setBlockOnOpen( true );
+        dialog.create();
+        dialog.open();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getText()
+    {
+        return "Export Connections...";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ImageDescriptor getImageDescriptor()
+    {
+        return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_EXPORT_CONNECTIONS
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getCommandId()
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled()
+    {
+        return true;
+    }
+}

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ImportConnectionsAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ImportConnectionsAction.java?rev=639670&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ImportConnectionsAction.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/ImportConnectionsAction.java
Fri Mar 21 08:34:38 2008
@@ -0,0 +1,101 @@
+/*
+ *  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.ldapbrowser.ui.actions;
+
+
+import org.apache.directory.studio.ldapbrowser.common.actions.BrowserAction;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.apache.directory.studio.ldapbrowser.ui.wizards.ImportConnectionsWizard;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This Action launches the Import Connections Wizard.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportConnectionsAction extends BrowserAction
+{
+    /**
+     * Creates a new instance of NewConnectionFolderAction.
+     */
+    public ImportConnectionsAction()
+    {
+        super();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run()
+    {
+        ImportConnectionsWizard wizard = new ImportConnectionsWizard();
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        wizard.init( window.getWorkbench(), ( IStructuredSelection ) window.getSelectionService().getSelection()
);
+        WizardDialog dialog = new WizardDialog( getShell(), wizard );
+        dialog.setBlockOnOpen( true );
+        dialog.create();
+        dialog.open();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getText()
+    {
+        return "Import Connections...";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ImageDescriptor getImageDescriptor()
+    {
+        return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_IMPORT_CONNECTIONS
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getCommandId()
+    {
+        return null;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled()
+    {
+        return true;
+    }
+}

Modified: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionViewActionGroup.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionViewActionGroup.java?rev=639670&r1=639669&r2=639670&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionViewActionGroup.java
(original)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionViewActionGroup.java
Fri Mar 21 08:34:38 2008
@@ -23,6 +23,8 @@
 
 import org.apache.directory.studio.connection.ui.actions.ConnectionViewActionProxy;
 import org.apache.directory.studio.connection.ui.widgets.ConnectionActionGroup;
+import org.apache.directory.studio.ldapbrowser.ui.actions.ExportConnectionsAction;
+import org.apache.directory.studio.ldapbrowser.ui.actions.ImportConnectionsAction;
 import org.apache.directory.studio.ldapbrowser.ui.actions.ImportExportAction;
 import org.apache.directory.studio.ldapbrowser.ui.actions.OpenSchemaBrowserAction;
 import org.eclipse.jface.action.IAction;
@@ -66,6 +68,12 @@
     /** The Constant exportExcelAction. */
     private static final String exportExcelAction = "exportExcelAction";
 
+    /** The Constant importConnectionsAction. */
+    private static final String importConnectionsAction = "importConnectionsAction";
+
+    /** The Constant importConnectionsAction. */
+    private static final String exportConnectionsAction = "exportConnectionsAction";
+
     /** The Constant openSchemaBrowserAction. */
     private static final String openSchemaBrowserAction = "openSchemaBrowserAction";
 
@@ -95,6 +103,10 @@
             ImportExportAction.TYPE_EXPORT_CSV ) ) );
         connectionActionMap.put( exportExcelAction, new ConnectionViewActionProxy( viewer,
this,
             new ImportExportAction( ImportExportAction.TYPE_EXPORT_EXCEL ) ) );
+        connectionActionMap.put( importConnectionsAction, new ConnectionViewActionProxy(
viewer, this,
+            new ImportConnectionsAction() ) );
+        connectionActionMap.put( exportConnectionsAction, new ConnectionViewActionProxy(
viewer, this,
+            new ExportConnectionsAction() ) );
 
         connectionActionMap.put( openSchemaBrowserAction, new ConnectionViewActionProxy(
viewer, this,
             new OpenSchemaBrowserAction() ) );
@@ -153,6 +165,8 @@
         importMenuManager.add( ( IAction ) connectionActionMap.get( importLdifAction ) );
         importMenuManager.add( ( IAction ) connectionActionMap.get( importDsmlAction ) );
         importMenuManager.add( new Separator() );
+        importMenuManager.add( ( IAction ) connectionActionMap.get( importConnectionsAction
) );
+        importMenuManager.add( new Separator() );
         menuManager.add( importMenuManager );
         MenuManager exportMenuManager = new MenuManager( "Export" );
         exportMenuManager.add( ( IAction ) connectionActionMap.get( exportLdifAction ) );
@@ -160,6 +174,9 @@
         exportMenuManager.add( new Separator() );
         exportMenuManager.add( ( IAction ) connectionActionMap.get( exportCsvAction ) );
         exportMenuManager.add( ( IAction ) connectionActionMap.get( exportExcelAction ) );
+        exportMenuManager.add( new Separator() );
+        exportMenuManager.add( ( IAction ) connectionActionMap.get( exportConnectionsAction
) );
+        exportMenuManager.add( new Separator() );
         menuManager.add( exportMenuManager );
         menuManager.add( new Separator() );
 

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizard.java?rev=639670&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizard.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizard.java
Fri Mar 21 08:34:38 2008
@@ -0,0 +1,163 @@
+/*
+ *  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.ldapbrowser.ui.wizards;
+
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.core.io.ConnectionIO;
+import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * This class implements the Wizard for Exporting connections.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportConnectionsWizard extends ExportBaseWizard
+{
+    /** The wizard page */
+    private ExportConnectionsWizardPage page;
+
+
+    /**
+     * Creates a new instance of ExportConnectionsWizard.
+     */
+    public ExportConnectionsWizard()
+    {
+        super( "Connections Export" );
+    }
+
+
+    /**
+     * Gets the ID of the Export Connections Wizard
+     * 
+     * @return The ID of the Export Connections Wizard
+     */
+    public static String getId()
+    {
+        return ExportConnectionsWizard.class.getName();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addPages()
+    {
+        page = new ExportConnectionsWizardPage();
+        addPage( page );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createPageControls( Composite pageContainer )
+    {
+        super.createPageControls( pageContainer );
+
+        // set help context ID
+        //        PlatformUI.getWorkbench().getHelpSystem().setHelp( fromPage.getControl(),
+        //            BrowserUIPlugin.PLUGIN_ID + "." + "tools_ldifexport_wizard" );
+        //TODO: Add Help Context
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean performFinish()
+    {
+        page.saveDialogSettings();
+
+        String exportFileName = page.getExportFileName();
+
+        try
+        {
+            // Creating the ZipOutputStream
+            ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( new File( exportFileName
) ) );
+            // Writing the Connections file.
+            zos.putNextEntry( new ZipEntry( "connections.xml" ) );
+            Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
+            Set<ConnectionParameter> connectionParameters = new HashSet<ConnectionParameter>();
+            for ( Connection connection : connections )
+            {
+                connectionParameters.add( connection.getConnectionParameter() );
+            }
+            ConnectionIO.save( connectionParameters, zos );
+            zos.closeEntry();
+            // Writing the Connection Folders file.
+            zos.putNextEntry( new ZipEntry( "connectionFolders.xml" ) );
+            ConnectionFolder[] connectionFolders = ConnectionCorePlugin.getDefault().getConnectionFolderManager()
+                .getConnectionFolders();
+            Set<ConnectionFolder> connectionFoldersSet = new HashSet<ConnectionFolder>();
+            for ( ConnectionFolder connectionFolder : connectionFolders )
+            {
+                connectionFoldersSet.add( connectionFolder );
+            }
+            ConnectionIO.saveConnectionFolders( connectionFoldersSet, zos );
+            zos.closeEntry();
+            // Writing the Browser Connections file.
+            zos.putNextEntry( new ZipEntry( "browserconnections.xml" ) );
+            IBrowserConnection[] browserConnections = BrowserCorePlugin.getDefault().getConnectionManager()
+                .getBrowserConnections();
+            Map<String, IBrowserConnection> browserConnectionsMap = new HashMap<String,
IBrowserConnection>();
+            for ( IBrowserConnection browserConnection : browserConnections )
+            {
+                browserConnectionsMap.put( browserConnection.getConnection().getId(), browserConnection
);
+            }
+            BrowserConnectionIO.save( zos, browserConnectionsMap );
+            zos.closeEntry();
+            // Closing the ZipOutputStream
+            zos.close();
+        }
+        catch ( FileNotFoundException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( IOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return true;
+    }
+}

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizardPage.java?rev=639670&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizardPage.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ExportConnectionsWizardPage.java
Fri Mar 21 08:34:38 2008
@@ -0,0 +1,231 @@
+/*
+ *  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.ldapbrowser.ui.wizards;
+
+
+import java.io.File;
+
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.FileBrowserWidget;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyEvent;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyListener;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * This class implements the page used to select the connections to export.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportConnectionsWizardPage extends WizardPage
+{
+    // UI widgets
+//    private CheckboxTreeViewer connectionsTreeViewer;
+//    private ConnectionContentProvider contentProvider;
+    private FileBrowserWidget fileBrowserWidget;
+    private Button overwriteFileButton;
+
+
+    /**
+     * Creates a new instance of ExportConnectionsWizardPage.
+     */
+    protected ExportConnectionsWizardPage()
+    {
+        super( ExportConnectionsWizardPage.class.getName() );
+        setTitle( "Export Connections" );
+        setDescription( "Define where connections should be exported." );
+        setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor(
+            BrowserUIConstants.IMG_EXPORT_CONNECTIONS_WIZARD ) );
+        setPageComplete( false );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        // Main Composite
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
+
+//        // Connections Group
+//        Group connectionsGroup = BaseWidgetUtils.createGroup( composite, "Connections",
1 );
+//        Composite connectionsGroupComposite = BaseWidgetUtils.createColumnContainer( connectionsGroup,
2, 1 );
+//
+//        // Connections Label
+//        BaseWidgetUtils.createLabel( connectionsGroupComposite, "Select the connections
to export: ", 1 );
+//        BaseWidgetUtils.createSpacer( connectionsGroupComposite, 1 );
+//
+//        // Connections TreeViewer
+//        connectionsTreeViewer = new CheckboxTreeViewer( new Tree( connectionsGroupComposite,
SWT.BORDER | SWT.CHECK
+//            | SWT.FULL_SELECTION ) );
+//        GridData connectionsTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true,
false, 1, 2 );
+//        connectionsTableViewerGridData.heightHint = 125;
+//        connectionsTreeViewer.getTree().setLayoutData( connectionsTableViewerGridData );
+//        contentProvider = new ConnectionContentProvider();
+//        connectionsTreeViewer.setContentProvider( contentProvider );
+//        connectionsTreeViewer.setLabelProvider( new ConnectionLabelProvider() );
+//        connectionsTreeViewer.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager()
);
+//        connectionsTreeViewer.addCheckStateListener( new ICheckStateListener()
+//        {
+//            public void checkStateChanged( CheckStateChangedEvent event )
+//            {
+//                Object checkedElement = event.getElement();
+//                Object[] children = contentProvider.getChildren( checkedElement );
+//                if ( ( children != null ) && ( children.length > 0 ) )
+//                {
+//                    for ( Object child : children )
+//                    {
+//                        connectionsTreeViewer.setChecked( child, event.getChecked() );
+//                    }
+//                }
+//            }
+//        } );
+//
+//        // Selection Buttons
+//        Button selectAllButton = BaseWidgetUtils.createButton( connectionsGroupComposite,
"Select All", 1 );
+//        selectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false
) );
+//        selectAllButton.addSelectionListener( new SelectionAdapter()
+//        {
+//            public void widgetSelected( SelectionEvent e )
+//            {
+//                connectionsTreeViewer.setAllChecked( true );
+//                validate();
+//            }
+//        } );
+//        Button deselectAllButton = BaseWidgetUtils.createButton( connectionsGroupComposite,
"Deselect All", 1 );
+//        deselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false,
false ) );
+//        deselectAllButton.addSelectionListener( new SelectionAdapter()
+//        {
+//            public void widgetSelected( SelectionEvent e )
+//            {
+//                connectionsTreeViewer.setAllChecked( false );
+//                validate();
+//            }
+//        } );
+
+        // Destination Group
+//        Group destinationGroup = BaseWidgetUtils.createGroup( composite, "Destination",
1 );
+//        Composite destinationGroupComposite = BaseWidgetUtils.createColumnContainer( destinationGroup,
3, 1 );
+
+        // Destination File
+        BaseWidgetUtils.createLabel( composite, "To file:", 1 );
+        fileBrowserWidget = new FileBrowserWidget( "Choose a file", new String[]
+            { "lbc" }, FileBrowserWidget.TYPE_SAVE );
+        fileBrowserWidget.createWidget( composite );
+        fileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener()
+        {
+            public void widgetModified( WidgetModifyEvent event )
+            {
+                validate();
+            }
+        } );
+
+        BaseWidgetUtils.createRadioIndent( composite, 1 );
+        overwriteFileButton = BaseWidgetUtils.createCheckbox( composite, "O&verwrite
existing file", 2 );
+        overwriteFileButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent event )
+            {
+                validate();
+            }
+        } );
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Validates this page. This method is responsible for displaying errors, 
+     * as well as enabling/disabling the "Finish" button
+     */
+    private void validate()
+    {
+        boolean ok = true;
+        File file = new File( fileBrowserWidget.getFilename() );
+        File fileDirectory = file.getParentFile();
+        if ( "".equals( fileBrowserWidget.getFilename() ) )
+        {
+            setErrorMessage( null );
+            ok = false;
+        }
+        else if ( file.isDirectory() )
+        {
+            setErrorMessage( "Selected file is not a file." );
+            ok = false;
+        }
+        else if ( file.exists() && !overwriteFileButton.getSelection() )
+        {
+            setErrorMessage( "Selected file already exists. Select option 'Overwrite existing
file' if you want to overwrite the file." );
+            ok = false;
+        }
+        else if ( file.exists() && !file.canWrite() )
+        {
+            setErrorMessage( "Selected file is not writeable." );
+            ok = false;
+        }
+        else if ( file.getParentFile() == null )
+        {
+            setErrorMessage( "Selected file directory is not writeable." );
+            ok = false;
+        }
+        else if ( !file.exists() && ( fileDirectory == null || !fileDirectory.canWrite()
) )
+        {
+            setErrorMessage( "Selected file directory is not writeable." );
+            ok = false;
+        }
+
+        if ( ok )
+        {
+            setErrorMessage( null );
+        }
+
+        setPageComplete( ok );
+    }
+
+
+    /**
+     * Gets the export file name.
+     * 
+     * @return
+     *      the export file name
+     */
+    public String getExportFileName()
+    {
+        return fileBrowserWidget.getFilename();
+    }
+
+
+    /**
+     * Saves the dialog settings.
+     */
+    public void saveDialogSettings()
+    {
+        fileBrowserWidget.saveDialogSettings();
+    }
+}

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizard.java?rev=639670&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizard.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizard.java
Fri Mar 21 08:34:38 2008
@@ -0,0 +1,215 @@
+/*
+ *  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.ldapbrowser.ui.wizards;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.ConnectionFolderManager;
+import org.apache.directory.studio.connection.core.ConnectionManager;
+import org.apache.directory.studio.connection.core.ConnectionParameter;
+import org.apache.directory.studio.connection.core.io.ConnectionIO;
+import org.apache.directory.studio.connection.core.io.ConnectionIOException;
+import org.apache.directory.studio.ldapbrowser.core.BrowserConnectionIO;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.BrowserConnection;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * This class implements the Wizard for Importing connections.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportConnectionsWizard extends ExportBaseWizard
+{
+    /** The wizard page */
+    private ImportConnectionsWizardPage page;
+
+
+    /**
+     * Creates a new instance of ImportConnectionsWizard.
+     */
+    public ImportConnectionsWizard()
+    {
+        super( "Connections Export" );
+    }
+
+
+    /**
+     * Gets the ID of the Import Connections Wizard
+     * 
+     * @return The ID of the Import Connections Wizard
+     */
+    public static String getId()
+    {
+        return ImportConnectionsWizard.class.getName();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addPages()
+    {
+        page = new ImportConnectionsWizardPage();
+        addPage( page );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createPageControls( Composite pageContainer )
+    {
+        super.createPageControls( pageContainer );
+
+        // set help context ID
+        //        PlatformUI.getWorkbench().getHelpSystem().setHelp( fromPage.getControl(),
+        //            BrowserUIPlugin.PLUGIN_ID + "." + "tools_ldifexport_wizard" );
+        //TODO: Add Help Context
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean performFinish()
+    {
+        page.saveDialogSettings();
+
+        String importFileName = page.getImportFileName();
+
+        try
+        {
+            ZipFile importFile = new ZipFile( new File( importFileName ) );
+
+            // Loading the Connections
+            ZipEntry connectionsEntry = importFile.getEntry( "connections.xml" );
+            if ( connectionsEntry != null )
+            {
+                InputStream connectionsInputStream = importFile.getInputStream( connectionsEntry
);
+                ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+                Set<ConnectionParameter> connectionParametersSet = ConnectionIO.load(
connectionsInputStream );
+                for ( ConnectionParameter connectionParameter : connectionParametersSet )
+                {
+                    connectionManager.addConnection( new Connection( connectionParameter
) );
+                }
+            }
+
+            // Loading the ConnectionFolders
+            ZipEntry connectionFoldersEntry = importFile.getEntry( "connectionFolders.xml"
);
+            ConnectionFolder rootConnectionFolder = null;
+            if ( connectionFoldersEntry != null )
+            {
+                InputStream connectionFoldersInputStream = importFile.getInputStream( connectionFoldersEntry
);
+                ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+                    .getConnectionFolderManager();
+                Set<ConnectionFolder> connectionFoldersSet = ConnectionIO
+                    .loadConnectionFolders( connectionFoldersInputStream );
+                for ( ConnectionFolder connectionFolder : connectionFoldersSet )
+                {
+                    if ( !"0".equals( connectionFolder.getId() ) )
+                    {
+                        connectionFolderManager.addConnectionFolder( connectionFolder );
+                    }
+                    else
+                    {
+                        rootConnectionFolder = connectionFolder;
+                    }
+                }
+
+                // Root ConnectionFolder must be the last one to be loaded 
+                if ( rootConnectionFolder != null )
+                {
+                    ConnectionFolder realRootConnectionFolder = connectionFolderManager.getRootConnectionFolder();
+                    // Adding subfolders
+                    List<String> realSubFolderIds = realRootConnectionFolder.getSubFolderIds();
+                    for ( String subFolderId : rootConnectionFolder.getSubFolderIds() )
+                    {
+                        if ( !realSubFolderIds.contains( subFolderId ) )
+                        {
+                            realRootConnectionFolder.addSubFolderId( subFolderId );
+                        }
+                    }
+
+                    // Adding connections 
+                    List<String> realConnectionIds = realRootConnectionFolder.getConnectionIds();
+                    for ( String connectionId : rootConnectionFolder.getConnectionIds() )
+                    {
+                        if ( !realConnectionIds.contains( connectionId ) )
+                        {
+                            realRootConnectionFolder.addConnectionId( connectionId );
+                        }
+                    }
+                }
+            }
+
+            // Loading the BrowserConnections
+            ZipEntry browserConnectionsEntry = importFile.getEntry( "browserconnections.xml"
);
+            if ( browserConnectionsEntry != null )
+            {
+                InputStream browserConnectionsInputStream = importFile.getInputStream( browserConnectionsEntry
);
+
+                Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
+                Map<String, IBrowserConnection> connectionsMap = new HashMap<String,
IBrowserConnection>();
+                for ( int i = 0; i < connections.length; i++ )
+                {
+                    Connection connection = connections[i];
+                    BrowserConnection browserConnection = new BrowserConnection( connection
);
+                    connectionsMap.put( connection.getId(), browserConnection );
+                }
+
+                BrowserConnectionIO.load( browserConnectionsInputStream, connectionsMap );
+            }
+        }
+        catch ( ZipException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( IOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( ConnectionIOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return true;
+    }
+}

Added: directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizardPage.java?rev=639670&view=auto
==============================================================================
--- directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizardPage.java
(added)
+++ directory/studio/trunk/ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/wizards/ImportConnectionsWizardPage.java
Fri Mar 21 08:34:38 2008
@@ -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.ldapbrowser.ui.wizards;
+
+
+import java.io.File;
+
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.FileBrowserWidget;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyEvent;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyListener;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIConstants;
+import org.apache.directory.studio.ldapbrowser.ui.BrowserUIPlugin;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * This class implements the page used to select the data to export to LDIF.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ImportConnectionsWizardPage extends WizardPage
+{
+    private FileBrowserWidget fileBrowserWidget;
+
+
+    protected ImportConnectionsWizardPage()
+    {
+        super( ImportConnectionsWizardPage.class.getName() );
+        setTitle( "Import Connections" );
+        setDescription( "Import connections from local file system." );
+        setImageDescriptor( BrowserUIPlugin.getDefault().getImageDescriptor(
+            BrowserUIConstants.IMG_IMPORT_CONNECTIONS_WIZARD ) );
+        setPageComplete( false );
+    }
+
+
+    public void createControl( Composite parent )
+    {
+        // Main Composite
+        Composite composite = BaseWidgetUtils.createColumnContainer( parent, 3, 1 );
+
+        // From File
+        BaseWidgetUtils.createLabel( composite, "From file:", 1 );
+        fileBrowserWidget = new FileBrowserWidget( "Choose a file", new String[]
+            { "lbc" }, FileBrowserWidget.TYPE_OPEN );
+        fileBrowserWidget.createWidget( composite );
+        fileBrowserWidget.addWidgetModifyListener( new WidgetModifyListener()
+        {
+            public void widgetModified( WidgetModifyEvent event )
+            {
+                validate();
+            }
+        } );
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Validates this page. This method is responsible for displaying errors, 
+     * as well as enabling/disabling the "Finish" button
+     */
+    private void validate()
+    {
+        boolean ok = true;
+        File file = new File( fileBrowserWidget.getFilename() );
+        if ( "".equals( fileBrowserWidget.getFilename() ) )
+        {
+            setErrorMessage( null );
+            ok = false;
+        }
+        else if ( !file.exists() )
+        {
+            setErrorMessage( "Selected file does not exist." );
+            ok = false;
+        }
+        else if ( file.isDirectory() )
+        {
+            setErrorMessage( "Selected file is not a file." );
+            ok = false;
+        }
+        else if ( file.exists() && !file.canRead() )
+        {
+            setErrorMessage( "Selected file is not readable." );
+            ok = false;
+        }
+
+        if ( ok )
+        {
+            setErrorMessage( null );
+        }
+
+        setPageComplete( ok );
+    }
+
+
+    /**
+     * Gets the export file name.
+     * 
+     * @return
+     *      the export file name
+     */
+    public String getImportFileName()
+    {
+        return fileBrowserWidget.getFilename();
+    }
+
+
+    /**
+     * Saves the dialog settings.
+     */
+    public void saveDialogSettings()
+    {
+        fileBrowserWidget.saveDialogSettings();
+    }
+}



Mime
View raw message