You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/18 18:53:22 UTC
svn commit: r488368 [4/23] - in /directory/sandbox/pamarcelot/ldapstudio:
ldapstudio-browser-ui/ ldapstudio-browser-ui/META-INF/
ldapstudio-browser-ui/about_files/ ldapstudio-browser-ui/icons/
ldapstudio-browser-ui/icons/ovr16/ ldapstudio-browser-ui/sr...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIPreferencesInitializer.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,211 @@
+/*
+ * 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.ui;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SyntaxValueProviderRelation;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.AddressValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.DnValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ImageValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.InPlaceGeneralizedTimeValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ObjectClassValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.PasswordValueProvider;
+
+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;
+
+
+public class BrowserUIPreferencesInitializer extends AbstractPreferenceInitializer
+{
+
+ public BrowserUIPreferencesInitializer()
+ {
+ super();
+ }
+
+
+ public void initializeDefaultPreferences()
+ {
+
+ IPreferenceStore store = BrowserUIPlugin.getDefault().getPreferenceStore();
+
+ // Common
+ store.setDefault( BrowserUIConstants.PREFERENCE_COUNT_LIMIT, 1000 );
+ store.setDefault( BrowserUIConstants.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, BrowserUIConstants.PREFERENCE_OBJECTCLASS_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_OBJECTCLASS_FONT, fontDataBoldItalic );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_MUSTATTRIBUTE_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_MUSTATTRIBUTE_FONT, fontDataBold );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_MAYATTRIBUTE_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_MAYATTRIBUTE_FONT, fontDataNormal );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR, rgbBlack );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT, fontDataItalic );
+ // Error/Warning colors and fonts
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_WARNING_FONT, fontDataBoldItalic );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_WARNING_COLOR, rgbYellow );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_ERROR_FONT, fontDataBoldItalic );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_ERROR_COLOR, rgbRed );
+ // Quick filter background colors and fonts
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT, fontDataBold );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR, rgbYellow );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR, rgbBlack );
+
+ // Attributes
+ store.setDefault( BrowserUIConstants.PREFERENCE_SHOW_RAW_VALUES, false );
+
+ // Value Editors
+ AttributeValueProviderRelation[] attributeValueProviderRelations = new AttributeValueProviderRelation[]
+ { new AttributeValueProviderRelation( "objectClass", ObjectClassValueProvider.class.getName() ),
+ new AttributeValueProviderRelation( "userPassword", PasswordValueProvider.class.getName() ) };
+ BrowserUIPlugin.getDefault().getUIPreferences().setDefaultAttributeValueProviderRelations(
+ attributeValueProviderRelations );
+ SyntaxValueProviderRelation[] syntaxValueProviderRelations = new SyntaxValueProviderRelation[]
+ {
+ new SyntaxValueProviderRelation( "1.3.6.1.4.1.1466.115.121.1.24",
+ InPlaceGeneralizedTimeValueProvider.class.getName() ),
+ new SyntaxValueProviderRelation( "1.3.6.1.4.1.1466.115.121.1.28", ImageValueProvider.class.getName() ),
+ new SyntaxValueProviderRelation( "1.3.6.1.4.1.1466.115.121.1.12", DnValueProvider.class.getName() ),
+ new SyntaxValueProviderRelation( "1.3.6.1.4.1.1466.115.121.1.41", AddressValueProvider.class.getName() ) };
+ BrowserUIPlugin.getDefault().getUIPreferences().setDefaultSyntaxValueProviderRelations(
+ syntaxValueProviderRelations );
+
+ // Browser
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES, false );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_ENABLE_FOLDING, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_FOLDING_SIZE, 100 );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_ENTRY_LABEL, BrowserUIConstants.SHOW_RDN );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH, 50 );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, BrowserUIConstants.SHOW_DN );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, 50 );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_DIT, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_SEARCHES, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES, false );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SORT_BY, BrowserCoreConstants.SORT_BY_RDN_VALUE );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SORT_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_SORT_LIMIT, 10000 );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, true );
+
+ // Entry Editor
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD, 10 );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES, false );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY,
+ BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION );
+ store.setDefault( BrowserUIConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER,
+ BrowserCoreConstants.SORT_ORDER_ASCENDING );
+
+ // Search Result Editor
+ store.setDefault( BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS, true );
+
+ // Text Format
+ store.setDefault( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER, "\t" );
+ store.setDefault( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER, "|" );
+ store.setDefault( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER, "\"" );
+ store
+ .setDefault( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR, BrowserCoreConstants.LINE_SEPARATOR );
+ store.setDefault( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING,
+ BrowserCoreConstants.BINARYENCODING_IGNORE );
+
+ // LDIF Editor
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_FORMATTER_AUTOWRAP, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS, false );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_INSERTSINGLEPROPOSALAUTO, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_ENABLEAUTOACTIVATION, true );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_AUTOACTIVATIONDELAY, 200 );
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_CONTENTASSIST_SMARTINSERTATTRIBUTEINMODSPEC, true );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_COMMENT
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 63, 127, 95 ) );// green
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_COMMENT
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.NORMAL );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_KEYWORD
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 128, 128, 128 ) );// gray
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_KEYWORD
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_DN
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 0, 0, 0 ) );// black
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_DN
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_ATTRIBUTE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 127, 0, 85 ) );// violett
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_ATTRIBUTE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUETYPE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 255, 0, 0 ) );// red
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUETYPE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 0, 0, 192 ) );// blue
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_VALUE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.NORMAL );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEADD
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 123, 170, 91 ) );// green
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEADD
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODIFY
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 214, 160, 100 ) );// yellow
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODIFY
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEDELETE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 242, 70, 86 ) );// red
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEDELETE
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+ PreferenceConverter.setDefault( store, BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODDN
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_RGB_SUFFIX, new RGB( 127, 159, 191 ) );// bright
+ // blue
+ store.setDefault( BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_CHANGETYPEMODDN
+ + BrowserUIConstants.PREFERENCE_LDIFEDITOR_SYNTAX_STYLE_SUFFIX, SWT.BOLD );
+
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIReferralHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIReferralHandler.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIReferralHandler.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/BrowserUIReferralHandler.java Mon Dec 18 09:52:58 2006
@@ -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.ldapstudio.browser.ui;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IReferralHandler;
+import org.apache.directory.ldapstudio.browser.core.model.URL;
+import org.apache.directory.ldapstudio.browser.ui.dialogs.SelectReferralConnectionDialog;
+
+import org.eclipse.ui.PlatformUI;
+
+
+public class BrowserUIReferralHandler implements IReferralHandler
+{
+
+ private Map referralUrlToReferralConnectionCache = new HashMap();
+
+
+ public IConnection getReferralConnection( final URL referralUrl )
+ {
+
+ // check cache
+ if ( referralUrlToReferralConnectionCache.containsKey( referralUrl ) )
+ {
+ IConnection referralConnection = ( IConnection ) referralUrlToReferralConnectionCache.get( referralUrl );
+ if ( referralConnection != null )
+ {
+ IConnection[] connections = BrowserCorePlugin.getDefault().getConnectionManager().getConnections();
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ IConnection connection = connections[i];
+ if ( referralConnection == connection )
+ {
+ return referralConnection;
+ }
+ }
+ }
+ }
+
+ referralUrlToReferralConnectionCache.remove( referralUrl );
+
+ // open dialog
+ final IConnection[] referralConnection = new IConnection[1];
+ PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable()
+ {
+ public void run()
+ {
+ SelectReferralConnectionDialog dialog = new SelectReferralConnectionDialog( PlatformUI.getWorkbench()
+ .getDisplay().getActiveShell(), referralUrl );
+ if ( dialog.open() == SelectReferralConnectionDialog.OK )
+ {
+ IConnection connection = dialog.getReferralConnection();
+ referralUrlToReferralConnectionCache.put( referralUrl, connection );
+ referralConnection[0] = connection;
+ }
+ }
+ } );
+
+ return referralConnection[0];
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/EventDispatcherSync.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/EventDispatcherSync.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/EventDispatcherSync.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/EventDispatcherSync.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,148 @@
+/*
+ * 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.ui;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.events.EventDispatcher;
+import org.apache.directory.ldapstudio.browser.core.events.EventListener;
+import org.apache.directory.ldapstudio.browser.core.events.EventRunnable;
+
+import org.eclipse.swt.widgets.Display;
+
+
+public class EventDispatcherSync implements EventDispatcher
+{
+
+ private Set pauseEventFireringThreadList;
+
+ private Object lock;
+
+
+ public EventDispatcherSync()
+ {
+ this.pauseEventFireringThreadList = new HashSet();;
+ this.lock = new Object();
+ }
+
+
+ public void resumeEventFireingInCurrentThread()
+ {
+ this.pauseEventFireringThreadList.remove( Thread.currentThread() );
+ }
+
+
+ public void suspendEventFireingInCurrentThread()
+ {
+ this.pauseEventFireringThreadList.add( Thread.currentThread() );
+ }
+
+
+ public boolean isEventFireingSuspendInCurrentThread()
+ {
+ return this.pauseEventFireringThreadList.contains( Thread.currentThread() );
+ }
+
+
+ public void dispatchEvent( Object source, EventListener target, EventRunnable runnable )
+ {
+
+ SourceTargetRunnableWrapper strw = new SourceTargetRunnableWrapper( source, target, runnable );
+
+ if ( isEventFireingSuspendInCurrentThread() )
+ {
+ return;
+ }
+
+ synchronized ( lock )
+ {
+ this.runSourceTargetRunnableWrapper( strw );
+ }
+ }
+
+
+ public synchronized void startEventDispatcher()
+ {
+ }
+
+
+ public synchronized void stopEventDispatcher()
+ {
+ }
+
+
+ private void runSourceTargetRunnableWrapper( SourceTargetRunnableWrapper strw )
+ {
+ // System.out.println(strw.toString());
+ Display.getDefault().asyncExec( strw.runnable );
+ // Display.getDefault().syncExec(strw.runnable);
+ }
+
+ class SourceTargetRunnableWrapper
+ {
+ Object source;
+
+ EventListener target;
+
+ EventRunnable runnable;
+
+
+ SourceTargetRunnableWrapper( Object source, EventListener target, EventRunnable runnable )
+ {
+ this.source = source;
+ this.target = target;
+ this.runnable = runnable;
+ }
+
+
+ public boolean equals( Object o )
+ {
+ if ( o instanceof SourceTargetRunnableWrapper )
+ {
+ SourceTargetRunnableWrapper strw = ( SourceTargetRunnableWrapper ) o;
+ return strw.source == this.source
+ && strw.target == this.target
+ && strw.runnable.getClass() == this.runnable.getClass()
+ && ( strw.runnable.getEventObject() == null || this.runnable.getEventObject() == null || strw.runnable
+ .getEventObject().getClass() == this.runnable.getEventObject().getClass() );
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ public int hashCode()
+ {
+ return this.source.hashCode() + this.target.hashCode() + this.runnable.getClass().hashCode();
+ }
+
+
+ public String toString()
+ {
+ return "" + source.getClass().getName() + " - " + target.getClass().getName();
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/ExceptionHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/ExceptionHandler.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/ExceptionHandler.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/ExceptionHandler.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.ui;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Display;
+
+
+public class ExceptionHandler
+{
+
+ public ExceptionHandler()
+ {
+ super();
+ }
+
+
+ public void handleException( IStatus status )
+ {
+ display( null, status );
+ }
+
+
+ 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 );
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/BrowserAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/BrowserAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/BrowserAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/BrowserAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,391 @@
+/*
+ * 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.ui.actions;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.BookmarkUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.ConnectionUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.events.EntryModificationEvent;
+import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+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.ISearchResult;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifFile;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifPart;
+import org.apache.directory.ldapstudio.browser.core.model.ldif.container.LdifContainer;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserCategory;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserEntryPage;
+import org.apache.directory.ldapstudio.browser.ui.widgets.browser.BrowserSearchResultPage;
+
+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;
+
+
+public abstract class BrowserAction implements IWorkbenchWindowActionDelegate
+{
+
+ private IConnection[] selectedConnections;
+
+ private BrowserCategory[] selectedBrowserViewCategories;
+
+ private IEntry[] selectedEntries;
+
+ private BrowserEntryPage[] selectedBrowserEntryPages;
+
+ private ISearch[] selectedSearches;
+
+ private ISearchResult[] selectedSearchResults;
+
+ private BrowserSearchResultPage[] selectedBrowserSearchResultPages;
+
+ private IBookmark[] selectedBookmarks;
+
+ private IAttribute[] selectedAttributes;
+
+ private AttributeHierachie[] selectedAttributeHierarchies;
+
+ private IValue[] selectedValues;
+
+ private LdifFile selectedLdifModel;
+
+ private LdifContainer[] selectedLdifContainers;
+
+ private LdifPart[] selectedLdifParts;
+
+ private Object input;
+
+
+ protected BrowserAction()
+ {
+ this.init();
+ }
+
+
+ public void init( IWorkbenchWindow window )
+ {
+ this.init();
+ }
+
+
+ public void run( IAction action )
+ {
+ this.run();
+ }
+
+
+ public void selectionChanged( IAction action, ISelection selection )
+ {
+ setSelectedConnections( SelectionUtils.getConnections( selection ) );
+
+ setSelectedBrowserViewCategories( SelectionUtils.getBrowserViewCategories( selection ) );
+ setSelectedEntries( SelectionUtils.getEntries( selection ) );
+ setSelectedBrowserEntryPages( SelectionUtils.getBrowserEntryPages( selection ) );
+ setSelectedSearchResults( SelectionUtils.getSearchResults( selection ) );
+ setSelectedBrowserSearchResultPages( SelectionUtils.getBrowserSearchResultPages( selection ) );
+ setSelectedBookmarks( SelectionUtils.getBookmarks( selection ) );
+
+ setSelectedSearches( SelectionUtils.getSearches( selection ) );
+
+ setSelectedAttributes( SelectionUtils.getAttributes( selection ) );
+ setSelectedAttributeHierarchies( SelectionUtils.getAttributeHierarchie( selection ) );
+ setSelectedValues( SelectionUtils.getValues( selection ) );
+
+ action.setEnabled( this.isEnabled() );
+ action.setText( this.getText() );
+ action.setToolTipText( this.getText() );
+ }
+
+
+ public abstract String getText();
+
+
+ public abstract ImageDescriptor getImageDescriptor();
+
+
+ public abstract String getCommandId();
+
+
+ public abstract boolean isEnabled();
+
+
+ public abstract void run();
+
+
+ private void init()
+ {
+ this.selectedConnections = new IConnection[0];
+ 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 AttributeHierachie[0];
+ this.selectedValues = new IValue[0];
+
+ this.selectedLdifModel = null;
+ this.selectedLdifContainers = new LdifContainer[0];
+ this.selectedLdifParts = new LdifPart[0];
+
+ this.input = null;
+ }
+
+
+ public void dispose()
+ {
+ this.selectedConnections = new IConnection[0];
+ 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 AttributeHierachie[0];
+ this.selectedValues = new IValue[0];
+
+ this.selectedLdifModel = null;
+ this.selectedLdifContainers = new LdifContainer[0];
+ this.selectedLdifParts = new LdifPart[0];
+
+ this.input = null;
+ }
+
+
+ protected Shell getShell()
+ {
+ return PlatformUI.getWorkbench().getDisplay().getActiveShell();
+ }
+
+
+ public final void entryUpdated( EntryModificationEvent event )
+ {
+ }
+
+
+ public void searchUpdated( SearchUpdateEvent searchUpdateEvent )
+ {
+ }
+
+
+ public void bookmarkUpdated( BookmarkUpdateEvent bookmarkUpdateEvent )
+ {
+ }
+
+
+ public final void connectionUpdated( ConnectionUpdateEvent connectionUpdateEvent )
+ {
+ }
+
+
+ public IAttribute[] getSelectedAttributes()
+ {
+ return selectedAttributes;
+ }
+
+
+ public void setSelectedAttributes( IAttribute[] selectedAttributes )
+ {
+ this.selectedAttributes = selectedAttributes;
+ }
+
+
+ public IBookmark[] getSelectedBookmarks()
+ {
+ return selectedBookmarks;
+ }
+
+
+ public void setSelectedBookmarks( IBookmark[] selectedBookmarks )
+ {
+ this.selectedBookmarks = selectedBookmarks;
+ }
+
+
+ public BrowserCategory[] getSelectedBrowserViewCategories()
+ {
+ return selectedBrowserViewCategories;
+ }
+
+
+ public void setSelectedBrowserViewCategories( BrowserCategory[] selectedBrowserViewCategories )
+ {
+ this.selectedBrowserViewCategories = selectedBrowserViewCategories;
+ }
+
+
+ public IConnection[] getSelectedConnections()
+ {
+ return selectedConnections;
+ }
+
+
+ public void setSelectedConnections( IConnection[] selectedConnections )
+ {
+ this.selectedConnections = selectedConnections;
+ }
+
+
+ public IEntry[] getSelectedEntries()
+ {
+ return selectedEntries;
+ }
+
+
+ public void setSelectedEntries( IEntry[] selectedEntries )
+ {
+ this.selectedEntries = selectedEntries;
+ }
+
+
+ public ISearch[] getSelectedSearches()
+ {
+ return selectedSearches;
+ }
+
+
+ public void setSelectedSearches( ISearch[] selectedSearches )
+ {
+ this.selectedSearches = selectedSearches;
+ }
+
+
+ public ISearchResult[] getSelectedSearchResults()
+ {
+ return selectedSearchResults;
+ }
+
+
+ public void setSelectedSearchResults( ISearchResult[] selectedSearchResults )
+ {
+ this.selectedSearchResults = selectedSearchResults;
+ }
+
+
+ public IValue[] getSelectedValues()
+ {
+ return selectedValues;
+ }
+
+
+ public void setSelectedValues( IValue[] selectedValues )
+ {
+ this.selectedValues = selectedValues;
+ }
+
+
+ public Object getInput()
+ {
+ return input;
+ }
+
+
+ public void setInput( Object input )
+ {
+ this.input = input;
+ }
+
+
+ public LdifContainer[] getSelectedLdifContainers()
+ {
+ return selectedLdifContainers;
+ }
+
+
+ public void setSelectedLdifContainers( LdifContainer[] selectedLdifContainers )
+ {
+ this.selectedLdifContainers = selectedLdifContainers;
+ }
+
+
+ public LdifFile getSelectedLdifModel()
+ {
+ return selectedLdifModel;
+ }
+
+
+ public void setSelectedLdifModel( LdifFile selectedLdifModel )
+ {
+ this.selectedLdifModel = selectedLdifModel;
+ }
+
+
+ public LdifPart[] getSelectedLdifParts()
+ {
+ return selectedLdifParts;
+ }
+
+
+ public void setSelectedLdifParts( LdifPart[] selectedLdifParts )
+ {
+ this.selectedLdifParts = selectedLdifParts;
+ }
+
+
+ public BrowserEntryPage[] getSelectedBrowserEntryPages()
+ {
+ return selectedBrowserEntryPages;
+ }
+
+
+ public void setSelectedBrowserEntryPages( BrowserEntryPage[] selectedBrowserEntryPages )
+ {
+ this.selectedBrowserEntryPages = selectedBrowserEntryPages;
+ }
+
+
+ public BrowserSearchResultPage[] getSelectedBrowserSearchResultPages()
+ {
+ return selectedBrowserSearchResultPages;
+ }
+
+
+ public void setSelectedBrowserSearchResultPages( BrowserSearchResultPage[] selectedBrowserSearchResultPages )
+ {
+ this.selectedBrowserSearchResultPages = selectedBrowserSearchResultPages;
+ }
+
+
+ public AttributeHierachie[] getSelectedAttributeHierarchies()
+ {
+ return selectedAttributeHierarchies;
+ }
+
+
+ public void setSelectedAttributeHierarchies( AttributeHierachie[] ahs )
+ {
+ this.selectedAttributeHierarchies = ahs;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CloseConnectionAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CloseConnectionAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CloseConnectionAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CloseConnectionAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,82 @@
+/*
+ * 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.ui.actions;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+public class CloseConnectionAction extends BrowserAction
+{
+
+ public CloseConnectionAction()
+ {
+ super();
+ }
+
+
+ public void run()
+ {
+ for ( int i = 0; i < getSelectedConnections().length; i++ )
+ {
+ if ( getSelectedConnections()[i].canClose() )
+ {
+ getSelectedConnections()[i].close();
+ }
+ }
+ }
+
+
+ public String getText()
+ {
+ return getSelectedConnections().length > 1 ? "Close Connections" : "Close Connection";
+ }
+
+
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_CONNECTION_DISCONNECT );
+ }
+
+
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ public boolean isEnabled()
+ {
+ boolean canClose = false;
+ for ( int i = 0; i < getSelectedConnections().length; i++ )
+ {
+ if ( getSelectedConnections()[i].canClose() )
+ {
+ canClose = true;
+ break;
+ }
+ }
+ return getSelectedConnections().length > 0 && canClose;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CollapseAllAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CollapseAllAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CollapseAllAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CollapseAllAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.ui.actions;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.TreeViewer;
+
+
+public class CollapseAllAction extends Action
+{
+
+ protected TreeViewer viewer;
+
+
+ public CollapseAllAction( TreeViewer viewer )
+ {
+ super( "Collapse All", BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COLLAPSEALL ) );
+ super.setToolTipText( getText() );
+ super.setEnabled( true );
+
+ this.viewer = viewer;
+ }
+
+
+ public void run()
+ {
+ this.viewer.collapseAll();
+ }
+
+
+ public void dispose()
+ {
+ this.viewer = null;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,294 @@
+/*
+ * 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.ui.actions;
+
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+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.apache.directory.ldapstudio.browser.ui.actions.proxy.BrowserActionProxy;
+import org.apache.directory.ldapstudio.browser.ui.dnd.ConnectionTransfer;
+import org.apache.directory.ldapstudio.browser.ui.dnd.EntryTransfer;
+import org.apache.directory.ldapstudio.browser.ui.dnd.ValuesTransfer;
+
+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;
+
+
+public class CopyAction extends BrowserAction
+{
+
+ protected BrowserActionProxy pasteActionProxy;
+
+
+ public CopyAction( BrowserActionProxy pasteActionProxy )
+ {
+ super();
+ this.pasteActionProxy = pasteActionProxy;
+ }
+
+
+ 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";
+ }
+
+
+ public ImageDescriptor getImageDescriptor()
+ {
+ return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_COPY );
+ }
+
+
+ public String getCommandId()
+ {
+ return IWorkbenchActionDefinitionIds.COPY;
+ }
+
+
+ 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();
+ }
+ }
+
+
+ protected 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();
+ }
+ }
+
+
+ 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;
+ }
+ }
+
+
+ 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;
+ }
+ }
+
+
+ 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;
+ }
+ }
+
+
+ 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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAttributeDescriptionAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAttributeDescriptionAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAttributeDescriptionAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyAttributeDescriptionAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,118 @@
+/*
+ * 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.ui.actions;
+
+
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+
+
+public class CopyAttributeDescriptionAction extends BrowserAction
+{
+
+ public CopyAttributeDescriptionAction()
+ {
+ }
+
+
+ public void run()
+ {
+ StringBuffer text = new StringBuffer();
+ for ( Iterator iterator = getAttributeNameSet().iterator(); iterator.hasNext(); )
+ {
+ text.append( iterator.next() );
+ if ( iterator.hasNext() )
+ text.append( BrowserCoreConstants.LINE_SEPARATOR );
+ }
+
+ if ( text.length() > 0 )
+ {
+ CopyAction.copyToClipboard( new Object[]
+ { text.toString() }, new Transfer[]
+ { TextTransfer.getInstance() } );
+ }
+ }
+
+
+ private Set getAttributeNameSet()
+ {
+ Set attributeNameSet = new LinkedHashSet();
+ for ( int i = 0; i < getSelectedAttributeHierarchies().length; i++ )
+ {
+ for ( Iterator it = getSelectedAttributeHierarchies()[i].iterator(); it.hasNext(); )
+ {
+ IAttribute att = ( IAttribute ) it.next();
+ attributeNameSet.add( att.getDescription() );
+ }
+ }
+ for ( int i = 0; i < getSelectedAttributes().length; i++ )
+ {
+ attributeNameSet.add( getSelectedAttributes()[i].getDescription() );
+ }
+ for ( int i = 0; i < getSelectedValues().length; i++ )
+ {
+ attributeNameSet.add( getSelectedValues()[i].getAttribute().getDescription() );
+ }
+ return attributeNameSet;
+ }
+
+
+ public String getText()
+ {
+ if ( getAttributeNameSet().size() > 1 )
+ {
+ return "Copy Attribute Descriptions";
+ }
+ else
+ {
+ return "Copy Attribute Description";
+ }
+ }
+
+
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_ATT );
+ }
+
+
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ public boolean isEnabled()
+ {
+ return getAttributeNameSet().size() > 0;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyDnAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyDnAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyDnAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyDnAction.java Mon Dec 18 09:52:58 2006
@@ -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.ui.actions;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+
+
+public class CopyDnAction extends BrowserAction
+{
+
+ public CopyDnAction()
+ {
+ }
+
+
+ public void run()
+ {
+ String dn = null;
+ if ( getSelectedEntries().length > 0 )
+ {
+ dn = getSelectedEntries()[0].getDn().toString();
+ }
+ else if ( getSelectedAttributes().length > 0 )
+ {
+ dn = getSelectedAttributes()[0].getEntry().getDn().toString();
+ }
+ else if ( getSelectedAttributeHierarchies().length > 0 )
+ {
+ dn = getSelectedAttributeHierarchies()[0].getAttribute().getEntry().getDn().toString();
+ }
+ else if ( getSelectedValues().length > 0 )
+ {
+ dn = getSelectedValues()[0].getAttribute().getEntry().getDn().toString();
+ }
+ else if ( getSelectedSearchResults().length > 0 )
+ {
+ dn = getSelectedSearchResults()[0].getDn().toString();
+ }
+ else if ( getSelectedBookmarks().length > 0 )
+ {
+ dn = getSelectedBookmarks()[0].getDn().toString();
+ }
+
+ if ( dn != null )
+ {
+ CopyAction.copyToClipboard( new Object[]
+ { dn }, new Transfer[]
+ { TextTransfer.getInstance() } );
+ }
+ }
+
+
+ public String getText()
+ {
+ return "Copy DN";
+ }
+
+
+ public ImageDescriptor getImageDescriptor()
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_DN );
+ }
+
+
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ public boolean isEnabled()
+ {
+ return getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 1
+ || getSelectedAttributes().length + getSelectedValues().length > 0;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,230 @@
+/*
+ * 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.ui.actions;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.jobs.InitializeAttributesJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.ReadEntryJob;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.jobs.RunnableContextJobAdapter;
+
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+
+
+public abstract class CopyEntryAsAction extends BrowserAction
+{
+
+ public static final int MODE_DN_ONLY = 1;
+
+ public static final int MODE_RETURNING_ATTRIBUTES_ONLY = 2;
+
+ public static final int MODE_NORMAL = 3;
+
+ public static final int MODE_INCLUDE_OPERATIONAL_ATTRIBUTES = 4;
+
+ protected int mode;
+
+ protected String type;
+
+ protected String appendix;
+
+
+ public CopyEntryAsAction( String type, int mode )
+ {
+ super();
+ this.type = type;
+ this.mode = mode;
+ if ( this.mode == MODE_DN_ONLY )
+ {
+ this.appendix = " (DN only)";
+ }
+ else if ( this.mode == MODE_RETURNING_ATTRIBUTES_ONLY )
+ {
+ this.appendix = " (returning attributes only)";
+ }
+ else if ( this.mode == MODE_INCLUDE_OPERATIONAL_ATTRIBUTES )
+ {
+ this.appendix = " (include operational attributes)";
+ }
+ else if ( this.mode == MODE_NORMAL )
+ {
+ this.appendix = " (all user attributes)";
+ }
+ else
+ {
+ appendix = "";
+ }
+ }
+
+
+ public String getText()
+ {
+ if ( getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length > 0
+ && getSelectedSearches().length == 0 )
+ {
+ String text = ( getSelectedEntries().length + getSelectedSearchResults().length
+ + getSelectedBookmarks().length > 1 ? "Copy Entries as " + type : "Copy Entry as " + type )
+ + appendix;
+ return text;
+ }
+ else if ( getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 0
+ && getSelectedSearches().length == 1 && getSelectedSearches()[0].getSearchResults() != null
+ && getSelectedSearches()[0].getSearchResults().length > 0 )
+ {
+ String text = ( getSelectedSearches()[0].getSearchResults().length > 1 ? "Copy Search Results as " + type
+ : "Copy Search Result as " + type )
+ + appendix;
+ return text;
+ }
+
+ return "Copy Entry as " + type + appendix;
+ }
+
+
+ public String getCommandId()
+ {
+ return null;
+ }
+
+
+ public void run()
+ {
+
+ // entries to copy
+ List entryList = new ArrayList();
+ for ( int i = 0; i < getSelectedEntries().length; i++ )
+ {
+ entryList.add( getSelectedEntries()[i] );
+ }
+ for ( int i = 0; i < getSelectedSearchResults().length; i++ )
+ {
+ entryList.add( getSelectedSearchResults()[i].getEntry() );
+ }
+ for ( int i = 0; i < getSelectedBookmarks().length; i++ )
+ {
+ IEntry entry = getSelectedBookmarks()[0].getConnection().getEntryFromCache(
+ getSelectedBookmarks()[0].getDn() );
+ if ( entry == null )
+ {
+ ReadEntryJob job = new ReadEntryJob( getSelectedBookmarks()[0].getConnection(),
+ getSelectedBookmarks()[0].getDn() );
+ RunnableContextJobAdapter.execute( job );
+ entry = job.getReadEntry();
+ }
+ entryList.add( entry );
+ }
+ if ( getSelectedSearches().length == 1 )
+ {
+ ISearchResult[] results = getSelectedSearches()[0].getSearchResults();
+ for ( int k = 0; k < results.length; k++ )
+ {
+ entryList.add( results[k].getEntry() );
+ }
+ }
+ IEntry[] entries = ( IEntry[] ) entryList.toArray( new IEntry[entryList.size()] );
+
+ // check uninitialized entries
+ List uninitializedEntryList = new ArrayList();
+ for ( int i = 0; entries != null && i < entries.length; i++ )
+ {
+ if ( !entries[i].isAttributesInitialized() )
+ {
+ uninitializedEntryList.add( entries[i] );
+ }
+ }
+ if ( uninitializedEntryList.size() > 0
+ && ( this.mode == MODE_NORMAL || this.mode == MODE_INCLUDE_OPERATIONAL_ATTRIBUTES ) )
+ {
+ IEntry[] uninitializedEntries = ( IEntry[] ) uninitializedEntryList
+ .toArray( new IEntry[uninitializedEntryList.size()] );
+
+ InitializeAttributesJob job = new InitializeAttributesJob( uninitializedEntries, false );
+ RunnableContextJobAdapter.execute( job );
+
+ // SyncInitializeEntryJob job = new
+ // SyncInitializeEntryJob(uninitializedEntries,
+ // InitializeEntryJob.INIT_ATTRIBUTES_MODE, null);
+ // job.execute();
+ }
+
+ // serialize
+ StringBuffer text = new StringBuffer();
+ serialializeEntries( entries, text );
+ copyToClipboard( text.toString() );
+ }
+
+
+ protected abstract void serialializeEntries( IEntry[] entries, StringBuffer text );
+
+
+ public boolean isEnabled()
+ {
+ boolean showOperational = BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES );
+
+ if ( getSelectedSearchResults().length > 0
+ && getSelectedEntries().length + getSelectedBookmarks().length + getSelectedSearches().length == 0 )
+ {
+ return ( this.mode == MODE_RETURNING_ATTRIBUTES_ONLY || this.mode == MODE_NORMAL
+ || this.mode == MODE_DN_ONLY || ( this.mode == MODE_INCLUDE_OPERATIONAL_ATTRIBUTES && showOperational ) );
+ }
+ if ( getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length > 0
+ && getSelectedSearches().length == 0 )
+ {
+ return ( this.mode == MODE_NORMAL || this.mode == MODE_DN_ONLY || ( this.mode == MODE_INCLUDE_OPERATIONAL_ATTRIBUTES && showOperational ) );
+ }
+ if ( getSelectedEntries().length + getSelectedSearchResults().length + getSelectedBookmarks().length == 0
+ && getSelectedSearches().length == 1 && getSelectedSearches()[0].getSearchResults() != null
+ && getSelectedSearches()[0].getSearchResults().length > 0 )
+ {
+ return ( this.mode != MODE_INCLUDE_OPERATIONAL_ATTRIBUTES || ( this.mode == MODE_INCLUDE_OPERATIONAL_ATTRIBUTES && showOperational ) );
+ }
+ return false;
+ }
+
+
+ protected void copyToClipboard( String text )
+ {
+ Clipboard clipboard = null;
+ try
+ {
+ clipboard = new Clipboard( Display.getCurrent() );
+ clipboard.setContents( new Object[]
+ { text }, new Transfer[]
+ { TextTransfer.getInstance() } );
+ }
+ finally
+ {
+ if ( clipboard != null )
+ clipboard.dispose();
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsCsvAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsCsvAction.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsCsvAction.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/actions/CopyEntryAsCsvAction.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,325 @@
+/*
+ * 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.ui.actions;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.ldapstudio.browser.core.internal.model.AttributeComparator;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierachie;
+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.ISearch;
+import org.apache.directory.ldapstudio.browser.core.model.ISearchResult;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+
+public class CopyEntryAsCsvAction extends CopyEntryAsAction
+{
+
+ public static final int MODE_TABLE = 5;
+
+
+ public CopyEntryAsCsvAction( int mode )
+ {
+ super( "CSV", mode );
+ }
+
+
+ public ImageDescriptor getImageDescriptor()
+ {
+ if ( this.mode == MODE_DN_ONLY )
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_CSV );
+ }
+ else if ( this.mode == MODE_RETURNING_ATTRIBUTES_ONLY )
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_CSV_SEARCHRESULT );
+ }
+ else if ( this.mode == MODE_INCLUDE_OPERATIONAL_ATTRIBUTES )
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_CSV_OPERATIONAL );
+ }
+ else if ( this.mode == MODE_NORMAL )
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_CSV_USER );
+ }
+ else if ( this.mode == MODE_TABLE )
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_TABLE );
+ }
+ else
+ {
+ return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_COPY_CSV );
+ }
+ }
+
+
+ public String getText()
+ {
+ if ( this.mode == MODE_TABLE )
+ {
+ return "Copy Table";
+ }
+
+ return super.getText();
+ }
+
+
+ public boolean isEnabled()
+ {
+ if ( this.mode == MODE_TABLE )
+ {
+ return getInput() != null && getInput() instanceof ISearch
+ && ( ( ISearch ) getInput() ).getSearchResults() != null
+ && ( ( ISearch ) getInput() ).getSearchResults().length > 0;
+ }
+
+ return super.isEnabled();
+ }
+
+
+ public void run()
+ {
+
+ if ( this.mode == MODE_TABLE )
+ {
+ if ( getInput() != null && getInput() instanceof ISearch
+ && ( ( ISearch ) getInput() ).getSearchResults() != null
+ && ( ( ISearch ) getInput() ).getSearchResults().length > 0 )
+ {
+ List entryList = new ArrayList();
+ ISearchResult[] results = ( ( ISearch ) getInput() ).getSearchResults();
+ for ( int k = 0; k < results.length; k++ )
+ {
+ entryList.add( results[k].getEntry() );
+ }
+ IEntry[] entries = ( IEntry[] ) entryList.toArray( new IEntry[entryList.size()] );
+
+ StringBuffer text = new StringBuffer();
+ serialializeEntries( entries, text );
+ copyToClipboard( text.toString() );
+ }
+ }
+ else
+ {
+ super.run();
+ }
+
+ }
+
+
+ public void serialializeEntries( IEntry[] entries, StringBuffer text )
+ {
+
+ String attributeDelimiter = BrowserUIPlugin.getDefault().getPreferenceStore().getString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER );
+ String valueDelimiter = BrowserUIPlugin.getDefault().getPreferenceStore().getString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER );
+ String quoteCharacter = BrowserUIPlugin.getDefault().getPreferenceStore().getString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER );
+ String lineSeparator = BrowserUIPlugin.getDefault().getPreferenceStore().getString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR );
+ int binaryEncoding = BrowserUIPlugin.getDefault().getPreferenceStore().getInt(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING );
+
+ String[] returningAttributes = null;
+ if ( this.mode == MODE_DN_ONLY )
+ {
+ returningAttributes = new String[0];
+ }
+ else if ( this.mode == MODE_RETURNING_ATTRIBUTES_ONLY && getSelectedSearchResults().length > 0
+ && getSelectedEntries().length + getSelectedBookmarks().length + getSelectedSearches().length == 0 )
+ {
+ returningAttributes = getSelectedSearchResults()[0].getSearch().getReturningAttributes();
+ }
+ else if ( ( this.mode == MODE_RETURNING_ATTRIBUTES_ONLY || this.mode == MODE_TABLE )
+ && getSelectedSearches().length == 1 )
+ {
+ returningAttributes = getSelectedSearches()[0].getReturningAttributes();
+ }
+ else if ( ( this.mode == MODE_RETURNING_ATTRIBUTES_ONLY || this.mode == MODE_TABLE )
+ && ( getInput() instanceof ISearch ) )
+ {
+ returningAttributes = ( ( ISearch ) ( getInput() ) ).getReturningAttributes();
+ }
+ else
+ {
+ Map attributeMap = new HashMap();
+ for ( int e = 0; entries != null && e < entries.length; e++ )
+ {
+ IAttribute[] attributes = entries[e].getAttributes();
+ for ( int a = 0; attributes != null && a < attributes.length; a++ )
+ {
+
+ if ( attributes[a].isOperationalAttribute() && this.mode != MODE_INCLUDE_OPERATIONAL_ATTRIBUTES )
+ continue;
+
+ if ( !attributeMap.containsKey( attributes[a].getDescription() ) )
+ {
+ attributeMap.put( attributes[a].getDescription(), attributes[a] );
+ }
+ }
+ }
+ IAttribute[] attributes = ( IAttribute[] ) attributeMap.values().toArray(
+ new IAttribute[attributeMap.size()] );
+
+ if ( attributes.length > 0 )
+ {
+ AttributeComparator comparator = new AttributeComparator( entries[0].getConnection() );
+ Arrays.sort( attributes, comparator );
+ }
+
+ returningAttributes = new String[attributes.length];
+ for ( int i = 0; i < attributes.length; i++ )
+ {
+ returningAttributes[i] = attributes[i].getDescription();
+ }
+ }
+
+ // header
+ if ( this.mode != MODE_TABLE
+ || BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN ) )
+ {
+ text.append( quoteCharacter );
+ text.append( "DN" );
+ text.append( quoteCharacter );
+ text.append( attributeDelimiter );
+ }
+ for ( int a = 0; returningAttributes != null && a < returningAttributes.length; a++ )
+ {
+ text.append( quoteCharacter );
+ text.append( returningAttributes[a] );
+ text.append( quoteCharacter );
+ if ( a + 1 < returningAttributes.length )
+ {
+ text.append( attributeDelimiter );
+ }
+ }
+ text.append( lineSeparator );
+
+ for ( int e = 0; entries != null && e < entries.length; e++ )
+ {
+
+ if ( this.mode != MODE_TABLE
+ || BrowserUIPlugin.getDefault().getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN ) )
+ {
+ text.append( quoteCharacter );
+ text.append( entries[e].getDn().toString() );
+ text.append( quoteCharacter );
+ text.append( attributeDelimiter );
+
+ }
+ for ( int a = 0; returningAttributes != null && a < returningAttributes.length; a++ )
+ {
+
+ AttributeComparator comparator = new AttributeComparator( entries[e] );
+ AttributeHierachie ah = entries[e].getAttributeWithSubtypes( returningAttributes[a] );
+ if ( ah != null )
+ {
+
+ StringBuffer valueSB = new StringBuffer();
+
+ for ( Iterator it = ah.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ if ( attribute != null )
+ {
+
+ IValue[] values = attribute.getValues();
+ Arrays.sort( values, comparator );
+
+ for ( int v = 0; v < values.length; v++ )
+ {
+ String val = LdifUtils.getStringValue( values[v], binaryEncoding );
+ valueSB.append( val );
+ if ( v + 1 < values.length )
+ {
+ valueSB.append( valueDelimiter );
+ }
+ }
+ }
+
+ if ( it.hasNext() )
+ {
+ valueSB.append( valueDelimiter );
+ }
+ }
+
+ String value = valueSB.toString().replaceAll( quoteCharacter, quoteCharacter + quoteCharacter );
+ text.append( quoteCharacter );
+ text.append( value );
+ text.append( quoteCharacter );
+
+ }
+
+ // IAttribute attribute =
+ // entries[e].getAttribute(returningAttributes[a]);
+ // if (attribute != null) {
+ //
+ // IValue[] values = attribute.getValues();
+ // Arrays.sort(values, comparator);
+ //
+ // StringBuffer valueSB = new StringBuffer();
+ // for (int v = 0; v < values.length; v++) {
+ // String val = LdifUtils.getStringValue(values[v],
+ // binaryEncoding);
+ // valueSB.append(val);
+ // if (v + 1 < values.length) {
+ // valueSB.append(valueDelimiter);
+ // ;
+ // }
+ // }
+ //
+ // String value = valueSB.toString().replaceAll(quoteCharacter,
+ // quoteCharacter + quoteCharacter);
+ // text.append(quoteCharacter);
+ // text.append(value);
+ // text.append(quoteCharacter);
+ //
+ // }
+
+ if ( a + 1 < returningAttributes.length )
+ {
+ text.append( attributeDelimiter );
+ }
+ }
+
+ if ( e < entries.length )
+ {
+ text.append( lineSeparator );
+ }
+ }
+ }
+
+}