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 [16/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/di...
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeTypeWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeTypeWizardPage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeTypeWizardPage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeTypeWizardPage.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,314 @@
+/*
+ * 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.wizards;
+
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.ldapstudio.browser.common.widgets.ListContentProposalProvider;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.eclipse.jface.fieldassist.ComboContentAdapter;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.DecoratedField;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IControlCreator;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * The AttributeTypeWizardPage provides a combo to select the attribute type,
+ * some filter and a preview field.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeTypeWizardPage extends WizardPage
+{
+
+ /** The parent wizard. */
+ private AttributeWizard wizard;
+
+ /** The initial show subschema attributes only. */
+ private boolean initialShowSubschemaAttributesOnly;
+
+ /** The initial hide existing attributes. */
+ private boolean initialHideExistingAttributes;
+
+ /** The parsed attribute type. */
+ private String parsedAttributeType;
+
+ /** The possible attribute types. */
+ private String[] possibleAttributeTypes;
+
+ /** The possible attribute types applicable to the entry's schema only. */
+ private String[] possibleAttributeTypesSubschemaOnly;
+
+ /** The possible attribute types applicable to the entry's schema only, existing attributes are hidden. */
+ private String[] possibleAttributeTypesSubschemaOnlyAndExistingHidden;
+
+ /** The attribute type combo field. */
+ private DecoratedField attributeTypeComboField;
+
+ /** The attribute type combo. */
+ private Combo attributeTypeCombo;
+
+ /** The attribute type content proposal adapter */
+ private ContentProposalAdapter attributeTypeCPA;
+
+ /** The show subschem attributes only button. */
+ private Button showSubschemAttributesOnlyButton;
+
+ /** The hide existing attributes button. */
+ private Button hideExistingAttributesButton;
+
+ /** The preview text. */
+ private Text previewText;
+
+
+ /**
+ * Creates a new instance of AttributeTypeWizardPage.
+ *
+ * @param pageName the page name
+ * @param initialEntry the initial entry
+ * @param initialAttributeDescription the initial attribute description
+ * @param initialShowSubschemaAttributesOnly the initial show subschema attributes only
+ * @param initialHideExistingAttributes the initial hide existing attributes
+ * @param wizard the wizard
+ */
+ public AttributeTypeWizardPage( String pageName, IEntry initialEntry, String initialAttributeDescription,
+ boolean initialShowSubschemaAttributesOnly, boolean initialHideExistingAttributes, AttributeWizard wizard )
+ {
+ super( pageName );
+ super.setTitle( "Attribute Type" );
+ super.setDescription( "Please enter or select the attribute type." );
+ // super.setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ATTRIBUTE_WIZARD));
+ super.setPageComplete( false );
+
+ this.wizard = wizard;
+ this.initialShowSubschemaAttributesOnly = initialShowSubschemaAttributesOnly;
+ this.initialHideExistingAttributes = initialHideExistingAttributes;
+
+ possibleAttributeTypes = initialEntry.getConnection().getSchema().getAttributeTypeDescriptionNames();
+ Arrays.sort( possibleAttributeTypes );
+ possibleAttributeTypesSubschemaOnly = initialEntry.getSubschema().getAllAttributeNames();
+ Arrays.sort( possibleAttributeTypesSubschemaOnly );
+
+ Set<String> set = new HashSet<String>( Arrays.asList( initialEntry.getSubschema().getAllAttributeNames() ) );
+ IAttribute[] existingAttributes = initialEntry.getAttributes();
+ for ( int i = 0; existingAttributes != null && i < existingAttributes.length; i++ )
+ {
+ set.remove( existingAttributes[i].getDescription() );
+ }
+ possibleAttributeTypesSubschemaOnlyAndExistingHidden = ( String[] ) set.toArray( new String[set.size()] );
+ Arrays.sort( possibleAttributeTypesSubschemaOnlyAndExistingHidden );
+
+ String attributeDescription = initialAttributeDescription;
+ if ( attributeDescription == null )
+ {
+ attributeDescription = "";
+ }
+ String[] attributeDescriptionComponents = attributeDescription.split( ";" );
+ parsedAttributeType = attributeDescriptionComponents[0];
+ }
+
+
+ /**
+ * Validates this page.
+ */
+ private void validate()
+ {
+ previewText.setText( wizard.getAttributeDescription() );
+ setPageComplete( !"".equals( attributeTypeCombo.getText() ) );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setVisible( boolean visible )
+ {
+ super.setVisible( visible );
+ if ( visible )
+ {
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( 2, false );
+ composite.setLayout( gl );
+ composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+
+ BaseWidgetUtils.createLabel( composite, "Attribute type:", 1 );
+// attributeTypeCombo = BaseWidgetUtils.createCombo( composite, possibleAttributeTypes, -1, 1 );
+// attributeTypeCombo.setText( parsedAttributeType );
+
+ // attribute combo with field decoration
+ final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+ attributeTypeComboField = new DecoratedField( composite, SWT.NONE, new IControlCreator()
+ {
+ public Control createControl( Composite parent, int style )
+ {
+ Combo combo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
+ combo.setVisibleItemCount( 20 );
+ return combo;
+ }
+ } );
+ attributeTypeComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true );
+ attributeTypeComboField.getLayoutControl().setLayoutData(
+ new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+ attributeTypeCombo = ( Combo ) attributeTypeComboField.getControl();
+ attributeTypeCombo.setItems( possibleAttributeTypes );
+ attributeTypeCombo.setText( parsedAttributeType );
+
+ // content proposal adapter
+ attributeTypeCPA = new ContentProposalAdapter (attributeTypeCombo, new ComboContentAdapter(),
+ new ListContentProposalProvider( attributeTypeCombo.getItems() ), null, null );
+ attributeTypeCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+ attributeTypeCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE );
+
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ showSubschemAttributesOnlyButton = BaseWidgetUtils.createCheckbox( composite, "Show subschema attributes only",
+ 1 );
+ showSubschemAttributesOnlyButton.setSelection( initialShowSubschemaAttributesOnly );
+
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ hideExistingAttributesButton = BaseWidgetUtils.createCheckbox( composite, "Hide existing attributes", 1 );
+ hideExistingAttributesButton.setSelection( initialHideExistingAttributes );
+
+ Label l = new Label( composite, SWT.NONE );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.horizontalSpan = 2;
+ l.setLayoutData( gd );
+
+ BaseWidgetUtils.createLabel( composite, "Preview:", 1 );
+ previewText = BaseWidgetUtils.createReadonlyText( composite, "", 1 );
+
+ // attribute type listener
+ attributeTypeCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ validate();
+ }
+ } );
+
+ // filter listener
+ showSubschemAttributesOnlyButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ updateFilter();
+ validate();
+ }
+ } );
+ hideExistingAttributesButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ updateFilter();
+ validate();
+ }
+ } );
+ updateFilter();
+
+ setControl( composite );
+ }
+
+
+ /**
+ * Updates the filter.
+ */
+ private void updateFilter()
+ {
+ // enable/disable filter buttons
+ hideExistingAttributesButton.setEnabled( showSubschemAttributesOnlyButton.getSelection() );
+ if ( possibleAttributeTypesSubschemaOnly.length == 0 )
+ {
+ showSubschemAttributesOnlyButton.setSelection( false );
+ showSubschemAttributesOnlyButton.setEnabled( false );
+ }
+ if ( possibleAttributeTypesSubschemaOnlyAndExistingHidden.length == 0 )
+ {
+ hideExistingAttributesButton.setEnabled( false );
+ hideExistingAttributesButton.setSelection( false );
+ }
+
+ // update combo items and proposals
+ String value = attributeTypeCombo.getText();
+ if ( hideExistingAttributesButton.getSelection() && showSubschemAttributesOnlyButton.getSelection() )
+ {
+ attributeTypeCombo.setItems( possibleAttributeTypesSubschemaOnlyAndExistingHidden );
+ }
+ else if ( showSubschemAttributesOnlyButton.getSelection() )
+ {
+ attributeTypeCombo.setItems( possibleAttributeTypesSubschemaOnly );
+ }
+ else
+ {
+ attributeTypeCombo.setItems( possibleAttributeTypes );
+ }
+ attributeTypeCPA.setContentProposalProvider( new ListContentProposalProvider( attributeTypeCombo.getItems() ) );
+ attributeTypeCombo.setText( value );
+ }
+
+
+ /**
+ * Gets the attribute type.
+ *
+ * @return the attribute type
+ */
+ String getAttributeType()
+ {
+ if ( attributeTypeCombo == null | attributeTypeCombo.isDisposed() )
+ {
+ return "";
+ }
+
+ return attributeTypeCombo.getText();
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeWizard.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeWizard.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeWizard.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/AttributeWizard.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.wizards;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The AttributeWizard is used to create a new attribute or
+ * to modify an existing attribute description.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AttributeWizard extends Wizard implements INewWizard
+{
+
+ /** The type page. */
+ private AttributeTypeWizardPage typePage;
+
+ /** The options page. */
+ private AttributeOptionsWizardPage optionsPage;
+
+ /** The initial show subschema attributes only. */
+ private boolean initialShowSubschemaAttributesOnly;
+
+ /** The initial hide existing attributes. */
+ private boolean initialHideExistingAttributes;
+
+ /** The initial attribute description. */
+ private String initialAttributeDescription;
+
+ /** The initial entry. */
+ private IEntry initialEntry;
+
+ /** The final attribute description. */
+ private String finalAttributeDescription = null;
+
+
+ /**
+ * Creates a new instance of AttributeWizard with an empty
+ * attriute description.
+ */
+ public AttributeWizard()
+ {
+ super.setWindowTitle( "New Attribute" );
+ super.setNeedsProgressMonitor( false );
+ this.initialShowSubschemaAttributesOnly = true;
+ this.initialHideExistingAttributes = true;
+ this.initialAttributeDescription = "";
+ this.initialEntry = null;
+ }
+
+
+ /**
+ * Creates a new instance of AttributeWizard with the given initial attribute desription
+ *
+ * @param title the title
+ * @param entry the entry
+ * @param showSubschemaAttributesOnly the show subschema attributes only
+ * @param hideExistingAttributes the hide existing attributes
+ * @param attributeDescription the attribute description
+ */
+ public AttributeWizard( String title, boolean showSubschemaAttributesOnly, boolean hideExistingAttributes,
+ String attributeDescription, IEntry entry )
+ {
+ super.setWindowTitle( title );
+ super.setNeedsProgressMonitor( false );
+ this.initialShowSubschemaAttributesOnly = showSubschemaAttributesOnly;
+ this.initialHideExistingAttributes = hideExistingAttributes;
+ this.initialAttributeDescription = attributeDescription;
+ this.initialEntry = entry;
+ }
+
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public static String getId()
+ {
+ return AttributeWizard.class.getName();
+ }
+
+
+ /**
+ * {@inheritDoc}}
+ */
+ public void init( IWorkbench workbench, IStructuredSelection selection )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}}
+ */
+ public void addPages()
+ {
+ if ( initialEntry != null )
+ {
+ typePage = new AttributeTypeWizardPage( AttributeTypeWizardPage.class.getName(), initialEntry,
+ initialAttributeDescription, initialShowSubschemaAttributesOnly, initialHideExistingAttributes, this );
+ addPage( typePage );
+
+ optionsPage = new AttributeOptionsWizardPage( AttributeOptionsWizardPage.class.getName(),
+ initialAttributeDescription, this );
+ addPage( optionsPage );
+ }
+ else
+ {
+ IWizardPage page = new DummyWizardPage();
+ addPage( page );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createPageControls( Composite pageContainer )
+ {
+ super.createPageControls( pageContainer );
+
+ // set help context ID
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( typePage.getControl(),
+ BrowserCommonActivator.PLUGIN_ID + "." + "tools_attribute_wizard" );
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( optionsPage.getControl(),
+ BrowserCommonActivator.PLUGIN_ID + "." + "tools_attribute_wizard" );
+ }
+
+ /**
+ * A dummy wizard page to show the user that no entry is selected.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ class DummyWizardPage extends WizardPage
+ {
+
+ /**
+ * Creates a new instance of DummyWizardPage.
+ */
+ protected DummyWizardPage()
+ {
+ super( "" );
+ super.setTitle( "No entry selected" );
+ super.setDescription( "In order to use the attribute creation wizard please select an entry." );
+ // super.setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ATTRIBUTE_WIZARD));
+ super.setPageComplete( true );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( 1, false );
+ composite.setLayout( gl );
+ composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+
+ setControl( composite );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean performFinish()
+ {
+ finalAttributeDescription = getAttributeDescription();
+ return true;
+ }
+
+
+ /**
+ * Gets the attribute description.
+ *
+ * @return the attribute description
+ */
+ public String getAttributeDescription()
+ {
+ if ( finalAttributeDescription != null )
+ {
+ return finalAttributeDescription;
+ }
+
+ return typePage.getAttributeType() + optionsPage.getAttributeOptions();
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionAuthWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionAuthWizardPage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionAuthWizardPage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionAuthWizardPage.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,139 @@
+/*
+ * 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.wizards;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionPageModifyListener;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * The NewConnectionAuthWizardPage is used to specify the
+ * authentication method of the new connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewConnectionAuthWizardPage extends WizardPage implements ConnectionPageModifyListener
+{
+
+ /** The wizard. */
+ private NewConnectionWizard wizard;
+
+
+ /**
+ * Creates a new instance of NewConnectionAuthWizardPage.
+ *
+ * @param pageName the page name
+ * @param wizard the wizard
+ */
+ public NewConnectionAuthWizardPage( String pageName, NewConnectionWizard wizard )
+ {
+ super( pageName );
+ setTitle( "Authentification" );
+ setDescription( "Please select an authentification method and input authentification data." );
+ setImageDescriptor( BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_CONNECTION_WIZARD ) );
+ setPageComplete( false );
+
+ this.wizard = wizard;
+ wizard.getCpw().addConnectionPageModifyListener( this );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void connectionPageModified()
+ {
+ if ( isCurrentPage() )
+ {
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setMessage( String message )
+ {
+ if ( isCurrentPage() )
+ {
+ super.setMessage( message );
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setErrorMessage( String errorMessage )
+ {
+ if ( isCurrentPage() )
+ {
+ super.setErrorMessage( errorMessage );
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IConnection getRealConnection()
+ {
+ return null;
+ }
+
+
+ /**
+ * Validates this page.
+ */
+ private void validate()
+ {
+ setPageComplete( getMessage() == null );
+ getContainer().updateButtons();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( 1, false );
+ composite.setLayout( gl );
+
+ wizard.getCpw().addAuthenticationMethodInput( IConnection.AUTH_SIMPLE, composite );
+ wizard.getCpw().addSimpleAuthInput( true, "", "", composite );
+
+ setControl( composite );
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionMainWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionMainWizardPage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionMainWizardPage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionMainWizardPage.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,139 @@
+/*
+ * 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.wizards;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionPageModifyListener;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * The NewConnectionMainWizardPage is used to specify the connection name
+ * and the network parameters of the new connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewConnectionMainWizardPage extends WizardPage implements ConnectionPageModifyListener
+{
+
+ /** The wizard. */
+ private NewConnectionWizard wizard;
+
+
+ /**
+ * Creates a new instance of NewConnectionMainWizardPage.
+ *
+ * @param pageName the page name
+ * @param wizard the wizard
+ */
+ public NewConnectionMainWizardPage( String pageName, NewConnectionWizard wizard )
+ {
+ super( pageName );
+ setTitle( "New LDAP Connection" );
+ setDescription( "Please enter connection name and network parameters." );
+ setImageDescriptor( BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_CONNECTION_WIZARD ) );
+ setPageComplete( false );
+
+ this.wizard = wizard;
+ wizard.getCpw().addConnectionPageModifyListener( this );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void connectionPageModified()
+ {
+ if ( isCurrentPage() )
+ {
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setMessage( String message )
+ {
+ if ( isCurrentPage() )
+ {
+ super.setMessage( message );
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setErrorMessage( String errorMessage )
+ {
+ if ( isCurrentPage() )
+ {
+ super.setErrorMessage( errorMessage );
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IConnection getRealConnection()
+ {
+ return null;
+ }
+
+
+ /**
+ * Validates this page.
+ */
+ private void validate()
+ {
+ setPageComplete( getMessage() == null );
+ getContainer().updateButtons();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( 1, false );
+ composite.setLayout( gl );
+
+ wizard.getCpw().addMainInput( "", "", 389, IConnection.ENCYRPTION_NONE, composite );
+ wizard.getCpw().addOpenConnectionInput( true, composite );
+
+ setControl( composite );
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionOptionsWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionOptionsWizardPage.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionOptionsWizardPage.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionOptionsWizardPage.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,143 @@
+/*
+ * 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.wizards;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionPageModifyListener;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * The NewConnectionAuthWizardPage is used to specify the
+ * advanced options of the new connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewConnectionOptionsWizardPage extends WizardPage implements ConnectionPageModifyListener
+{
+
+ /** The wizard. */
+ private NewConnectionWizard wizard;
+
+
+ /**
+ * Creates a new instance of NewConnectionOptionsWizardPage.
+ *
+ * @param pageName the page name
+ * @param wizard the wizard
+ */
+ public NewConnectionOptionsWizardPage( String pageName, NewConnectionWizard wizard )
+ {
+ super( pageName );
+ setTitle( "Connection Parameter" );
+ setDescription( "You can specify additional connection parameters." );
+ setImageDescriptor( BrowserCommonActivator.getDefault().getImageDescriptor( BrowserCommonConstants.IMG_CONNECTION_WIZARD ) );
+ setPageComplete( true );
+
+ this.wizard = wizard;
+ wizard.getCpw().addConnectionPageModifyListener( this );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void connectionPageModified()
+ {
+ if ( isCurrentPage() )
+ {
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setMessage( String message )
+ {
+ if ( isCurrentPage() )
+ {
+ super.setMessage( message );
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setErrorMessage( String errorMessage )
+ {
+ if ( isCurrentPage() )
+ {
+ super.setErrorMessage( errorMessage );
+ validate();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public IConnection getRealConnection()
+ {
+ return null;
+ }
+
+
+ /**
+ * Validates this page.
+ */
+ private void validate()
+ {
+ setPageComplete( getMessage() == null );
+ getContainer().updateButtons();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( 1, false );
+ composite.setLayout( gl );
+
+ wizard.getCpw().addBaseDNInput( true, "", composite );
+ wizard.getCpw().addLimitInput(
+ BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_COUNT_LIMIT ),
+ BrowserCommonActivator.getDefault().getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_TIME_LIMIT ),
+ IConnection.DEREFERENCE_ALIASES_ALWAYS, IConnection.HANDLE_REFERRALS_FOLLOW, composite );
+
+ setControl( composite );
+ // baseDNText.setFocus();
+ }
+
+}
\ No newline at end of file
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionWizard.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionWizard.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionWizard.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/wizards/NewConnectionWizard.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,174 @@
+/*
+ * 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.wizards;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.widgets.connection.ConnectionPageWrapper;
+import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
+import org.apache.directory.ldapstudio.browser.core.jobs.OpenConnectionsJob;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * The NewConnectionWizard is used to create a new connection.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewConnectionWizard extends Wizard implements INewWizard
+{
+
+ /** The connection page wrapper. */
+ private ConnectionPageWrapper cpw;
+
+ /** The main page. */
+ private NewConnectionMainWizardPage mainPage;
+
+ /** The auth page. */
+ private NewConnectionAuthWizardPage authPage;
+
+ /** The options page. */
+ private NewConnectionOptionsWizardPage optionsPage;
+
+
+ /**
+ * Creates a new instance of NewConnectionWizard.
+ */
+ public NewConnectionWizard()
+ {
+ setWindowTitle( "New LDAP Connection" );
+ setNeedsProgressMonitor( true );
+ }
+
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public static String getId()
+ {
+ return NewConnectionWizard.class.getName();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init( IWorkbench workbench, IStructuredSelection selection )
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addPages()
+ {
+ cpw = new ConnectionPageWrapper( null, getContainer() );
+
+ mainPage = new NewConnectionMainWizardPage( NewConnectionMainWizardPage.class.getName(), this );
+ addPage( mainPage );
+
+ authPage = new NewConnectionAuthWizardPage( NewConnectionAuthWizardPage.class.getName(), this );
+ addPage( authPage );
+
+ optionsPage = new NewConnectionOptionsWizardPage( NewConnectionOptionsWizardPage.class.getName(), this );
+ addPage( optionsPage );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createPageControls( Composite pageContainer )
+ {
+ super.createPageControls( pageContainer );
+
+ // set help context ID
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( mainPage.getControl(),
+ BrowserCommonActivator.PLUGIN_ID + "." + "tools_newconnection_wizard" );
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( authPage.getControl(),
+ BrowserCommonActivator.PLUGIN_ID + "." + "tools_newconnection_wizard" );
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( optionsPage.getControl(),
+ BrowserCommonActivator.PLUGIN_ID + "." + "tools_newconnection_wizard" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canFinish()
+ {
+ if ( cpw.getAuthenticationMethod() == IConnection.AUTH_ANONYMOUS )
+ {
+ return mainPage.isPageComplete() && optionsPage.isPageComplete();
+ }
+ else if ( cpw.getAuthenticationMethod() == IConnection.AUTH_SIMPLE )
+ {
+ return mainPage.isPageComplete() && authPage.isPageComplete() && optionsPage.isPageComplete();
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean performFinish()
+ {
+ final IConnection conn = cpw.getTestConnection();
+ conn.setName( cpw.getName() );
+ if ( conn != null )
+ {
+ BrowserCorePlugin.getDefault().getConnectionManager().addConnection( conn );
+ if ( cpw.isOpenConnectionOnFinish() )
+ {
+ new OpenConnectionsJob( conn ).execute();
+ }
+ cpw.saveDialogSettings();
+ return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Gets the connection page wrapper.
+ *
+ * @return the connection page wrapper
+ */
+ public ConnectionPageWrapper getCpw()
+ {
+ return cpw;
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogBinaryValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogBinaryValueEditor.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogBinaryValueEditor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogBinaryValueEditor.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,327 @@
+/*
+ * 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.valueeditors;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
+import org.apache.directory.ldapstudio.browser.core.jobs.CreateValuesJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.DeleteAttributesValueJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.ModifyValueJob;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+import org.apache.directory.ldapstudio.browser.core.utils.Utils;
+
+
+/**
+ *
+ * Abstract base class for value editors that handle binary values
+ * in a dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractDialogBinaryValueEditor extends AbstractDialogValueEditor
+{
+
+ /**
+ * Creates a new instance of AbstractDialogBinaryValueEditor.
+ */
+ protected AbstractDialogBinaryValueEditor()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation of getDisplayValue just returns a note,
+ * that the value is binary and the size of the data.
+ */
+ public String getDisplayValue( IValue value )
+ {
+ if ( showRawValues() )
+ {
+ return getPrintableString( value );
+ }
+ else
+ {
+ if ( value == null )
+ {
+ return "NULL";
+ }
+ else if ( value.isBinary() )
+ {
+ byte[] data = value.getBinaryValue();
+ return "Binary Data (" + data.length + " Bytes)";
+ }
+ else
+ {
+ return "Invalid Data";
+ }
+ }
+ }
+
+
+ /**
+ * Helper method, returns a printable string if the value
+ * is binary.
+ *
+ * @param value the value
+ *
+ * @return the printable string
+ */
+ public static String getPrintableString( IValue value )
+ {
+ if ( value == null )
+ {
+ return "NULL";
+ }
+ else if ( value.isBinary() )
+ {
+ byte[] data = value.getBinaryValue();
+ StringBuffer sb = new StringBuffer();
+ for ( int i = 0; data != null && i < data.length && i < 128; i++ )
+ {
+ if ( data[i] > 32 && data[i] < 127 )
+ sb.append( ( char ) data[i] );
+ else
+ sb.append( '.' );
+ }
+ return sb.toString();
+ }
+ else if ( value.isString() )
+ {
+ return value.getStringValue();
+ }
+ else
+ {
+ return "NULL";
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns IValue.EMPTY_BINARY_VALUE if
+ * the attribute is binary.
+ */
+ protected Object getEmptyRawValue( IAttribute attribute )
+ {
+ if ( attribute.isBinary() )
+ {
+ return IValue.EMPTY_BINARY_VALUE;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns the binary (byte[]) value
+ * of the given value.
+ */
+ public Object getRawValue( IValue value )
+ {
+ if ( value == null )
+ {
+ return null;
+ }
+ else if ( value.isString() )
+ {
+ return value.getBinaryValue();
+ }
+ else if ( value.isBinary() )
+ {
+ return value.getBinaryValue();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns the value itself if it is
+ * of type byte[] or a byte[] with the UTF-8 encoded string
+ * value if it is of type String.
+ */
+ public Object getRawValue( IConnection connection, Object value )
+ {
+ if ( value == null )
+ {
+ return null;
+ }
+ else if ( value instanceof String )
+ {
+ return LdifUtils.utf8encode( ( String ) value );
+ }
+ else if ( value instanceof byte[] )
+ {
+ return value;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation always return the binary value
+ * as byte[].
+ */
+ public Object getStringOrBinaryValue( Object rawValue )
+ {
+ if ( rawValue == null )
+ {
+ return null;
+ }
+ else if ( rawValue instanceof byte[] )
+ {
+ return rawValue;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void createValue( IEntry entry, String attributeDescription, Object newRawValue )
+ throws ModelModificationException
+ {
+ if ( entry != null && attributeDescription != null && newRawValue != null && newRawValue instanceof byte[] )
+ {
+ if ( entry.getAttribute( attributeDescription ) != null )
+ {
+ this.modify( entry.getAttribute( attributeDescription ), newRawValue );
+ }
+ else
+ {
+ EventRegistry.suspendEventFireingInCurrentThread();
+ IAttribute attribute = new Attribute( entry, attributeDescription );
+ entry.addAttribute( attribute );
+ EventRegistry.resumeEventFireingInCurrentThread();
+
+ Object newValue;
+ if ( entry.getConnection().getSchema().getAttributeTypeDescription( attributeDescription )
+ .getSyntaxDescription().isString() )
+ {
+ newValue = LdifUtils.utf8decode( ( byte[] ) newRawValue );
+ }
+ else
+ {
+ newValue = ( byte[] ) newRawValue;
+ }
+
+ new CreateValuesJob( attribute, newValue ).execute();
+ }
+ }
+ }
+
+
+ private final void modify( IAttribute attribute, Object newRawValue ) throws ModelModificationException
+ {
+ if ( attribute != null && newRawValue != null && newRawValue instanceof byte[] )
+ {
+ if ( attribute.getValueSize() == 0 )
+ {
+ byte[] newValue = ( byte[] ) newRawValue;
+ new CreateValuesJob( attribute, newValue ).execute();
+ }
+ else if ( attribute.getValueSize() == 1 )
+ {
+ this.modifyValue( attribute.getValues()[0], newRawValue );
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void modifyValue( IValue oldValue, Object newRawValue ) throws ModelModificationException
+ {
+ if ( oldValue != null && newRawValue != null && newRawValue instanceof byte[] )
+ {
+ byte[] newValue = ( byte[] ) newRawValue;
+ IAttribute attribute = oldValue.getAttribute();
+ if ( !Utils.equals( oldValue.getBinaryValue(), newValue ) )
+ {
+ if ( oldValue.isEmpty() )
+ {
+ EventRegistry.suspendEventFireingInCurrentThread();
+ attribute.deleteEmptyValue();
+ EventRegistry.resumeEventFireingInCurrentThread();
+ new CreateValuesJob( attribute, newValue ).execute();
+ }
+ else
+ {
+ new ModifyValueJob( attribute, oldValue, newValue ).execute();
+ }
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void deleteAttribute( AttributeHierarchy ah ) throws ModelModificationException
+ {
+ if ( ah != null )
+ {
+ new DeleteAttributesValueJob( ah ).execute();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void deleteValue( IValue oldValue ) throws ModelModificationException
+ {
+ if ( oldValue != null )
+ {
+ new DeleteAttributesValueJob( oldValue ).execute();
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogStringValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogStringValueEditor.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogStringValueEditor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogStringValueEditor.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,301 @@
+/*
+ * 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.valueeditors;
+
+
+import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
+import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
+import org.apache.directory.ldapstudio.browser.core.jobs.CreateValuesJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.DeleteAttributesValueJob;
+import org.apache.directory.ldapstudio.browser.core.jobs.ModifyValueJob;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+
+
+/**
+ *
+ * Abstract base class for value editors that handle string values
+ * in a dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractDialogStringValueEditor extends AbstractDialogValueEditor
+{
+
+ /**
+ * Creates a new instance of AbstractDialogStringValueEditor.
+ */
+ protected AbstractDialogStringValueEditor()
+ {
+ super();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just returns the raw value
+ */
+ public String getDisplayValue( IValue value )
+ {
+ Object obj = this.getRawValue( value );
+ return obj == null ? "NULL" : obj.toString();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns IValue.EMPTY_STRING_VALUE if
+ * the attribute is string.
+ */
+ protected Object getEmptyRawValue( IAttribute attribute )
+ {
+ if ( attribute.isString() )
+ {
+ return IValue.EMPTY_STRING_VALUE;
+ }
+ else
+ {
+ return IValue.EMPTY_BINARY_VALUE;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns the string value
+ * of the given value.
+ */
+ public Object getRawValue( IValue value )
+ {
+ if ( value == null )
+ {
+ return null;
+ }
+ else if ( value.isString() )
+ {
+ return value.getStringValue();
+ }
+ else if ( value.isBinary() )
+ {
+ return isEditable( value.getBinaryValue() ) ? value.getStringValue() : null;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns the value itself if it is
+ * of type String. If the value is of type byte[] then the binary
+ * data is converted to a String using UTF-8 encoding.
+ */
+ public Object getRawValue( IConnection connection, Object value )
+ {
+ if ( value == null )
+ {
+ return null;
+ }
+ else if ( value instanceof String )
+ {
+ return value;
+ }
+ else if ( value instanceof byte[] )
+ {
+ String s = LdifUtils.utf8decode( ( byte[] ) value );
+ for ( int i = 0; i < s.length(); i++ )
+ {
+ if ( Character.isISOControl( s.charAt( i ) ) && s.charAt( i ) != '\n' && s.charAt( i ) != '\r' )
+ {
+ return null;
+ }
+ }
+ return s;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Small helper.
+ */
+ private boolean isEditable( byte[] b )
+ {
+ if ( b == null )
+ {
+ return false;
+ }
+
+ for ( int i = 0; i < b.length; i++ )
+ {
+ if ( !( b[i] == '\n' || b[i] == '\r' || ( b[i] >= '\u0020' && b[i] <= '\u007F' ) ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation always return the string value
+ * as String.
+ */
+ public Object getStringOrBinaryValue( Object rawValue )
+ {
+ if ( rawValue == null )
+ {
+ return null;
+ }
+ else if ( rawValue instanceof String )
+ {
+ return rawValue;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void createValue( IEntry entry, String attributeDescription, Object newRawValue )
+ throws ModelModificationException
+ {
+ if ( entry != null && attributeDescription != null && newRawValue != null && newRawValue instanceof String )
+ {
+ if ( entry.getAttribute( attributeDescription ) != null )
+ {
+ this.modify( entry.getAttribute( attributeDescription ), newRawValue );
+ }
+ else
+ {
+ EventRegistry.suspendEventFireingInCurrentThread();
+ IAttribute attribute = new Attribute( entry, attributeDescription );
+ entry.addAttribute( attribute );
+ EventRegistry.resumeEventFireingInCurrentThread();
+
+ Object newValue;
+ if ( entry.getConnection().getSchema().getAttributeTypeDescription( attributeDescription )
+ .getSyntaxDescription().isString() )
+ {
+ newValue = ( String ) newRawValue;
+ }
+ else
+ {
+ newValue = LdifUtils.utf8encode( ( String ) newRawValue );
+ }
+
+ new CreateValuesJob( attribute, newValue ).execute();
+ }
+ }
+ }
+
+
+ private final void modify( IAttribute attribute, Object newRawValue ) throws ModelModificationException
+ {
+ if ( attribute != null && newRawValue != null && newRawValue instanceof String )
+ {
+ if ( attribute.getValueSize() == 0 )
+ {
+ String newValue = ( String ) newRawValue;
+ new CreateValuesJob( attribute, newValue ).execute();
+ }
+ else if ( attribute.getValueSize() == 1 )
+ {
+ this.modifyValue( attribute.getValues()[0], newRawValue );
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void modifyValue( IValue oldValue, Object newRawValue ) throws ModelModificationException
+ {
+ if ( oldValue != null && newRawValue != null && newRawValue instanceof String )
+ {
+
+ String newValue = ( String ) newRawValue;
+ IAttribute attribute = oldValue.getAttribute();
+ if ( !oldValue.getStringValue().equals( newValue ) )
+ {
+ if ( oldValue.isEmpty() )
+ {
+ EventRegistry.suspendEventFireingInCurrentThread();
+ attribute.deleteEmptyValue();
+ EventRegistry.resumeEventFireingInCurrentThread();
+ new CreateValuesJob( attribute, newValue ).execute();
+ }
+ else
+ {
+ new ModifyValueJob( attribute, oldValue, newValue ).execute();
+ }
+ }
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void deleteAttribute( AttributeHierarchy ah ) throws ModelModificationException
+ {
+ if ( ah != null )
+ {
+ new DeleteAttributesValueJob( ah ).execute();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void deleteValue( IValue oldValue ) throws ModelModificationException
+ {
+ if ( oldValue != null )
+ {
+ new DeleteAttributesValueJob( oldValue ).execute();
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogValueEditor.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogValueEditor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractDialogValueEditor.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,290 @@
+/*
+ * 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.valueeditors;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * Abstract base class for value editors that handle values
+ * in a dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractDialogValueEditor extends CellEditor implements IValueEditor
+{
+
+ /** The value to handle */
+ private Object value;
+
+ /** The shell, used to open the editor */
+ private Shell shell;
+
+ /** The name of this value editor */
+ private String name;
+
+ /** The image of this value editor */
+ private ImageDescriptor imageDescriptor;
+
+
+ /**
+ *
+ * Creates a new instance of AbstractDialogEditor.
+ */
+ protected AbstractDialogValueEditor()
+ {
+ }
+
+
+ /**
+ * Returns true if the user wishes to show raw values rather than
+ * user-friendly values. If true the getDisplayValue() methods
+ * shouldnot modify the value.
+ *
+ * @return true if raw values should be displayed
+ */
+ protected boolean showRawValues()
+ {
+ return BrowserCommonActivator.getDefault().getPreferenceStore()
+ .getBoolean( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation simple returns itself.
+ */
+ public CellEditor getCellEditor()
+ {
+ return this;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This is a dialog editor, it doesn't create a control.
+ * It just extracts and saves the shell reference from parent.
+ */
+ protected final Control createControl( Composite parent )
+ {
+ this.shell = parent.getShell();
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This is a dialog editor, doesn't set focus.
+ */
+ protected final void doSetFocus()
+ {
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * Returns the value object stored in a member.
+ */
+ protected final Object doGetValue()
+ {
+ return this.value;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * Stores the value object in a member.
+ */
+ protected final void doSetValue( Object value )
+ {
+ if ( value != null && value instanceof IValue.EmptyValue )
+ {
+ IValue.EmptyValue emptyValue = ( IValue.EmptyValue ) value;
+ if ( emptyValue.isBinary() )
+ value = emptyValue.getBinaryValue();
+ else
+ value = emptyValue.getStringValue();
+ }
+ this.value = value;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * The activate method is called from the JFace framework
+ * to start editing.
+ */
+ public final void activate()
+ {
+ boolean save = this.openDialog( shell );
+ //doSetValue( newValue );
+ if ( !save || this.value == null )
+ {
+ this.value = null;
+ fireCancelEditor();
+ }
+ else
+ {
+ fireApplyEditorValue();
+ deactivate();
+ }
+ }
+
+
+ /**
+ * Opens the edit dialog.
+ * Call getValue() to get the current value to edit.
+ * Call setValue() to set the new value after editing.
+ *
+ * @param shell The shell to use to open the dialog
+ * @return true if the new value should be stored, false
+ * to cancel the editor.
+ */
+ protected abstract boolean openDialog( Shell shell );
+
+
+ /**
+ * Returns a raw value that represents an empty value.
+ *
+ * @param attribute the attribute
+ * @return a raw value that represents an empty value
+ */
+ protected abstract Object getEmptyRawValue( IAttribute attribute );
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation of getDisplayValue() returns a
+ * comma-separated list of all values.
+ */
+ public String getDisplayValue( AttributeHierarchy attributeHierarchy )
+ {
+ if ( attributeHierarchy == null )
+ {
+ return "NULL";
+ }
+
+ List<IValue> valueList = new ArrayList<IValue>();
+ for ( Iterator it = attributeHierarchy.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ valueList.addAll( Arrays.asList( attribute.getValues() ) );
+ }
+
+ StringBuffer sb = new StringBuffer();
+ for ( Iterator<IValue> it = valueList.iterator(); it.hasNext(); )
+ {
+ IValue value = it.next();
+ sb.append( getDisplayValue( value ) );
+ if ( it.hasNext() )
+ sb.append( ", " );
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation calls getEmptyRawValue(IAttribute) if there are no values
+ * in attributeHierarchy and getRawValue(IValue) if attributeHierarchy
+ * contains exactly one value. Otherwise null is returned.
+ */
+ public Object getRawValue( AttributeHierarchy attributeHierarchy )
+ {
+ if ( attributeHierarchy == null )
+ {
+ return null;
+ }
+ else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 0 )
+ {
+ return getEmptyRawValue( attributeHierarchy.getAttribute() );
+ }
+ else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 1 )
+ {
+ return getRawValue( attributeHierarchy.getAttribute().getValues()[0] );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValueEditorName( String name )
+ {
+ this.name = name;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getValueEditorName()
+ {
+ return name;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValueEditorImageDescriptor( ImageDescriptor imageDescriptor )
+ {
+ this.imageDescriptor = imageDescriptor;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getValueEditorImageDescriptor()
+ {
+ return imageDescriptor;
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractInPlaceStringValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractInPlaceStringValueEditor.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractInPlaceStringValueEditor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/AbstractInPlaceStringValueEditor.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,381 @@
+/*
+ * 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.valueeditors;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
+import org.apache.directory.ldapstudio.browser.core.model.IConnection;
+import org.apache.directory.ldapstudio.browser.core.model.IEntry;
+import org.apache.directory.ldapstudio.browser.core.model.IValue;
+import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.utils.LdifUtils;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.TextCellEditor;
+
+
+/**
+ *
+ * Abstract base class for value editors that handle string values
+ * withing the table or tree control.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractInPlaceStringValueEditor extends TextCellEditor implements IValueEditor
+{
+
+ /**
+ * @deprecated will be removed soon. Just used to delegate
+ * createValue(), deleteValue() and modifyValue().
+ */
+ private TextValueEditor delegate;
+
+ /** The name of this value editor */
+ private String name;
+
+ /** The image of this value editor */
+ private ImageDescriptor imageDescriptor;
+
+
+ /**
+ * Creates a new instance of AbstractInPlaceStringValueEditor.
+ */
+ protected AbstractInPlaceStringValueEditor()
+ {
+ super();
+ this.delegate = new TextValueEditor();
+ }
+
+
+ /**
+ * Returns true if the user wishes to show raw values rather than
+ * user-friendly values. If true the getDisplayValue() methods
+ * shouldnot modify the value.
+ *
+ * @return true if raw values should be displayed
+ */
+ protected boolean showRawValues()
+ {
+ return BrowserCommonActivator.getDefault().getPreferenceStore()
+ .getBoolean( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation of getDisplayValue() returns a
+ * comma-separated list of all values.
+ */
+ public String getDisplayValue( AttributeHierarchy attributeHierarchy )
+ {
+ if ( attributeHierarchy == null )
+ {
+ return "NULL";
+ }
+
+ List<IValue> valueList = new ArrayList<IValue>();
+ for ( Iterator it = attributeHierarchy.iterator(); it.hasNext(); )
+ {
+ IAttribute attribute = ( IAttribute ) it.next();
+ valueList.addAll( Arrays.asList( attribute.getValues() ) );
+ }
+
+ StringBuffer sb = new StringBuffer();
+ for ( Iterator<IValue> it = valueList.iterator(); it.hasNext(); )
+ {
+ IValue value = it.next();
+ sb.append( getDisplayValue( value ) );
+ if ( it.hasNext() )
+ sb.append( ", " );
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation just returns the raw value
+ */
+ public String getDisplayValue( IValue value )
+ {
+ Object obj = this.getRawValue( value );
+ return obj == null ? "NULL" : obj.toString();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns IValue.EMPTY_xx_VALUE if there are no values
+ * in attributeHierarchy or calls getRawValue(IValue) if attributeHierarchy
+ * contains exactly one value. Otherwise null is returned.
+ */
+ public Object getRawValue( AttributeHierarchy attributeHierarchy )
+ {
+ if ( attributeHierarchy == null )
+ {
+ return null;
+ }
+ else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 0 )
+ {
+ if ( attributeHierarchy.getAttribute().isString() )
+ {
+ return IValue.EMPTY_STRING_VALUE;
+ }
+ else
+ {
+ return IValue.EMPTY_BINARY_VALUE;
+ }
+ }
+ else if ( attributeHierarchy.size() == 1 && attributeHierarchy.getAttribute().getValueSize() == 1 )
+ {
+ return getRawValue( attributeHierarchy.getAttribute().getValues()[0] );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns the string value
+ * of the given value.
+ */
+ public Object getRawValue( IValue value )
+ {
+ if ( value == null )
+ {
+ return null;
+ }
+ else if ( value.isString() )
+ {
+ return value.getStringValue();
+ }
+ else if ( value.isBinary() )
+ {
+ return isEditable( value.getBinaryValue() ) ? value.getStringValue() : null;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Small helper.
+ */
+ private boolean isEditable( byte[] b )
+ {
+ if ( b == null )
+ {
+ return false;
+ }
+
+ for ( int i = 0; i < b.length; i++ )
+ {
+ if ( !( b[i] == '\n' || b[i] == '\r' || ( b[i] >= '\u0020' && b[i] <= '\u007F' ) ) )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation returns the value itself if it is
+ * of type byte[] or a byte[] with the UTF-8 encoded string
+ * value if it is of type String.
+ */
+ public Object getRawValue( IConnection connection, Object value )
+ {
+ if ( value == null )
+ {
+ return null;
+ }
+ else if ( value instanceof String )
+ {
+ return value;
+ }
+ else if ( value instanceof byte[] )
+ {
+ String s = LdifUtils.utf8decode( ( byte[] ) value );
+ for ( int i = 0; i < s.length(); i++ )
+ {
+ if ( Character.isISOControl( s.charAt( i ) ) && s.charAt( i ) != '\n' && s.charAt( i ) != '\r' )
+ {
+ return null;
+ }
+ }
+ return s;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation always return the string value
+ * as String.
+ */
+ public Object getStringOrBinaryValue( Object rawValue )
+ {
+ if ( rawValue == null )
+ {
+ return null;
+ }
+ else if ( rawValue instanceof String )
+ {
+ return rawValue;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public CellEditor getCellEditor()
+ {
+ return this;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Object doGetValue()
+ {
+ return "".equals( text.getText() ) ? null : text.getText();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void doSetValue( Object value )
+ {
+ if ( value != null && value instanceof IValue.EmptyValue )
+ {
+ value = ( ( IValue.EmptyValue ) value ).getStringValue();
+ }
+ super.doSetValue( value );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValueEditorName( String name )
+ {
+ this.name = name;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getValueEditorName()
+ {
+ return name;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setValueEditorImageDescriptor( ImageDescriptor imageDescriptor )
+ {
+ this.imageDescriptor = imageDescriptor;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImageDescriptor getValueEditorImageDescriptor()
+ {
+ return imageDescriptor;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void createValue( IEntry entry, String attributeDescription, Object newRawValue )
+ throws ModelModificationException
+ {
+ delegate.createValue( entry, attributeDescription, newRawValue );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void deleteAttribute( AttributeHierarchy ah ) throws ModelModificationException
+ {
+ delegate.deleteAttribute( ah );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void deleteValue( IValue oldValue ) throws ModelModificationException
+ {
+ delegate.deleteValue( oldValue );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void modifyValue( IValue oldValue, Object newRawValue ) throws ModelModificationException
+ {
+ delegate.modifyValue( oldValue, newRawValue );
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/HexValueEditor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/HexValueEditor.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/HexValueEditor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/valueeditors/HexValueEditor.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.valueeditors;
+
+
+import org.apache.directory.ldapstudio.browser.common.dialogs.HexDialog;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * The default editor for binary values. Uses the HexDialog.
+ *
+ * The HexDialog is currently only able to save and load binary data
+ * to and from file. It is not possible to edit the data in the dialog
+ * directly.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HexValueEditor extends AbstractDialogBinaryValueEditor
+{
+
+ /**
+ * {@inheritDoc}
+ *
+ * This implementation opens the HexDialog.
+ */
+ protected boolean openDialog( Shell shell )
+ {
+ Object value = getValue();
+ if ( value != null && value instanceof byte[] )
+ {
+ byte[] initialData = ( byte[] ) value;
+ HexDialog dialog = new HexDialog( shell, initialData );
+ if ( dialog.open() == HexDialog.OK && dialog.getData() != null )
+ {
+ setValue( dialog.getData() );
+ return true;
+ }
+ }
+ return false;
+ }
+
+}