You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/09/24 23:04:29 UTC
svn commit: r578966 [1/2] - in /directory/studio/trunk:
studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/
studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/
studio-connection-core/src...
Author: seelmann
Date: Mon Sep 24 14:04:06 2007
New Revision: 578966
URL: http://svn.apache.org/viewvc?rev=578966&view=rev
Log:
DIRSTUDIO-187: Initial code to organize connections in folders
Added:
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java (with props)
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java (with props)
directory/studio/trunk/studio-connection-ui/resources/icons/connection_folder.gif (with props)
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java (with props)
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java (with props)
Modified:
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/DeleteAction.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java
directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/proxy/BrowserActionProxy.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectBrowserConnectionDialog.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/SelectReferralConnectionDialog.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/browser/BrowserUniversalListener.java
directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/BrowserConnectionManager.java
directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/internal/model/BrowserConnection.java
directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/actions/OpenSchemaBrowserAction.java
directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/editors/schemabrowser/ConnectionComboContributionItem.java
directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionView.java
directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/ConnectionViewActionGroup.java
directory/studio/trunk/studio-ldapbrowser-ui/src/main/java/org/apache/directory/studio/ldapbrowser/ui/views/connection/DropConnectionListener.java
directory/studio/trunk/studio-ldifeditor/src/main/java/org/apache/directory/studio/ldifeditor/editor/LdifEditor.java
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/NewProjectWizardConnectionSelectionPage.java
Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java Mon Sep 24 14:04:06 2007
@@ -41,6 +41,9 @@
/** The connection manager */
private ConnectionManager connectionManager;
+ /** The connection folder manager */
+ private ConnectionFolderManager connectionFolderManager;
+
/** The event runner. */
private EventRunner eventRunner;
@@ -73,6 +76,11 @@
{
connectionManager = new ConnectionManager();
}
+
+ if ( connectionFolderManager == null )
+ {
+ connectionFolderManager = new ConnectionFolderManager();
+ }
}
@@ -98,6 +106,11 @@
}
connectionManager = null;
}
+
+ if ( connectionFolderManager != null )
+ {
+ connectionFolderManager = null;
+ }
}
@@ -121,6 +134,17 @@
public ConnectionManager getConnectionManager()
{
return connectionManager;
+ }
+
+
+ /**
+ * Gets the connection folder manager.
+ *
+ * @return the connection folder manager
+ */
+ public ConnectionFolderManager getConnectionFolderManager()
+ {
+ return connectionFolderManager;
}
Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java?rev=578966&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java Mon Sep 24 14:04:06 2007
@@ -0,0 +1,237 @@
+/*
+ * 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.connection.core;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+
+
+/**
+ * A ConnectionFolder helps to organize connections in folders.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionFolder
+{
+ private String id;
+
+ private String name;
+
+ private List<String> subFolderIds;
+
+ private List<String> connectionIds;
+
+
+ /**
+ * Creates a new instance of ConnectionFolder.
+ */
+ public ConnectionFolder()
+ {
+ this.subFolderIds = new ArrayList<String>();
+ this.connectionIds = new ArrayList<String>();
+ }
+
+
+ /**
+ * Creates a new instance of ConnectionFolder.
+ *
+ * @param name the folder name
+ */
+ public ConnectionFolder( String name )
+ {
+ this();
+ this.id = createId();
+ this.name = name;
+ }
+
+
+ /**
+ * Adds the connection id to the end of the connection list.
+ *
+ * @param connectionId the connection id
+ */
+ public void addConnectionId( String connectionId )
+ {
+ addConnectionId( connectionIds.size(), connectionId );
+ }
+
+
+ /**
+ * Adds the connection id at the specified position of the connection list.
+ *
+ * @param index the index
+ * @param connectionId the connection id
+ */
+ public void addConnectionId( int index, String connectionId )
+ {
+ connectionIds.add( index, connectionId );
+ ConnectionEventRegistry.fireConnectonFolderModified( this, this );
+ }
+
+
+ /**
+ * Adds the folder id to the end of the sub-folder list.
+ *
+ * @param folderId the folder id
+ */
+ public void addSubFolderId( String folderId )
+ {
+ addSubFolderId( subFolderIds.size(), folderId );
+ }
+
+
+ /**
+ * Adds the folder id to the end of the sub-folder list.
+ *
+ * @param index the index
+ * @param folderId the folder id
+ */
+ public void addSubFolderId( int index, String folderId )
+ {
+ subFolderIds.add( index, folderId );
+ ConnectionEventRegistry.fireConnectonFolderModified( this, this );
+ }
+
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public String getId()
+ {
+ return id;
+ }
+
+
+ /**
+ * Sets the id.
+ *
+ * @param id the new id
+ */
+ public void setId( String id )
+ {
+ this.id = id;
+ }
+
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+
+ /**
+ * Sets the name.
+ *
+ * @param name the new name
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ ConnectionEventRegistry.fireConnectonFolderModified( this, this );
+ }
+
+
+ /**
+ * Gets the sub-folder ids.
+ *
+ * @return the sub-folder ids
+ */
+ public List<String> getSubFolderIds()
+ {
+ List<String> ids = new ArrayList<String>();
+ for ( String id : subFolderIds )
+ {
+ if ( ConnectionCorePlugin.getDefault().getConnectionFolderManager().getConnectionFolderById( id ) != null )
+ {
+ ids.add( id );
+ }
+ }
+ return ids;
+ }
+
+
+ /**
+ * Sets the sub-folder ids.
+ *
+ * @param subFolderIds the new sub-folder ids
+ */
+ public void setSubFolderIds( List<String> subFolderIds )
+ {
+ this.subFolderIds = subFolderIds;
+ ConnectionEventRegistry.fireConnectonFolderModified( this, this );
+ }
+
+
+ /**
+ * Gets the connection ids.
+ *
+ * @return the connection ids
+ */
+ public List<String> getConnectionIds()
+ {
+ List<String> ids = new ArrayList<String>();
+ for ( String id : connectionIds )
+ {
+ if ( ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionById( id ) != null )
+ {
+ ids.add( id );
+ }
+ }
+ return ids;
+ }
+
+
+ /**
+ * Sets the connection ids.
+ *
+ * @param connectionIds the new connection ids
+ */
+ public void setConnectionIds( List<String> connectionIds )
+ {
+ this.connectionIds = connectionIds;
+ ConnectionEventRegistry.fireConnectonFolderModified( this, this );
+ }
+
+
+ /**
+ * Creates a unique id.
+ *
+ * @return the created id
+ */
+ private String createId()
+ {
+ long id = new Random( System.currentTimeMillis() ).nextLong();
+ return Long.valueOf( id ).toString();
+ }
+
+}
Propchange: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java?rev=578966&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java (added)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java Mon Sep 24 14:04:06 2007
@@ -0,0 +1,323 @@
+/*
+ * 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.connection.core;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
+import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
+import org.apache.directory.studio.connection.core.io.ConnectionIO;
+import org.apache.directory.studio.connection.core.io.ConnectionIOException;
+
+
+/**
+ * This class is used to manage {@link ConnectionFolder}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionFolderManager implements ConnectionUpdateListener
+{
+
+ /** The root connection folder. */
+ private ConnectionFolder root;
+
+ /** The list of folders. */
+ private List<ConnectionFolder> folderList;
+
+
+ /**
+ * Creates a new instance of ConnectionFolderManager.
+ */
+ public ConnectionFolderManager()
+ {
+ this.root = new ConnectionFolder( "" );
+ this.root.setId( "0" ); //$NON-NLS-1$s
+ this.folderList = new ArrayList<ConnectionFolder>();
+
+ loadConnectionFolders();
+ ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionCorePlugin.getDefault().getEventRunner() );
+
+ this.folderList.add( this.root );
+ }
+
+
+ /**
+ * Gets the filename of the connection folder store.
+ *
+ * @return
+ * the filename of the connection folder store
+ */
+ public static final String getConnectionFolderStoreFileName()
+ {
+ String filename = ConnectionCorePlugin.getDefault().getStateLocation()
+ .append( "connectionFolders.xml" ).toOSString(); //$NON-NLS-1$
+ return filename;
+ }
+
+
+ /**
+ * Adds the ConnectionFolder to the connection folder list. If there is already a
+ * connection folder with the same name the new connection folder is renamed.
+ *
+ * @param connectionFolder the connection folder
+ */
+ public void addConnectionFolder( ConnectionFolder connectionFolder )
+ {
+ if ( getConnectionFolderByName( connectionFolder.getName() ) != null )
+ {
+ String newConnectionFolderName = Messages.bind( Messages.copy_n_of_s, "", connectionFolder.getName() ); //$NON-NLS-1$
+ for ( int i = 2; getConnectionFolderByName( newConnectionFolderName ) != null; i++ )
+ {
+ newConnectionFolderName = Messages.bind( Messages.copy_n_of_s, i + " ", connectionFolder.getName() ); //$NON-NLS-1$
+ }
+ connectionFolder.setName( newConnectionFolderName );
+ }
+
+ folderList.add( connectionFolder );
+ ConnectionEventRegistry.fireConnectonFolderModified( connectionFolder, this );
+ }
+
+
+ /**
+ * Removes the given ConnectionFolder from the connection folder list.
+ *
+ * @param connectionFolder
+ * the connection folder to remove
+ */
+ public void removeConnectionFolder( ConnectionFolder connectionFolder )
+ {
+ folderList.remove( connectionFolder );
+ ConnectionEventRegistry.fireConnectonFolderModified( connectionFolder, this );
+ }
+
+
+ /**
+ * Gets a connection folder from its id.
+ *
+ * @param id
+ * the id of the connection folder
+ * @return
+ * the corresponding connection folder
+ */
+ public ConnectionFolder getConnectionFolderById( String id )
+ {
+ for ( ConnectionFolder folder : folderList )
+ {
+ if ( folder.getId().equals( id ) )
+ {
+ return folder;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Gets a connection folder from its name.
+ *
+ * @param name
+ * the name of the connection folder
+ * @return
+ * the corresponding connection folder
+ */
+ public ConnectionFolder getConnectionFolderByName( String name )
+ {
+ for ( ConnectionFolder folder : folderList )
+ {
+ if ( folder.getName().equals( name ) )
+ {
+ return folder;
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * Gets the root connection folder.
+ *
+ * @return the root connection folder
+ */
+ public ConnectionFolder getRootConnectionFolder()
+ {
+ return root;
+ }
+
+
+ /**
+ * Sets the root connection folder.
+ *
+ * @param root the new root connection folder
+ */
+ public void setRootConnectionFolder( ConnectionFolder root )
+ {
+ this.root = root;
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionAdded( Connection connection )
+ {
+ saveConnectionFolders();
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionRemoved( Connection connection )
+ {
+ saveConnectionFolders();
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionUpdated( Connection connection )
+ {
+ saveConnectionFolders();
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionOpened( Connection connection )
+ {
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionClosed( Connection connection )
+ {
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
+ */
+ public void connectionFolderModified( ConnectionFolder connectionFolder )
+ {
+ saveConnectionFolders();
+ }
+
+
+ /**
+ * Saves the Connection Folders
+ */
+ private synchronized void saveConnectionFolders()
+ {
+ // To avoid a corrupt file, save object to a temp file first
+ try
+ {
+ ConnectionIO.saveConnectionFolders( folderList, new FileOutputStream( getConnectionFolderStoreFileName()
+ + "-temp" ) );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // move temp file to good file
+ File file = new File( getConnectionFolderStoreFileName() );
+ File tempFile = new File( getConnectionFolderStoreFileName() + "-temp" );
+ if ( file.exists() )
+ {
+ file.delete();
+ }
+
+ try
+ {
+ String content = FileUtils.readFileToString( tempFile, "UTF-8" );
+ FileUtils.writeStringToFile( file, content, "UTF-8" );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * Loads the Connection Folders
+ */
+ private synchronized void loadConnectionFolders()
+ {
+ try
+ {
+ folderList = ConnectionIO.loadConnectionFolders( new FileInputStream( getConnectionFolderStoreFileName() ) );
+ }
+ catch ( Exception e )
+ {
+ // If loading failed, try with temp file
+ try
+ {
+ folderList = ConnectionIO.loadConnectionFolders( new FileInputStream(
+ getConnectionFolderStoreFileName() + "-temp" ) );
+ }
+ catch ( FileNotFoundException e1 )
+ {
+ // TODO Auto-generated catch block
+ }
+ catch ( ConnectionIOException e1 )
+ {
+ // TODO Auto-generated catch block
+ }
+ }
+
+ if ( !folderList.isEmpty() )
+ {
+ for ( ConnectionFolder folder : folderList )
+ {
+ if ( "0".equals( folder.getId() ) )
+ {
+ root = folder;
+ }
+ }
+ }
+ else
+ {
+ Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections();
+ for ( Connection connection : connections )
+ {
+ root.addConnectionId( connection.getId() );
+ }
+ }
+
+ }
+
+}
Propchange: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionFolderManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionManager.java Mon Sep 24 14:04:06 2007
@@ -249,6 +249,14 @@
/**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
+ */
+ public void connectionFolderModified( ConnectionFolder connectionFolder )
+ {
+ }
+
+
+ /**
* Saves the Connections
*/
private synchronized void saveConnections()
Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionEventRegistry.java Mon Sep 24 14:04:06 2007
@@ -28,6 +28,7 @@
import java.util.Set;
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
/**
@@ -287,6 +288,43 @@
}
};
+ EventRunner runner = listeners.get( listener );
+ synchronized ( lock )
+ {
+ runner.execute( runnable );
+ }
+ }
+ }
+
+
+ /**
+ * Notifies each {@link ConnectionUpdateListener} about the modified connection folder.
+ * Uses the {@link EventRunner}s.
+ *
+ * @param connectionFolder the modified connection folder
+ * @param source the source
+ */
+ public static void fireConnectonFolderModified( final ConnectionFolder connectionFolder, final Object source )
+ {
+ if ( isEventFireingSuspendedInCurrentThread() )
+ {
+ return;
+ }
+
+ Map<ConnectionUpdateListener, EventRunner> listeners = new HashMap<ConnectionUpdateListener, EventRunner>(
+ connectionUpdateListeners );
+ Iterator<ConnectionUpdateListener> it = listeners.keySet().iterator();
+ while ( it.hasNext() )
+ {
+ final ConnectionUpdateListener listener = it.next();
+ EventRunnable runnable = new EventRunnable()
+ {
+ public void run()
+ {
+ listener.connectionFolderModified( connectionFolder );
+ }
+ };
+
EventRunner runner = listeners.get( listener );
synchronized ( lock )
{
Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/event/ConnectionUpdateListener.java Mon Sep 24 14:04:06 2007
@@ -24,6 +24,7 @@
import java.util.EventListener;
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
/**
@@ -73,5 +74,13 @@
* @param connection the updated connection
*/
public void connectionUpdated( Connection connection );
+
+
+ /**
+ * Called when {@link ConnectionFolder}s were modified.
+ *
+ * @param connectionFolder the modified connection folder
+ */
+ public void connectionFolderModified( ConnectionFolder connectionFolder );
}
Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionIO.java Mon Sep 24 14:04:06 2007
@@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.apache.directory.studio.connection.core.ConnectionParameter;
import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
@@ -66,6 +67,10 @@
private static final String KEY_TAG = "key";
private static final String VALUE_TAG = "value";
+ private static final String CONNECTION_FOLDERS_TAG = "connectionFolders";
+ private static final String CONNECTION_FOLDER_TAG = "connectionFolder";
+ private static final String SUB_FOLDERS_TAG = "subFolders";
+ private static final String SUB_FOLDER_TAG = "subFolder";
/**
* Loads the connections using the reader
@@ -313,4 +318,184 @@
}
}
}
+
+
+ /**
+ * Loads the connection folders using the reader
+ *
+ * @param stream
+ * the FileInputStream
+ * @return
+ * the connection folders
+ * @throws ConnectionIOException
+ * if an error occurs when converting the document
+ */
+ public static List<ConnectionFolder> loadConnectionFolders( FileInputStream stream ) throws ConnectionIOException
+ {
+ List<ConnectionFolder> connectionFolders = new ArrayList<ConnectionFolder>();
+
+ SAXReader saxReader = new SAXReader();
+ Document document = null;
+
+ try
+ {
+ document = saxReader.read( stream );
+ }
+ catch ( DocumentException e )
+ {
+ throw new ConnectionIOException( e.getMessage() );
+ }
+
+ Element rootElement = document.getRootElement();
+ if ( !rootElement.getName().equals( CONNECTION_FOLDERS_TAG ) )
+ {
+ throw new ConnectionIOException( "The file does not seem to be a valid ConnectionFolders file." );
+ }
+
+ for ( Iterator<?> i = rootElement.elementIterator( CONNECTION_FOLDER_TAG ); i.hasNext(); )
+ {
+ Element connectionFolderElement = ( Element ) i.next();
+ connectionFolders.add( readConnectionFolder( connectionFolderElement ) );
+ }
+
+ return connectionFolders;
+ }
+
+
+ /**
+ * Reads a connection folder from the given Element.
+ *
+ * @param element
+ * the element
+ * @return
+ * the corresponding connection folder
+ * @throws ConnectionIOException
+ * if an error occurs when converting values
+ */
+ private static ConnectionFolder readConnectionFolder( Element element ) throws ConnectionIOException
+ {
+ ConnectionFolder connectionFolder = new ConnectionFolder();
+
+ // ID
+ Attribute idAttribute = element.attribute( ID_TAG );
+ if ( idAttribute != null )
+ {
+ connectionFolder.setId( idAttribute.getValue() );
+ }
+
+ // Name
+ Attribute nameAttribute = element.attribute( NAME_TAG );
+ if ( nameAttribute != null )
+ {
+ connectionFolder.setName( nameAttribute.getValue() );
+ }
+
+ // Connections
+ Element connectionsElement = element.element( CONNECTIONS_TAG );
+ if ( connectionsElement != null )
+ {
+ for ( Iterator<?> i = connectionsElement.elementIterator( CONNECTION_TAG ); i.hasNext(); )
+ {
+ Element connectionElement = ( Element ) i.next();
+
+ Attribute connectionIdAttribute = connectionElement.attribute( ID_TAG );
+
+ if ( connectionIdAttribute != null )
+ {
+ connectionFolder.addConnectionId( connectionIdAttribute.getValue() );
+ }
+ }
+ }
+
+ // Sub-folders
+ Element foldersElement = element.element( SUB_FOLDERS_TAG );
+ if ( foldersElement != null )
+ {
+ for ( Iterator<?> i = foldersElement.elementIterator( SUB_FOLDER_TAG ); i.hasNext(); )
+ {
+ Element folderElement = ( Element ) i.next();
+
+ Attribute folderIdAttribute = folderElement.attribute( ID_TAG );
+
+ if ( folderIdAttribute != null )
+ {
+ connectionFolder.addSubFolderId( folderIdAttribute.getValue() );
+ }
+ }
+ }
+
+ return connectionFolder;
+ }
+
+
+ /**
+ * Saves the connection folders using the writer.
+ *
+ * @param connectionFolders
+ * the connection folders
+ * @param stream
+ * the OutputStream
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public static void saveConnectionFolders( List<ConnectionFolder> connectionFolders, FileOutputStream stream ) throws IOException
+ {
+ // Creating the Document
+ Document document = DocumentHelper.createDocument();
+
+ // Creating the root element
+ Element root = document.addElement( CONNECTION_FOLDERS_TAG );
+
+ if ( connectionFolders != null )
+ {
+ for ( ConnectionFolder connectionFolder : connectionFolders )
+ {
+ addFolderConnection( root, connectionFolder );
+ }
+ }
+
+ // Writing the file to disk
+ OutputFormat outformat = OutputFormat.createPrettyPrint();
+ outformat.setEncoding( "UTF-8" );
+ XMLWriter writer = new XMLWriter( stream, outformat );
+ writer.write( document );
+ writer.flush();
+ }
+
+
+ /**
+ * Adds the given connection folder to the given parent Element.
+ *
+ * @param parent
+ * the parent Element
+ * @param connectionFolder
+ * the connection folder
+ */
+ private static void addFolderConnection( Element parent, ConnectionFolder connectionFolder )
+ {
+ Element connectionFolderElement = parent.addElement( CONNECTION_FOLDER_TAG );
+
+ // ID
+ connectionFolderElement.addAttribute( ID_TAG, connectionFolder.getId() );
+
+ // Name
+ connectionFolderElement.addAttribute( NAME_TAG, connectionFolder.getName() );
+
+ // Connections
+ Element connectionsElement = connectionFolderElement.addElement( CONNECTIONS_TAG );
+ for ( String connectionId : connectionFolder.getConnectionIds() )
+ {
+ Element connectionElement = connectionsElement.addElement( CONNECTION_TAG );
+ connectionElement.addAttribute( ID_TAG, connectionId );
+ }
+
+ // Sub-folders
+ Element foldersElement = connectionFolderElement.addElement( SUB_FOLDERS_TAG );
+ for ( String folderId : connectionFolder.getSubFolderIds() )
+ {
+ Element folderElement = foldersElement.addElement( SUB_FOLDER_TAG );
+ folderElement.addAttribute( ID_TAG, folderId );
+ }
+ }
+
}
Added: directory/studio/trunk/studio-connection-ui/resources/icons/connection_folder.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/resources/icons/connection_folder.gif?rev=578966&view=auto
==============================================================================
Binary file - no diff available.
Propchange: directory/studio/trunk/studio-connection-ui/resources/icons/connection_folder.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIConstants.java Mon Sep 24 14:04:06 2007
@@ -43,4 +43,9 @@
public static final String IMG_CONNECTION_WIZARD = "resources/icons/connection_wizard.gif";
public static final String IMG_PULLDOWN = "resources/icons/pulldown.gif";
+
+ public static final String IMG_CONNECTION_FOLDER = "resources/icons/connection_folder.gif";
+
+ public static final String IMG_CONNECTION_FOLDER_ADD = "resources/icons/connection_folder.gif";
+
}
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/ConnectionUIPlugin.java Mon Sep 24 14:04:06 2007
@@ -42,7 +42,7 @@
/** The Constant PLUGIN_ID. */
public static final String PLUGIN_ID = "org.apache.directory.studio.connection.ui";
- /** The shared plugin instande. */
+ /** The shared plugin instance. */
private static ConnectionUIPlugin plugin;
/** The event dispatcher */
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/DeleteAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/DeleteAction.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/DeleteAction.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/DeleteAction.java Mon Sep 24 14:04:06 2007
@@ -21,9 +21,15 @@
package org.apache.directory.studio.connection.ui.actions;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.ConnectionCoreConstants;
import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.apache.directory.studio.connection.core.jobs.CloseConnectionsJob;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.ISharedImages;
@@ -44,20 +50,20 @@
*/
public String getText()
{
- try
+ Connection[] connections = getSelectedConnections();
+ ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
+ if ( connections.length > 0 && connectionFolders.length == 0 )
{
- Connection[] connections = getConnections();
-
- if ( connections.length > 0 )
- {
- return connections.length > 1 ? "Delete Connections" : "Delete Connection";
- }
+ return connections.length > 1 ? "Delete Connections" : "Delete Connection";
}
- catch ( Exception e )
+ else if ( connectionFolders.length > 0 && connections.length == 0 )
{
+ return connectionFolders.length > 1 ? "Delete Connection Folders" : "Delete Connection Folder";
+ }
+ else
+ {
+ return "Delete";
}
-
- return "Delete";
}
@@ -84,99 +90,171 @@
*/
public void run()
{
- try
- {
- Connection[] connections = getConnections();
+ Connection[] connections = getSelectedConnections();
+ ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
- StringBuffer message = new StringBuffer();
+ StringBuffer message = new StringBuffer();
- if ( connections.length > 0 )
+ if ( connections.length > 0 )
+ {
+ if ( connections.length <= 5 )
{
- if ( connections.length <= 5 )
+ message.append( connections.length == 1 ? "Are your sure to delete the following connection?"
+ : "Are your sure to delete the following connections?" );
+ for ( int i = 0; i < connections.length; i++ )
{
- message.append( connections.length == 1 ? "Are your sure to delete the following connection?"
- : "Are your sure to delete the following connections?" );
- for ( int i = 0; i < connections.length; i++ )
- {
- message.append( ConnectionCoreConstants.LINE_SEPARATOR );
- message.append( " - " );
- message.append( connections[i].getName() );
- }
+ message.append( ConnectionCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( connections[i].getName() );
}
- else
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected connections?" );
+ }
+ message.append( ConnectionCoreConstants.LINE_SEPARATOR );
+ message.append( ConnectionCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( connectionFolders.length > 0 )
+ {
+ if ( connectionFolders.length <= 5 )
+ {
+ message.append( connectionFolders.length == 1 ? "Are your sure to delete the following connection folder including all connections?"
+ : "Are your sure to delete the following connection folders including all connections?" );
+ for ( int i = 0; i < connectionFolders.length; i++ )
{
- message.append( "Are your sure to delete the selected connections?" );
+ message.append( ConnectionCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( connectionFolders[i].getName() );
}
- message.append( ConnectionCoreConstants.LINE_SEPARATOR );
- message.append( ConnectionCoreConstants.LINE_SEPARATOR );
}
+ else
+ {
+ message.append( "Are your sure to delete the selected connection folders including all connections?" );
+ }
+ message.append( ConnectionCoreConstants.LINE_SEPARATOR );
+ message.append( ConnectionCoreConstants.LINE_SEPARATOR );
+ }
- if ( message.length() == 0 || MessageDialog.openConfirm( getShell(), getText(), message.toString() ) )
+ if ( message.length() == 0 || MessageDialog.openConfirm( getShell(), getText(), message.toString() ) )
+ {
+ List<Connection> connectionsToDelete = getConnectionsToDelete();
+ List<ConnectionFolder> connectionsFoldersToDelete = getConnectionsFoldersToDelete();
+
+ if ( connections.length > 0 )
+ {
+ deleteConnections( connectionsToDelete );
+ }
+ if ( connectionFolders.length > 0 )
{
+ deleteConnectionFolders( connectionsFoldersToDelete );
+ }
+ }
+ }
+
+
+ private List<ConnectionFolder> getConnectionsFoldersToDelete()
+ {
+ List<ConnectionFolder> selectedFolders = new ArrayList<ConnectionFolder>(Arrays.asList( getSelectedConnectionFolders() ));
+ List<ConnectionFolder> foldersToDelete = new ArrayList<ConnectionFolder>();
+ while( !selectedFolders.isEmpty() )
+ {
+ ConnectionFolder folder = selectedFolders.get( 0 );
- if ( connections.length > 0 )
+ List<String> subFolderIds = folder.getSubFolderIds();
+ for ( String subFolderId : subFolderIds )
+ {
+ ConnectionFolder subFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager().getConnectionFolderById( subFolderId );
+ if ( subFolder != null )
{
- deleteConnections( connections );
+ selectedFolders.add( subFolder );
}
}
+
+ if( !foldersToDelete.contains( folder ) )
+ {
+ foldersToDelete.add( folder );
+ }
+
+ selectedFolders.remove( folder );
}
- catch ( Exception e )
+ return foldersToDelete;
+ }
+
+
+ private List<Connection> getConnectionsToDelete()
+ {
+ List<ConnectionFolder> selectedFolders = new ArrayList<ConnectionFolder>(Arrays.asList( getSelectedConnectionFolders() ));
+ List<Connection> selectedConnections = new ArrayList<Connection>(Arrays.asList( getSelectedConnections() ));
+ List<Connection> connectionsToDelete = new ArrayList<Connection>( selectedConnections );
+ while( !selectedFolders.isEmpty() )
{
+ ConnectionFolder folder = selectedFolders.get( 0 );
+
+ List<String> subFolderIds = folder.getSubFolderIds();
+ for ( String subFolderId : subFolderIds )
+ {
+ ConnectionFolder subFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager().getConnectionFolderById( subFolderId );
+ if ( subFolder != null )
+ {
+ selectedFolders.add( subFolder );
+ }
+ }
+
+ List<String> connectionIds = folder.getConnectionIds();
+ for ( String connectionId : connectionIds )
+ {
+ Connection connection = ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionById( connectionId );
+ if(connection != null && !connectionsToDelete.contains( connection ))
+ {
+ connectionsToDelete.add( connection );
+ }
+ }
+
+ selectedFolders.remove( folder );
}
+ return connectionsToDelete;
}
-
+
/**
* {@inheritDoc}
*/
public boolean isEnabled()
{
- try
- {
- Connection[] connections = getConnections();
- return connections.length > 0;
- }
- catch ( Exception e )
- {
- // e.printStackTrace();
- return false;
- }
+ return getSelectedConnections().length + getSelectedConnectionFolders().length > 0;
}
/**
- * Gets the Connections
+ * Deletes Connections
*
- * @return
- * the Connections
- * @throws Exception
- * when a is opened
+ * @param connectionsToDelete
+ * the Connections to delete
*/
- protected Connection[] getConnections() throws Exception
+ private void deleteConnections( List<Connection> connectionsToDelete )
{
- for ( int i = 0; i < getSelectedConnections().length; i++ )
+ new CloseConnectionsJob( connectionsToDelete.toArray( new Connection[connectionsToDelete.size()] ) ).execute();
+ for ( Connection connection : connectionsToDelete )
{
- if ( getSelectedConnections()[i].getJNDIConnectionWrapper().isConnected() )
- {
- throw new Exception();
- }
+ ConnectionCorePlugin.getDefault().getConnectionManager().removeConnection( connection);
}
-
- return getSelectedConnections();
}
/**
- * Deletes Connections
+ * Deletes Connection Folders
*
- * @param connections
- * the Connections to delete
+ * @param connectionsFoldersToDelete
+ * the Connection Folders to delete
*/
- protected void deleteConnections( Connection[] connections )
+ private void deleteConnectionFolders( List<ConnectionFolder> connectionsFoldersToDelete )
{
- for ( int i = 0; i < connections.length; i++ )
+ for ( ConnectionFolder connectionFolder : connectionsFoldersToDelete )
{
- ConnectionCorePlugin.getDefault().getConnectionManager().removeConnection( connections[i] );
+ ConnectionCorePlugin.getDefault().getConnectionFolderManager().removeConnectionFolder( connectionFolder );
}
}
+
}
Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java?rev=578966&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java Mon Sep 24 14:04:06 2007
@@ -0,0 +1,113 @@
+/*
+ * 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.connection.ui.actions;
+
+
+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.ui.PlatformUI;
+
+
+/**
+ * This Action launches the New Connection Folder Dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewConnectionFolderAction extends StudioAction
+{
+ /**
+ * Creates a new instance of NewConnectionFolderAction.
+ */
+ public NewConnectionFolderAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ ConnectionFolderDialog dialog = new ConnectionFolderDialog( PlatformUI.getWorkbench().getDisplay()
+ .getActiveShell(), "New Connection Folder", "Please enter the name of the new connection folder:", "", null );
+ if ( dialog.open() == CredentialsDialog.OK )
+ {
+ String name = dialog.getValue();
+ ConnectionFolder folder = new ConnectionFolder( name );
+ ConnectionCorePlugin.getDefault().getConnectionFolderManager().addConnectionFolder( folder );
+
+ ConnectionFolder[] folders = getSelectedConnectionFolders();
+ if ( folders != null && folders.length > 0 )
+ {
+ folders[0].addSubFolderId( folder.getId() );
+ }
+ else
+ {
+ ConnectionCorePlugin.getDefault().getConnectionFolderManager().getRootConnectionFolder()
+ .addSubFolderId( folder.getId() );
+ }
+ }
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return "New Connection Folder...";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_CONNECTION_FOLDER_ADD );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return true;
+ }
+}
Propchange: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java Mon Sep 24 14:04:06 2007
@@ -23,6 +23,7 @@
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.ui.dnd.ConnectionTransfer;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.dnd.Clipboard;
@@ -112,6 +113,16 @@
{
Connection newConnection = ( Connection ) connections[i].clone();
ConnectionCorePlugin.getDefault().getConnectionManager().addConnection( newConnection );
+ ConnectionFolder[] folders = getSelectedConnectionFolders();
+ if(folders != null && folders.length > 0)
+ {
+ folders[0].addConnectionId( newConnection.getId() );
+ }
+ else
+ {
+ ConnectionCorePlugin.getDefault().getConnectionFolderManager().getRootConnectionFolder()
+ .addConnectionId( newConnection.getId() );
+ }
}
return;
}
@@ -119,22 +130,17 @@
/**
- * Conditions: - a connection is selected - there are connections in
- * clipboard
+ * Condition: there are connections in clipboard
*
* @return the connections to paste
*/
private Connection[] getConnectionsToPaste()
{
- if ( getSelectedConnections().length > 0 )
+ Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
+ if ( content != null && content instanceof Connection[] )
{
-
- Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
- if ( content != null && content instanceof Connection[] )
- {
- Connection[] connections = ( Connection[] ) content;
- return connections;
- }
+ Connection[] connections = ( Connection[] ) content;
+ return connections;
}
return null;
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java Mon Sep 24 14:04:06 2007
@@ -23,6 +23,7 @@
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.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -52,13 +53,16 @@
*/
public String getText()
{
-
- Connection[] connections = getConnections();
-
- if ( connections.length == 1 )
+ Connection[] connections = getSelectedConnections();
+ ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
+ if ( connections.length == 1 && connectionFolders.length == 0 )
{
return "Rename Connection...";
}
+ else if ( connectionFolders.length == 1 && connections.length == 0 )
+ {
+ return "Rename Connection Folder...";
+ }
else
{
return "Rename";
@@ -89,48 +93,25 @@
*/
public void run()
{
- Connection[] connections = getConnections();
-
+ Connection[] connections = getSelectedConnections();
+ ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
if ( connections.length == 1 )
{
renameConnection( connections[0] );
}
- }
-
-
- /**
- * {@inheritDoc}
- */
- public boolean isEnabled()
- {
- try
- {
- Connection[] connections = getConnections();
- return connections.length == 1;
- }
- catch ( Exception e )
+ else if ( connectionFolders.length == 1 )
{
- return false;
+ renameConnectionFolder( connectionFolders[0] );
}
}
/**
- * Gets the Connections
- *
- * @return
- * the Connections
+ * {@inheritDoc}
*/
- protected Connection[] getConnections()
+ public boolean isEnabled()
{
- if ( getSelectedConnections().length == 1 )
- {
- return getSelectedConnections();
- }
- else
- {
- return new Connection[0];
- }
+ return getSelectedConnections().length + getSelectedConnectionFolders().length == 1;
}
@@ -140,18 +121,24 @@
* @param connection
* the Connection to rename
*/
- protected void renameConnection( final Connection connection )
+ private void renameConnection( final Connection connection )
{
IInputValidator validator = new IInputValidator()
{
public String isValid( String newName )
{
if ( connection.getName().equals( newName ) )
+ {
return null;
+ }
else if ( ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionByName( newName ) != null )
+ {
return "A connection with this name already exists.";
+ }
else
+ {
return null;
+ }
}
};
@@ -165,4 +152,44 @@
connection.setName( newName );
}
}
+
+
+ /**
+ * Renames a ConnectionFolder.
+ *
+ * @param connectionFolder
+ * the ConnectionFolder to rename
+ */
+ private void renameConnectionFolder( final ConnectionFolder connectionFolder )
+ {
+ IInputValidator validator = new IInputValidator()
+ {
+ public String isValid( String newName )
+ {
+ if ( connectionFolder.getName().equals( newName ) )
+ {
+ return null;
+ }
+ else if ( ConnectionCorePlugin.getDefault().getConnectionFolderManager().getConnectionFolderByName( newName ) != null )
+ {
+ return "A connection folder with this name already exists.";
+ }
+ else
+ {
+ return null;
+ }
+ }
+ };
+
+ InputDialog dialog = new InputDialog( getShell(), "Rename Connection Folder", "New name:", connectionFolder.getName(),
+ validator );
+
+ dialog.open();
+ String newName = dialog.getValue();
+ if ( newName != null )
+ {
+ connectionFolder.setName( newName );
+ }
+ }
+
}
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java Mon Sep 24 14:04:06 2007
@@ -26,6 +26,7 @@
import java.util.List;
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -60,13 +61,13 @@
* @param type the requested type
* @return a list containg beans of the requesten type
*/
- private static List<Object> getTypes( ISelection selection, Class type )
+ private static List<Object> getTypes( ISelection selection, Class<?> type )
{
List<Object> list = new ArrayList<Object>();
if ( selection instanceof IStructuredSelection )
{
IStructuredSelection structuredSelection = ( IStructuredSelection ) selection;
- Iterator it = structuredSelection.iterator();
+ Iterator<?> it = structuredSelection.iterator();
while ( it.hasNext() )
{
Object o = it.next();
@@ -93,6 +94,19 @@
}
+ /**
+ * Gets the ConnectionFolder beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with ConnectionFolder beans, may be empty.
+ */
+ public static ConnectionFolder[] getConnectionFolders( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, ConnectionFolder.class );
+ return list.toArray( new ConnectionFolder[list.size()] );
+ }
+
+
/**
* Gets the objects contained in the given selection.
*
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java Mon Sep 24 14:04:06 2007
@@ -22,6 +22,7 @@
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
@@ -42,6 +43,9 @@
/** The selected Connections */
private Connection[] selectedConnections;
+ /** The selected connection folders */
+ private ConnectionFolder[] selectedConnectionFolders;
+
/** The input */
private Object input;
@@ -79,6 +83,7 @@
public void selectionChanged( IAction action, ISelection selection )
{
setSelectedConnections( SelectionUtils.getConnections( selection ) );
+ setSelectedConnectionFolders( SelectionUtils.getConnectionFolders( selection ) );
action.setEnabled( this.isEnabled() );
action.setText( this.getText() );
@@ -147,6 +152,7 @@
private void init()
{
this.selectedConnections = new Connection[0];
+ this.selectedConnectionFolders = new ConnectionFolder[0];
this.input = null;
}
@@ -158,6 +164,7 @@
public void dispose()
{
this.selectedConnections = new Connection[0];
+ this.selectedConnectionFolders = new ConnectionFolder[0];
this.input = null;
}
@@ -176,17 +183,6 @@
/**
- * This method is fired when a Connection is updated.
- *
- * @param connection
- * the connection
- */
- public void connectionUpdated( Connection connection )
- {
- }
-
-
- /**
* Gets the selected Connections.
*
* @return
@@ -209,6 +205,30 @@
this.selectedConnections = selectedConnections;
}
+
+ /**
+ * Gets the selected connection folders.
+ *
+ * @return
+ * the selected connection folders
+ */
+ public ConnectionFolder[] getSelectedConnectionFolders()
+ {
+ return selectedConnectionFolders;
+ }
+
+
+ /**
+ * Sets the selected connection folders.
+ *
+ * @param selectedConnectionFolders
+ * the selected connections folders to set
+ */
+ public void setSelectedConnectionFolders( ConnectionFolder[] selectedConnectionFolders )
+ {
+ this.selectedConnectionFolders = selectedConnectionFolders;
+ }
+
/**
* Gets the input.
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java Mon Sep 24 14:04:06 2007
@@ -22,6 +22,7 @@
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
@@ -125,7 +126,6 @@
{
if ( !isDisposed() )
{
- action.connectionUpdated( connection );
updateAction();
}
}
@@ -168,6 +168,15 @@
/**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
+ */
+ public void connectionFolderModified( ConnectionFolder connectionFolder )
+ {
+ connectionUpdated( null );
+ }
+
+
+ /**
* Input changed.
*
* @param input the input
@@ -192,6 +201,7 @@
{
ISelection selection = event.getSelection();
action.setSelectedConnections( SelectionUtils.getConnections( selection ) );
+ action.setSelectedConnectionFolders( SelectionUtils.getConnectionFolders( selection ) );
updateAction();
}
}
Added: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java?rev=578966&view=auto
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java (added)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java Mon Sep 24 14:04:06 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.connection.ui.dialogs;
+
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * The ConnectionFolderDialog is used to create or rename a connection folder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionFolderDialog extends InputDialog
+{
+
+ /**
+ * Creates a new instance of ConnectionFolderDialog.
+ *
+ * @param parentShell the parent shell
+ * @param dialogTitle the dialog title
+ * @param dialogMessage the dialog message
+ * @param initialValue the initial value
+ * @param validator the validator
+ */
+ public ConnectionFolderDialog( Shell parentShell, String dialogTitle, String dialogMessage, String initialValue,
+ IInputValidator validator )
+ {
+ super( parentShell, dialogTitle, dialogMessage, initialValue, validator );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ return composite;
+ }
+
+}
Propchange: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java Mon Sep 24 14:04:06 2007
@@ -26,23 +26,24 @@
import java.util.Map;
import org.apache.directory.studio.connection.ui.actions.ActionHandlerManager;
-import org.apache.directory.studio.connection.ui.actions.StudioActionProxy;
import org.apache.directory.studio.connection.ui.actions.CloseConnectionAction;
import org.apache.directory.studio.connection.ui.actions.ConnectionViewActionProxy;
import org.apache.directory.studio.connection.ui.actions.CopyAction;
import org.apache.directory.studio.connection.ui.actions.DeleteAction;
import org.apache.directory.studio.connection.ui.actions.NewConnectionAction;
+import org.apache.directory.studio.connection.ui.actions.NewConnectionFolderAction;
import org.apache.directory.studio.connection.ui.actions.OpenConnectionAction;
import org.apache.directory.studio.connection.ui.actions.PasteAction;
import org.apache.directory.studio.connection.ui.actions.PropertiesAction;
import org.apache.directory.studio.connection.ui.actions.RenameAction;
+import org.apache.directory.studio.connection.ui.actions.StudioActionProxy;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.commands.ActionHandler;
-import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
@@ -62,6 +63,9 @@
/** The Constant newConnectionAction. */
protected static final String newConnectionAction = "newConnectionAction";
+ /** The Constant newConnectionFolderAction. */
+ protected static final String newConnectionFolderAction = "newConnectionFolderAction";
+
/** The Constant openConnectionAction. */
protected static final String openConnectionAction = "openConnectionAction";
@@ -104,9 +108,11 @@
this.mainWidget = mainWidget;
this.connectionActionMap = new HashMap<String, ConnectionViewActionProxy>();
- TableViewer viewer = mainWidget.getViewer();
+ TreeViewer viewer = mainWidget.getViewer();
connectionActionMap.put( newConnectionAction, new ConnectionViewActionProxy( viewer, this,
new NewConnectionAction() ) );
+ connectionActionMap.put( newConnectionFolderAction, new ConnectionViewActionProxy( viewer, this,
+ new NewConnectionFolderAction() ) );
connectionActionMap.put( openConnectionAction, new ConnectionViewActionProxy( viewer, this,
new OpenConnectionAction() ) );
connectionActionMap.put( closeConnectionAction, new ConnectionViewActionProxy( viewer, this,
@@ -131,9 +137,9 @@
{
if ( mainWidget != null )
{
- for ( Iterator it = connectionActionMap.keySet().iterator(); it.hasNext(); )
+ for ( Iterator<String> it = connectionActionMap.keySet().iterator(); it.hasNext(); )
{
- String key = ( String ) it.next();
+ String key = it.next();
ConnectionViewActionProxy action = ( ConnectionViewActionProxy ) this.connectionActionMap.get( key );
action.dispose();
action = null;
@@ -210,6 +216,7 @@
{
// add
menuManager.add( ( IAction ) connectionActionMap.get( newConnectionAction ) );
+ menuManager.add( ( IAction ) connectionActionMap.get( newConnectionFolderAction ) );
menuManager.add( new Separator() );
// open/close
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java Mon Sep 24 14:04:06 2007
@@ -23,7 +23,7 @@
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Menu;
@@ -97,7 +97,7 @@
*
* @return the context menu manager
*/
- public IMenuManager getContextMenuManager( TableViewer viewer )
+ public IMenuManager getContextMenuManager( TreeViewer viewer )
{
if ( this.contextMenuManager == null )
{
@@ -116,7 +116,7 @@
*
* @return the content provider
*/
- public ConnectionContentProvider getContentProvider( TableViewer viewer )
+ public ConnectionContentProvider getContentProvider( TreeViewer viewer )
{
if ( contentProvider == null )
{
@@ -134,7 +134,7 @@
*
* @return the label provider
*/
- public ConnectionLabelProvider getLabelProvider( TableViewer viewer )
+ public ConnectionLabelProvider getLabelProvider( TreeViewer viewer )
{
if ( labelProvider == null )
{
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java Mon Sep 24 14:04:06 2007
@@ -21,8 +21,14 @@
package org.apache.directory.studio.connection.ui.widgets;
-import org.apache.directory.studio.connection.core.ConnectionManager;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
+import java.util.ArrayList;
+import java.util.List;
+
+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.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
@@ -34,7 +40,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ConnectionContentProvider implements IStructuredContentProvider
+public class ConnectionContentProvider implements ITreeContentProvider
{
/**
@@ -60,20 +66,69 @@
/**
* {@inheritDoc}
*
- * This implementation accepts the ConnectionManager and returns its connections.
+ * This implementation accepts the ConnectionFolderManager and returns its connections.
*/
public Object[] getElements( Object inputElement )
{
- if ( inputElement != null && inputElement instanceof ConnectionManager )
+ if ( inputElement != null && inputElement instanceof ConnectionFolderManager )
{
- ConnectionManager cm = ( ConnectionManager ) inputElement;
- return cm.getConnections();
+ ConnectionFolderManager cfm = ( ConnectionFolderManager ) inputElement;
+ ConnectionFolder rootConnectionFolder = cfm.getRootConnectionFolder();
+ Object[] elements = getChildren( rootConnectionFolder );
+ return elements;
}
else
{
- return new Object[]
- {};
+ return getChildren( inputElement );
+ }
+ }
+
+
+ public Object[] getChildren( Object parentElement )
+ {
+ if ( parentElement != null && parentElement instanceof ConnectionFolder )
+ {
+ List<Object> children = new ArrayList<Object>();
+
+ ConnectionFolder folder = ( ConnectionFolder ) parentElement;
+ List<String> subFolderIds = folder.getSubFolderIds();
+ List<String> connectionIds = folder.getConnectionIds();
+
+ for ( String subFolderId : subFolderIds )
+ {
+ ConnectionFolder subFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager()
+ .getConnectionFolderById( subFolderId );
+ if ( subFolder != null )
+ {
+ children.add( subFolder );
+ }
+ }
+ for ( String connectionId : connectionIds )
+ {
+ Connection conn = ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionById(
+ connectionId );
+ if ( conn != null )
+ {
+ children.add( conn );
+ }
+ }
+
+ return children.toArray();
}
+ return null;
+ }
+
+
+ public Object getParent( Object element )
+ {
+ return null;
+ }
+
+
+ public boolean hasChildren( Object element )
+ {
+ Object[] children = getChildren( element );
+ return children != null && children.length > 0;
}
}
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java Mon Sep 24 14:04:06 2007
@@ -22,6 +22,7 @@
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
@@ -47,6 +48,11 @@
*/
public String getText( Object obj )
{
+ if ( obj instanceof ConnectionFolder )
+ {
+ ConnectionFolder folder = (ConnectionFolder) obj;
+ return folder.getName();
+ }
if ( obj instanceof Connection )
{
Connection conn = ( Connection ) obj;
@@ -81,7 +87,11 @@
*/
public Image getImage( Object obj )
{
- if ( obj instanceof Connection )
+ if ( obj instanceof ConnectionFolder )
+ {
+ return ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_FOLDER );
+ }
+ else if ( obj instanceof Connection )
{
Connection conn = ( Connection ) obj;
return conn.getJNDIConnectionWrapper().isConnected() ? ConnectionUIPlugin.getDefault().getImage(
Modified: directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java?rev=578966&r1=578965&r2=578966&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java (original)
+++ directory/studio/trunk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java Mon Sep 24 14:04:06 2007
@@ -22,11 +22,12 @@
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry;
import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
/**
@@ -38,16 +39,16 @@
public class ConnectionUniversalListener implements ConnectionUpdateListener
{
- /** The table viewer */
- protected TableViewer viewer;
+ /** The tree viewer */
+ protected TreeViewer viewer;
/**
* Creates a new instance of ConnectionUniversalListener.
*
- * @param viewer the table viewer
+ * @param viewer the tree viewer
*/
- public ConnectionUniversalListener( TableViewer viewer )
+ public ConnectionUniversalListener( TreeViewer viewer )
{
this.viewer = viewer;
@@ -117,6 +118,15 @@
public void connectionClosed( Connection connection )
{
connectionUpdated( connection );
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder)
+ */
+ public void connectionFolderModified( ConnectionFolder connectionFolder )
+ {
+ connectionUpdated( null );
}
}