You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/04/09 11:49:57 UTC
svn commit: r526693 [7/17] - in
/directory/ldapstudio/trunk/ldapstudio-browser-common: ./ META-INF/
resources/ resources/icons/ resources/templates/ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/dir...
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/TextFormatsPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/TextFormatsPreferencePage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/TextFormatsPreferencePage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/TextFormatsPreferencePage.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,486 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.common.widgets.BinaryEncodingInput;
+import org.apache.directory.ldapstudio.browser.common.widgets.FileEncodingInput;
+import org.apache.directory.ldapstudio.browser.common.widgets.LineSeparatorInput;
+import org.apache.directory.ldapstudio.browser.common.widgets.OptionsInput;
+import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
+import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class TextFormatsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage,
+ WidgetModifyListener, ModifyListener
+{
+
+ public static final String LDIF_TAB = "LDIF";
+
+ public static final String CSV_TAB = "CSV";
+
+ public static final String XLS_TAB = "XLS";
+
+ public static final String TABLE_TAB = "TABLE";
+
+ private Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences();
+
+ private TabFolder tabFolder;
+
+ private TabItem ldifTab;
+
+ private TabItem tableTab;
+
+ private TabItem csvTab;
+
+ private TabItem xlsTab;
+
+ private Text ldifLineLengthText;
+
+ private Button ldifSpaceAfterColonButton;
+
+ private LineSeparatorInput ldifLineSeparator;
+
+ // private Button ldifSpaceBetweenRDNsButton;
+
+ private OptionsInput tableAttributeDelimiterWidget;
+
+ private OptionsInput tableValueDelimiterWidget;
+
+ private OptionsInput tableQuoteWidget;
+
+ private LineSeparatorInput tableLineSeparator;
+
+ private BinaryEncodingInput tableBinaryEncodingWidget;
+
+ private OptionsInput csvAttributeDelimiterWidget;
+
+ private OptionsInput csvValueDelimiterWidget;
+
+ private OptionsInput csvQuoteWidget;
+
+ private LineSeparatorInput csvLineSeparator;
+
+ private BinaryEncodingInput csvBinaryEncodingWidget;
+
+ private FileEncodingInput csvEncodingWidget;
+
+ private OptionsInput xlsValueDelimiterWidget;
+
+ private OptionsInput xlsBinaryEncodingWidget;
+
+
+ public TextFormatsPreferencePage()
+ {
+ super();
+ super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() );
+ super.setDescription( "Settings for text formats" );
+ }
+
+
+ public void init( IWorkbench workbench )
+ {
+ }
+
+
+ public void applyData( Object data )
+ {
+ if ( data != null && tabFolder != null )
+ {
+ if ( LDIF_TAB.equals( data ) )
+ {
+ tabFolder.setSelection( 0 );
+ }
+ else if ( TABLE_TAB.equals( data ) )
+ {
+ tabFolder.setSelection( 1 );
+ }
+ else if ( CSV_TAB.equals( data ) )
+ {
+ tabFolder.setSelection( 2 );
+ }
+ else if ( XLS_TAB.equals( data ) )
+ {
+ tabFolder.setSelection( 3 );
+ }
+ }
+ }
+
+
+ protected Control createContents( Composite parent )
+ {
+ BaseWidgetUtils.createSpacer( parent, 1 );
+ tabFolder = new TabFolder( parent, SWT.TOP );
+
+ createLdifTab();
+ createTableTab();
+ createCsvTab();
+ createXlsTab();
+
+ updateEnabled();
+ validate();
+
+ applyDialogFont( tabFolder );
+
+ return tabFolder;
+ }
+
+
+ private void createTableTab()
+ {
+
+ tableTab = new TabItem( tabFolder, SWT.NONE );
+ tableTab.setText( "CSV Copy" );
+
+ Composite tableComposite = new Composite( tabFolder, SWT.NONE );
+ tableComposite.setLayout( new GridLayout( 1, false ) );
+ Composite tableInnerComposite = BaseWidgetUtils.createColumnContainer( tableComposite, 3, 1 );
+
+ BaseWidgetUtils.createLabel( tableInnerComposite, "Select CSV copy format options:", 3 );
+ BaseWidgetUtils.createSpacer( tableInnerComposite, 3 );
+
+ tableAttributeDelimiterWidget = new OptionsInput( "Attribute Delimiter", "Tabulator (\\t)", "\t", new String[]
+ { "Tabulator (\\t)", "Comma (,)", "Semikolon (;)" }, new String[]
+ { "\t", ",", ";" }, getPreferenceStore().getString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER ), false, true );
+ tableAttributeDelimiterWidget.createWidget( tableInnerComposite );
+ tableAttributeDelimiterWidget.addWidgetModifyListener( this );
+
+ tableValueDelimiterWidget = new OptionsInput( "Value Delimiter", "Pipe (|)", "|", new String[]
+ { "Pipe (|)", "Comma (,)", "Semikolon (;)", "Newline (\\n)" }, new String[]
+ { "|", ",", ";", "\n" }, getPreferenceStore().getString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER ), false, true );
+ tableValueDelimiterWidget.createWidget( tableInnerComposite );
+ tableValueDelimiterWidget.addWidgetModifyListener( this );
+
+ tableQuoteWidget = new OptionsInput( "Quote Character", "Double Quote (\")", "\"", new String[]
+ { "Double Quote (\")", "Single Quote (')" }, new String[]
+ { "\"", "'" }, getPreferenceStore().getString( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER ),
+ false, true );
+ tableQuoteWidget.createWidget( tableInnerComposite );
+ tableQuoteWidget.addWidgetModifyListener( this );
+
+ tableLineSeparator = new LineSeparatorInput( getPreferenceStore().getString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR ), false );
+ tableLineSeparator.createWidget( tableInnerComposite );
+ tableLineSeparator.addWidgetModifyListener( this );
+
+ tableBinaryEncodingWidget = new BinaryEncodingInput( getPreferenceStore().getString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING ), false );
+ tableBinaryEncodingWidget.createWidget( tableInnerComposite );
+ tableBinaryEncodingWidget.addWidgetModifyListener( this );
+
+ Composite copyTableHintComposite = BaseWidgetUtils.createColumnContainer( tableInnerComposite, 3, 3 );
+ BaseWidgetUtils.createWrappedLabeledText( copyTableHintComposite,
+ "Hint: The default settings are suitable to paste the copied data into Excel or OpenOffice.", 1 );
+
+ tableTab.setControl( tableComposite );
+ }
+
+
+ private void createCsvTab()
+ {
+
+ csvTab = new TabItem( tabFolder, SWT.NONE );
+ csvTab.setText( "CSV Export" );
+
+ Composite csvComposite = new Composite( tabFolder, SWT.NONE );
+ csvComposite.setLayout( new GridLayout( 1, false ) );
+ Composite csvInnerComposite = BaseWidgetUtils.createColumnContainer( csvComposite, 3, 1 );
+
+ BaseWidgetUtils.createLabel( csvInnerComposite, "Select CSV export file format options:", 3 );
+ BaseWidgetUtils.createSpacer( csvInnerComposite, 3 );
+
+ csvAttributeDelimiterWidget = new OptionsInput( "Attribute Delimiter", "Comma (,)", ",", new String[]
+ { "Comma (,)", "Semikolon (;)", "Tabulator (\\t)" }, new String[]
+ { ",", ";", "\t" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER ),
+ false, true );
+ csvAttributeDelimiterWidget.createWidget( csvInnerComposite );
+ csvAttributeDelimiterWidget.addWidgetModifyListener( this );
+
+ csvValueDelimiterWidget = new OptionsInput( "Value Delimiter", "Pipe (|)", "|", new String[]
+ { "Pipe (|)", "Comma (,)", "Semikolon (;)", "Newline (\\n)" }, new String[]
+ { "|", ",", ";", "\n" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER ),
+ false, true );
+ csvValueDelimiterWidget.createWidget( csvInnerComposite );
+ csvValueDelimiterWidget.addWidgetModifyListener( this );
+
+ csvQuoteWidget = new OptionsInput( "Quote Character", "Double Quote (\")", "\"", new String[]
+ { "Double Quote (\")", "Single Quote (')" }, new String[]
+ { "\"", "'" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER ), false,
+ true );
+ csvQuoteWidget.createWidget( csvInnerComposite );
+ csvQuoteWidget.addWidgetModifyListener( this );
+
+ csvLineSeparator = new LineSeparatorInput( coreStore
+ .getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR ), false );
+ csvLineSeparator.createWidget( csvInnerComposite );
+ csvLineSeparator.addWidgetModifyListener( this );
+
+ csvBinaryEncodingWidget = new BinaryEncodingInput( coreStore
+ .getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING ), false );
+ csvBinaryEncodingWidget.createWidget( csvInnerComposite );
+ csvBinaryEncodingWidget.addWidgetModifyListener( this );
+
+ csvEncodingWidget = new FileEncodingInput( coreStore
+ .getString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING ), false );
+ csvEncodingWidget.createWidget( csvInnerComposite );
+ csvEncodingWidget.addWidgetModifyListener( this );
+
+ csvTab.setControl( csvComposite );
+ }
+
+
+ private void createXlsTab()
+ {
+
+ xlsTab = new TabItem( tabFolder, SWT.NONE );
+ xlsTab.setText( "Excel Export" );
+
+ Composite xlsComposite = new Composite( tabFolder, SWT.NONE );
+ xlsComposite.setLayout( new GridLayout( 1, false ) );
+ Composite xlsInnerComposite = BaseWidgetUtils.createColumnContainer( xlsComposite, 3, 1 );
+
+ BaseWidgetUtils.createWrappedLabeledText( xlsInnerComposite, "Select Excel export file format options:", 3 );
+ BaseWidgetUtils.createSpacer( xlsInnerComposite, 3 );
+
+ xlsValueDelimiterWidget = new OptionsInput( "Value Delimiter", "Pipe (|)", "|", new String[]
+ { "Pipe (|)", "Comma (,)", "Semikolon (;)", "Newline (\\n)" }, new String[]
+ { "|", ",", ";", "\n" }, coreStore.getString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER ),
+ false, true );
+ xlsValueDelimiterWidget.createWidget( xlsInnerComposite );
+ xlsValueDelimiterWidget.addWidgetModifyListener( this );
+
+ xlsBinaryEncodingWidget = new BinaryEncodingInput( coreStore
+ .getString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING ), false );
+ xlsBinaryEncodingWidget.createWidget( xlsInnerComposite );
+ xlsBinaryEncodingWidget.addWidgetModifyListener( this );
+
+ xlsTab.setControl( xlsComposite );
+ }
+
+
+ private void createLdifTab()
+ {
+
+ ldifTab = new TabItem( tabFolder, SWT.NONE );
+ ldifTab.setText( "LDIF" );
+
+ Composite ldifComposite = new Composite( tabFolder, SWT.NONE );
+ ldifComposite.setLayout( new GridLayout( 1, false ) );
+ Composite ldifInnerComposite = BaseWidgetUtils.createColumnContainer( ldifComposite, 1, 1 );
+
+ BaseWidgetUtils.createLabel( ldifInnerComposite, "Select LDIF format options:", 1 );
+ BaseWidgetUtils.createSpacer( ldifInnerComposite, 1 );
+
+ ldifLineSeparator = new LineSeparatorInput( coreStore
+ .getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR ), true );
+ ldifLineSeparator.createWidget( ldifInnerComposite );
+ ldifLineSeparator.addWidgetModifyListener( this );
+
+ BaseWidgetUtils.createSpacer( ldifInnerComposite, 1 );
+
+ Composite lineLengthComposite = BaseWidgetUtils.createColumnContainer( ldifInnerComposite, 3, 1 );
+ BaseWidgetUtils.createLabel( lineLengthComposite, "Line length:", 1 );
+ ldifLineLengthText = BaseWidgetUtils.createText( lineLengthComposite, "", 3, 1 );
+ ldifLineLengthText.setText( coreStore.getString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH ) );
+ ldifLineLengthText.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-9]*" ) )
+ {
+ e.doit = false;
+ }
+ if ( "".equals( ldifLineLengthText.getText() ) && e.text.matches( "[0]" ) )
+ {
+ e.doit = false;
+ }
+ }
+ } );
+ ldifLineLengthText.addModifyListener( this );
+ BaseWidgetUtils.createLabel( lineLengthComposite, "characters", 1 );
+
+ ldifSpaceAfterColonButton = BaseWidgetUtils.createCheckbox( ldifInnerComposite, "Space after colon", 1 );
+ ldifSpaceAfterColonButton.setSelection( coreStore
+ .getBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON ) );
+
+ // ldifSpaceBetweenRDNsButton =
+ // BaseWidgetUtils.createCheckbox(ldifComposite, "Space between RDNs",
+ // 1);
+ // ldifSpaceBetweenRDNsButton.setSelection(coreStore.getBoolean(BrowserCoreConstants.PREFERENCE_LDIF_SPACE_BETWEEN_RDNS));
+
+ ldifTab.setControl( ldifComposite );
+ }
+
+
+ private void updateEnabled()
+ {
+
+ }
+
+
+ public boolean performOk()
+ {
+
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH, this.ldifLineLengthText.getText() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR, this.ldifLineSeparator.getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON, this.ldifSpaceAfterColonButton
+ .getSelection() );
+ // coreStore.setValue(BrowserCoreConstants.PREFERENCE_LDIF_SPACE_BETWEEN_RDNS,
+ // this.ldifSpaceBetweenRDNsButton.getSelection());
+ BrowserCorePlugin.getDefault().savePluginPreferences();
+
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER,
+ this.csvAttributeDelimiterWidget.getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER, this.csvValueDelimiterWidget
+ .getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER, this.csvQuoteWidget
+ .getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR, this.csvLineSeparator
+ .getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING, this.csvBinaryEncodingWidget
+ .getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING, this.csvEncodingWidget.getRawValue() );
+
+ getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER,
+ this.tableAttributeDelimiterWidget.getRawValue() );
+ getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER,
+ this.tableValueDelimiterWidget.getRawValue() );
+ getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER,
+ this.tableQuoteWidget.getRawValue() );
+ getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR,
+ this.tableLineSeparator.getRawValue() );
+ getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING,
+ this.tableBinaryEncodingWidget.getRawValue() );
+
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER, this.xlsValueDelimiterWidget
+ .getRawValue() );
+ coreStore.setValue( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING, this.xlsBinaryEncodingWidget
+ .getRawValue() );
+
+ updateEnabled();
+ validate();
+
+ return true;
+ }
+
+
+ protected void performDefaults()
+ {
+
+ this.ldifLineLengthText.setText( coreStore.getDefaultString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_WIDTH ) );
+ this.ldifLineSeparator.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_LDIF_LINE_SEPARATOR ) );
+ this.ldifSpaceAfterColonButton.setSelection( coreStore
+ .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_LDIF_SPACE_AFTER_COLON ) );
+ // this.ldifSpaceBetweenRDNsButton.setSelection(coreStore.getDefaultBoolean(BrowserCoreConstants.PREFERENCE_LDIF_SPACE_BETWEEN_RDNS));
+
+ this.csvAttributeDelimiterWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ATTRIBUTEDELIMITER ) );
+ this.csvValueDelimiterWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_VALUEDELIMITER ) );
+ this.csvQuoteWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_QUOTECHARACTER ) );
+ this.csvLineSeparator.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_LINESEPARATOR ) );
+ this.csvBinaryEncodingWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_BINARYENCODING ) );
+ this.csvEncodingWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_CSV_ENCODING ) );
+
+ this.tableAttributeDelimiterWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER ) );
+ this.tableValueDelimiterWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER ) );
+ this.tableQuoteWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER ) );
+ this.tableLineSeparator.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR ) );
+ this.tableBinaryEncodingWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING ) );
+
+ this.xlsValueDelimiterWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_VALUEDELIMITER ) );
+ this.xlsBinaryEncodingWidget.setRawValue( coreStore
+ .getDefaultString( BrowserCoreConstants.PREFERENCE_FORMAT_XLS_BINARYENCODING ) );
+
+ updateEnabled();
+ validate();
+
+ super.performDefaults();
+ }
+
+
+ public void widgetModified( WidgetModifyEvent event )
+ {
+ updateEnabled();
+ validate();
+ }
+
+
+ public void modifyText( ModifyEvent e )
+ {
+ updateEnabled();
+ validate();
+ }
+
+
+ protected void validate()
+ {
+ setValid( !"".equals( csvAttributeDelimiterWidget.getRawValue() )
+ && !"".equals( csvValueDelimiterWidget.getRawValue() ) && !"".equals( csvQuoteWidget.getRawValue() )
+ && !"".equals( csvLineSeparator.getRawValue() ) && !"".equals( csvBinaryEncodingWidget.getRawValue() )
+ && !"".equals( csvEncodingWidget.getRawValue() ) &&
+
+ !"".equals( tableAttributeDelimiterWidget.getRawValue() )
+ && !"".equals( tableValueDelimiterWidget.getRawValue() ) && !"".equals( tableQuoteWidget.getRawValue() )
+ && !"".equals( tableLineSeparator.getRawValue() ) && !"".equals( tableBinaryEncodingWidget.getRawValue() )
+ &&
+
+ !"".equals( xlsValueDelimiterWidget.getRawValue() ) && !"".equals( xlsBinaryEncodingWidget.getRawValue() )
+ &&
+
+ !"".equals( ldifLineLengthText.getText() ) && !"".equals( ldifLineSeparator.getRawValue() ) );
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/ValueEditorsPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/ValueEditorsPreferencePage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/ValueEditorsPreferencePage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/ValueEditorsPreferencePage.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,598 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.dialogs.preferences;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation;
+import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.apache.directory.ldapstudio.browser.core.model.schema.SyntaxValueProviderRelation;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
+import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager.ValueEditorExtension;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class ValueEditorsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+
+ private SortedMap<String, ValueEditorExtension> class2ValueEditorProxyMap;
+
+ private SortedMap attributeOid2AtdMap;
+
+ private SortedMap attributeTypes2AtdMap;
+
+ private String[] attributeTypesAndOids;
+
+ private SortedMap syntaxOid2LsdMap;
+
+ private SortedMap syntaxDesc2LsdMap;
+
+ private String[] syntaxDescsAndOids;
+
+ private List attributeList;
+
+ private TableViewer attributeViewer;
+
+ private Button attributeAddButton;
+
+ private Button attributeEditButton;
+
+ private Button attributeRemoveButton;
+
+ private List syntaxList;
+
+ private TableViewer syntaxViewer;
+
+ private Button syntaxAddButton;
+
+ private Button syntaxEditButton;
+
+ private Button syntaxRemoveButton;
+
+
+ public ValueEditorsPreferencePage()
+ {
+ super();
+ super.setDescription( "Specify value editors:" );
+ }
+
+
+ public void init( IWorkbench workbench )
+ {
+ }
+
+
+ protected Control createContents( Composite parent )
+ {
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+ composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+
+ // init available value providers
+ this.class2ValueEditorProxyMap = new TreeMap<String, ValueEditorExtension>();
+ Composite dummyComposite = new Composite( composite, SWT.NONE );
+ dummyComposite.setLayoutData( new GridData( 1, 1 ) );
+
+ Collection<ValueEditorExtension> valueEditorProxys = ValueEditorManager.getValueEditorProxys();
+ for ( ValueEditorExtension proxy : valueEditorProxys )
+ {
+ this.class2ValueEditorProxyMap.put( proxy.className, proxy );
+ }
+
+ // init available attribute types
+ this.attributeTypes2AtdMap = new TreeMap();
+ this.attributeOid2AtdMap = new TreeMap();
+ ConnectionManager cm = BrowserCorePlugin.getDefault().getConnectionManager();
+ IConnection[] connections = cm.getConnections();
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ Schema schema = connections[i].getSchema();
+ if ( schema != null )
+ {
+ createAttributeMaps( schema );
+ }
+ }
+ createAttributeMaps( Schema.DEFAULT_SCHEMA );
+ this.attributeTypesAndOids = new String[this.attributeTypes2AtdMap.size() + this.attributeOid2AtdMap.size()];
+ System.arraycopy( this.attributeTypes2AtdMap.keySet().toArray(), 0, this.attributeTypesAndOids, 0,
+ this.attributeTypes2AtdMap.size() );
+ System.arraycopy( this.attributeOid2AtdMap.keySet().toArray(), 0, this.attributeTypesAndOids,
+ this.attributeTypes2AtdMap.size(), this.attributeOid2AtdMap.size() );
+
+ // init available syntaxes
+ this.syntaxOid2LsdMap = new TreeMap();
+ this.syntaxDesc2LsdMap = new TreeMap();
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ Schema schema = connections[i].getSchema();
+ if ( schema != null )
+ {
+ createSyntaxMaps( schema );
+ }
+ }
+ createSyntaxMaps( Schema.DEFAULT_SCHEMA );
+ this.syntaxDescsAndOids = new String[this.syntaxOid2LsdMap.size()];
+ System.arraycopy( this.syntaxOid2LsdMap.keySet().toArray(), 0, this.syntaxDescsAndOids, 0,
+ this.syntaxOid2LsdMap.size() );
+
+ // create attribute contents
+ // BaseWidgetUtils.createSpacer(composite, 1);
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ this.createAttributeContents( composite );
+ this.attributeList = new ArrayList( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+ .getAttributeValueProviderRelations() ) );
+ attributeViewer.setInput( this.attributeList );
+ attributeViewer.getTable().getColumn( 0 ).pack();
+ // attributeViewer.getTable().getColumn(1).pack();
+ attributeViewer.getTable().getColumn( 2 ).pack();
+ attributeViewer.getTable().pack();
+
+ // create syntax contents
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ this.createSyntaxContents( composite );
+ this.syntaxList = new ArrayList( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+ .getSyntaxValueProviderRelations() ) );
+ syntaxViewer.setInput( this.syntaxList );
+ syntaxViewer.getTable().getColumn( 0 ).pack();
+ // syntaxViewer.getTable().getColumn(1).pack();
+ syntaxViewer.getTable().getColumn( 2 ).pack();
+ syntaxViewer.getTable().pack();
+
+ return composite;
+ }
+
+
+ private void createAttributeMaps( Schema schema )
+ {
+ AttributeTypeDescription[] atds = schema.getAttributeTypeDescriptions();
+ for ( int i = 0; i < atds.length; i++ )
+ {
+
+ attributeOid2AtdMap.put( atds[i].getNumericOID(), atds[i] );
+
+ String[] names = atds[i].getNames();
+ for ( int j = 0; j < names.length; j++ )
+ {
+ attributeTypes2AtdMap.put( names[j], atds[i] );
+ }
+
+ }
+ }
+
+
+ private void createSyntaxMaps( Schema schema )
+ {
+ LdapSyntaxDescription[] lsds = schema.getLdapSyntaxDescriptions();
+ for ( int i = 0; i < lsds.length; i++ )
+ {
+
+ syntaxOid2LsdMap.put( lsds[i].getNumericOID(), lsds[i] );
+
+ if ( lsds[i].getDesc() != null )
+ {
+ syntaxDesc2LsdMap.put( lsds[i].getDesc(), lsds[i] );
+ }
+
+ }
+ }
+
+
+ private void createAttributeContents( Composite parent )
+ {
+
+ BaseWidgetUtils.createLabel( parent, "Value Editors by Attribute Types", 1 );
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
+ composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ Composite listComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+ listComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+ buttonComposite.setLayoutData( new GridData( GridData.VERTICAL_ALIGN_BEGINNING ) );
+
+ Table table = new Table( listComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION );
+ GridData data = new GridData( GridData.FILL_BOTH );
+ data.widthHint = 360;
+ data.heightHint = convertHeightInCharsToPixels( 10 );
+ table.setLayoutData( data );
+ table.setHeaderVisible( true );
+ table.setLinesVisible( true );
+ attributeViewer = new TableViewer( table );
+
+ TableColumn c1 = new TableColumn( table, SWT.NONE );
+ c1.setText( "Attribute" );
+ c1.setWidth( 80 );
+ TableColumn c2 = new TableColumn( table, SWT.NONE );
+ c2.setText( "Alias" );
+ c2.setWidth( 80 );
+ TableColumn c3 = new TableColumn( table, SWT.NONE );
+ c3.setText( "Value Editor" );
+ c3.setWidth( 200 );
+
+ attributeViewer.setColumnProperties( new String[]
+ { "Attribute", "Value Editor" } );
+ attributeViewer.setContentProvider( new ArrayContentProvider() );
+ attributeViewer.setLabelProvider( new AttributeLabelProvider() );
+
+ attributeViewer.addDoubleClickListener( new IDoubleClickListener()
+ {
+ public void doubleClick( DoubleClickEvent event )
+ {
+ editAttribute();
+ }
+ } );
+
+ attributeAddButton = BaseWidgetUtils.createButton( buttonComposite, "Add...", 1 );
+ attributeAddButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ addAttribute();
+ }
+ } );
+ attributeEditButton = BaseWidgetUtils.createButton( buttonComposite, "Edit...", 1 );
+ attributeEditButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ editAttribute();
+ }
+ } );
+ attributeRemoveButton = BaseWidgetUtils.createButton( buttonComposite, "Remove", 1 );
+ attributeRemoveButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ removeAttribute();
+ }
+ } );
+
+ // c1.pack();
+ // c2.pack();
+ // table.pack();
+ }
+
+
+ private void createSyntaxContents( Composite parent )
+ {
+
+ BaseWidgetUtils.createLabel( parent, "Value Editors by Syntax", 1 );
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 );
+ composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ Composite listComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+ listComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 );
+ buttonComposite.setLayoutData( new GridData( GridData.VERTICAL_ALIGN_BEGINNING ) );
+
+ Table table = new Table( listComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION );
+ GridData data = new GridData( GridData.FILL_BOTH );
+ data.widthHint = 360;
+ data.heightHint = convertHeightInCharsToPixels( 10 );
+ table.setLayoutData( data );
+ table.setHeaderVisible( true );
+ table.setLinesVisible( true );
+ syntaxViewer = new TableViewer( table );
+
+ TableColumn c1 = new TableColumn( table, SWT.NONE );
+ c1.setText( "Syntax" );
+ c1.setWidth( 80 );
+ TableColumn c2 = new TableColumn( table, SWT.NONE );
+ c2.setText( "Desc" );
+ c2.setWidth( 80 );
+ TableColumn c3 = new TableColumn( table, SWT.NONE );
+ c3.setText( "Value Editor" );
+ c3.setWidth( 200 );
+
+ syntaxViewer.setColumnProperties( new String[]
+ { "Syntax", "Value Editor" } );
+ syntaxViewer.setContentProvider( new ArrayContentProvider() );
+ syntaxViewer.setLabelProvider( new SyntaxLabelProvider() );
+
+ syntaxViewer.addDoubleClickListener( new IDoubleClickListener()
+ {
+ public void doubleClick( DoubleClickEvent event )
+ {
+ editSyntax();
+ }
+ } );
+
+ syntaxAddButton = BaseWidgetUtils.createButton( buttonComposite, "Add...", 1 );
+ syntaxAddButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ addSyntax();
+ }
+ } );
+ syntaxEditButton = BaseWidgetUtils.createButton( buttonComposite, "Edit...", 1 );
+ syntaxEditButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ editSyntax();
+ }
+ } );
+ syntaxRemoveButton = BaseWidgetUtils.createButton( buttonComposite, "Remove", 1 );
+ syntaxRemoveButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ removeSyntax();
+ }
+ } );
+
+ // c1.pack();
+ // c2.pack();
+ // table.pack();
+ }
+
+
+ protected void addAttribute()
+ {
+ AttributeValueEditorDialog dialog = new AttributeValueEditorDialog( getShell(), null,
+ this.class2ValueEditorProxyMap, this.attributeTypesAndOids );
+ if ( dialog.open() == AttributeValueEditorDialog.OK )
+ {
+ this.attributeList.add( dialog.getRelation() );
+ this.attributeViewer.refresh();
+ }
+ }
+
+
+ protected void removeAttribute()
+ {
+ Object o = ( ( StructuredSelection ) this.attributeViewer.getSelection() ).getFirstElement();
+ this.attributeList.remove( o );
+ this.attributeViewer.refresh();
+ }
+
+
+ protected void editAttribute()
+ {
+ StructuredSelection sel = ( StructuredSelection ) this.attributeViewer.getSelection();
+ if ( !sel.isEmpty() )
+ {
+ AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) sel.getFirstElement();
+ AttributeValueEditorDialog dialog = new AttributeValueEditorDialog( getShell(), relation,
+ this.class2ValueEditorProxyMap, this.attributeTypesAndOids );
+ if ( dialog.open() == AttributeValueEditorDialog.OK )
+ {
+ int index = this.attributeList.indexOf( relation );
+ this.attributeList.set( index, dialog.getRelation() );
+ this.attributeViewer.refresh();
+ }
+ }
+ }
+
+
+ protected void addSyntax()
+ {
+ SyntaxValueEditorDialog dialog = new SyntaxValueEditorDialog( getShell(), null,
+ this.class2ValueEditorProxyMap, this.syntaxDescsAndOids );
+ if ( dialog.open() == SyntaxValueEditorDialog.OK )
+ {
+ this.syntaxList.add( dialog.getRelation() );
+ this.syntaxViewer.refresh();
+ }
+ }
+
+
+ protected void removeSyntax()
+ {
+ Object o = ( ( StructuredSelection ) this.syntaxViewer.getSelection() ).getFirstElement();
+ this.syntaxList.remove( o );
+ this.syntaxViewer.refresh();
+ }
+
+
+ protected void editSyntax()
+ {
+ StructuredSelection sel = ( StructuredSelection ) this.syntaxViewer.getSelection();
+ if ( !sel.isEmpty() )
+ {
+ SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) sel.getFirstElement();
+ SyntaxValueEditorDialog dialog = new SyntaxValueEditorDialog( getShell(), relation,
+ this.class2ValueEditorProxyMap, this.syntaxDescsAndOids );
+ if ( dialog.open() == SyntaxValueEditorDialog.OK )
+ {
+ int index = this.syntaxList.indexOf( relation );
+ this.syntaxList.set( index, dialog.getRelation() );
+ this.syntaxViewer.refresh();
+ }
+ }
+ }
+
+
+ public boolean performOk()
+ {
+ AttributeValueProviderRelation[] aRelations = ( AttributeValueProviderRelation[] ) this.attributeList
+ .toArray( new AttributeValueProviderRelation[this.attributeList.size()] );
+ BrowserCommonActivator.getDefault().getValueEditorsPreferences().setAttributeValueProviderRelations( aRelations );
+
+ SyntaxValueProviderRelation[] sRelations = ( SyntaxValueProviderRelation[] ) this.syntaxList
+ .toArray( new SyntaxValueProviderRelation[this.syntaxList.size()] );
+ BrowserCommonActivator.getDefault().getValueEditorsPreferences().setSyntaxValueProviderRelations( sRelations );
+
+ return true;
+ }
+
+
+ protected void performDefaults()
+ {
+ this.attributeList.clear();
+ this.attributeList.addAll( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+ .getDefaultAttributeValueProviderRelations() ) );
+ this.attributeViewer.refresh();
+
+ this.syntaxList.clear();
+ this.syntaxList.addAll( Arrays.asList( BrowserCommonActivator.getDefault().getValueEditorsPreferences()
+ .getDefaultSyntaxValueProviderRelations() ) );
+ this.syntaxViewer.refresh();
+
+ super.performDefaults();
+ }
+
+ class AttributeLabelProvider extends LabelProvider implements ITableLabelProvider
+ {
+ public String getColumnText( Object obj, int index )
+ {
+ if ( obj instanceof AttributeValueProviderRelation )
+ {
+ AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) obj;
+ if ( index == 0 )
+ {
+ return relation.getAttributeNumericOidOrType();
+ }
+ else if ( index == 1 )
+ {
+ if ( relation.getAttributeNumericOidOrType() != null )
+ {
+ if ( attributeTypes2AtdMap.containsKey( relation.getAttributeNumericOidOrType() ) )
+ {
+ AttributeTypeDescription atd = ( AttributeTypeDescription ) attributeTypes2AtdMap
+ .get( relation.getAttributeNumericOidOrType() );
+ String s = atd.getNumericOID();
+ for ( int i = 0; i < atd.getNames().length; i++ )
+ {
+ if ( !relation.getAttributeNumericOidOrType().equals( atd.getNames()[i] ) )
+ {
+ s += ", " + atd.getNames()[i];
+ }
+ }
+ return s;
+ }
+ else if ( attributeOid2AtdMap.containsKey( relation.getAttributeNumericOidOrType() ) )
+ {
+ AttributeTypeDescription atd = ( AttributeTypeDescription ) attributeOid2AtdMap
+ .get( relation.getAttributeNumericOidOrType() );
+ return atd.toString();
+ }
+ }
+ }
+ else if ( index == 2 )
+ {
+ ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+ return vp != null ? vp.name : null;
+ }
+ }
+ return null;
+ }
+
+
+ public Image getColumnImage( Object obj, int index )
+ {
+ if ( obj instanceof AttributeValueProviderRelation )
+ {
+ AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) obj;
+ if ( index == 2 )
+ {
+ ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+ return vp != null ? vp.icon.createImage() : null;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ class SyntaxLabelProvider extends LabelProvider implements ITableLabelProvider
+ {
+ public String getColumnText( Object obj, int index )
+ {
+ if ( obj instanceof SyntaxValueProviderRelation )
+ {
+ SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) obj;
+ if ( index == 0 )
+ {
+ return relation.getSyntaxOID();
+ }
+ else if ( index == 1 )
+ {
+ if ( relation.getSyntaxOID() != null )
+ {
+ if ( syntaxOid2LsdMap.containsKey( relation.getSyntaxOID() ) )
+ {
+ LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) syntaxOid2LsdMap.get( relation
+ .getSyntaxOID() );
+ return lsd.toString();
+ }
+ }
+ }
+ else if ( index == 2 )
+ {
+ ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+ return vp != null ? vp.name : null;
+ }
+ }
+ return null;
+ }
+
+
+ public Image getColumnImage( Object obj, int index )
+ {
+ if ( obj instanceof SyntaxValueProviderRelation )
+ {
+ SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) obj;
+ if ( index == 2 )
+ {
+ ValueEditorExtension vp = class2ValueEditorProxyMap.get( relation.getValueProviderClassname() );
+ return vp != null ? vp.icon.createImage() : null;
+ }
+ }
+
+ return null;
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ConnectionTransfer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ConnectionTransfer.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ConnectionTransfer.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ConnectionTransfer.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link IConnection} objects.
+ * Note that only the connection name is converted to a platform specific
+ * representation, not the complete object. To convert it back to an {@link IConnection}
+ * object the {@link ConnectionManager#getConnection(String)} method is invoked.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ConnectionTransfer extends ByteArrayTransfer
+{
+
+ /** The Constant TYPENAME. */
+ private static final String TYPENAME = "org.apache.directory.ldapstudio.browser.connection";
+
+ /** The Constant TYPEID. */
+ private static final int TYPEID = registerType( TYPENAME );
+
+ /** The instance. */
+ private static ConnectionTransfer instance = new ConnectionTransfer();
+
+
+ /**
+ * Creates a new instance of ConnectionTransfer.
+ */
+ private ConnectionTransfer()
+ {
+ }
+
+
+ /**
+ * Gets the instance.
+ *
+ * @return the instance
+ */
+ public static ConnectionTransfer getInstance()
+ {
+ return instance;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation only accepts {@link IConnection} objects.
+ * It just converts the name of the connection to the platform
+ * specific representation.
+ */
+ public void javaToNative( Object object, TransferData transferData )
+ {
+ if ( object == null || !( object instanceof IConnection[] ) )
+ {
+ return;
+ }
+
+ if ( isSupportedType( transferData ) )
+ {
+ IConnection[] connections = ( IConnection[] ) object;
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DataOutputStream writeOut = new DataOutputStream( out );
+
+ for ( int i = 0; i < connections.length; i++ )
+ {
+ byte[] name = connections[i].getName().getBytes();
+ writeOut.writeInt( name.length );
+ writeOut.write( name );
+ }
+
+ byte[] buffer = out.toByteArray();
+ writeOut.close();
+
+ super.javaToNative( buffer, transferData );
+
+ }
+ catch ( IOException e )
+ {
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just converts the platform specific representation
+ * to the connection name and invokes
+ * {@link ConnectionManager#getConnection(String)} to get the
+ * {@link IConnection} object.
+ */
+ public Object nativeToJava( TransferData transferData )
+ {
+ if ( isSupportedType( transferData ) )
+ {
+ byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+ if ( buffer == null )
+ {
+ return null;
+ }
+
+ List<IConnection> connectionList = new ArrayList<IConnection>();
+ try
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+ DataInputStream readIn = new DataInputStream( in );
+
+ do
+ {
+ if ( readIn.available() > 1 )
+ {
+ int size = readIn.readInt();
+ byte[] connectionName = new byte[size];
+ readIn.read( connectionName );
+ IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+ new String( connectionName ) );
+ connectionList.add( connection );
+ }
+ }
+ while ( readIn.available() > 1 );
+
+ readIn.close();
+ }
+ catch ( IOException ex )
+ {
+ return null;
+ }
+
+ return connectionList.toArray( new IConnection[0] );
+ }
+
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String[] getTypeNames()
+ {
+ return new String[]
+ { TYPENAME };
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected int[] getTypeIds()
+ {
+ return new int[]
+ { TYPEID };
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/EntryTransfer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/EntryTransfer.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/EntryTransfer.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/EntryTransfer.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link IEntry} objects.
+ * Note that only the connection name and entry's DN is converted to a platform specific
+ * representation, not the complete object.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryTransfer extends ByteArrayTransfer
+{
+
+ /** The Constant TYPENAME. */
+ private static final String TYPENAME = "org.apache.directory.ldapstudio.browser.entry";
+
+ /** The Constant TYPEID. */
+ private static final int TYPEID = registerType( TYPENAME );
+
+ /** The instance. */
+ private static EntryTransfer instance = new EntryTransfer();
+
+
+ /**
+ * Gets the instance.
+ *
+ * @return the instance
+ */
+ public static EntryTransfer getInstance()
+ {
+ return instance;
+ }
+
+
+ /**
+ * Creates a new instance of EntryTransfer.
+ */
+ private EntryTransfer()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation only accepts {@link IEntry} objects.
+ * It just converts the name of the connection and the entry's DN
+ * to the platform specific representation.
+ */
+ public void javaToNative( Object object, TransferData transferData )
+ {
+ if ( object == null || !( object instanceof IEntry[] ) )
+ {
+ return;
+ }
+
+ if ( isSupportedType( transferData ) )
+ {
+ IEntry[] entries = ( IEntry[] ) object;
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DataOutputStream writeOut = new DataOutputStream( out );
+
+ for ( int i = 0; i < entries.length; i++ )
+ {
+ byte[] connectionName = entries[i].getConnection().getName().getBytes();
+ writeOut.writeInt( connectionName.length );
+ writeOut.write( connectionName );
+ byte[] dn = entries[i].getDn().toString().getBytes();
+ writeOut.writeInt( dn.length );
+ writeOut.write( dn );
+ }
+
+ byte[] buffer = out.toByteArray();
+ writeOut.close();
+
+ super.javaToNative( buffer, transferData );
+
+ }
+ catch ( IOException e )
+ {
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just converts the platform specific representation
+ * to the connection name and entry DN and invokes
+ * {@link ConnectionManager#getConnection(String)} to get the
+ * {@link IConnection} object and {@link IConnection#getEntryFromCache(DN)}
+ * to get the {@link IEntry} object.
+ */
+ public Object nativeToJava( TransferData transferData )
+ {
+ try
+ {
+ if ( isSupportedType( transferData ) )
+ {
+ byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+ if ( buffer == null )
+ {
+ return null;
+ }
+
+ List<IEntry> entryList = new ArrayList<IEntry>();
+ try
+ {
+ IConnection connection = null;
+ ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+ DataInputStream readIn = new DataInputStream( in );
+
+ do
+ {
+ if ( readIn.available() > 1 )
+ {
+ int size = readIn.readInt();
+ byte[] connectionName = new byte[size];
+ readIn.read( connectionName );
+ connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+ new String( connectionName ) );
+ }
+
+ IEntry entry = null;
+ if ( readIn.available() > 1 && connection != null )
+ {
+ int size = readIn.readInt();
+ byte[] dn = new byte[size];
+ readIn.read( dn );
+ entry = connection.getEntryFromCache( new DN( new String( dn ) ) );
+ }
+ else
+ {
+ return null;
+ }
+
+ if ( entry != null )
+ {
+ entryList.add( entry );
+ }
+ }
+ while ( readIn.available() > 1 );
+
+ readIn.close();
+ }
+ catch ( IOException ex )
+ {
+ return null;
+ }
+
+ return entryList.isEmpty() ? null : entryList.toArray( new IEntry[0] );
+ }
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return null;
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String[] getTypeNames()
+ {
+ return new String[]
+ { TYPENAME };
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected int[] getTypeIds()
+ {
+ return new int[]
+ { TYPEID };
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/SearchTransfer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/SearchTransfer.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/SearchTransfer.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/SearchTransfer.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.ISearch;
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link ISearch} objects.
+ * Note that only the connection name and search name is converted to a platform specific
+ * representation, not the complete object.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchTransfer extends ByteArrayTransfer
+{
+
+ /** The Constant TYPENAME. */
+ private static final String TYPENAME = "org.apache.directory.ldapstudio.browser.search";
+
+ /** The Constant TYPEID. */
+ private static final int TYPEID = registerType( TYPENAME );
+
+ /** The instance. */
+ private static SearchTransfer instance = new SearchTransfer();
+
+
+ /**
+ * Creates a new instance of SearchTransfer.
+ */
+ private SearchTransfer()
+ {
+ }
+
+
+ /**
+ * Gets the instance.
+ *
+ * @return the instance
+ */
+ public static SearchTransfer getInstance()
+ {
+ return instance;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation only accepts {@link ISearch} objects.
+ * It just converts the name of the connection and the name of the search
+ * to the platform specific representation.
+ */
+ public void javaToNative( Object object, TransferData transferData )
+ {
+ if ( object == null || !( object instanceof ISearch[] ) )
+ {
+ return;
+ }
+
+ if ( isSupportedType( transferData ) )
+ {
+ ISearch[] searches = ( ISearch[] ) object;
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DataOutputStream writeOut = new DataOutputStream( out );
+
+ for ( int i = 0; i < searches.length; i++ )
+ {
+ byte[] connectionName = searches[i].getConnection().getName().getBytes();
+ writeOut.writeInt( connectionName.length );
+ writeOut.write( connectionName );
+ byte[] searchName = searches[i].getName().getBytes();
+ writeOut.writeInt( searchName.length );
+ writeOut.write( searchName );
+ }
+
+ byte[] buffer = out.toByteArray();
+ writeOut.close();
+
+ super.javaToNative( buffer, transferData );
+
+ }
+ catch ( IOException e )
+ {
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just converts the platform specific representation
+ * to the connection name and search name and invokes
+ * {@link ConnectionManager#getConnection(String)} to get the
+ * {@link IConnection} object and {@link IConnection#getSearchManager()}
+ * to get the {@link ISearch} object.
+ */
+ public Object nativeToJava( TransferData transferData )
+ {
+ try
+ {
+ if ( isSupportedType( transferData ) )
+ {
+ byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+ if ( buffer == null )
+ {
+ return null;
+ }
+
+ List<ISearch> searchList = new ArrayList<ISearch>();
+ try
+ {
+ IConnection connection = null;
+ ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+ DataInputStream readIn = new DataInputStream( in );
+
+ do
+ {
+ if ( readIn.available() > 1 )
+ {
+ int size = readIn.readInt();
+ byte[] connectionName = new byte[size];
+ readIn.read( connectionName );
+ connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+ new String( connectionName ) );
+ }
+
+ ISearch search = null;
+ if ( readIn.available() > 1 && connection != null )
+ {
+ int size = readIn.readInt();
+ byte[] searchName = new byte[size];
+ readIn.read( searchName );
+ search = connection.getSearchManager().getSearch( new String( searchName ) );
+ }
+ else
+ {
+ return null;
+ }
+
+ if ( search != null )
+ {
+ searchList.add( search );
+ }
+ }
+ while ( readIn.available() > 1 );
+
+ readIn.close();
+ }
+ catch ( IOException ex )
+ {
+ return null;
+ }
+
+ return searchList.isEmpty() ? null : searchList.toArray( new ISearch[0] );
+ }
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return null;
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String[] getTypeNames()
+ {
+ return new String[]
+ { TYPENAME };
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected int[] getTypeIds()
+ {
+ return new int[]
+ { TYPEID };
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ValuesTransfer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ValuesTransfer.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ValuesTransfer.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dnd/ValuesTransfer.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.dnd;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.model.DN;
+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.eclipse.swt.dnd.ByteArrayTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.dnd.TransferData;
+
+
+/**
+ * A {@link Transfer} that could be used to transfer {@link IValue} objects.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ValuesTransfer extends ByteArrayTransfer
+{
+
+ /** The Constant TYPENAME. */
+ private static final String TYPENAME = "org.apache.directory.ldapstudio.browser.value";
+
+ /** The Constant TYPEID. */
+ private static final int TYPEID = registerType( TYPENAME );
+
+ /** The instance. */
+ private static ValuesTransfer instance = new ValuesTransfer();
+
+
+ /**
+ * Gets the instance.
+ *
+ * @return the instance
+ */
+ public static ValuesTransfer getInstance()
+ {
+ return instance;
+ }
+
+
+ /**
+ * Creates a new instance of ValuesTransfer.
+ */
+ private ValuesTransfer()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation only accepts {@link IValue} objects.
+ * It converts the name of the connection, the entry's DN, the
+ * attribute description and the value to the platform specific
+ * representation.
+ */
+ public void javaToNative( Object object, TransferData transferData )
+ {
+ if ( object == null || !( object instanceof IValue[] ) )
+ {
+ return;
+ }
+
+ if ( isSupportedType( transferData ) )
+ {
+ IValue[] values = ( IValue[] ) object;
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ DataOutputStream writeOut = new DataOutputStream( out );
+
+ for ( int i = 0; i < values.length; i++ )
+ {
+ byte[] connectionName = values[i].getAttribute().getEntry().getConnection().getName().getBytes();
+ writeOut.writeInt( connectionName.length );
+ writeOut.write( connectionName );
+ byte[] dn = values[i].getAttribute().getEntry().getDn().toString().getBytes();
+ writeOut.writeInt( dn.length );
+ writeOut.write( dn );
+ byte[] attributeName = values[i].getAttribute().getDescription().getBytes();
+ writeOut.writeInt( attributeName.length );
+ writeOut.write( attributeName );
+ if ( values[i].isString() )
+ {
+ byte[] value = values[i].getStringValue().getBytes();
+ writeOut.writeBoolean( true );
+ writeOut.writeInt( value.length );
+ writeOut.write( value );
+ }
+ else if ( values[i].isBinary() )
+ {
+ byte[] value = values[i].getBinaryValue();
+ writeOut.writeBoolean( false );
+ writeOut.writeInt( value.length );
+ writeOut.write( value );
+ }
+ }
+
+ byte[] buffer = out.toByteArray();
+ writeOut.close();
+
+ super.javaToNative( buffer, transferData );
+
+ }
+ catch ( IOException e )
+ {
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation converts the platform specific representation
+ * to the connection name, entry DN, attribute description and value and
+ * restores the {@link IValue} object.
+ */
+ public Object nativeToJava( TransferData transferData )
+ {
+ try
+ {
+ if ( isSupportedType( transferData ) )
+ {
+ byte[] buffer = ( byte[] ) super.nativeToJava( transferData );
+ if ( buffer == null )
+ {
+ return null;
+ }
+
+ List<IValue> valueList = new ArrayList<IValue>();
+ try
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream( buffer );
+ DataInputStream readIn = new DataInputStream( in );
+
+ do
+ {
+ IConnection connection = null;
+ if ( readIn.available() > 1 )
+ {
+ int size = readIn.readInt();
+ byte[] connectionName = new byte[size];
+ readIn.read( connectionName );
+ connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
+ new String( connectionName ) );
+ }
+
+ IEntry entry = null;
+ if ( readIn.available() > 1 && connection != null )
+ {
+ int size = readIn.readInt();
+ byte[] dn = new byte[size];
+ readIn.read( dn );
+ entry = connection.getEntryFromCache( new DN( new String( dn ) ) );
+ }
+ else
+ {
+ return null;
+ }
+
+ IAttribute attribute = null;
+ if ( readIn.available() > 1 && entry != null )
+ {
+ int size = readIn.readInt();
+ byte[] attributeName = new byte[size];
+ readIn.read( attributeName );
+ attribute = entry.getAttribute( new String( attributeName ) );
+ }
+ else
+ {
+ return null;
+ }
+
+ IValue value = null;
+ if ( readIn.available() > 1 && attribute != null )
+ {
+ boolean isString = readIn.readBoolean();
+ int size = readIn.readInt();
+ byte[] val = new byte[size];
+ readIn.read( val );
+ String test = new String( val );
+
+ IValue[] values = attribute.getValues();
+ for ( int i = 0; i < values.length; i++ )
+ {
+ if ( isString && values[i].isString() && test.equals( values[i].getStringValue() ) )
+ {
+ value = values[i];
+ break;
+ }
+ else if ( !isString && values[i].isBinary()
+ && test.equals( new String( values[i].getBinaryValue() ) ) )
+ {
+ value = values[i];
+ break;
+ }
+ }
+ }
+ else
+ {
+ return null;
+ }
+
+ if ( value != null )
+ {
+ valueList.add( value );
+ }
+ }
+ while ( readIn.available() > 1 );
+
+ readIn.close();
+ }
+ catch ( IOException ex )
+ {
+ return null;
+ }
+
+ return valueList.isEmpty() ? null : valueList.toArray( new IValue[valueList.size()] );
+ }
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return null;
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String[] getTypeNames()
+ {
+ return new String[]
+ { TYPENAME };
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected int[] getTypeIds()
+ {
+ return new int[]
+ { TYPEID };
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.filtereditor;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
+
+import org.eclipse.jface.text.DefaultAutoIndentStrategy;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.source.SourceViewer;
+
+
+// TODO: Refactor Filter Editor
+public class FilterAutoEditStrategy extends DefaultAutoIndentStrategy implements IAutoEditStrategy
+{
+
+ public static final String INDENT_STRING = " ";
+
+ private LdapFilterParser parser;
+
+ private SourceViewer sourceViewer;
+
+ private int autoRightParenthesisFilterOffset;
+
+
+ public FilterAutoEditStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.sourceViewer = sourceViewer;
+ this.parser = parser;
+ this.autoRightParenthesisFilterOffset = -1;
+ }
+
+
+ public void customizeDocumentCommand( IDocument d, DocumentCommand c )
+ {
+
+ LdapFilter filter = this.parser.getModel().getFilter( c.offset );
+
+ // this.dumpDocumentCommand(c);
+
+ if ( c.length == 0 && c.text != null )
+ {
+ // new line
+ if ( TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
+ {
+ super.customizeDocumentCommand( d, c );
+ if ( filter != null && filter.getFilterComponent() != null )
+ {
+ LdapFilterToken startToken = filter.getFilterComponent().getStartToken();
+ if ( startToken != null
+ && ( startToken.getType() == LdapFilterToken.AND || startToken.getType() == LdapFilterToken.OR ) )
+ {
+
+ if ( startToken.getOffset() == c.offset - 1 )
+ {
+ c.text += INDENT_STRING;
+ if ( filter.getStopToken() != null && filter.getStopToken().getOffset() == c.offset )
+ {
+ c.caretOffset = c.offset + c.text.length();
+ c.shiftsCaret = false;
+ c.text += "\n";
+ super.customizeDocumentCommand( d, c );
+ }
+ }
+ }
+ }
+ }
+
+ // filter start/stop
+ if ( c.text.equals( "(" ) )
+ {
+ c.text = "()";
+ c.caretOffset = c.offset + 1;
+ c.shiftsCaret = false;
+ this.autoRightParenthesisFilterOffset = c.offset;
+ }
+ else if ( c.text.equals( ")" ) )
+ {
+ LdapFilter filter2 = this.parser.getModel().getFilter( this.autoRightParenthesisFilterOffset );
+ if ( filter2 != null && filter2.getStopToken() != null
+ && filter2.getStopToken().getOffset() == c.offset )
+ {
+ c.text = "";
+ c.caretOffset = c.offset + 1;
+ c.shiftsCaret = false;
+ }
+ this.autoRightParenthesisFilterOffset = -1;
+ }
+
+ // tab to IDENT_STRING
+ if ( c.text.equals( "\t" ) )
+ {
+ c.text = INDENT_STRING;
+ }
+
+ // smart formatting
+ if ( filter != null && filter.getStartToken() != null && filter.getFilterComponent() == null )
+ {
+ if ( c.text.equals( "&" ) || c.text.equals( "|" ) )
+ {
+ if ( filter.getStartToken().getOffset() == c.offset - 1 )
+ {
+ c.text += "\n";
+ super.customizeDocumentCommand( d, c );
+ c.text += INDENT_STRING + "()";
+ c.caretOffset = c.offset + c.text.length() - 1;
+ c.shiftsCaret = false;
+ if ( filter.getStopToken() != null && filter.getStopToken().getOffset() == c.offset )
+ {
+ c.text += "\n";
+ super.customizeDocumentCommand( d, c );
+ }
+
+ }
+ }
+ else if ( c.text.equals( "!" ) )
+ {
+ if ( filter.getStartToken().getOffset() == c.offset - 1 )
+ {
+ c.text += "()";
+ c.caretOffset = c.offset + c.text.length() - 1;
+ c.shiftsCaret = false;
+ }
+ }
+ }
+
+ }
+ }
+
+
+ private void autoIndentAfterNewLine()
+ {
+
+ }
+
+
+ private void dumpDocumentCommand( DocumentCommand command )
+ {
+ System.out.println( "----------------------------------" );
+ System.out.println( " offset : " + command.offset );
+ System.out.println( " length : " + command.length );
+ System.out.println( " text : " + command.text );
+ System.out.println( " caretoffset: " + command.caretOffset );
+ System.out.println( " shiftsCaret: " + command.shiftsCaret );
+ System.out.println( " doit : " + command.doit );
+
+ }
+}