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/04/09 11:49:57 UTC
svn commit: r526693 [3/17] - in
/directory/ldapstudio/trunk/ldapstudio-browser-common: ./ META-INF/
resources/ resources/icons/ resources/templates/ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/dir...
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/CopyAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/CopyAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/CopyAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,345 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+import org.apache.directory.ldapstudio.browser.common.actions.proxy.BrowserActionProxy;
+import org.apache.directory.ldapstudio.browser.common.dnd.ConnectionTransfer;
+import org.apache.directory.ldapstudio.browser.common.dnd.EntryTransfer;
+import org.apache.directory.ldapstudio.browser.common.dnd.ValuesTransfer;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+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 Copy Action
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CopyAction extends BrowserAction
+{
+ protected BrowserActionProxy pasteActionProxy;
+
+
+ /**
+ * Creates a new instance of CopyAction.
+ *
+ * @param pasteActionProxy
+ * the associated Paste Action
+ */
+ public CopyAction( BrowserActionProxy pasteActionProxy )
+ {
+ super();
+ this.pasteActionProxy = pasteActionProxy;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+
+ // connection
+ IConnection[] connections = getConnections();
+ if ( connections != null )
+ {
+ return connections.length > 1 ? "Copy Connections" : "Copy Connection";
+ }
+
+ // entry/searchresult/bookmark
+ IEntry[] entries = getEntries();
+ if ( entries != null )
+ {
+ return entries.length > 1 ? "Copy Entries / DNs" : "Copy Entry / DN";
+ }
+
+ // values
+ IValue[] values = getValues();
+ if ( values != null )
+ {
+ return values.length > 1 ? "Copy Values" : "Copy Value";
+ }
+
+ return "Copy";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_COPY );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return IWorkbenchActionDefinitionIds.COPY;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ IConnection[] connections = getConnections();
+ IEntry[] entries = getEntries();
+ IValue[] values = getValues();
+
+ // connection
+ if ( connections != null )
+ {
+ copyToClipboard( new Object[]
+ { connections }, new Transfer[]
+ { ConnectionTransfer.getInstance() } );
+ }
+
+ // entry/searchresult/bookmark
+ else if ( entries != null )
+ {
+ StringBuffer text = new StringBuffer();
+ for ( int i = 0; i < entries.length; i++ )
+ {
+ text.append( entries[i].getDn().toString() );
+ if ( i + 1 < entries.length )
+ {
+ text.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ }
+ copyToClipboard( new Object[]
+ { entries, text.toString() }, new Transfer[]
+ { EntryTransfer.getInstance(), TextTransfer.getInstance() } );
+ }
+
+ // values
+ else if ( values != null )
+ {
+
+ // LdifAttrValLine[] lines = new LdifAttrValLine[values.length];
+ StringBuffer text = new StringBuffer();
+
+ for ( int i = 0; i < values.length; i++ )
+ {
+
+ // lines[i] = ModelConverter.valueToLdifAttrValLine(values[i]);
+
+ if ( values[i].isString() )
+ {
+ text.append( values[i].getStringValue() );
+ }
+ else if ( values[i].isBinary() )
+ {
+ text.append( LdifUtils.base64encode( values[i].getBinaryValue() ) );
+ }
+ if ( i + 1 < values.length )
+ {
+ text.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ }
+
+ copyToClipboard( new Object[]
+ { values, text.toString() }, new Transfer[]
+ { ValuesTransfer.getInstance(), TextTransfer.getInstance() } );
+ }
+
+ // update paste action
+ if ( this.pasteActionProxy != null )
+ {
+ this.pasteActionProxy.updateAction();
+ }
+ }
+
+
+ /**
+ * Copies data to Clipboard
+ *
+ * @param data
+ * the data to be set in the clipboard
+ * @param dataTypes
+ * the transfer agents that will convert the data to its platform specific format;
+ * each entry in the data array must have a corresponding dataType
+ */
+ public static void copyToClipboard( Object[] data, Transfer[] dataTypes )
+ {
+ Clipboard clipboard = null;
+ try
+ {
+ clipboard = new Clipboard( Display.getCurrent() );
+ clipboard.setContents( data, dataTypes );
+ }
+ finally
+ {
+ if ( clipboard != null )
+ clipboard.dispose();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+
+ // connection
+ if ( getConnections() != null )
+ {
+ return true;
+ }
+
+ // entry/searchresult/bookmark
+ else if ( getEntries() != null )
+ {
+ return true;
+ }
+
+ // values
+ else if ( getValues() != null )
+ {
+ return true;
+ }
+
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * Get the Connections
+ *
+ * @return
+ * the Connections
+ */
+ private IConnection[] getConnections()
+ {
+
+ if ( getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length
+ + getSelectedSearches().length + getSelectedAttributeHierarchies().length + getSelectedAttributes().length
+ + getSelectedValues().length == 0
+ && getSelectedConnections().length > 0 )
+ {
+ return getSelectedConnections();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Get the Entries
+ *
+ * @return
+ * the Entries
+ */
+ private IEntry[] getEntries()
+ {
+ if ( getSelectedConnections().length + getSelectedSearches().length + getSelectedAttributeHierarchies().length
+ + getSelectedAttributes().length + getSelectedValues().length == 0
+ && getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length > 0 )
+ {
+
+ LinkedHashSet entriesSet = new LinkedHashSet();
+ for ( int i = 0; i < getSelectedEntries().length; i++ )
+ {
+ entriesSet.add( getSelectedEntries()[i] );
+ }
+ for ( int i = 0; i < this.getSelectedSearchResults().length; i++ )
+ {
+ entriesSet.add( this.getSelectedSearchResults()[i].getEntry() );
+ }
+ for ( int i = 0; i < this.getSelectedBookmarks().length; i++ )
+ {
+ entriesSet.add( this.getSelectedBookmarks()[i].getEntry() );
+ }
+ return ( IEntry[] ) entriesSet.toArray( new IEntry[entriesSet.size()] );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Get the Values
+ *
+ * @return
+ * the Values
+ */
+ private IValue[] getValues()
+ {
+ if ( getSelectedConnections().length + getSelectedBookmarks().length + getSelectedEntries().length
+ + getSelectedSearches().length == 0
+ && getSelectedAttributeHierarchies().length + getSelectedAttributes().length + getSelectedValues().length > 0 )
+ {
+
+ LinkedHashSet valuesSet = new LinkedHashSet();
+ for ( int i = 0; i < this.getSelectedAttributeHierarchies().length; i++ )
+ {
+ IAttribute[] attributes = getSelectedAttributeHierarchies()[i].getAttributes();
+ for ( int k = 0; k < attributes.length; k++ )
+ {
+ valuesSet.addAll( Arrays.asList( attributes[k].getValues() ) );
+ }
+ }
+ for ( int i = 0; i < this.getSelectedAttributes().length; i++ )
+ {
+ valuesSet.addAll( Arrays.asList( this.getSelectedAttributes()[i].getValues() ) );
+ }
+ for ( int i = 0; i < this.getSelectedValues().length; i++ )
+ {
+ valuesSet.add( this.getSelectedValues()[i] );
+ }
+ return ( IValue[] ) valuesSet.toArray( new IValue[valuesSet.size()] );
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,753 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.jobs.DeleteAttributesValueJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.DeleteEntriesJob;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IBookmark;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.RDNPart;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
+
+
+/**
+ * This Action implements the Delete Action. It deletes Connections, Entries, Searches, Bookmarks, Attributes or Values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DeleteAction extends BrowserAction
+{
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ try
+ {
+ IConnection[] connections = getConnections();
+ IEntry[] entries = getEntries();
+ ISearch[] searches = getSearches();
+ IBookmark[] bookmarks = getBookmarks();
+ IAttribute[] attributes = getAttributes();
+ IValue[] values = getValues();
+
+ if ( connections.length > 0 && entries.length == 0 && searches.length == 0 && bookmarks.length == 0
+ && attributes.length == 0 && values.length == 0 )
+ {
+ return connections.length > 1 ? "Delete Connections" : "Delete Connection";
+ }
+ if ( entries.length > 0 && connections.length == 0 && searches.length == 0 && bookmarks.length == 0
+ && attributes.length == 0 && values.length == 0 )
+ {
+ return entries.length > 1 ? "Delete Entries" : "Delete Entry";
+ }
+ if ( searches.length > 0 && connections.length == 0 && entries.length == 0 && bookmarks.length == 0
+ && attributes.length == 0 && values.length == 0 )
+ {
+ return searches.length > 1 ? "Delete Searches" : "Delete Search";
+ }
+ if ( bookmarks.length > 0 && connections.length == 0 && entries.length == 0 && searches.length == 0
+ && attributes.length == 0 && values.length == 0 )
+ {
+ return bookmarks.length > 1 ? "Delete Bookmarks" : "Delete Bookmark";
+ }
+ if ( attributes.length > 0 && connections.length == 0 && entries.length == 0 && searches.length == 0
+ && bookmarks.length == 0 && values.length == 0 )
+ {
+ return attributes.length > 1 ? "Delete Attributes" : "Delete Attribute";
+ }
+ if ( values.length > 0 && connections.length == 0 && entries.length == 0 && searches.length == 0
+ && bookmarks.length == 0 && attributes.length == 0 )
+ {
+ return values.length > 1 ? "Delete Values" : "Delete Value";
+ }
+ }
+ catch ( Exception e )
+ {
+ }
+
+ return "Delete";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_DELETE );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return IWorkbenchActionDefinitionIds.DELETE;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ try
+ {
+ IConnection[] connections = getConnections();
+ IEntry[] entries = getEntries();
+ ISearch[] searches = getSearches();
+ IBookmark[] bookmarks = getBookmarks();
+ IAttribute[] attributes = getAttributes();
+ IValue[] values = getValues();
+
+ StringBuffer message = new StringBuffer();
+
+ if ( connections.length > 0 )
+ {
+ 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( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( connections[i].getName() );
+ }
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected connections?" );
+ }
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( entries.length > 0 )
+ {
+ if ( entries.length <= 5 )
+ {
+ message
+ .append( entries.length == 1 ? "Are your sure to delete the following entry, including all children?"
+ : "Are your sure to delete the following entries, including all children?" );
+ for ( int i = 0; i < entries.length; i++ )
+ {
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( entries[i].getDn() );
+ }
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected entries, including all children?" );
+ }
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( searches.length > 0 )
+ {
+ if ( searches.length <= 5 )
+ {
+ message.append( searches.length == 1 ? "Are your sure to delete the following search?"
+ : "Are your sure to delete the following searches?" );
+ for ( int i = 0; i < searches.length; i++ )
+ {
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( searches[i].getName() );
+ }
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected searches?" );
+ }
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( bookmarks.length > 0 )
+ {
+ if ( bookmarks.length <= 5 )
+ {
+ message.append( bookmarks.length == 1 ? "Are your sure to delete the following bookmark?"
+ : "Are your sure to delete the following bookmarks?" );
+ for ( int i = 0; i < bookmarks.length; i++ )
+ {
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( bookmarks[i].getName() );
+ }
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected bookmarks?" );
+ }
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( attributes.length > 0 )
+ {
+ if ( attributes.length <= 5 )
+ {
+ message.append( attributes.length == 1 ? "Are your sure to delete the following attribute?"
+ : "Are your sure to delete the following attribute?" );
+ for ( int i = 0; i < attributes.length; i++ )
+ {
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( attributes[i].getDescription() );
+ }
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected attributes?" );
+ }
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( values.length > 0 )
+ {
+ boolean emptyValuesOnly = true;
+ for ( int i = 0; i < values.length; i++ )
+ {
+ if ( !values[i].isEmpty() )
+ {
+ emptyValuesOnly = false;
+ }
+ }
+ if ( !emptyValuesOnly )
+ {
+ if ( values.length <= 5 )
+ {
+ message.append( values.length == 1 ? "Are your sure to delete the following value?"
+ : "Are your sure to delete the following values?" );
+ for ( int i = 0; i < values.length; i++ )
+ {
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( " - " );
+ message.append( values[i].toString() );
+ }
+ }
+ else
+ {
+ message.append( "Are your sure to delete the selected values?" );
+ }
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ message.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+ }
+
+ if ( message.length() == 0 || MessageDialog.openConfirm( getShell(), getText(), message.toString() ) )
+ {
+
+ if ( connections.length > 0 )
+ {
+ deleteConnections( connections );
+ }
+ if ( entries.length > 0 )
+ {
+ deleteEntries( entries );
+ }
+ if ( searches.length > 0 )
+ {
+ deleteSearches( searches );
+ }
+ if ( bookmarks.length > 0 )
+ {
+ deleteBookmarks( bookmarks );
+ }
+ if ( attributes.length + values.length > 0 )
+ {
+
+ List attributeList = new ArrayList( Arrays.asList( attributes ) );
+ List valueList = new ArrayList( Arrays.asList( values ) );
+
+ // filter empty attributes and values
+ for ( Iterator it = attributeList.iterator(); it.hasNext(); )
+ {
+ IAttribute att = ( IAttribute ) it.next();
+ IValue[] vals = att.getValues();
+ for ( int i = 0; i < vals.length; i++ )
+ {
+ if ( vals[i].isEmpty() )
+ {
+ att.deleteEmptyValue();
+ }
+ }
+ if ( att.getValueSize() == 0 )
+ {
+ try
+ {
+ att.getEntry().deleteAttribute( att );
+ }
+ catch ( ModelModificationException e )
+ {
+ }
+ it.remove();
+ }
+ }
+ for ( Iterator it = valueList.iterator(); it.hasNext(); )
+ {
+ IValue value = ( IValue ) it.next();
+ if ( value.isEmpty() )
+ {
+ value.getAttribute().deleteEmptyValue();
+ it.remove();
+ }
+ }
+
+ if ( !attributeList.isEmpty() || !valueList.isEmpty() )
+ {
+ deleteAttributesAndValues( ( IAttribute[] ) attributeList.toArray( new IAttribute[attributeList
+ .size()] ), ( IValue[] ) valueList.toArray( new IValue[valueList.size()] ) );
+ }
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ try
+ {
+ IConnection[] connections = getConnections();
+ IEntry[] entries = getEntries();
+ ISearch[] searches = getSearches();
+ IBookmark[] bookmarks = getBookmarks();
+ IAttribute[] attributes = getAttributes();
+ IValue[] values = getValues();
+
+ return connections.length + entries.length + searches.length + bookmarks.length + attributes.length
+ + values.length > 0;
+
+ }
+ catch ( Exception e )
+ {
+ // e.printStackTrace();
+ return false;
+ }
+ }
+
+
+ /**
+ * Gets the Connections
+ *
+ * @return
+ * the Connections
+ * @throws Exception
+ * when a is opened
+ */
+ protected IConnection[] getConnections() throws Exception
+ {
+ for ( int i = 0; i < getSelectedConnections().length; i++ )
+ {
+ if ( getSelectedConnections()[i].isOpened() )
+ {
+ throw new Exception();
+ }
+ }
+
+ return getSelectedConnections();
+ }
+
+
+ /**
+ * Deletes Connections
+ *
+ * @param connections
+ * the Connections to delete
+ */
+ protected void deleteConnections( IConnection[] connections )
+ {
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ BrowserCorePlugin.getDefault().getConnectionManager().removeConnection( connections[i] );
+ }
+ }
+
+
+ /**
+ * Gets the Entries.
+ *
+ * @return
+ * the Entries
+ * @throws Exception
+ * when an Entry has parent Entries
+ */
+ protected IEntry[] getEntries() throws Exception
+ {
+ LinkedHashSet entriesSet = new LinkedHashSet();
+ for ( int i = 0; i < getSelectedEntries().length; i++ )
+ {
+ if ( !getSelectedEntries()[i].hasParententry() )
+ {
+ throw new Exception();
+ }
+ entriesSet.add( getSelectedEntries()[i] );
+ }
+ for ( int i = 0; i < this.getSelectedSearchResults().length; i++ )
+ {
+ if ( !getSelectedSearchResults()[i].getEntry().hasParententry() )
+ {
+ throw new Exception();
+ }
+ entriesSet.add( this.getSelectedSearchResults()[i].getEntry() );
+ }
+
+ IEntry[] allEntries = ( IEntry[] ) entriesSet.toArray( new IEntry[entriesSet.size()] );
+ for ( int i = 0; i < allEntries.length; i++ )
+ {
+ IEntry entry = allEntries[i];
+ if ( entriesSet.contains( entry.getParententry() ) )
+ {
+ entriesSet.remove( entry );
+ }
+ }
+
+ return ( IEntry[] ) entriesSet.toArray( new IEntry[entriesSet.size()] );
+ }
+
+
+ /**
+ * Deletes Entries
+ *
+ * @param entries
+ * the Entries to delete
+ */
+ protected void deleteEntries( IEntry[] entries )
+ {
+ new DeleteEntriesJob( entries ).execute();
+ }
+
+
+ /**
+ * Gets the Searches
+ *
+ * @return
+ * the Searches
+ * @throws Exception
+ */
+ protected ISearch[] getSearches() throws Exception
+ {
+ return getSelectedSearches();
+ }
+
+
+ /**
+ * Delete Searches
+ *
+ * @param searches
+ * the Searches to delete
+ */
+ protected void deleteSearches( ISearch[] searches )
+ {
+ for ( int i = 0; i < searches.length; i++ )
+ {
+ ISearch search = searches[i];
+ search.getConnection().getSearchManager().removeSearch( search );
+ }
+ }
+
+
+ /**
+ * Get the Bookmarks
+ *
+ * @return
+ * @throws Exception
+ */
+ protected IBookmark[] getBookmarks() throws Exception
+ {
+ return getSelectedBookmarks();
+ }
+
+
+ /**
+ * Delete Bookmarks
+ *
+ * @param bookmarks
+ * the Bookmarks to delete
+ */
+ protected void deleteBookmarks( IBookmark[] bookmarks )
+ {
+ for ( int i = 0; i < bookmarks.length; i++ )
+ {
+ IBookmark bookmark = bookmarks[i];
+ bookmark.getConnection().getBookmarkManager().removeBookmark( bookmark );
+ }
+ }
+
+
+ /**
+ * Gets the Attributes
+ *
+ * @return
+ * the Attributes
+ * @throws Exception
+ */
+ protected IAttribute[] getAttributes() throws Exception
+ {
+
+ for ( int i = 0; i < getSelectedAttributes().length; i++ )
+ {
+ // check if a non-modifyable, must or objectClass attribute is
+ // selected
+ IAttribute att = getSelectedAttributes()[i];
+ if ( !SchemaUtils.isModifyable( att.getAttributeTypeDescription() ) || att.isMustAttribute()
+ || att.isObjectClassAttribute() )
+ {
+ throw new Exception();
+ }
+ }
+
+ for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ )
+ {
+ // check if a non-modifyable, must or objectClass attribute is
+ // selected
+ AttributeHierarchy ah = getSelectedAttributeHierarchies()[i];
+ for ( Iterator it = ah.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ if ( !SchemaUtils.isModifyable( attribute.getAttributeTypeDescription() )
+ || attribute.isMustAttribute() || attribute.isObjectClassAttribute() )
+ {
+ throw new Exception();
+ }
+ }
+ }
+
+ List attributeList = new ArrayList();
+
+ // add selected attributes
+ for ( int i = 0; i < getSelectedAttributes().length; i++ )
+ {
+ IAttribute attribute = getSelectedAttributes()[i];
+ if ( attribute != null && attribute.getValueSize() > 0 )
+ {
+ attributeList.add( attribute );
+ }
+ }
+
+ // add selected hierarchies
+ for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ )
+ {
+ // check if a operational, must or objectClass attribute is
+ // selected
+ AttributeHierarchy ah = getSelectedAttributeHierarchies()[i];
+ for ( Iterator it = ah.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ if ( attribute != null && attribute.getValueSize() > 0 )
+ {
+ attributeList.add( attribute );
+ }
+ }
+ }
+
+ // check if ALL values of an attribute are selected -> delete whole
+ // attribute
+ Map attributeNameToSelectedValuesCountMap = new HashMap();
+ for ( int i = 0; i < getSelectedValues().length; i++ )
+ {
+ if ( !attributeNameToSelectedValuesCountMap.containsKey( getSelectedValues()[i].getAttribute()
+ .getDescription() ) )
+ {
+ attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
+ new Integer( 0 ) );
+ }
+ int count = ( ( Integer ) attributeNameToSelectedValuesCountMap.get( getSelectedValues()[i].getAttribute()
+ .getDescription() ) ).intValue() + 1;
+ attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
+ new Integer( count ) );
+ if ( count >= getSelectedValues()[i].getAttribute().getValueSize() )
+ {
+ IAttribute attribute = getSelectedValues()[i].getAttribute();
+ if ( attribute != null && !attributeList.contains( attribute ) )
+ {
+ attributeList.add( attribute );
+ }
+ }
+ }
+
+ return ( IAttribute[] ) attributeList.toArray( new IAttribute[attributeList.size()] );
+ }
+
+
+ /**
+ * Gets the Values
+ *
+ * @return
+ * the Values
+ * @throws Exception
+ */
+ protected IValue[] getValues() throws Exception
+ {
+
+ Map attributeNameToSelectedValuesCountMap = new HashMap();
+ Set selectedObjectClasses = new HashSet();
+ for ( int i = 0; i < getSelectedValues().length; i++ )
+ {
+ // check if a value of an operational attribute is selected
+ if ( !SchemaUtils.isModifyable( getSelectedValues()[i].getAttribute().getAttributeTypeDescription() ) )
+ {
+ throw new Exception();
+ }
+
+ // check if (part of) RDN is selected
+ RDNPart[] parts = this.getSelectedValues()[i].getAttribute().getEntry().getRdn().getParts();
+ for ( int p = 0; p < parts.length; p++ )
+ {
+ if ( getSelectedValues()[i].getAttribute().getDescription().equals( parts[p].getType() )
+ && getSelectedValues()[i].getStringValue().equals( parts[p].getValue() ) )
+ {
+ throw new Exception();
+ }
+ }
+
+ // check if a required objectClass is selected
+ if ( getSelectedValues()[i].getAttribute().isObjectClassAttribute() )
+ {
+ selectedObjectClasses.add( getSelectedValues()[i].getStringValue() );
+ }
+
+ // check if ALL values of objectClass or a MUST attribute are
+ // selected
+ if ( !attributeNameToSelectedValuesCountMap.containsKey( getSelectedValues()[i].getAttribute()
+ .getDescription() ) )
+ {
+ attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
+ new Integer( 0 ) );
+ }
+ int count = ( ( Integer ) attributeNameToSelectedValuesCountMap.get( getSelectedValues()[i].getAttribute()
+ .getDescription() ) ).intValue() + 1;
+ attributeNameToSelectedValuesCountMap.put( getSelectedValues()[i].getAttribute().getDescription(),
+ new Integer( count ) );
+ if ( ( getSelectedValues()[i].getAttribute().isObjectClassAttribute() || getSelectedValues()[i]
+ .getAttribute().isMustAttribute() /*
+ * || this.selectedEntry ==
+ * null
+ */)
+ && count >= getSelectedValues()[i].getAttribute().getValueSize() )
+ {
+ throw new Exception();
+ }
+ }
+ // check if a required objectClass is selected
+ if ( getSelectedValues().length > 0 && !selectedObjectClasses.isEmpty() )
+ {
+ IEntry entry = getSelectedValues()[0].getAttribute().getEntry();
+ // get remaining attributes
+ String[] ocValues = entry.getSubschema().getObjectClassNames();
+ Set remainingObjectClassesSet = new HashSet( Arrays.asList( ocValues ) );
+ remainingObjectClassesSet.removeAll( selectedObjectClasses );
+ Set remainingAttributeSet = new HashSet();
+ for ( Iterator it = remainingObjectClassesSet.iterator(); it.hasNext(); )
+ {
+ String oc = ( String ) it.next();
+ ObjectClassDescription ocd = entry.getConnection().getSchema().getObjectClassDescription( oc );
+ if ( ocd != null )
+ {
+ remainingAttributeSet
+ .addAll( Arrays.asList( ocd.getMustAttributeTypeDescriptionNamesTransitive() ) );
+ remainingAttributeSet.addAll( Arrays.asList( ocd.getMayAttributeTypeDescriptionNamesTransitive() ) );
+ }
+ }
+ // check against attributes
+ IAttribute[] attributes = entry.getAttributes();
+ for ( int i = 0; i < attributes.length; i++ )
+ {
+ IAttribute attribute = attributes[i];
+ if ( attribute.isMayAttribute() || attribute.isMustAttribute() )
+ {
+ if ( !remainingAttributeSet.contains( attribute.getType() ) )
+ {
+ throw new Exception();
+ }
+ }
+ }
+ }
+
+ List valueList = new ArrayList();
+
+ // add selected values
+ Set attributeSet = new HashSet( Arrays.asList( getAttributes() ) );
+ for ( int i = 0; i < getSelectedValues().length; i++ )
+ {
+ if ( !attributeSet.contains( getSelectedValues()[i].getAttribute() ) )
+ {
+ valueList.add( getSelectedValues()[i] );
+ }
+ }
+
+ return ( IValue[] ) valueList.toArray( new IValue[valueList.size()] );
+ }
+
+
+ /**
+ * Deletes Attributes and Values
+ *
+ * @param attributes
+ * the Attributes to delete
+ * @param values
+ * the Values to delete
+ */
+ protected void deleteAttributesAndValues( IAttribute[] attributes, IValue[] values )
+ {
+ new DeleteAttributesValueJob( attributes, values ).execute();
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAllValuesAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAllValuesAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAllValuesAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/DeleteAllValuesAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+/**
+ * This Action deletes all the values of an Attribute (a whole Attribute).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DeleteAllValuesAction extends DeleteAction
+{
+ /**
+ * Creates a new instance of DeleteAllValuesAction.
+ */
+ public DeleteAllValuesAction()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ super.run();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ if ( getSelectedValues().length == 1 )
+ {
+ return "Delete Attribute '" + getSelectedValues()[0].getAttribute().getDescription() + "'";
+ }
+ else
+ {
+ return "Delete Attribute";
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_DELETE_ALL );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return super.isEnabled();
+ // return getSelectedAttributes().length == 0 &&
+ // getSelectedValues().length == 1 &&
+ // getSelectedValues()[0].getAttribute().getValueSize() > 1 &&
+ // !getSelectedValues()[0].getAttribute().isMustAttribute() &&
+ // !getSelectedValues()[0].getAttribute().isObjectClassAttribute() &&
+ // !getSelectedValues()[0].getAttribute().isOperationalAttribute();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected IAttribute[] getAttributes() throws Exception
+ {
+ if ( getSelectedAttributes().length == 0 && getSelectedValues().length == 1
+ && getSelectedValues()[0].getAttribute().getValueSize() > 1
+ && !getSelectedValues()[0].getAttribute().isMustAttribute()
+ && !getSelectedValues()[0].getAttribute().isObjectClassAttribute()
+ && SchemaUtils.isModifyable( getSelectedValues()[0].getAttribute().getAttributeTypeDescription() ) )
+ {
+
+ return new IAttribute[]
+ { getSelectedValues()[0].getAttribute() };
+
+ }
+ else
+ {
+ return new IAttribute[0];
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected IValue[] getValues() throws Exception
+ {
+ return new IValue[0];
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/FilterChildrenAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/FilterChildrenAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/FilterChildrenAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/FilterChildrenAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.dialogs.FilterWidgetDialog;
+import org.apache.directory.ldapstudio.browser.core.jobs.InitializeChildrenJob;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+/**
+ * This action opens the Filter Children Dialog and sets the children filter to the
+ * currently selected entry. It is useful when browsing the DIT and entries with
+ * many child nodes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FilterChildrenAction extends BrowserAction
+{
+
+ /**
+ * Creates a new instance of FilterChildrenAction.
+ */
+ public FilterChildrenAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ if ( getSelectedEntries().length == 1 )
+ {
+ FilterWidgetDialog dialog = new FilterWidgetDialog( getShell(), "Filter Children", getSelectedEntries()[0]
+ .getChildrenFilter(), getSelectedEntries()[0].getConnection() );
+ if ( dialog.open() == Dialog.OK )
+ {
+ String newFilter = dialog.getFilter();
+
+ if ( newFilter == null || "".equals( newFilter.trim() ) )
+ {
+ getSelectedEntries()[0].setChildrenFilter( null );
+ }
+ else
+ {
+ getSelectedEntries()[0].setChildrenFilter( newFilter.trim() );
+ }
+ new InitializeChildrenJob( new IEntry[]
+ { getSelectedEntries()[0] } ).execute();
+
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return "Filter Children...";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_FILTER_DIT );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return getSelectedSearches().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 0
+ && getSelectedEntries().length == 1
+ && ( getSelectedEntries()[0].hasChildren() || getSelectedEntries()[0].getChildrenFilter() != null );
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewAttributeAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewAttributeAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewAttributeAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewAttributeAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.wizards.AttributeWizard;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This Action creates a new Attribute
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewAttributeAction extends BrowserAction
+{
+ /**
+ * Creates a new instance of NewAttributeAction.
+ */
+ public NewAttributeAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose()
+ {
+ super.dispose();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+
+ IEntry entry = null;
+ if ( getInput() != null && getInput() instanceof IEntry )
+ {
+ entry = ( IEntry ) getInput();
+ }
+ else if ( getSelectedEntries().length > 0 )
+ {
+ entry = getSelectedEntries()[0];
+ }
+ else if ( getSelectedAttributes().length > 0 )
+ {
+ entry = getSelectedAttributes()[0].getEntry();
+ }
+ else if ( getSelectedValues().length > 0 )
+ {
+ entry = getSelectedValues()[0].getAttribute().getEntry();
+ }
+
+ if ( entry != null )
+ {
+ AttributeWizard wizard = new AttributeWizard( "New Attribute", true, true, null, entry );
+ WizardDialog dialog = new WizardDialog( getShell(), wizard );
+ dialog.setBlockOnOpen( true );
+ dialog.create();
+ if ( dialog.open() == WizardDialog.OK )
+ {
+ String newAttributeDescription = wizard.getAttributeDescription();
+ if ( newAttributeDescription != null && !"".equals( newAttributeDescription ) )
+ {
+ try
+ {
+ IAttribute att = entry.getAttribute( newAttributeDescription );
+ if ( att == null )
+ {
+ att = new Attribute( entry, newAttributeDescription );
+ entry.addAttribute( att ) ;
+ }
+
+ att.addEmptyValue();
+ }
+ catch ( ModelModificationException mme )
+ {
+ MessageDialog.openError( Display.getDefault().getActiveShell(), "Error While Adding Attribute",
+ mme.getMessage() );
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return "New Attribute...";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_ATTRIBUTE_ADD );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return "org.apache.directory.ldapstudio.browser.action.addAttribute";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+
+ if ( ( getSelectedSearchResults().length == 1 && getSelectedAttributes().length > 0 ) )
+ {
+ return false;
+ }
+
+ return ( ( getInput() != null && getInput() instanceof IEntry ) || getSelectedEntries().length == 1
+ || getSelectedAttributes().length > 0 || getSelectedValues().length > 0 );
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewConnectionAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewConnectionAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewConnectionAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewConnectionAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.wizards.NewConnectionWizard;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.wizard.WizardDialog;
+
+
+/**
+ * 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 BrowserAction
+{
+ /**
+ * Creates a new instance of NewConnectionAction.
+ */
+ public NewConnectionAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ NewConnectionWizard wizard = new NewConnectionWizard();
+ 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 BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_CONNECTION_ADD );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ return true;
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewValueAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewValueAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewValueAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/NewValueAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+/**
+ * This Action adds a new Value to an Attribute.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewValueAction extends BrowserAction
+{
+ /**
+ * Creates a new instance of NewValueAction.
+ */
+ public NewValueAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose()
+ {
+ super.dispose();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ if ( getSelectedValues().length == 1 )
+ {
+ getSelectedValues()[0].getAttribute().addEmptyValue();
+ }
+ else if ( getSelectedAttributes().length == 1 )
+ {
+ getSelectedAttributes()[0].addEmptyValue();
+ }
+ else if ( getSelectedAttributeHierarchies().length == 1 )
+ {
+ getSelectedAttributeHierarchies()[0].getAttribute().addEmptyValue();
+ }
+
+ if ( getSelectedSearchResults().length > 0 )
+ {
+
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ return "New Value";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_VALUE_ADD );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getCommandId()
+ {
+ return "org.apache.directory.ldapstudio.browser.action.addValue";
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ // System.out.println(getSelectedAttributeArrays());
+ // System.out.print("==> ");
+ // IAttribute[][] attArr = getSelectedAttributeArrays();
+ // for (int i = 0; i < attArr.length; i++) {
+ // for (int j = 0; j < attArr[i].length; j++) {
+ // IAttribute att = attArr[i][j];
+ // System.out.print(att + "|");
+ // }
+ // }
+ // System.out.println();
+
+ return ( getSelectedSearchResults().length == 0 && getSelectedAttributes().length == 0
+ && getSelectedValues().length == 1 && SchemaUtils.isModifyable( getSelectedValues()[0].getAttribute()
+ .getAttributeTypeDescription() ) )
+
+ || ( getSelectedSearchResults().length == 0 && getSelectedValues().length == 0
+ && getSelectedAttributes().length == 1 && SchemaUtils.isModifyable( getSelectedAttributes()[0]
+ .getAttributeTypeDescription() ) )
+
+ || ( getSelectedSearchResults().length == 1 && getSelectedValues().length == 0
+ && getSelectedAttributes().length == 0 && getSelectedAttributeHierarchies().length == 1 && SchemaUtils
+ .isModifyable( getSelectedAttributeHierarchies()[0].getAttribute().getAttributeTypeDescription() ) );
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/OpenConnectionAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/OpenConnectionAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/OpenConnectionAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/OpenConnectionAction.java Mon Apr 9 02:49:48 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.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.jobs.OpenConnectionsJob;
+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 BrowserAction
+{
+ /**
+ * 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 BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.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].canOpen() )
+ {
+ canOpen = true;
+ break;
+ }
+ }
+ return getSelectedConnections().length > 0 && canOpen;
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PasteAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PasteAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PasteAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.common.dialogs.ScopeDialog;
+import org.apache.directory.ldapstudio.browser.common.dnd.ConnectionTransfer;
+import org.apache.directory.ldapstudio.browser.common.dnd.EntryTransfer;
+import org.apache.directory.ldapstudio.browser.common.dnd.ValuesTransfer;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.jobs.CopyEntriesJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.CreateValuesJob;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContentRecord;
+
+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 BrowserAction
+{
+ /**
+ * Creates a new instance of PasteAction.
+ */
+ public PasteAction()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText()
+ {
+ // connection
+ IConnection[] connections = getConnectionsToPaste();
+ if ( connections != null )
+ {
+ return connections.length > 1 ? "Paste Connections" : "Paste Connection";
+ }
+
+ // entry
+ IEntry[] entries = getEntriesToPaste();
+ if ( entries != null )
+ {
+ return entries.length > 1 ? "Paste Entries" : "Paste Entry";
+ }
+
+ // value
+ IValue[] values = getValuesToPaste();
+ if ( values != null )
+ {
+ return values.length > 1 ? "Paste Values" : "Paste Value";
+ }
+
+ 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()
+ {
+
+ // connection
+ if ( getConnectionsToPaste() != null )
+ {
+ return true;
+ }
+
+ // entry
+ else if ( getEntriesToPaste() != null )
+ {
+ return true;
+ }
+
+ // value
+ else if ( getValuesToPaste() != null )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ // connection
+ IConnection[] connections = getConnectionsToPaste();
+ if ( connections != null )
+ {
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ IConnection newConnection = ( IConnection ) connections[i].clone();
+ BrowserCorePlugin.getDefault().getConnectionManager().addConnection( newConnection );
+ }
+ return;
+ }
+
+ // entry
+ IEntry[] entries = getEntriesToPaste();
+ if ( entries != null )
+ {
+ this.pasteEntries( getSelectedEntries()[0], entries );
+ return;
+ }
+
+ // value
+ IValue[] values = getValuesToPaste();
+ if ( values != null )
+ {
+ this.pasteValues( values );
+ return;
+ }
+
+ }
+
+
+ /**
+ * Pastes the given entries
+ *
+ * @param parent
+ * the parent Entry
+ * @param entriesToPaste
+ * the Entries to paste
+ */
+ private void pasteEntries( final IEntry parent, final IEntry[] entriesToPaste )
+ {
+
+ int scope = ISearch.SCOPE_OBJECT;
+ boolean askForScope = false;
+ for ( int i = 0; i < entriesToPaste.length; i++ )
+ {
+ if ( entriesToPaste[i].hasChildren() )
+ {
+ askForScope = true;
+ break;
+ }
+ }
+ if ( askForScope )
+ {
+ ScopeDialog scopeDialog = new ScopeDialog( Display.getDefault().getActiveShell(), "Select Copy Depth",
+ entriesToPaste.length > 1 );
+ scopeDialog.open();
+ scope = scopeDialog.getScope();
+ }
+
+ new CopyEntriesJob( parent, entriesToPaste, scope ).execute();
+ }
+
+
+ /**
+ * Paste Values
+ *
+ * @param values
+ * the Values to paste
+ */
+ private void pasteValues( IValue[] values )
+ {
+ IEntry entry = null;
+ if ( getSelectedAttributes().length > 0 )
+ {
+ entry = getSelectedAttributes()[0].getEntry();
+ }
+ else if ( getSelectedValues().length > 0 )
+ {
+ entry = getSelectedValues()[0].getAttribute().getEntry();
+ }
+ else if ( getSelectedEntries().length == 1 )
+ {
+ entry = getSelectedEntries()[0];
+ }
+ else if ( getSelectedSearchResults().length == 1 )
+ {
+ entry = getSelectedSearchResults()[0].getEntry();
+ }
+ else if ( getSelectedBookmarks().length == 1 )
+ {
+ entry = getSelectedBookmarks()[0].getEntry();
+ }
+
+ if ( entry != null )
+ {
+ String[] attributeNames = new String[values.length];
+ Object[] rawValues = new Object[values.length];
+ for ( int v = 0; v < values.length; v++ )
+ {
+ attributeNames[v] = values[v].getAttribute().getDescription();
+ rawValues[v] = values[v].getRawValue();
+ }
+ new CreateValuesJob( entry, attributeNames, rawValues ).execute();
+ }
+ }
+
+
+ /**
+ * Conditions: - a connection is selected - there are connections in
+ * clipboard
+ *
+ * @return
+ */
+ private IConnection[] getConnectionsToPaste()
+ {
+ if ( getSelectedBookmarks().length + getSelectedEntries().length + getSelectedSearchResults().length
+ + getSelectedSearches().length + getSelectedAttributes().length + getSelectedValues().length == 0
+ && getSelectedConnections().length > 0 )
+ {
+
+ Object content = this.getFromClipboard( ConnectionTransfer.getInstance() );
+ if ( content != null && content instanceof IConnection[] )
+ {
+ IConnection[] connections = ( IConnection[] ) content;
+ return connections;
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Conditions: - an entry is selected - there are entries in clipboard
+ *
+ * @return
+ */
+ private IEntry[] getEntriesToPaste()
+ {
+ if ( getSelectedBookmarks().length + getSelectedSearchResults().length + getSelectedSearches().length
+ + getSelectedConnections().length + getSelectedAttributes().length + getSelectedValues().length == 0
+ && getSelectedEntries().length == 1 )
+ {
+
+ Object content = this.getFromClipboard( EntryTransfer.getInstance() );
+ if ( content != null && content instanceof IEntry[] )
+ {
+ IEntry[] entries = ( IEntry[] ) content;
+ return entries;
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Conditions: - an attribute or value is selected - there are values in
+ * clipboard
+ *
+ * @return
+ */
+ private IValue[] getValuesToPaste()
+ {
+ if ( ( getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length
+ + getSelectedSearches().length + getSelectedConnections().length == 0 && ( getSelectedAttributes().length
+ + getSelectedValues().length > 0 ) )
+ || ( getSelectedAttributes().length + getSelectedValues().length + getSelectedSearchResults().length
+ + getSelectedBookmarks().length + getSelectedSearches().length + getSelectedConnections().length == 0 && ( getSelectedEntries().length == 1 ) )
+ || ( getSelectedAttributes().length + getSelectedValues().length + getSelectedEntries().length
+ + getSelectedSearchResults().length + getSelectedSearches().length + getSelectedConnections().length == 0 && ( getSelectedBookmarks().length == 1 ) )
+ || ( getSelectedAttributes().length + getSelectedValues().length + getSelectedEntries().length
+ + getSelectedBookmarks().length + getSelectedSearches().length + getSelectedConnections().length == 0 && ( getSelectedSearchResults().length == 1 ) )
+
+ )
+ {
+
+ Object content = this.getFromClipboard( ValuesTransfer.getInstance() );
+ if ( content != null && content instanceof IValue[] )
+ {
+ IValue[] values = ( IValue[] ) content;
+ return values;
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * 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();
+ }
+ }
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PropertiesAction.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PropertiesAction.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PropertiesAction.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/actions/PropertiesAction.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.utils.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 BrowserAction
+{
+ /**
+ * 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
+ || getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length
+ + getSelectedSearches().length == 1 || getSelectedAttributes().length + getSelectedValues().length == 1
+ || ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 );
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+
+ IAdaptable element = null;
+ String pageId = null;
+ String title = null;
+
+ if ( getSelectedValues().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedValues()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.ValuePropertyPage";
+ title = getSelectedValues()[0].toString();
+ }
+ else if ( getSelectedAttributes().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedAttributes()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.AttributePropertyPage";
+ title = getSelectedAttributes()[0].toString();
+ }
+ else if ( getSelectedAttributeHierarchies().length == 1 )
+ {
+ IAttribute att = getSelectedAttributeHierarchies()[0].getAttribute();
+ element = att;
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.AttributePropertyPage";
+ title = att.toString();
+ }
+ else if ( getSelectedSearches().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedSearches()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.SearchPropertyPage";
+ title = getSelectedSearches()[0].getName();
+ }
+ else if ( getSelectedBookmarks().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedBookmarks()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.BookmarkPropertyPage";
+ title = getSelectedBookmarks()[0].getName();
+ }
+ else if ( getSelectedEntries().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedEntries()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.EntryPropertyPage";
+ title = getSelectedEntries()[0].getDn().toString();
+ }
+ else if ( getSelectedSearchResults().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedSearchResults()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.properties.EntryPropertyPage";
+ title = getSelectedSearchResults()[0].getDn().toString();
+ }
+ else if ( getSelectedConnections().length == 1 )
+ {
+ element = ( IAdaptable ) getSelectedConnections()[0];
+ pageId = "org.apache.directory.ldapstudio.browser.ui.dialogs.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();
+
+ }
+ }
+}