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 17:48:54 UTC
svn commit: r592079 [2/17] - in
/directory/sandbox/felixk/studio-ldapbrowser-common: ./ 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/ ...
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.java Mon Nov 5 08:48:35 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.studio.ldapbrowser.common;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeValueProviderRelation;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SyntaxValueProviderRelation;
+import org.apache.directory.studio.valueeditors.ValueEditorManager;
+import org.apache.directory.studio.valueeditors.ValueEditorManager.ValueEditorExtension;
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This class is used to set default preference values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BrowserCommonPreferencesInitializer extends AbstractPreferenceInitializer
+{
+ /**
+ * {@inheritDoc}
+ */
+ public void initializeDefaultPreferences()
+ {
+
+ IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+
+ // Common
+ store.setDefault( BrowserCommonConstants.PREFERENCE_COUNT_LIMIT, 1000 );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_TIME_LIMIT, 0 );
+
+ // Colors and Fonts
+ RGB rgbBlack = Display.getDefault().getSystemColor( SWT.COLOR_BLACK ).getRGB();
+ RGB rgbRed = Display.getDefault().getSystemColor( SWT.COLOR_RED ).getRGB();
+ RGB rgbYellow = Display.getDefault().getSystemColor( SWT.COLOR_YELLOW ).getRGB();
+ FontData[] fontData = Display.getDefault().getSystemFont().getFontData();
+ FontData fontDataNormal = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.NORMAL );
+ FontData fontDataItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.ITALIC );
+ FontData fontDataBold = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD );
+ FontData fontDataBoldItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD
+ | SWT.ITALIC );
+ // Attributes colors and fonts
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OBJECTCLASS_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OBJECTCLASS_FONT, fontDataBoldItalic );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_FONT, fontDataBold );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_FONT, fontDataNormal );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT, fontDataItalic );
+ // Error/Warning colors and fonts
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_WARNING_FONT, fontDataBoldItalic );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_WARNING_COLOR, rgbYellow );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_ERROR_FONT, fontDataBoldItalic );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_ERROR_COLOR, rgbRed );
+ // Quick filter background colors and fonts
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT, fontDataBold );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR, rgbYellow );
+ PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR, rgbBlack );
+
+ // Attributes
+ store.setDefault( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES, false );
+
+ // Value Editors
+ Collection<AttributeValueProviderRelation> avprs = new ArrayList<AttributeValueProviderRelation>();
+ Collection<SyntaxValueProviderRelation> svprs = new ArrayList<SyntaxValueProviderRelation>();
+ Collection<ValueEditorExtension> valueEditorProxys = ValueEditorManager.getValueEditorProxys();
+ for ( ValueEditorExtension proxy : valueEditorProxys )
+ {
+ for ( String attributeType : proxy.attributeTypes )
+ {
+ AttributeValueProviderRelation avpr = new AttributeValueProviderRelation( attributeType,
+ proxy.className );
+ avprs.add( avpr );
+ }
+ for ( String syntaxOid : proxy.syntaxOids )
+ {
+ SyntaxValueProviderRelation svpr = new SyntaxValueProviderRelation( syntaxOid, proxy.className );
+ svprs.add( svpr );
+ }
+ }
+ BrowserCommonActivator.getDefault().getValueEditorsPreferences().setDefaultAttributeValueProviderRelations(
+ avprs.toArray( new AttributeValueProviderRelation[0] ) );
+ BrowserCommonActivator.getDefault().getValueEditorsPreferences().setDefaultSyntaxValueProviderRelations(
+ svprs.toArray( new SyntaxValueProviderRelation[0] ) );
+
+ // Browser
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES, false );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE, 100 );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL, BrowserCommonConstants.SHOW_RDN );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH, 50 );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, BrowserCommonConstants.SHOW_DN );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, 50 );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIT, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_SEARCHES, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES, false );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY, BrowserCoreConstants.SORT_BY_RDN_VALUE );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT, 10000 );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, true );
+
+ // Entry Editor
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD, 10 );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES, false );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST, true );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY,
+ BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER,
+ BrowserCoreConstants.SORT_ORDER_ASCENDING );
+
+
+
+ // Text Format
+ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER, "\t" );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER, "|" );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER, "\"" );
+ store
+ .setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR, BrowserCoreConstants.LINE_SEPARATOR );
+ store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING,
+ BrowserCoreConstants.BINARYENCODING_IGNORE );
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonPreferencesInitializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectReferralConnectionDialog;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IReferralHandler;
+import org.apache.directory.studio.ldapbrowser.core.model.URL;
+
+import org.eclipse.ui.PlatformUI;
+
+
+public class BrowserCommonReferralHandler implements IReferralHandler
+{
+
+ private Map referralUrlToReferralConnectionCache = new HashMap();
+
+
+ public IBrowserConnection getReferralConnection( final URL referralUrl )
+ {
+
+ // check cache
+ if ( referralUrlToReferralConnectionCache.containsKey( referralUrl ) )
+ {
+ IBrowserConnection referralConnection = ( IBrowserConnection ) referralUrlToReferralConnectionCache.get( referralUrl );
+ if ( referralConnection != null )
+ {
+ IBrowserConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getBrowserConnections();
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ IBrowserConnection connection = connections[i];
+ if ( referralConnection == connection )
+ {
+ return referralConnection;
+ }
+ }
+ }
+ }
+
+ referralUrlToReferralConnectionCache.remove( referralUrl );
+
+ // open dialog
+ final IBrowserConnection[] referralConnection = new IBrowserConnection[1];
+ PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable()
+ {
+ public void run()
+ {
+ SelectReferralConnectionDialog dialog = new SelectReferralConnectionDialog( PlatformUI.getWorkbench()
+ .getDisplay().getActiveShell(), referralUrl );
+ if ( dialog.open() == SelectReferralConnectionDialog.OK )
+ {
+ IBrowserConnection connection = dialog.getReferralConnection();
+ referralUrlToReferralConnectionCache.put( referralUrl, connection );
+ referralConnection[0] = connection;
+ }
+ }
+ } );
+
+ return referralConnection[0];
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/BrowserCommonReferralHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ExceptionHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ExceptionHandler.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ExceptionHandler.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ExceptionHandler.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common;
+
+
+import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This class is used to handle exceptions thrown at runtime.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExceptionHandler
+{
+ /**
+ * Opens an error dialog to display the given error.
+ *
+ * @param status
+ * the error to show to the user
+ */
+ public void handleException( IStatus status )
+ {
+ display( null, status );
+ }
+
+
+ /**
+ * Opens an error dialog to display the given error.
+ *
+ * @param message
+ * the message to show in this dialog, or null to indicate that the error's message should be shown as the primary message
+ * @param status
+ * the error to show to the user
+ */
+ private void display( final String message, final IStatus status )
+ {
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ ErrorDialog.openError( Display.getDefault().getActiveShell(), "Error", message, status );
+ }
+ };
+ Display.getDefault().asyncExec( runnable );
+ BrowserCorePlugin.getDefault().getLog().log( status );
+ }
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ExceptionHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/UiThreadEventRunner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/UiThreadEventRunner.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/UiThreadEventRunner.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/UiThreadEventRunner.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.ldapbrowser.common;
+
+import org.apache.directory.studio.ldapbrowser.core.events.EventRunnable;
+import org.apache.directory.studio.ldapbrowser.core.events.EventRunner;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * Implementation of {@link EventRunner} that executes an {@link EventRunnable}
+ * withing the SWT UI thread.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class UiThreadEventRunner implements EventRunner
+{
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation executes the given {@link EventRunnable} within
+ * the SWT UI thread.
+ */
+ public void execute( EventRunnable runnable )
+ {
+ Display.getDefault().asyncExec( runnable );
+ }
+
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/UiThreadEventRunner.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeValueProviderRelation;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.SyntaxValueProviderRelation;
+import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+
+/**
+ * This class is used to manage and access the preferences of the Value Editors Plugin.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ValueEditorsPreferences
+{
+
+ /** The attribute value editor cache. */
+ private Map<String, String> attributeValueEditorCache;
+
+ /** The syntax value editor cache. */
+ private Map<String, String> syntaxValueEditorCache;
+
+
+ /**
+ * Gets a Map containing all the Attribute Value Editors.
+ *
+ * @return
+ * a Map containing all the Attribute Value Editors
+ */
+ public Map getAttributeValueEditorMap()
+ {
+ if ( attributeValueEditorCache == null )
+ {
+ attributeValueEditorCache = new HashMap<String, String>();
+ AttributeValueProviderRelation[] relations = getAttributeValueProviderRelations();
+ for ( int i = 0; i < relations.length; i++ )
+ {
+ if ( relations[i].getAttributeNumericOidOrType() != null )
+ {
+ attributeValueEditorCache.put( relations[i].getAttributeNumericOidOrType()
+ .toLowerCase(), relations[i].getValueProviderClassname() );
+ }
+ }
+ }
+ return attributeValueEditorCache;
+ }
+
+
+ /**
+ * Gets an array containing all the Attribute Value Provider Relations.
+ *
+ * @return
+ * an array containing all the Attribute Value Provider Relations
+ */
+ public AttributeValueProviderRelation[] getAttributeValueProviderRelations()
+ {
+ AttributeValueProviderRelation[] avpr = ( AttributeValueProviderRelation[] ) load( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS );
+ return avpr;
+ }
+
+
+ /**
+ * Sets the Attribute Value Provider Relations.
+ *
+ * @param attributeValueProviderRelations
+ * an array containing all the Attribute Value Provider Relations
+ */
+ public void setAttributeValueProviderRelations( AttributeValueProviderRelation[] attributeValueProviderRelations )
+ {
+ store( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS, attributeValueProviderRelations );
+ attributeValueEditorCache = null;
+ }
+
+
+ /**
+ * Gets the default Attribute Value Provider Relations.
+ *
+ * @return
+ * an array containing all the default Attribute Value Provider Relations
+ */
+ public AttributeValueProviderRelation[] getDefaultAttributeValueProviderRelations()
+ {
+ AttributeValueProviderRelation[] avpr = ( AttributeValueProviderRelation[] ) loadDefault( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS );
+ return avpr;
+ }
+
+
+ /**
+ * Sets the default Attribute Value Provider Relations.
+ *
+ * @param attributeValueProviderRelations
+ * an array containing all the default Attribute Value Provider Relations
+ */
+ public void setDefaultAttributeValueProviderRelations(
+ AttributeValueProviderRelation[] attributeValueProviderRelations )
+ {
+ storeDefault( BrowserCommonConstants.PREFERENCE_ATTRIBUTE_VALUEPROVIDER_RELATIONS, attributeValueProviderRelations );
+ }
+
+
+
+ /**
+ * Gets a Map containing all the Syntax Value Editors.
+ *
+ * @return
+ * a Map containing all the Syntax Value Editors
+ */
+ public Map getSyntaxValueEditorMap()
+ {
+ if ( syntaxValueEditorCache == null )
+ {
+ syntaxValueEditorCache = new HashMap<String, String>();
+ SyntaxValueProviderRelation[] relations = getSyntaxValueProviderRelations();
+ for ( int i = 0; i < relations.length; i++ )
+ {
+ if ( relations[i].getSyntaxOID() != null )
+ {
+ syntaxValueEditorCache.put( relations[i].getSyntaxOID().toLowerCase(), relations[i]
+ .getValueProviderClassname() );
+ }
+ }
+ }
+ return syntaxValueEditorCache;
+ }
+
+
+ /**
+ * Sets the Syntax Value Provider Relations.
+ *
+ * @param syntaxValueProviderRelations
+ * an array containing the Syntax Value Provider Relations to set
+ */
+ public void setSyntaxValueProviderRelations( SyntaxValueProviderRelation[] syntaxValueProviderRelations )
+ {
+ store( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS, syntaxValueProviderRelations );
+ syntaxValueEditorCache = null;
+ }
+
+
+ /**
+ * Gets an array containing all the Syntax Value Provider Relations
+ *
+ * @return
+ * an array containing all the Syntax Value Provider Relations
+ */
+ public SyntaxValueProviderRelation[] getSyntaxValueProviderRelations()
+ {
+ SyntaxValueProviderRelation[] svpr = ( SyntaxValueProviderRelation[] ) load( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS );
+ return svpr;
+ }
+
+
+ /**
+ * Gets an array containing all the default Syntax Value Provider Relations
+ *
+ * @return
+ * an array containing all the default Syntax Value Provider Relations
+ */
+ public SyntaxValueProviderRelation[] getDefaultSyntaxValueProviderRelations()
+ {
+ SyntaxValueProviderRelation[] svpr = ( SyntaxValueProviderRelation[] ) loadDefault( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS );
+ return svpr;
+ }
+
+
+ /**
+ * Sets the default Syntax Value Provider Relations.
+ *
+ * @param syntaxValueProviderRelations
+ * an array containing the default Syntax Value Provider Relations to set
+ */
+ public void setDefaultSyntaxValueProviderRelations( SyntaxValueProviderRelation[] syntaxValueProviderRelations )
+ {
+ storeDefault( BrowserCommonConstants.PREFERENCE_SYNTAX_VALUEPROVIDER_RELATIONS, syntaxValueProviderRelations );
+ }
+
+
+ /**
+ * Loads the current value of the string-valued property with the given name.
+ *
+ * @param key
+ * the name of the property
+ * @return
+ * the corresponding object
+ */
+ private static Object load( String key )
+ {
+ IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+ String s = store.getString( key );
+ return Utils.deserialize( s );
+ }
+
+
+ /**
+ * Stores the current value of the string-valued property with the given name.
+ *
+ * @param key
+ * the name of the property
+ * @param o
+ * the new current value of the property
+ */
+ private static void store( String key, Object o )
+ {
+ IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+ String s = Utils.serialize( o );
+ store.setValue( key, s );
+ }
+
+
+ /**
+ * Loads the default value for the string-valued property with the given name.
+ *
+ * @param key
+ * the name of the property
+ * @return
+ * the default value of the named property
+ */
+ private static Object loadDefault( String key )
+ {
+ IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+ String s = store.getDefaultString( key );
+ return Utils.deserialize( s );
+ }
+
+
+ /**
+ * Stores the default value for the string-valued property with the given name.
+ *
+ * @param key
+ * the name of the property
+ * @param o
+ * the new default value for the property
+ */
+ private static void storeDefault( String key, Object o )
+ {
+ IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
+ String s = Utils.serialize( o );
+ store.setDefault( key, s );
+ }
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/ValueEditorsPreferences.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,626 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.actions;
+
+
+import org.apache.directory.studio.connection.ui.actions.StudioAction;
+import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserCategory;
+import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserEntryPage;
+import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserSearchResultPage;
+import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBookmark;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifFile;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifPart;
+import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer;
+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 BrowserAction extends StudioAction implements IWorkbenchWindowActionDelegate
+{
+ /** The selected Browser View Categories */
+ private BrowserCategory[] selectedBrowserViewCategories;
+
+ /** The selected Entries */
+ private IEntry[] selectedEntries;
+
+ /** The selected Browser Entry Pages */
+ private BrowserEntryPage[] selectedBrowserEntryPages;
+
+ /** The selected Searches */
+ private ISearch[] selectedSearches;
+
+ /** The selected Search Results */
+ private ISearchResult[] selectedSearchResults;
+
+ /** The selected Browser Search Result Pages */
+ private BrowserSearchResultPage[] selectedBrowserSearchResultPages;
+
+ /** The selected Bookmarks */
+ private IBookmark[] selectedBookmarks;
+
+ /** The selected Attributes */
+ private IAttribute[] selectedAttributes;
+
+ /** The selected Attribute Hierarchies */
+ private AttributeHierarchy[] selectedAttributeHierarchies;
+
+ /** The selected Values */
+ private IValue[] selectedValues;
+
+ /** The selectec LDIF Model */
+ private LdifFile selectedLdifModel;
+
+ /** The selected LDIF Containers */
+ private LdifContainer[] selectedLdifContainers;
+
+ /** The selected LDIF Parts */
+ private LdifPart[] selectedLdifParts;
+
+ /** The selected properties. */
+ protected String[] selectedProperties;
+
+ /** The input */
+ private Object input;
+
+
+ /**
+ * Creates a new instance of BrowserAction.
+ */
+ protected BrowserAction()
+ {
+ this.init();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init( IWorkbenchWindow window )
+ {
+ this.init();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run( IAction action )
+ {
+ this.run();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void selectionChanged( IAction action, ISelection selection )
+ {
+ setSelectedBrowserViewCategories( BrowserSelectionUtils.getBrowserViewCategories( selection ) );
+ setSelectedEntries( BrowserSelectionUtils.getEntries( selection ) );
+ setSelectedBrowserEntryPages( BrowserSelectionUtils.getBrowserEntryPages( selection ) );
+ setSelectedSearchResults( BrowserSelectionUtils.getSearchResults( selection ) );
+ setSelectedBrowserSearchResultPages( BrowserSelectionUtils.getBrowserSearchResultPages( selection ) );
+ setSelectedBookmarks( BrowserSelectionUtils.getBookmarks( selection ) );
+
+ setSelectedSearches( BrowserSelectionUtils.getSearches( selection ) );
+
+ setSelectedAttributes( BrowserSelectionUtils.getAttributes( selection ) );
+ setSelectedAttributeHierarchies( BrowserSelectionUtils.getAttributeHierarchie( selection ) );
+ setSelectedValues( BrowserSelectionUtils.getValues( 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.selectedBrowserViewCategories = new BrowserCategory[0];
+ this.selectedEntries = new IEntry[0];
+ this.selectedBrowserEntryPages = new BrowserEntryPage[0];
+ this.selectedSearches = new ISearch[0];
+ this.selectedSearchResults = new ISearchResult[0];
+ this.selectedBrowserSearchResultPages = new BrowserSearchResultPage[0];
+ this.selectedBookmarks = new IBookmark[0];
+ this.selectedAttributes = new IAttribute[0];
+ this.selectedAttributeHierarchies = new AttributeHierarchy[0];
+ this.selectedValues = new IValue[0];
+
+ this.selectedLdifModel = null;
+ this.selectedLdifContainers = new LdifContainer[0];
+ this.selectedLdifParts = new LdifPart[0];
+
+ this.selectedProperties = new String[0];
+
+ this.input = null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose()
+ {
+ this.selectedBrowserViewCategories = new BrowserCategory[0];
+ this.selectedEntries = new IEntry[0];
+ this.selectedBrowserEntryPages = new BrowserEntryPage[0];
+ this.selectedSearches = new ISearch[0];
+ this.selectedSearchResults = new ISearchResult[0];
+ this.selectedBrowserSearchResultPages = new BrowserSearchResultPage[0];
+ this.selectedBookmarks = new IBookmark[0];
+ this.selectedAttributes = new IAttribute[0];
+ this.selectedAttributeHierarchies = new AttributeHierarchy[0];
+ this.selectedValues = new IValue[0];
+
+ this.selectedLdifModel = null;
+ this.selectedLdifContainers = new LdifContainer[0];
+ this.selectedLdifParts = new LdifPart[0];
+
+ this.selectedProperties = new String[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 Attributes.
+ *
+ * @return
+ * the selected attributes
+ */
+ public IAttribute[] getSelectedAttributes()
+ {
+ return selectedAttributes;
+ }
+
+
+ /**
+ * Sets the selected Attributes.
+ *
+ * @param selectedAttributes
+ * the selected attributes to set
+ */
+ public void setSelectedAttributes( IAttribute[] selectedAttributes )
+ {
+ this.selectedAttributes = selectedAttributes;
+ }
+
+
+ /**
+ * Gets the selected Bookmarks.
+ *
+ * @return
+ * the selected Bookmarks
+ */
+ public IBookmark[] getSelectedBookmarks()
+ {
+ return selectedBookmarks;
+ }
+
+
+ /**
+ * Sets the selected Bookmarks.
+ *
+ * @param selectedBookmarks
+ * the selected Bookmarks to set
+ */
+ public void setSelectedBookmarks( IBookmark[] selectedBookmarks )
+ {
+ this.selectedBookmarks = selectedBookmarks;
+ }
+
+
+ /**
+ * Gets the selected Browser View categories.
+ *
+ * @return
+ * the selected Browser View categories
+ */
+ public BrowserCategory[] getSelectedBrowserViewCategories()
+ {
+ return selectedBrowserViewCategories;
+ }
+
+
+ /**
+ * Sets the selected Browser View categories.
+ *
+ * @param selectedBrowserViewCategories
+ * the selected Browser View categories to set
+ */
+ public void setSelectedBrowserViewCategories( BrowserCategory[] selectedBrowserViewCategories )
+ {
+ this.selectedBrowserViewCategories = selectedBrowserViewCategories;
+ }
+
+
+ /**
+ * Get the selected Entries.
+ *
+ * @return the selected entries
+ */
+ public IEntry[] getSelectedEntries()
+ {
+ return selectedEntries;
+ }
+
+
+ /**
+ * Sets the selected Entries.
+ *
+ * @param selectedEntries
+ * the selected Entries to set
+ */
+ public void setSelectedEntries( IEntry[] selectedEntries )
+ {
+ this.selectedEntries = selectedEntries;
+ }
+
+
+ /**
+ * Gets the selected Searches.
+ *
+ * @return
+ * the selected Searches
+ */
+ public ISearch[] getSelectedSearches()
+ {
+ return selectedSearches;
+ }
+
+
+ /**
+ * Sets the selected Searches.
+ *
+ * @param selectedSearches
+ * the selected Searches to set
+ */
+ public void setSelectedSearches( ISearch[] selectedSearches )
+ {
+ this.selectedSearches = selectedSearches;
+ }
+
+
+ /**
+ * Gets the selected Search Results.
+ *
+ * @return
+ * the selected Search Results
+ */
+ public ISearchResult[] getSelectedSearchResults()
+ {
+ return selectedSearchResults;
+ }
+
+
+ /**
+ * Sets the selected Search Results.
+ *
+ * @param selectedSearchResults
+ * the selected Search Results to set
+ */
+ public void setSelectedSearchResults( ISearchResult[] selectedSearchResults )
+ {
+ this.selectedSearchResults = selectedSearchResults;
+ }
+
+
+ /**
+ * Gets the selected Values.
+ *
+ * @return
+ * the selected Values
+ */
+ public IValue[] getSelectedValues()
+ {
+ return selectedValues;
+ }
+
+
+ /**
+ * Sets the selected Values.
+ *
+ * @param selectedValues
+ * the selected values to set
+ */
+ public void setSelectedValues( IValue[] selectedValues )
+ {
+ this.selectedValues = selectedValues;
+ }
+
+
+ /**
+ * 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;
+ }
+
+
+ /**
+ * Gets the selected LDIF Containers.
+ *
+ * @return
+ * the selected LDIF Containers
+ */
+ public LdifContainer[] getSelectedLdifContainers()
+ {
+ return selectedLdifContainers;
+ }
+
+
+ /**
+ * Sets the selected LDIF Containers.
+ *
+ * @param selectedLdifContainers
+ * the selected LDIF Containers to set
+ */
+ public void setSelectedLdifContainers( LdifContainer[] selectedLdifContainers )
+ {
+ this.selectedLdifContainers = selectedLdifContainers;
+ }
+
+
+ /**
+ * Gets the selected LDIF Model.
+ *
+ * @return
+ * the selected LDIF Model
+ */
+ public LdifFile getSelectedLdifModel()
+ {
+ return selectedLdifModel;
+ }
+
+
+ /**
+ * Sets the selected LDIF Model.
+ *
+ * @param selectedLdifModel
+ * the selected LDIF Model to set
+ */
+ public void setSelectedLdifModel( LdifFile selectedLdifModel )
+ {
+ this.selectedLdifModel = selectedLdifModel;
+ }
+
+
+ /**
+ * Gets the selected LDIF Parts.
+ *
+ * @return
+ * the selected LDIF Parts
+ */
+ public LdifPart[] getSelectedLdifParts()
+ {
+ return selectedLdifParts;
+ }
+
+
+ /**
+ * Sets the selected LDIF Parts.
+ *
+ * @param selectedLdifParts
+ * the selected LDIF Parts to set
+ */
+ public void setSelectedLdifParts( LdifPart[] selectedLdifParts )
+ {
+ this.selectedLdifParts = selectedLdifParts;
+ }
+
+
+ /**
+ * Gets the selected Browser Entry Pages.
+ *
+ * @return
+ * the selected Browser Entru Pages
+ */
+ public BrowserEntryPage[] getSelectedBrowserEntryPages()
+ {
+ return selectedBrowserEntryPages;
+ }
+
+
+ /**
+ * Sets the selected Browser Entry Pages.
+ *
+ * @param selectedBrowserEntryPages
+ * the selected Browser Entry Pages to set
+ */
+ public void setSelectedBrowserEntryPages( BrowserEntryPage[] selectedBrowserEntryPages )
+ {
+ this.selectedBrowserEntryPages = selectedBrowserEntryPages;
+ }
+
+
+ /**
+ * Gets the selected Browser Search Result Pages.
+ *
+ * @return
+ * the selected Browser Search Result Pages
+ */
+ public BrowserSearchResultPage[] getSelectedBrowserSearchResultPages()
+ {
+ return selectedBrowserSearchResultPages;
+ }
+
+
+ /**
+ * Sets the selected Browser Search Result Pages.
+ *
+ * @param selectedBrowserSearchResultPages
+ * the selected Browser Search result Pages to set
+ */
+ public void setSelectedBrowserSearchResultPages( BrowserSearchResultPage[] selectedBrowserSearchResultPages )
+ {
+ this.selectedBrowserSearchResultPages = selectedBrowserSearchResultPages;
+ }
+
+
+ /**
+ * Gets the selected Attribute Hierarchies.
+ *
+ * @return
+ * the selected Attribute Hierarchies
+ */
+ public AttributeHierarchy[] getSelectedAttributeHierarchies()
+ {
+ return selectedAttributeHierarchies;
+ }
+
+
+ /**
+ * Sets the selected Attribute Hierarchies.
+ *
+ * @param ahs
+ * the selected Attribute Hierarchies to set
+ */
+ public void setSelectedAttributeHierarchies( AttributeHierarchy[] ahs )
+ {
+ this.selectedAttributeHierarchies = ahs;
+ }
+
+
+ /**
+ * Gets the selected properties.
+ *
+ * @return the selected properties
+ */
+ public String[] getSelectedProperties()
+ {
+ return selectedProperties;
+ }
+
+
+ /**
+ * Sets the selected properties.
+ *
+ * @param selectedProperties the selected properties
+ */
+ public void setSelectedProperties( String[] selectedProperties )
+ {
+ this.selectedProperties = selectedProperties;
+ }
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,467 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.actions;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.directory.studio.connection.ui.actions.SelectionUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserCategory;
+import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserEntryPage;
+import org.apache.directory.studio.ldapbrowser.common.widgets.browser.BrowserSearchResultPage;
+import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBookmark;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
+import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
+import org.apache.directory.studio.ldapbrowser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.studio.ldapbrowser.core.utils.LdapFilterUtils;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+
+/**
+ * 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 BrowserSelectionUtils extends SelectionUtils
+{
+
+ /**
+ * This method creates a prototype search from the given selection.
+ *
+ * Dependend on the selected element it determines the best connection,
+ * search base and filter:
+ * <ul>
+ * <li>ISearch: all parameters are copied to the prototype search (clone)
+ * <li>IEntry or ISearchResult or IBookmark: DN is used as search base
+ * <li>IAttribute or IValue: the entry's DN is used as search base,
+ * the filter is built using the name-value-pairs (query by example).
+ * </ul>
+ *
+ *
+ * @param selection the current selection
+ * @return a prototype search
+ */
+ public static ISearch getExampleSearch( ISelection selection )
+ {
+
+ ISearch exampleSearch = new Search();
+ String oldName = exampleSearch.getSearchParameter().getName();
+ exampleSearch.getSearchParameter().setName( null );
+ exampleSearch.setScope( SearchScope.SUBTREE );
+
+ if ( selection != null && !selection.isEmpty() && selection instanceof StructuredSelection )
+ {
+
+ Object[] objects = ( ( IStructuredSelection ) selection ).toArray();
+ Comparator<Object> comparator = new Comparator<Object>()
+ {
+ public int compare( Object o1, Object o2 )
+ {
+ if ( ( o1 instanceof IValue ) && !( o2 instanceof IValue ) )
+ {
+ return -1;
+ }
+ else if ( !( o1 instanceof IValue ) && ( o2 instanceof IValue ) )
+ {
+ return 1;
+ }
+ else if ( ( o1 instanceof IAttribute ) && !( o2 instanceof IAttribute ) )
+ {
+ return -1;
+ }
+ else if ( !( o1 instanceof IAttribute ) && ( o2 instanceof IAttribute ) )
+ {
+ return 1;
+ }
+ else if ( ( o1 instanceof AttributeHierarchy ) && !( o2 instanceof AttributeHierarchy ) )
+ {
+ return -1;
+ }
+ else if ( !( o1 instanceof AttributeHierarchy ) && ( o2 instanceof AttributeHierarchy ) )
+ {
+ return 1;
+ }
+ return 0;
+ }
+ };
+ Arrays.sort( objects, comparator );
+ Object obj = objects[0];
+
+ if ( obj instanceof ISearch )
+ {
+ ISearch search = ( ISearch ) obj;
+ exampleSearch = ( ISearch ) search.clone();
+ exampleSearch.setName( null );
+ }
+ else if ( obj instanceof IEntry )
+ {
+ IEntry entry = ( IEntry ) obj;
+ exampleSearch.setBrowserConnection( entry.getBrowserConnection() );
+ exampleSearch.setSearchBase( entry.getDn() );
+ }
+ else if ( obj instanceof ISearchResult )
+ {
+ ISearchResult searchResult = ( ISearchResult ) obj;
+ exampleSearch.setBrowserConnection( searchResult.getEntry().getBrowserConnection() );
+ exampleSearch.setSearchBase( searchResult.getEntry().getDn() );
+ }
+ else if ( obj instanceof IBookmark )
+ {
+ IBookmark bookmark = ( IBookmark ) obj;
+ exampleSearch.setBrowserConnection( bookmark.getBrowserConnection() );
+ exampleSearch.setSearchBase( bookmark.getDn() );
+ }
+
+ else if ( obj instanceof AttributeHierarchy || obj instanceof IAttribute || obj instanceof IValue )
+ {
+
+ IEntry entry = null;
+ Set<String> filterSet = new LinkedHashSet<String>();
+ for ( int i = 0; i < objects.length; i++ )
+ {
+ Object object = objects[i];
+ if ( object instanceof AttributeHierarchy )
+ {
+ AttributeHierarchy ah = ( AttributeHierarchy ) object;
+ for ( Iterator it = ah.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ entry = attribute.getEntry();
+ IValue[] values = attribute.getValues();
+ for ( int v = 0; v < values.length; v++ )
+ {
+ filterSet.add( LdapFilterUtils.getFilter( values[v] ) );
+ }
+ }
+ }
+ else if ( object instanceof IAttribute )
+ {
+ IAttribute attribute = ( IAttribute ) object;
+ entry = attribute.getEntry();
+ IValue[] values = attribute.getValues();
+ for ( int v = 0; v < values.length; v++ )
+ {
+ filterSet.add( LdapFilterUtils.getFilter( values[v] ) );
+ }
+ }
+ else if ( object instanceof IValue )
+ {
+ IValue value = ( IValue ) object;
+ entry = value.getAttribute().getEntry();
+ filterSet.add( LdapFilterUtils.getFilter( value ) );
+ }
+ }
+
+ exampleSearch.setBrowserConnection( entry.getBrowserConnection() );
+ exampleSearch.setSearchBase( entry.getDn() );
+ StringBuffer filter = new StringBuffer();
+ if ( filterSet.size() > 1 )
+ {
+ filter.append( "(&" );
+ for ( Iterator<String> filterIterator = filterSet.iterator(); filterIterator.hasNext(); )
+ {
+ filter.append( filterIterator.next() );
+ }
+ filter.append( ")" );
+ }
+ else if ( filterSet.size() == 1 )
+ {
+ filter.append( filterSet.toArray()[0] );
+ }
+ else
+ {
+ filter.append( ISearch.FILTER_TRUE );
+ }
+ exampleSearch.setFilter( filter.toString() );
+ }
+
+ else if ( obj instanceof IBrowserConnection )
+ {
+ IBrowserConnection connection = ( IBrowserConnection ) obj;
+ exampleSearch.setBrowserConnection( connection );
+ if ( connection.getRootDSE().getChildrenCount() > 0 )
+ {
+ exampleSearch.setSearchBase( connection.getRootDSE().getChildren()[0].getDn() );
+ }
+ else
+ {
+ exampleSearch.setSearchBase( connection.getRootDSE().getDn() );
+ }
+ }
+ else if ( obj instanceof BrowserCategory )
+ {
+ BrowserCategory cat = ( BrowserCategory ) obj;
+ exampleSearch.setBrowserConnection( cat.getParent() );
+ if ( cat.getParent().getRootDSE().getChildrenCount() > 0 )
+ {
+ exampleSearch.setSearchBase( cat.getParent().getRootDSE().getChildren()[0].getDn() );
+ }
+ else
+ {
+ exampleSearch.setSearchBase( cat.getParent().getRootDSE().getDn() );
+ }
+ }
+
+ }
+
+ exampleSearch.getSearchParameter().setName( oldName );
+ return exampleSearch;
+ }
+
+
+ /**
+ * Gets the BrowserCategory beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with BrowserCategory beans, may be empty.
+ */
+ public static BrowserCategory[] getBrowserViewCategories( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, BrowserCategory.class );
+ return list.toArray( new BrowserCategory[list.size()] );
+ }
+
+
+ /**
+ * Gets the IValue beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with IValue beans, may be empty.
+ */
+ public static IValue[] getValues( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, IValue.class );
+ return list.toArray( new IValue[list.size()] );
+ }
+
+
+ /**
+ * Gets the IAttribute beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with IAttribute beans, may be empty.
+ */
+ public static IAttribute[] getAttributes( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, IAttribute.class );
+ return list.toArray( new IAttribute[list.size()] );
+ }
+
+
+ /**
+ * Gets the AttributeHierarchy beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with AttributeHierarchy beans, may be empty.
+ */
+ public static AttributeHierarchy[] getAttributeHierarchie( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, AttributeHierarchy.class );
+ return list.toArray( new AttributeHierarchy[list.size()] );
+ }
+
+
+ /**
+ * 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 the AttributeTypeDescription beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with AttributeTypeDescription beans, may be empty.
+ */
+ public static AttributeTypeDescription[] getAttributeTypeDescription( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, AttributeTypeDescription.class );
+ return list.toArray( new AttributeTypeDescription[list.size()] );
+ }
+
+
+ /**
+ * Gets the IEntry beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with IEntry beans, may be empty.
+ */
+ public static IEntry[] getEntries( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, IEntry.class );
+ return list.toArray( new IEntry[list.size()] );
+ }
+
+
+ /**
+ * Gets the IBookmark beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with IBookmark beans, may be empty.
+ */
+ public static IBookmark[] getBookmarks( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, IBookmark.class );
+ return list.toArray( new IBookmark[list.size()] );
+ }
+
+
+ /**
+ * Gets the ISearchResult beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with ISearchResult beans, may be empty.
+ */
+ public static ISearchResult[] getSearchResults( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, ISearchResult.class );
+ return list.toArray( new ISearchResult[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 ISearch beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with ISearch beans, may be empty.
+ */
+ public static ISearch[] getSearches( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, ISearch.class );
+ return list.toArray( new ISearch[list.size()] );
+ }
+
+
+// /**
+// * Gets the IConnection beans contained in the given selection.
+// *
+// * @param selection the selection
+// * @return an array with IConnection beans, may be empty.
+// */
+// public static IConnection[] getConnections( ISelection selection )
+// {
+// List<Object> list1 = getTypes( selection, IConnection.class );
+//
+// List<Object> list2 = getTypes( selection, Connection.class );
+// for ( Object object : list2 )
+// {
+// Connection connection = ( Connection ) object;
+// String name = connection.getName();
+// IConnection conn = BrowserCorePlugin.getDefault().getConnectionManager().getConnection( name );
+// if ( conn != null )
+// {
+// list1.add( conn );
+// }
+// }
+//
+// return list1.toArray( new IConnection[list1.size()] );
+// }
+
+
+ /**
+ * Gets the BrowserEntryPage beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with BrowserEntryPage beans, may be empty.
+ */
+ public static BrowserEntryPage[] getBrowserEntryPages( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, BrowserEntryPage.class );
+ return list.toArray( new BrowserEntryPage[list.size()] );
+ }
+
+
+ /**
+ * Gets the BrowserSearchResultPage beans contained in the given selection.
+ *
+ * @param selection the selection
+ * @return an array with BrowserSearchResultPage beans, may be empty.
+ */
+ public static BrowserSearchResultPage[] getBrowserSearchResultPages( ISelection selection )
+ {
+ List<Object> list = getTypes( selection, BrowserSearchResultPage.class );
+ return list.toArray( new BrowserSearchResultPage[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-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/BrowserSelectionUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CollapseAllAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CollapseAllAction.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CollapseAllAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CollapseAllAction.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.actions;
+
+
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+/**
+ * This action collapses all nodes of the viewer's tree, starting with the root.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CollapseAllAction extends Action
+{
+ protected TreeViewer viewer;
+
+
+ /**
+ * Creates a new instance of CollapseAllAction.
+ *
+ * @param viewer
+ * the attached Viewer
+ */
+ public CollapseAllAction( TreeViewer viewer )
+ {
+ super( "Collapse All", BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_COLLAPSEALL ) );
+ super.setToolTipText( getText() );
+ super.setEnabled( true );
+
+ this.viewer = viewer;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ this.viewer.collapseAll();
+ }
+
+
+ /**
+ * Disposes the action delegate.
+ */
+ public void dispose()
+ {
+ this.viewer = null;
+ }
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CollapseAllAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java?rev=592079&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java (added)
+++ directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java Mon Nov 5 08:48:35 2007
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.actions;
+
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+import org.apache.directory.studio.ldapbrowser.common.actions.proxy.BrowserActionProxy;
+import org.apache.directory.studio.ldapbrowser.common.dnd.EntryTransfer;
+import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer;
+import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
+import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+import org.apache.directory.studio.ldapbrowser.core.model.IValue;
+import org.apache.directory.studio.ldapbrowser.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
+{
+ private 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()
+ {
+
+ // 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()
+ {
+ IEntry[] entries = getEntries();
+ IValue[] values = getValues();
+
+ // entry/searchresult/bookmark
+ if ( entries != null )
+ {
+ StringBuffer text = new StringBuffer();
+ for ( int i = 0; i < entries.length; i++ )
+ {
+ text.append( entries[i].getDn().getUpName() );
+ 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()
+ {
+
+ // entry/searchresult/bookmark
+ if ( getEntries() != null )
+ {
+ return true;
+ }
+
+ // values
+ else if ( getValues() != null )
+ {
+ return true;
+ }
+
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * 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;
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/CopyAction.java
------------------------------------------------------------------------------
svn:eol-style = native