You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/05 15:46:37 UTC
svn commit: r592022 [2/4] - in
/directory/sandbox/felixk/studio-connection-ui: ./ META-INF/ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/directory/
src/main/java/org/apache/directory/studio/ src/ma...
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionAction.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,106 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
+import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.apache.directory.studio.connection.ui.wizards.NewConnectionWizard;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This Action launches the New Connection Wizard.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewConnectionAction extends StudioAction
+{
+ /**
+ * Creates a new instance of NewConnectionAction.
+ */
+ public NewConnectionAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ List<Object> selectedObjects = new ArrayList<Object>();
+ selectedObjects.addAll( Arrays.asList( getSelectedConnectionFolders() ) );
+ selectedObjects.addAll( Arrays.asList( getSelectedConnections() ) );
+
+ NewConnectionWizard wizard = new NewConnectionWizard();
+ wizard.init( PlatformUI.getWorkbench(), new StructuredSelection( selectedObjects ) );
+ WizardDialog dialog = new WizardDialog( getShell(), wizard );
+ dialog.setBlockOnOpen( true );
+ dialog.create();
+ dialog.open();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return "New Connection...";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_CONNECTION_ADD );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return true;
+ }
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java Mon Nov 5 06:46:32 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/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/NewConnectionFolderAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,100 @@
+/*
+ * 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.jobs.OpenConnectionsJob;
+import org.apache.directory.studio.connection.ui.ConnectionUIConstants;
+import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+/**
+ * This Action opens a Connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class OpenConnectionAction extends StudioAction
+{
+ /**
+ * Creates a new instance of OpenConnectionAction.
+ */
+ public OpenConnectionAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ OpenConnectionsJob ocj = new OpenConnectionsJob( getSelectedConnections() );
+ ocj.execute();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return getSelectedConnections().length > 1 ? "Open Connections" : "Open Connection";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_CONNECTION_CONNECT );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ boolean canOpen = false;
+ for ( int i = 0; i < getSelectedConnections().length; i++ )
+ {
+ if ( !getSelectedConnections()[i].getJNDIConnectionWrapper().isConnected() )
+ {
+ canOpen = true;
+ break;
+ }
+ }
+ return getSelectedConnections().length > 0 && canOpen;
+ }
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,227 @@
+/*
+ * 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 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.apache.directory.studio.connection.core.ConnectionManager;
+import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+
+/**
+ * This class implements the Paste Action.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PasteAction extends StudioAction
+{
+ /**
+ * Creates a new instance of PasteAction.
+ */
+ public PasteAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ List<Connection> connections = getConnectionsToPaste();
+ List<ConnectionFolder> connectionFolders = getConnectionFoldersToPaste();
+ if ( connections.size() > 0 && connectionFolders.size() == 0 )
+ {
+ return connections.size() > 1 ? "Paste Connections" : "Paste Connection";
+ }
+ else if ( connectionFolders.size() > 0 && connections.size() == 0 )
+ {
+ return connectionFolders.size() > 1 ? "Paste Connection Folders" : "Paste Connection Folder";
+ }
+ else
+ {
+ return "Paste";
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_PASTE );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return IWorkbenchActionDefinitionIds.PASTE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return this.getFromClipboard( ConnectionTransfer.getInstance() ) != null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+ .getConnectionFolderManager();
+ ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+
+ ConnectionFolder[] selectedFolders = getSelectedConnectionFolders();
+ Connection[] selectedConnections = getSelectedConnections();
+ ConnectionFolder targetFolder = null;
+ if ( selectedFolders.length > 0 )
+ {
+ targetFolder = selectedFolders[0];
+ }
+ else if ( selectedConnections.length > 0 )
+ {
+ targetFolder = connectionFolderManager.getParentConnectionFolder( selectedConnections[0] );
+ }
+ if ( targetFolder == null )
+ {
+ targetFolder = connectionFolderManager.getRootConnectionFolder();
+ }
+
+ // connections
+ List<Connection> connections = getConnectionsToPaste();
+ for ( Connection connection : connections )
+ {
+ Connection newConnection = ( Connection ) connection.clone();
+ connectionManager.addConnection( newConnection );
+ targetFolder.addConnectionId( newConnection.getId() );
+ }
+
+ // connection folders
+ List<ConnectionFolder> connectionFolders = getConnectionFoldersToPaste();
+ for ( ConnectionFolder connectionFolder : connectionFolders )
+ {
+ ConnectionFolder newConnectionFolder = ( ConnectionFolder ) connectionFolder.clone();
+ connectionFolderManager.addConnectionFolder( newConnectionFolder );
+ targetFolder.addSubFolderId( newConnectionFolder.getId() );
+ }
+ }
+
+
+ /**
+ * Condition: there are connections in clipboard
+ *
+ * @return the connections to paste
+ */
+ private List<Connection> getConnectionsToPaste()
+ {
+ List<Connection> connections = new ArrayList<Connection>();
+
+ Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
+ if ( content != null && content instanceof Object[] )
+ {
+ Object[] objects = ( Object[] ) content;
+ for ( Object object : objects )
+ {
+ if ( object instanceof Connection )
+ {
+ connections.add( ( Connection ) object );
+ }
+ }
+ }
+
+ return connections;
+ }
+
+
+ /**
+ * Condition: there are connection folders in clipboard
+ *
+ * @return the connection folders to paste
+ */
+ private List<ConnectionFolder> getConnectionFoldersToPaste()
+ {
+ List<ConnectionFolder> folders = new ArrayList<ConnectionFolder>();
+
+ Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
+ if ( content != null && content instanceof Object[] )
+ {
+ Object[] objects = ( Object[] ) content;
+ for ( Object object : objects )
+ {
+ if ( object instanceof ConnectionFolder )
+ {
+ folders.add( ( ConnectionFolder ) object );
+ }
+ }
+ }
+
+ return folders;
+ }
+
+
+ /**
+ * Retrieve the data of the specified type currently available on the system clipboard.
+ *
+ * @param dataType
+ * the transfer agent for the type of data being requested
+ * @return
+ * the data obtained from the clipboard or null if no data of this type is available
+ */
+ protected Object getFromClipboard( Transfer dataType )
+ {
+ Clipboard clipboard = null;
+ try
+ {
+ clipboard = new Clipboard( Display.getCurrent() );
+ return clipboard.getContents( dataType );
+ }
+ finally
+ {
+ if ( clipboard != null )
+ clipboard.dispose();
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PasteAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PropertiesAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PropertiesAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PropertiesAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PropertiesAction.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,114 @@
+/*
+ * 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.Utils;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+
+/**
+ * This Action opens the Property Dialog for a given object.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PropertiesAction extends StudioAction
+{
+ /**
+ * Creates a new instance of PropertiesAction.
+ */
+ public PropertiesAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return "Properties";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return IWorkbenchActionDefinitionIds.PROPERTIES;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+
+ return getSelectedConnections().length == 1;
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ IAdaptable element = null;
+ String pageId = null;
+ String title = null;
+
+ if ( getSelectedConnections().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedConnections()[0];
+ pageId = "org.apache.directory.studio.connection.ui.properties.ConnectionPropertyPage";
+ title = getSelectedConnections()[0].getName();
+ }
+
+ if ( element != null )
+ {
+ PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn( getShell(), element, pageId, null, null );
+ if ( dialog != null )
+ title = Utils.shorten( title, 30 );
+ dialog.getShell().setText( "Properties for '" + title + "'" );
+ dialog.open();
+
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/PropertiesAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,195 @@
+/*
+ * 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.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;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+
+/**
+ * This Action renames Connections, Entries, Searches, or Bookmarks.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class RenameAction extends StudioAction
+{
+ /**
+ * Creates a new instance of RenameAction.
+ *
+ */
+ public RenameAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ 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";
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return IWorkbenchActionDefinitionIds.RENAME;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ Connection[] connections = getSelectedConnections();
+ ConnectionFolder[] connectionFolders = getSelectedConnectionFolders();
+ if ( connections.length == 1 )
+ {
+ renameConnection( connections[0] );
+ }
+ else if ( connectionFolders.length == 1 )
+ {
+ renameConnectionFolder( connectionFolders[0] );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return getSelectedConnections().length + getSelectedConnectionFolders().length == 1;
+ }
+
+
+ /**
+ * Renames a Connection.
+ *
+ * @param connection
+ * the Connection to rename
+ */
+ 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;
+ }
+ }
+ };
+
+ InputDialog dialog = new InputDialog( getShell(), "Rename Connection", "New name:", connection.getName(),
+ validator );
+
+ dialog.open();
+ String newName = dialog.getValue();
+ if ( newName != null )
+ {
+ 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 );
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/RenameAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,121 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Iterator;
+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;
+
+
+/**
+ * The SelectionUtils are used to extract specific beans from the current
+ * selection (org.eclipse.jface.viewers.ISelection).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class SelectionUtils
+{
+
+ /**
+ * Gets the Strings contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with Strings, may be empty.
+ */
+ public static String[] getProperties( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, String.class );
+ return list.toArray( new String[list.size()] );
+ }
+
+
+ /**
+ * Gets all beans of the requested type contained in the given selection.
+ *
+ * @param selection the selection
+ * @param type the requested type
+ * @return a list containg beans of the requesten 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();
+ while ( it.hasNext() )
+ {
+ Object o = it.next();
+ if ( type.isInstance( o ) )
+ {
+ list.add( o );
+ }
+ }
+ }
+ return list;
+ }
+
+
+ /**
+ * Gets the Connection beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with Connection beans, may be empty.
+ */
+ public static Connection[] getConnections( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, Connection.class );
+ return list.toArray( new Connection[list.size()] );
+ }
+
+
+ /**
+ * 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.
+ *
+ * @param selection the selection
+ * @return an array with object, may be empty.
+ */
+ public static Object[] getObjects( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, Object.class );
+ return list.toArray( new Object[list.size()] );
+ }
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,256 @@
+/*
+ * 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.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;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This abstract class must be extended by each Action related to the Browser.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class StudioAction implements IWorkbenchWindowActionDelegate
+{
+ /** The selected Connections */
+ private Connection[] selectedConnections;
+
+ /** The selected connection folders */
+ private ConnectionFolder[] selectedConnectionFolders;
+
+ /** The input */
+ private Object input;
+
+
+ /**
+ * Creates a new instance of BrowserAction.
+ */
+ protected StudioAction()
+ {
+ this.init();
+ }
+
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+ */
+ public void init( IWorkbenchWindow window )
+ {
+ this.init();
+ }
+
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run( IAction action )
+ {
+ this.run();
+ }
+
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged( IAction action, ISelection selection )
+ {
+ setSelectedConnections( SelectionUtils.getConnections( selection ) );
+ setSelectedConnectionFolders( SelectionUtils.getConnectionFolders( selection ) );
+
+ action.setEnabled( this.isEnabled() );
+ action.setText( this.getText() );
+ action.setToolTipText( this.getText() );
+ }
+
+
+ /**
+ * Returns the text for this action.
+ * <p>
+ * This method is associated with the <code>TEXT</code> property;
+ * property change events are reported when its value changes.
+ * </p>
+ *
+ * @return the text, or <code>null</code> if none
+ */
+ public abstract String getText();
+
+
+ /**
+ * Returns the image for this action as an image descriptor.
+ * <p>
+ * This method is associated with the <code>IMAGE</code> property;
+ * property change events are reported when its value changes.
+ * </p>
+ *
+ * @return the image, or <code>null</code> if this action has no image
+ */
+ public abstract ImageDescriptor getImageDescriptor();
+
+
+ /**
+ * Returns the command identifier.
+ *
+ * @return
+ * the command identifier
+ */
+ public abstract String getCommandId();
+
+
+ /**
+ * Returns whether this action is enabled.
+ * <p>
+ * This method is associated with the <code>ENABLED</code> property;
+ * property change events are reported when its value changes.
+ * </p>
+ *
+ * @return <code>true</code> if enabled, and
+ * <code>false</code> if disabled
+ */
+ public abstract boolean isEnabled();
+
+
+ /**
+ * Runs this action.
+ * Each action implementation must define the steps needed to carry out this action.
+ * The default implementation of this method in <code>Action</code>
+ * does nothing.
+ */
+ public abstract void run();
+
+
+ /**
+ * Initializes this action
+ */
+ private void init()
+ {
+ this.selectedConnections = new Connection[0];
+ this.selectedConnectionFolders = new ConnectionFolder[0];
+
+ this.input = null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose()
+ {
+ this.selectedConnections = new Connection[0];
+ this.selectedConnectionFolders = new ConnectionFolder[0];
+
+ this.input = null;
+ }
+
+
+ /**
+ * Returns the current active shell
+ *
+ * @return
+ * the current active shell
+ */
+ protected Shell getShell()
+ {
+ return PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ }
+
+
+ /**
+ * Gets the selected Connections.
+ *
+ * @return
+ * the selected Connections
+ */
+ public Connection[] getSelectedConnections()
+ {
+ return selectedConnections;
+ }
+
+
+ /**
+ * Sets the selected Connections.
+ *
+ * @param selectedConnections
+ * the selected Connections to set
+ */
+ public void setSelectedConnections( Connection[] selectedConnections )
+ {
+ 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.
+ *
+ * @return
+ * the input
+ */
+ public Object getInput()
+ {
+ return input;
+ }
+
+
+ /**
+ * Sets the input.
+ *
+ * @param input
+ * the input to set
+ */
+ public void setInput( Object input )
+ {
+ this.input = input;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,259 @@
+/*
+ * 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.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.action.Action;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+
+/**
+ * Proxy class for actions. The proxy class registers for modification events and
+ * updates the real actions on every modificaton.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class StudioActionProxy extends Action implements ISelectionChangedListener, ConnectionUpdateListener
+{
+
+ /** The action handler manager, used to deactivate and activate the action handlers and key bindings. */
+ private ActionHandlerManager actionHandlerManager;
+
+ /** The real action. */
+ protected StudioAction action;
+
+ /** The selection provider. */
+ protected ISelectionProvider selectionProvider;
+
+
+ /**
+ * Creates a new instance of StudioActionProxy.
+ *
+ * @param selectionProvider the selection provider
+ * @param actionHandlerManager the action handler manager
+ * @param action the action
+ * @param style the style
+ */
+ protected StudioActionProxy( ISelectionProvider selectionProvider, ActionHandlerManager actionHandlerManager,
+ StudioAction action, int style )
+ {
+ super( action.getText(), style );
+ this.selectionProvider = selectionProvider;
+ this.actionHandlerManager = actionHandlerManager;
+ this.action = action;
+
+ super.setImageDescriptor( action.getImageDescriptor() );
+ super.setActionDefinitionId( action.getCommandId() );
+
+ selectionProvider.addSelectionChangedListener( this );
+
+ ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() );
+
+ updateAction();
+ }
+
+
+ /**
+ * Creates a new instance of StudioActionProxy.
+ *
+ * @param selectionProvider the selection provider
+ * @param actionHandlerManager the action handler manager
+ * @param action the action
+ */
+ protected StudioActionProxy( ISelectionProvider selectionProvider, ActionHandlerManager actionHandlerManager,
+ StudioAction action )
+ {
+ this( selectionProvider, actionHandlerManager, action, Action.AS_PUSH_BUTTON );
+ }
+
+
+ /**
+ * Disposes this action proxy.
+ */
+ public void dispose()
+ {
+ ConnectionEventRegistry.removeConnectionUpdateListener( this );
+ selectionProvider.removeSelectionChangedListener( this );
+
+ action.dispose();
+ action = null;
+ }
+
+
+ /**
+ * Checks if is disposed.
+ *
+ * @return true, if is disposed
+ */
+ public boolean isDisposed()
+ {
+ return action == null;
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionUpdated(org.apache.directory.studio.connection.core.Connection)
+ */
+ public final void connectionUpdated( Connection connection )
+ {
+ if ( !isDisposed() )
+ {
+ updateAction();
+ }
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionAdded(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionAdded( Connection connection )
+ {
+ connectionUpdated( connection );
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionRemoved(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionRemoved( Connection connection )
+ {
+ connectionUpdated( connection );
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionOpened(org.apache.directory.studio.connection.core.Connection)
+ */
+ public void connectionOpened( Connection connection )
+ {
+ connectionUpdated( connection );
+ }
+
+
+ /**
+ * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener#connectionClosed(org.apache.directory.studio.connection.core.Connection)
+ */
+ 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 );
+ }
+
+
+ /**
+ * Input changed.
+ *
+ * @param input the input
+ */
+ public void inputChanged( Object input )
+ {
+ if ( !isDisposed() )
+ {
+ action.setInput( input );
+ selectionChanged( new SelectionChangedEvent( this.selectionProvider, new StructuredSelection() ) );
+ // updateAction();
+ }
+ }
+
+
+ /**
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ if ( !isDisposed() )
+ {
+ ISelection selection = event.getSelection();
+ action.setSelectedConnections( SelectionUtils.getConnections( selection ) );
+ action.setSelectedConnectionFolders( SelectionUtils.getConnectionFolders( selection ) );
+ updateAction();
+ }
+ }
+
+
+ /**
+ * Updates the action.
+ */
+ public void updateAction()
+ {
+ if ( !isDisposed() )
+ {
+ setText( action.getText() );
+ setToolTipText( action.getText() );
+ setEnabled( action.isEnabled() );
+ setImageDescriptor( action.getImageDescriptor() );
+ }
+ }
+
+
+ /**
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run()
+ {
+ if ( !isDisposed() )
+ {
+ // deactivate global actions
+ if ( actionHandlerManager != null )
+ {
+ actionHandlerManager.deactivateGlobalActionHandlers();
+ }
+
+ action.run();
+
+ // activate global actions
+ if ( actionHandlerManager != null )
+ {
+ actionHandlerManager.activateGlobalActionHandlers();
+ }
+ }
+ }
+
+
+ /**
+ * Gets the real action.
+ *
+ * @return the real action
+ */
+ public StudioAction getAction()
+ {
+ return action;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioActionProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java Mon Nov 5 06:46:32 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/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,66 @@
+/*
+ * 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 CredentialsDialog is used to ask the user for credentials (paasword).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CredentialsDialog extends InputDialog
+{
+
+ /**
+ * Creates a new instance of CredentialsDialog.
+ *
+ * @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 CredentialsDialog( 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 );
+ super.getText().setEchoChar( '*' );
+ return composite;
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CredentialsDialog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,217 @@
+/*
+ * 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.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+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.apache.directory.studio.connection.core.ConnectionManager;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link Connection} objects.
+ * Note that only the connection id is converted to a platform specific
+ * representation, not the complete object. To convert it back to an {@link Connection}
+ * object the {@link ConnectionManager#getConnectionById(String)} method is invoked.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionTransfer extends ByteArrayTransfer
+{
+
+ /** The Constant TYPENAME. */
+ private static final String TYPENAME = "org.apache.directory.studio.ldapbrowser.connection";
+
+ /** The Constant TYPEID. */
+ private static final int TYPEID = registerType( TYPENAME );
+
+ /** The instance. */
+ private static ConnectionTransfer instance = new ConnectionTransfer();
+
+
+ /**
+ * Creates a new instance of ConnectionTransfer.
+ */
+ private ConnectionTransfer()
+ {
+ }
+
+
+ /**
+ * Gets the instance.
+ *
+ * @return the instance
+ */
+ public static ConnectionTransfer getInstance()
+ {
+ return instance;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation only accepts {@link Connection} and {@link ConnectionFolder} objects.
+ * It just converts the id of the connection or connection folder to the platform
+ * specific representation.
+ */
+ public void javaToNative( Object object, TransferData transferData )
+ {
+ if ( object == null || !( object instanceof Object[] ) )
+ {
+ return;
+ }
+
+ if ( isSupportedType( transferData ) )
+ {
+ Object[] objects = ( Object[] ) object;
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DataOutputStream writeOut = new DataOutputStream( out );
+
+ for ( int i = 0; i < objects.length; i++ )
+ {
+ if ( objects[i] instanceof Connection )
+ {
+ byte[] id = ( ( Connection ) objects[i] ).getConnectionParameter().getId().getBytes();
+ writeOut.writeInt( id.length );
+ writeOut.write( id );
+ }
+ else if ( objects[i] instanceof ConnectionFolder )
+ {
+ byte[] id = ( ( ConnectionFolder ) objects[i] ).getId().getBytes();
+ writeOut.writeInt( id.length );
+ writeOut.write( id );
+ }
+ }
+
+ byte[] buffer = out.toByteArray();
+ writeOut.close();
+
+ super.javaToNative( buffer, transferData );
+ }
+ catch ( IOException e )
+ {
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just converts the platform specific representation
+ * to the connection id or connection folder id and invokes
+ * {@link ConnectionManager#getConnectionById(String)} to get the
+ * {@link Connection} object or {@link ConnectionFolderManager#getConnectionFolderById(String)}
+ * to get the {@link ConnectionFolder} object.
+ */
+ public Object nativeToJava( TransferData transferData )
+ {
+ if ( isSupportedType( transferData ) )
+ {
+ byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+ if ( buffer == null )
+ {
+ return null;
+ }
+
+ List<Object> objectList = new ArrayList<Object>();
+ try
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+ DataInputStream readIn = new DataInputStream( in );
+
+ do
+ {
+ if ( readIn.available() > 1 )
+ {
+ int size = readIn.readInt();
+ byte[] id = new byte[size];
+ readIn.read( id );
+ Connection connection = ConnectionCorePlugin.getDefault().getConnectionManager()
+ .getConnectionById( new String( id ) );
+ if ( connection != null )
+ {
+ objectList.add( connection );
+ }
+ else
+ {
+ ConnectionFolder folder = ConnectionCorePlugin.getDefault().getConnectionFolderManager()
+ .getConnectionFolderById( new String( id ) );
+ if ( folder != null )
+ {
+ objectList.add( folder );
+ }
+ }
+ }
+ }
+ while ( readIn.available() > 1 );
+
+ readIn.close();
+ }
+ catch ( IOException ex )
+ {
+ return null;
+ }
+
+ return objectList.toArray();
+ }
+
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String[] getTypeNames()
+ {
+ return new String[]
+ { TYPENAME };
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected int[] getTypeIds()
+ {
+ return new int[]
+ { TYPEID };
+ }
+
+}
\ No newline at end of file
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/ConnectionTransfer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,105 @@
+/*
+ * 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.dnd;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionFolder;
+import org.eclipse.swt.dnd.DragSource;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.DragSourceListener;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+
+/**
+ * This class implements a {@link DragSourceListener} that is used to
+ * drag and drop connections withing the connections view.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DragConnectionListener implements DragSourceListener
+{
+
+ /**
+ * Creates a new instance of DragConnectionListener.
+ */
+ public DragConnectionListener()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation does nothing.
+ */
+ public void dragStart( DragSourceEvent event )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation adds the dragged connections and connection folders to the
+ * given event data.
+ */
+ public void dragSetData( DragSourceEvent event )
+ {
+ if ( ConnectionTransfer.getInstance().isSupportedType( event.dataType ) )
+ {
+ if ( event.widget instanceof DragSource )
+ {
+ DragSource dragSource = ( DragSource ) event.widget;
+ if ( dragSource.getControl() instanceof Tree )
+ {
+ Tree tree = ( Tree ) dragSource.getControl();
+ TreeItem[] items = tree.getSelection();
+ List<Object> objectList = new ArrayList<Object>();
+ for ( int i = 0; i < items.length; i++ )
+ {
+ if ( items[i].getData() instanceof Connection || items[i].getData() instanceof ConnectionFolder )
+ {
+ objectList.add( items[i].getData() );
+ }
+ }
+ event.data = objectList.toArray();
+ }
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation does nothing.
+ */
+ public void dragFinished( DragSourceEvent event )
+ {
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DragConnectionListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DropConnectionListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DropConnectionListener.java?rev=592022&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DropConnectionListener.java (added)
+++ directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DropConnectionListener.java Mon Nov 5 06:46:32 2007
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.connection.ui.dnd;
+
+
+import java.util.Set;
+
+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.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.DropTargetListener;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+
+/**
+ * This class implements a {@link DropTargetListener} that is used to
+ * drag and drop connections within the connections view.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DropConnectionListener implements DropTargetListener
+{
+
+ /**
+ * Creates a new instance of DropConnectionListener.
+ */
+ public DropConnectionListener()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation checks if the event's data type is
+ * supported. If not supported dropping is rejected.
+ */
+ public void dragEnter( DropTargetEvent event )
+ {
+ if ( !ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
+ {
+ event.detail = DND.DROP_NONE;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just calls {@link #dragOver(DropTargetEvent)}.
+ */
+ public void dragOperationChanged( DropTargetEvent event )
+ {
+ dragOver( event );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation does nothing.
+ */
+ public void dragLeave( DropTargetEvent event )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation checks if the event's data type is
+ * supported. If not supported dropping is rejected.
+ */
+ public void dragOver( DropTargetEvent event )
+ {
+ try
+ {
+ // move connection folder: check that the new connection folder is not the same or a parent folder
+ boolean isMoveConnectionFolderForbidden = false;
+ if ( event.detail == DND.DROP_MOVE || event.detail == DND.DROP_NONE )
+ {
+ if ( ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
+ {
+ if ( event.item != null && event.item.getData() instanceof ConnectionFolder )
+ {
+ ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+ .getConnectionFolderManager();
+ ConnectionFolder overFolder = ( ConnectionFolder ) event.item.getData();
+ Set<ConnectionFolder> allParentFolders = connectionFolderManager
+ .getAllParentFolders( overFolder );
+
+ if ( event.widget instanceof DropTarget )
+ {
+ DropTarget dropTarget = ( DropTarget ) event.widget;
+ if ( dropTarget.getControl() instanceof Tree )
+ {
+ Tree tree = ( Tree ) dropTarget.getControl();
+ TreeItem[] items = tree.getSelection();
+ for ( int i = 0; i < items.length; i++ )
+ {
+ if ( items[i].getData() instanceof ConnectionFolder )
+ {
+ ConnectionFolder folder = ( ConnectionFolder ) items[i].getData();
+ if ( allParentFolders.contains( folder ) )
+ {
+ isMoveConnectionFolderForbidden = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if ( !ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
+ {
+ event.detail = DND.DROP_NONE;
+ }
+ else if ( isMoveConnectionFolderForbidden )
+ {
+ event.detail = DND.DROP_NONE;
+ }
+ else if ( event.detail == DND.DROP_LINK )
+ {
+ event.detail = DND.DROP_NONE;
+ }
+ else if ( event.detail == DND.DROP_NONE )
+ {
+ event.detail = DND.DROP_DEFAULT;
+ }
+ }
+ catch ( Exception e )
+ {
+ event.detail = DND.DROP_NONE;
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation does nothing.
+ */
+ public void dropAccept( DropTargetEvent event )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation drops the dragged connection to
+ * the selected position.
+ */
+ public void drop( DropTargetEvent event )
+ {
+ ConnectionManager connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager();
+ ConnectionFolderManager connectionFolderManager = ConnectionCorePlugin.getDefault()
+ .getConnectionFolderManager();
+
+ try
+ {
+ if ( ConnectionTransfer.getInstance().isSupportedType( event.currentDataType ) )
+ {
+ // get connection and folders to handle
+ Object[] objects = ( Object[] ) event.data;
+ Object target = event.item != null ? event.item.getData() : connectionFolderManager
+ .getRootConnectionFolder();
+
+ ConnectionFolder targetFolder = null;
+ if ( target instanceof ConnectionFolder )
+ {
+ targetFolder = ( ConnectionFolder ) target;
+ }
+ else if ( target instanceof Connection )
+ {
+ Connection connection = ( Connection ) target;
+ targetFolder = connectionFolderManager.getParentConnectionFolder( connection );
+ }
+
+ for ( Object object : objects )
+ {
+ if ( object instanceof Connection )
+ {
+ Connection connection = ( Connection ) object;
+ if ( event.detail == DND.DROP_MOVE )
+ {
+ ConnectionFolder parentConnectionFolder = connectionFolderManager
+ .getParentConnectionFolder( connection );
+ parentConnectionFolder.removeConnectionId( connection.getId() );
+ targetFolder.addConnectionId( connection.getId() );
+ }
+ else if ( event.detail == DND.DROP_COPY )
+ {
+ Connection newConnection = ( Connection ) connection.clone();
+ connectionManager.addConnection( newConnection );
+ targetFolder.addConnectionId( newConnection.getId() );
+ }
+ }
+ else if ( object instanceof ConnectionFolder )
+ {
+ ConnectionFolder folder = ( ConnectionFolder ) object;
+ if ( event.detail == DND.DROP_MOVE )
+ {
+ ConnectionFolder parentConnectionFolder = connectionFolderManager
+ .getParentConnectionFolder( folder );
+ parentConnectionFolder.removeSubFolderId( folder.getId() );
+ targetFolder.addSubFolderId( folder.getId() );
+ // TODO: expand target folder
+ }
+ else if ( event.detail == DND.DROP_COPY )
+ {
+ ConnectionFolder newFolder = ( ConnectionFolder ) folder.clone();
+ connectionFolderManager.addConnectionFolder( newFolder );
+ targetFolder.addSubFolderId( newFolder.getId() );
+ // TODO: expand target folder
+ }
+ }
+ }
+ }
+ else
+ {
+ event.detail = DND.DROP_NONE;
+ }
+ }
+ catch ( Exception e )
+ {
+ event.detail = DND.DROP_NONE;
+ e.printStackTrace();
+ }
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-connection-ui/src/main/java/org/apache/directory/studio/connection/ui/dnd/DropConnectionListener.java
------------------------------------------------------------------------------
svn:eol-style = native