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 [11/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/s...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/MainPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/MainPreferencePage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/MainPreferencePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/MainPreferencePage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,250 @@
+/*
+ * 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.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.eclipse.jface.preference.ColorSelector;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+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.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class MainPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
+{
+
+ private final String[] ERROR_TYPES = new String[]
+ { "Warnings:", "Errors:" };
+
+ private final String[] ERROR_FONT_CONSTANTS = new String[]
+ { BrowserUIConstants.PREFERENCE_WARNING_FONT, BrowserUIConstants.PREFERENCE_ERROR_FONT };
+
+ private final String[] ERROR_COLOR_CONSTANTS = new String[]
+ { BrowserUIConstants.PREFERENCE_WARNING_COLOR, BrowserUIConstants.PREFERENCE_ERROR_COLOR };
+
+ private Label[] errorTypeLabels = new Label[ERROR_TYPES.length];
+
+ private ColorSelector[] errorColorSelectors = new ColorSelector[ERROR_TYPES.length];
+
+ private Button[] errorBoldButtons = new Button[ERROR_TYPES.length];
+
+ private Button[] errorItalicButtons = new Button[ERROR_TYPES.length];
+
+ private Label quickfilterTypeLabel;
+
+ private ColorSelector quickfilterForegroundColorSelector;;
+
+ private ColorSelector quickfilterBackgroundColorSelector;;
+
+ private Button quickfilterBoldButton;
+
+ private Button quickfilterItalicButton;
+
+
+ public MainPreferencePage()
+ {
+ super( "LDAP" );
+ super.setPreferenceStore( BrowserUIPlugin.getDefault().getPreferenceStore() );
+ super.setDescription( "General settings for the LDAP plugin:" );
+ }
+
+
+ public void init( IWorkbench workbench )
+ {
+ }
+
+
+ protected Control createContents( Composite parent )
+ {
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ Group errorGroup = BaseWidgetUtils.createGroup( composite, "Warning and Error Colors and Fonts", 1 );
+ errorGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ Composite errorComposite = BaseWidgetUtils.createColumnContainer( errorGroup, 4, 1 );
+ for ( int i = 0; i < ERROR_TYPES.length; i++ )
+ {
+ final int index = i;
+
+ errorTypeLabels[i] = BaseWidgetUtils.createLabel( errorComposite, ERROR_TYPES[i], 1 );
+ errorTypeLabels[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ errorColorSelectors[i] = new ColorSelector( errorComposite );
+ errorBoldButtons[i] = BaseWidgetUtils.createCheckbox( errorComposite, "Bold", 1 );
+ errorItalicButtons[i] = BaseWidgetUtils.createCheckbox( errorComposite, "Italic", 1 );
+
+ FontData[] fontDatas = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+ .getPreferenceStore(), ERROR_FONT_CONSTANTS[i] );
+ RGB rgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ ERROR_COLOR_CONSTANTS[i] );
+ setErrors( index, fontDatas, rgb );
+ }
+
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ Group otherGroup = BaseWidgetUtils.createGroup( composite, "Quick Filter Colors and Fonts", 1 );
+ otherGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ Composite otherComposite = BaseWidgetUtils.createColumnContainer( otherGroup, 4, 1 );
+ quickfilterTypeLabel = BaseWidgetUtils.createLabel( otherComposite, "Quick Filter", 1 );
+ quickfilterTypeLabel.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ quickfilterForegroundColorSelector = new ColorSelector( otherComposite );
+ quickfilterBoldButton = BaseWidgetUtils.createCheckbox( otherComposite, "Bold", 1 );
+ quickfilterItalicButton = BaseWidgetUtils.createCheckbox( otherComposite, "Italic", 1 );
+ Label quickfilterBgLabel = BaseWidgetUtils.createLabel( otherComposite, "Quick Filter Background", 1 );
+ quickfilterBgLabel.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ quickfilterBackgroundColorSelector = new ColorSelector( otherComposite );
+ FontData[] qfFontDatas = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+ .getPreferenceStore(), BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT );
+ RGB qfBgRgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+ RGB qfFgRgb = PreferenceConverter.getColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+ setQuickfilter( qfFontDatas, qfFgRgb, qfBgRgb );
+
+ return composite;
+ }
+
+
+ private void setErrors( int index, FontData[] fontDatas, RGB rgb )
+ {
+ boolean bold = isBold( fontDatas );
+ boolean italic = isItalic( fontDatas );
+ errorColorSelectors[index].setColorValue( rgb );
+ errorBoldButtons[index].setSelection( bold );
+ errorItalicButtons[index].setSelection( italic );
+ }
+
+
+ private void setQuickfilter( FontData[] fontDatas, RGB fgRgb, RGB bgRgb )
+ {
+ boolean bold = isBold( fontDatas );
+ boolean italic = isItalic( fontDatas );
+ quickfilterBackgroundColorSelector.setColorValue( bgRgb );
+ quickfilterForegroundColorSelector.setColorValue( fgRgb );
+ quickfilterBoldButton.setSelection( bold );
+ quickfilterItalicButton.setSelection( italic );
+ }
+
+
+ protected void performDefaults()
+ {
+ for ( int i = 0; i < ERROR_TYPES.length; i++ )
+ {
+ FontData[] fontDatas = PreferenceConverter.getDefaultFontDataArray( BrowserUIPlugin.getDefault()
+ .getPreferenceStore(), ERROR_FONT_CONSTANTS[i] );
+ RGB rgb = PreferenceConverter.getDefaultColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ ERROR_COLOR_CONSTANTS[i] );
+ setErrors( i, fontDatas, rgb );
+ }
+
+ FontData[] qfFontDatas = PreferenceConverter.getDefaultFontDataArray( BrowserUIPlugin.getDefault()
+ .getPreferenceStore(), BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT );
+ RGB qfBgRgb = PreferenceConverter.getDefaultColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR );
+ RGB qfFgRgb = PreferenceConverter.getDefaultColor( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR );
+ setQuickfilter( qfFontDatas, qfFgRgb, qfBgRgb );
+
+ super.performDefaults();
+ }
+
+
+ public boolean performOk()
+ {
+ for ( int i = 0; i < ERROR_TYPES.length; i++ )
+ {
+ FontData[] fontDatas = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+ .getPreferenceStore(), ERROR_FONT_CONSTANTS[i] );
+ setFontData( fontDatas, this.errorBoldButtons[i], this.errorBoldButtons[i] );
+ RGB rgb = errorColorSelectors[i].getColorValue();
+ PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(), ERROR_FONT_CONSTANTS[i],
+ fontDatas );
+ PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(), ERROR_COLOR_CONSTANTS[i],
+ rgb );
+ }
+
+ FontData[] qfFontDatas = PreferenceConverter.getFontDataArray( BrowserUIPlugin.getDefault()
+ .getPreferenceStore(), BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT );
+ setFontData( qfFontDatas, this.quickfilterBoldButton, this.quickfilterItalicButton );
+ RGB qfBgRgb = quickfilterBackgroundColorSelector.getColorValue();
+ RGB qfFgRgb = quickfilterForegroundColorSelector.getColorValue();
+ PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_FONT, qfFontDatas );
+ PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR, qfBgRgb );
+ PreferenceConverter.setValue( BrowserUIPlugin.getDefault().getPreferenceStore(),
+ BrowserUIConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR, qfFgRgb );
+
+ return true;
+ }
+
+
+ private void setFontData( FontData[] fontDatas, Button boldButton, Button italicButton )
+ {
+ for ( int j = 0; j < fontDatas.length; j++ )
+ {
+ int style = SWT.NORMAL;
+ if ( boldButton.getSelection() )
+ style |= SWT.BOLD;
+ if ( italicButton.getSelection() )
+ style |= SWT.ITALIC;
+ fontDatas[j].setStyle( style );
+ }
+ }
+
+
+ private boolean isBold( FontData[] fontDatas )
+ {
+ boolean bold = false;
+ for ( int j = 0; j < fontDatas.length; j++ )
+ {
+ if ( ( fontDatas[j].getStyle() & SWT.BOLD ) != SWT.NORMAL )
+ bold = true;
+ }
+ return bold;
+ }
+
+
+ private boolean isItalic( FontData[] fontDatas )
+ {
+ boolean italic = false;
+ for ( int j = 0; j < fontDatas.length; j++ )
+ {
+ if ( ( fontDatas[j].getStyle() & SWT.ITALIC ) != SWT.NORMAL )
+ italic = true;
+ }
+ return italic;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SearchResultEditorPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SearchResultEditorPreferencePage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SearchResultEditorPreferencePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SearchResultEditorPreferencePage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,129 @@
+/*
+ * 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.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyEvent;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyListener;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class SearchResultEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage,
+ WidgetModifyListener
+{
+
+ private Button showDnButton;
+
+ private Button showLinksButton;
+
+
+ public SearchResultEditorPreferencePage()
+ {
+ super();
+ super.setPreferenceStore( BrowserUIPlugin.getDefault().getPreferenceStore() );
+ super.setDescription( "General settings for the LDAP search result editor:" );
+ }
+
+
+ public void init( IWorkbench workbench )
+ {
+ }
+
+
+ protected Control createContents( Composite parent )
+ {
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ showDnButton = BaseWidgetUtils.createCheckbox( composite, "Show DN as first column", 1 );
+ showDnButton.setSelection( getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN ) );
+ showLinksButton = BaseWidgetUtils.createCheckbox( composite, "Show DN a link", 1 );
+ showLinksButton.setSelection( getPreferenceStore().getBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS ) );
+
+ updateEnabled();
+ validate();
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ private void updateEnabled()
+ {
+
+ }
+
+
+ public boolean performOk()
+ {
+
+ getPreferenceStore().setValue( BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN,
+ this.showDnButton.getSelection() );
+ getPreferenceStore().setValue( BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS,
+ this.showLinksButton.getSelection() );
+
+ updateEnabled();
+ validate();
+
+ return true;
+ }
+
+
+ protected void performDefaults()
+ {
+
+ this.showDnButton.setSelection( getPreferenceStore().getDefaultBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_DN ) );
+ this.showLinksButton.setSelection( getPreferenceStore().getDefaultBoolean(
+ BrowserUIConstants.PREFERENCE_SEARCHRESULTEDITOR_SHOW_LINKS ) );
+
+ updateEnabled();
+ validate();
+
+ super.performDefaults();
+ }
+
+
+ public void widgetModified( WidgetModifyEvent event )
+ {
+ updateEnabled();
+ validate();
+ }
+
+
+ protected void validate()
+ {
+
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,108 @@
+/*
+ * 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.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.BinarySyntax;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class SyntaxDialog extends Dialog
+{
+
+ private BinarySyntax currentSyntax;
+
+ private String[] syntaxOids;
+
+ private BinarySyntax returnSyntax;
+
+ private Combo oidCombo;
+
+
+ public SyntaxDialog( Shell parentShell, BinarySyntax currentSyntax, String[] syntaxOids )
+ {
+ super( parentShell );
+ this.currentSyntax = currentSyntax;
+ this.syntaxOids = syntaxOids;
+
+ this.returnSyntax = null;
+ }
+
+
+ protected void configureShell( Shell newShell )
+ {
+ super.configureShell( newShell );
+ newShell.setText( "Select Syntax OID" );
+ }
+
+
+ protected void okPressed()
+ {
+ this.returnSyntax = new BinarySyntax( oidCombo.getText() );
+ super.okPressed();
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+
+ Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+ BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 );
+ this.oidCombo = BaseWidgetUtils.createCombo( c, this.syntaxOids, -1, 1 );
+ if ( this.currentSyntax != null )
+ {
+ this.oidCombo.setText( currentSyntax.getSyntaxNumericOid() );
+ }
+ this.oidCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ validate();
+ }
+ } );
+
+ return composite;
+ }
+
+
+ private void validate()
+ {
+ super.getButton( IDialogConstants.OK_ID ).setEnabled( !"".equals( this.oidCombo.getText() ) );
+ }
+
+
+ public BinarySyntax getSyntax()
+ {
+ return returnSyntax;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxValueProviderDialog.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxValueProviderDialog.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxValueProviderDialog.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/SyntaxValueProviderDialog.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,147 @@
+/*
+ * 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.dialogs.preferences;
+
+
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.directory.ldapstudio.browser.core.model.schema.SyntaxValueProviderRelation;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+public class SyntaxValueProviderDialog extends Dialog
+{
+
+ private SyntaxValueProviderRelation relation;
+
+ private SortedMap class2ValueProviderMap;
+
+ private String[] syntaxOids;
+
+ private SortedMap vpName2classMap;
+
+ private SyntaxValueProviderRelation returnRelation;
+
+ private Combo oidCombo;
+
+ private Combo valueEditorCombo;
+
+
+ public SyntaxValueProviderDialog( Shell parentShell, SyntaxValueProviderRelation relation,
+ SortedMap class2ValueProviderMap, String[] syntaxOids )
+ {
+ super( parentShell );
+ this.relation = relation;
+ this.class2ValueProviderMap = class2ValueProviderMap;
+ this.syntaxOids = syntaxOids;
+
+ this.returnRelation = null;
+
+ this.vpName2classMap = new TreeMap();
+ for ( Iterator it = this.class2ValueProviderMap.values().iterator(); it.hasNext(); )
+ {
+ ValueProvider vp = ( ValueProvider ) it.next();
+ vpName2classMap.put( vp.getCellEditorName(), vp.getClass().getName() );
+ }
+ }
+
+
+ protected void configureShell( Shell newShell )
+ {
+ super.configureShell( newShell );
+ newShell.setText( "Attribute Value Editor" );
+ }
+
+
+ protected void okPressed()
+ {
+ this.returnRelation = new SyntaxValueProviderRelation( this.oidCombo.getText(), ( String ) this.vpName2classMap
+ .get( this.valueEditorCombo.getText() ) );
+ super.okPressed();
+ }
+
+
+ protected Control createDialogArea( Composite parent )
+ {
+
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+
+ Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+ BaseWidgetUtils.createLabel( c, "Syntax OID:", 1 );
+ this.oidCombo = BaseWidgetUtils.createCombo( c, this.syntaxOids, -1, 1 );
+ if ( this.relation != null && this.relation.getSyntaxOID() != null )
+ {
+ this.oidCombo.setText( this.relation.getSyntaxOID() );
+ }
+ this.oidCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ validate();
+ }
+ } );
+
+ BaseWidgetUtils.createLabel( c, "Value Editor:", 1 );
+ this.valueEditorCombo = BaseWidgetUtils.createReadonlyCombo( c, ( String[] ) vpName2classMap.keySet().toArray(
+ new String[0] ), -1, 1 );
+ if ( this.relation != null && this.relation.getValueProviderClassname() != null
+ && this.class2ValueProviderMap.containsKey( this.relation.getValueProviderClassname() ) )
+ {
+ this.valueEditorCombo.setText( ( ( ValueProvider ) this.class2ValueProviderMap.get( this.relation
+ .getValueProviderClassname() ) ).getCellEditorName() );
+ }
+ this.valueEditorCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ validate();
+ }
+ } );
+
+ return composite;
+ }
+
+
+ private void validate()
+ {
+ super.getButton( IDialogConstants.OK_ID ).setEnabled(
+ !"".equals( this.valueEditorCombo.getText() ) && !"".equals( this.oidCombo.getText() ) );
+ }
+
+
+ public SyntaxValueProviderRelation getRelation()
+ {
+ return returnRelation;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/TextFormatsPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/TextFormatsPreferencePage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/TextFormatsPreferencePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/TextFormatsPreferencePage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,487 @@
+/*
+ * 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.dialogs.preferences;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
+import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BinaryEncodingInput;
+import org.apache.directory.ldapstudio.browser.ui.widgets.FileEncodingInput;
+import org.apache.directory.ldapstudio.browser.ui.widgets.LineSeparatorInput;
+import org.apache.directory.ldapstudio.browser.ui.widgets.OptionsInput;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyEvent;
+import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyListener;
+
+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( BrowserUIPlugin.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(
+ BrowserUIConstants.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(
+ BrowserUIConstants.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( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER ),
+ false, true );
+ tableQuoteWidget.createWidget( tableInnerComposite );
+ tableQuoteWidget.addWidgetModifyListener( this );
+
+ tableLineSeparator = new LineSeparatorInput( getPreferenceStore().getString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR ), false );
+ tableLineSeparator.createWidget( tableInnerComposite );
+ tableLineSeparator.addWidgetModifyListener( this );
+
+ tableBinaryEncodingWidget = new BinaryEncodingInput( getPreferenceStore().getString(
+ BrowserUIConstants.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( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER,
+ this.tableAttributeDelimiterWidget.getRawValue() );
+ getPreferenceStore().setValue( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER,
+ this.tableValueDelimiterWidget.getRawValue() );
+ getPreferenceStore().setValue( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER,
+ this.tableQuoteWidget.getRawValue() );
+ getPreferenceStore().setValue( BrowserUIConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR,
+ this.tableLineSeparator.getRawValue() );
+ getPreferenceStore().setValue( BrowserUIConstants.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(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER ) );
+ this.tableValueDelimiterWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER ) );
+ this.tableQuoteWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER ) );
+ this.tableLineSeparator.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserUIConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR ) );
+ this.tableBinaryEncodingWidget.setRawValue( getPreferenceStore().getDefaultString(
+ BrowserUIConstants.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/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/ValueEditorsPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/ValueEditorsPreferencePage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/ValueEditorsPreferencePage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/preferences/ValueEditorsPreferencePage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,601 @@
+/*
+ * 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.dialogs.preferences;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
+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.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.browser.ui.BrowserUIPlugin;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProvider;
+import org.apache.directory.ldapstudio.browser.ui.valueproviders.ValueProviderManager;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+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 class2ValueProviderMap;
+
+ 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.class2ValueProviderMap = new TreeMap();
+ Composite dummyComposite = new Composite( composite, SWT.NONE );
+ dummyComposite.setLayoutData( new GridData( 1, 1 ) );
+ ValueProvider[] valueProviders = ValueProviderManager.getValueProviders( dummyComposite );
+ for ( int i = 0; i < valueProviders.length; i++ )
+ {
+ this.class2ValueProviderMap.put( valueProviders[i].getClass().getName(), valueProviders[i] );
+ }
+
+ // 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( BrowserUIPlugin.getDefault().getUIPreferences()
+ .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( BrowserUIPlugin.getDefault().getUIPreferences()
+ .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()
+ {
+ AttributeValueProviderDialog dialog = new AttributeValueProviderDialog( getShell(), null,
+ this.class2ValueProviderMap, this.attributeTypesAndOids );
+ if ( dialog.open() == AttributeValueProviderDialog.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();
+ AttributeValueProviderDialog dialog = new AttributeValueProviderDialog( getShell(), relation,
+ this.class2ValueProviderMap, this.attributeTypesAndOids );
+ if ( dialog.open() == AttributeValueProviderDialog.OK )
+ {
+ int index = this.attributeList.indexOf( relation );
+ this.attributeList.set( index, dialog.getRelation() );
+ this.attributeViewer.refresh();
+ }
+ }
+ }
+
+
+ protected void addSyntax()
+ {
+ SyntaxValueProviderDialog dialog = new SyntaxValueProviderDialog( getShell(), null,
+ this.class2ValueProviderMap, this.syntaxDescsAndOids );
+ if ( dialog.open() == SyntaxValueProviderDialog.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();
+ SyntaxValueProviderDialog dialog = new SyntaxValueProviderDialog( getShell(), relation,
+ this.class2ValueProviderMap, this.syntaxDescsAndOids );
+ if ( dialog.open() == SyntaxValueProviderDialog.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()] );
+ BrowserUIPlugin.getDefault().getUIPreferences().setAttributeValueProviderRelations( aRelations );
+
+ SyntaxValueProviderRelation[] sRelations = ( SyntaxValueProviderRelation[] ) this.syntaxList
+ .toArray( new SyntaxValueProviderRelation[this.syntaxList.size()] );
+ BrowserUIPlugin.getDefault().getUIPreferences().setSyntaxValueProviderRelations( sRelations );
+
+ return true;
+ }
+
+
+ protected void performDefaults()
+ {
+ this.attributeList.clear();
+ this.attributeList.addAll( Arrays.asList( BrowserUIPlugin.getDefault().getUIPreferences()
+ .getDefaultAttributeValueProviderRelations() ) );
+ this.attributeViewer.refresh();
+
+ this.syntaxList.clear();
+ this.syntaxList.addAll( Arrays.asList( BrowserUIPlugin.getDefault().getUIPreferences()
+ .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 )
+ {
+ ValueProvider vp = ( ValueProvider ) class2ValueProviderMap.get( relation
+ .getValueProviderClassname() );
+ return vp != null ? vp.getCellEditorName() : null;
+ }
+ }
+ return null;
+ }
+
+
+ public Image getColumnImage( Object obj, int index )
+ {
+ if ( obj instanceof AttributeValueProviderRelation )
+ {
+ AttributeValueProviderRelation relation = ( AttributeValueProviderRelation ) obj;
+ if ( index == 2 )
+ {
+ ValueProvider vp = ( ValueProvider ) class2ValueProviderMap.get( relation
+ .getValueProviderClassname() );
+ return vp != null ? vp.getCellEditorImageDescriptor().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 )
+ {
+ ValueProvider vp = ( ValueProvider ) class2ValueProviderMap.get( relation
+ .getValueProviderClassname() );
+ return vp != null ? vp.getCellEditorName() : null;
+ }
+ }
+ return null;
+ }
+
+
+ public Image getColumnImage( Object obj, int index )
+ {
+ if ( obj instanceof SyntaxValueProviderRelation )
+ {
+ SyntaxValueProviderRelation relation = ( SyntaxValueProviderRelation ) obj;
+ if ( index == 2 )
+ {
+ ValueProvider vp = ( ValueProvider ) class2ValueProviderMap.get( relation
+ .getValueProviderClassname() );
+ return vp != null ? vp.getCellEditorImageDescriptor().createImage() : null;
+ }
+ }
+
+ return null;
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/AttributePropertyPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/AttributePropertyPage.java?view=auto&rev=488368
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/AttributePropertyPage.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-ui/src/org/apache/directory/ldapstudio/browser/ui/dialogs/properties/AttributePropertyPage.java Mon Dec 18 09:52:58 2006
@@ -0,0 +1,254 @@
+/*
+ * 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.dialogs.properties;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+
+public class AttributePropertyPage extends PropertyPage implements IWorkbenchPropertyPage
+{
+
+ private Text attributeNameText;
+
+ private Text attributeTypeText;
+
+ private Text attributeValuesText;
+
+ private Text attributeSizeText;
+
+ private Text atdOidText;
+
+ private Text atdNamesText;
+
+ private Text atdDescText;
+
+ private Text atdUsageText;
+
+ private Button singleValuedFlag;
+
+ private Button collectiveFlag;
+
+ private Button obsoleteFlag;
+
+ private Button noUserModificationFlag;
+
+ private Text equalityMatchingRuleText;
+
+ private Text substringMatchingRuleText;
+
+ private Text orderingMatchingRuleText;
+
+ private Text syntaxOidText;
+
+ private Text syntaxDescText;
+
+ private Text syntaxLengthText;
+
+
+ public AttributePropertyPage()
+ {
+ super();
+ super.noDefaultAndApplyButton();
+ }
+
+
+ protected Control createContents( Composite parent )
+ {
+
+ Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+
+ Composite mainGroup = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
+
+ BaseWidgetUtils.createLabel( mainGroup, "Description:", 1 );
+ attributeNameText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
+
+ BaseWidgetUtils.createLabel( mainGroup, "Type:", 1 );
+ attributeTypeText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
+
+ BaseWidgetUtils.createLabel( mainGroup, "Number of Values:", 1 );
+ attributeValuesText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
+
+ BaseWidgetUtils.createLabel( mainGroup, "Attribute Size:", 1 );
+ attributeSizeText = BaseWidgetUtils.createLabeledText( mainGroup, "", 1 );
+
+ Group atdGroup = BaseWidgetUtils.createGroup( composite, "Attribute Type", 1 );
+ Composite atdComposite = BaseWidgetUtils.createColumnContainer( atdGroup, 2, 1 );
+
+ BaseWidgetUtils.createLabel( atdComposite, "Numeric OID:", 1 );
+ atdOidText = BaseWidgetUtils.createLabeledText( atdComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( atdComposite, "Alternative Names:", 1 );
+ atdNamesText = BaseWidgetUtils.createLabeledText( atdComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( atdComposite, "Description:", 1 );
+ atdDescText = BaseWidgetUtils.createWrappedLabeledText( atdComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( atdComposite, "Usage:", 1 );
+ atdUsageText = BaseWidgetUtils.createLabeledText( atdComposite, "", 1 );
+
+ Group flagsGroup = BaseWidgetUtils.createGroup( composite, "Flags", 1 );
+ Composite flagsComposite = BaseWidgetUtils.createColumnContainer( flagsGroup, 4, 1 );
+
+ singleValuedFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Single valued", 1 );
+ singleValuedFlag.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ singleValuedFlag.setSelection( !singleValuedFlag.getSelection() );
+ }
+ } );
+
+ noUserModificationFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Read only", 1 );
+ noUserModificationFlag.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ noUserModificationFlag.setSelection( !noUserModificationFlag.getSelection() );
+ }
+ } );
+
+ collectiveFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Collective", 1 );
+ collectiveFlag.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ collectiveFlag.setSelection( !collectiveFlag.getSelection() );
+ }
+ } );
+
+ obsoleteFlag = BaseWidgetUtils.createCheckbox( flagsComposite, "Obsolete", 1 );
+ obsoleteFlag.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ obsoleteFlag.setSelection( !obsoleteFlag.getSelection() );
+ }
+ } );
+
+ Group syntaxGroup = BaseWidgetUtils.createGroup( composite, "Syntax", 1 );
+ Composite syntaxComposite = BaseWidgetUtils.createColumnContainer( syntaxGroup, 2, 1 );
+
+ BaseWidgetUtils.createLabel( syntaxComposite, "Syntax OID:", 1 );
+ syntaxOidText = BaseWidgetUtils.createLabeledText( syntaxComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( syntaxComposite, "Syntax Description:", 1 );
+ syntaxDescText = BaseWidgetUtils.createLabeledText( syntaxComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( syntaxComposite, "Syntax Length:", 1 );
+ syntaxLengthText = BaseWidgetUtils.createLabeledText( syntaxComposite, "", 1 );
+
+ Group matchingGroup = BaseWidgetUtils.createGroup( composite, "Matching Rules", 1 );
+ Composite matchingComposite = BaseWidgetUtils.createColumnContainer( matchingGroup, 2, 1 );
+
+ BaseWidgetUtils.createLabel( matchingComposite, "Equality Match:", 1 );
+ equalityMatchingRuleText = BaseWidgetUtils.createLabeledText( matchingComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( matchingComposite, "Substring Match:", 1 );
+ substringMatchingRuleText = BaseWidgetUtils.createLabeledText( matchingComposite, "", 1 );
+
+ BaseWidgetUtils.createLabel( matchingComposite, "Ordering Match:", 1 );
+ orderingMatchingRuleText = BaseWidgetUtils.createLabeledText( matchingComposite, "", 1 );
+
+ IAttribute attribute = getAttribute( getElement() );
+ if ( attribute != null )
+ {
+
+ int bytes = 0;
+ int valCount = 0;
+ IValue[] allValues = attribute.getValues();
+ for ( int valIndex = 0; valIndex < allValues.length; valIndex++ )
+ {
+ if ( !allValues[valIndex].isEmpty() )
+ {
+ valCount++;
+ bytes += allValues[valIndex].getBinaryValue().length;
+ }
+ }
+
+ this.setMessage( "Attribute " + attribute.getDescription() );
+ attributeNameText.setText( attribute.getDescription() );
+ attributeTypeText.setText( attribute.isString() ? "String" : "Binary" );
+ attributeValuesText.setText( "" + valCount );
+ attributeSizeText.setText( Utils.formatBytes( bytes ) );
+
+ if ( attribute.getEntry().getConnection().getSchema().hasAttributeTypeDescription(
+ attribute.getDescription() ) )
+ {
+ AttributeTypeDescription atd = attribute.getEntry().getConnection().getSchema()
+ .getAttributeTypeDescription( attribute.getDescription() );
+
+ atdOidText.setText( atd.getNumericOID() );
+ String atdNames = Arrays.asList( atd.getNames() ).toString();
+ atdNamesText.setText( atdNames.substring( 1, atdNames.length() - 1 ) );
+ atdDescText.setText( Utils.getNonNullString( atd.getDesc() ) );
+ atdUsageText.setText( Utils.getNonNullString( atd.getUsage() ) );
+
+ singleValuedFlag.setSelection( atd.isSingleValued() );
+ noUserModificationFlag.setSelection( atd.isNoUserModification() );
+ collectiveFlag.setSelection( atd.isCollective() );
+ obsoleteFlag.setSelection( atd.isObsolete() );
+
+ syntaxOidText.setText( Utils.getNonNullString( atd.getSyntaxDescriptionNumericOIDTransitive() ) );
+ syntaxDescText.setText( Utils.getNonNullString( atd.getSyntaxDescription().getDesc() ) );
+ syntaxLengthText.setText( Utils.getNonNullString( atd.getSyntaxDescriptionLengthTransitive() ) );
+
+ equalityMatchingRuleText.setText( Utils.getNonNullString( atd
+ .getEqualityMatchingRuleDescriptionOIDTransitive() ) );
+ substringMatchingRuleText.setText( Utils.getNonNullString( atd
+ .getSubstringMatchingRuleDescriptionOIDTransitive() ) );
+ orderingMatchingRuleText.setText( Utils.getNonNullString( atd
+ .getOrderingMatchingRuleDescriptionOIDTransitive() ) );
+ }
+ }
+
+ return parent;
+ }
+
+
+ private static IAttribute getAttribute( Object element )
+ {
+ IAttribute attribute = null;
+ if ( element instanceof IAdaptable )
+ {
+ attribute = ( IAttribute ) ( ( IAdaptable ) element ).getAdapter( IAttribute.class );
+ }
+ return attribute;
+ }
+
+}