You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/07/10 00:35:42 UTC
svn commit: r1690182 - in
/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor:
dialogs/DnValueDialog.java wrappers/DnDecorator.java wrappers/DnWrapper.java
Author: elecharny
Date: Thu Jul 9 22:35:42 2015
New Revision: 1690182
URL: http://svn.apache.org/r1690182
Log:
Added a Dn Dialog, decorator and wrapper for the list of database Suffix
Added:
directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/dialogs/DnValueDialog.java
directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnDecorator.java
directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnWrapper.java
Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/dialogs/DnValueDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/dialogs/DnValueDialog.java?rev=1690182&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/dialogs/DnValueDialog.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/dialogs/DnValueDialog.java Thu Jul 9 22:35:42 2015
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.openldap.config.editor.dialogs;
+
+
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.studio.common.ui.AddEditDialog;
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.openldap.config.editor.wrappers.DnWrapper;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+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.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * The DnValueDialog is used to edit a DN
+ *
+ * <pre>
+ * +---------------------------------------+
+ * | .-----------------------------------. |
+ * | | DN : [ ] | |
+ * | '-----------------------------------' |
+ * | |
+ * | (cancel) (OK) |
+ * +---------------------------------------+
+ *
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DnValueDialog extends AddEditDialog<DnWrapper>
+{
+ // UI widgets
+ /** The DN Text */
+ private Text dnText;
+
+ /**
+ * Create a new instance of the String
+ *
+ * @param parentShell The parent Shell
+ */
+ public DnValueDialog( Shell parentShell )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ }
+
+
+ /**
+ * The listener for the DN Text
+ */
+ private ModifyListener dnValueTextListener = new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ Display display = dnText.getDisplay();
+ Button okButton = getButton( IDialogConstants.OK_ID );
+
+ // This button might be null when the dialog is called.
+ if ( okButton == null )
+ {
+ return;
+ }
+
+ try
+ {
+ Dn dn = new Dn( dnText.getText() );
+
+ getEditedElement().setDn( dn );
+ okButton.setEnabled( true );
+ dnText.setForeground( display.getSystemColor( SWT.COLOR_BLACK ) );
+ }
+ catch ( LdapInvalidDnException e1 )
+ {
+ okButton.setEnabled( false );
+ dnText.setForeground( display.getSystemColor( SWT.COLOR_RED ) );
+ }
+ }
+ };
+
+
+ /**
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( "DN" );
+ }
+
+
+ /**
+ * Create the Dialog for DnValue :
+ * <pre>
+ * +---------------------------------------+
+ * | .-----------------------------------. |
+ * | | Dn : [ ] | |
+ * | '-----------------------------------' |
+ * | |
+ * | (cancel) (OK) |
+ * +---------------------------------------+
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ composite.setLayoutData( gd );
+
+ // DnValue Group
+ Group dnValueGroup = BaseWidgetUtils.createGroup( parent, null, 1 );
+ GridLayout stringValueGroupGridLayout = new GridLayout( 2, false );
+ dnValueGroup.setLayout( stringValueGroupGridLayout );
+ dnValueGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ // DN Text
+ BaseWidgetUtils.createLabel( dnValueGroup, "DN :", 1 );
+ dnText = BaseWidgetUtils.createText( dnValueGroup, "", 1 );
+ dnText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ initDialog();
+ addListeners();
+
+ applyDialogFont( composite );
+
+ return composite;
+ }
+
+
+ /**
+ * Initializes the UI from the String
+ */
+ protected void initDialog()
+ {
+ DnWrapper editedElement = (DnWrapper)getEditedElement();
+
+ if ( editedElement != null )
+ {
+ Dn dn = editedElement.getDn();
+
+ if ( dn == null )
+ {
+ dnText.setText( "" );
+ }
+ else
+ {
+ dnText.setText( dn.toString() );
+ }
+ }
+ }
+
+
+ /**
+ * Add a new Element that will be edited
+ */
+ public void addNewElement()
+ {
+ setEditedElement( new DnWrapper( Dn.EMPTY_DN ) );
+ }
+
+
+ public void addNewElement( DnWrapper editedElement )
+ {
+ // No need to clone, the Dn is immutable
+ setEditedElement( editedElement );
+ }
+
+
+ /**
+ * Adds listeners.
+ */
+ private void addListeners()
+ {
+ dnText.addModifyListener( dnValueTextListener );
+ }
+}
Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnDecorator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnDecorator.java?rev=1690182&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnDecorator.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnDecorator.java Thu Jul 9 22:35:42 2015
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.openldap.config.editor.wrappers;
+
+import org.apache.directory.studio.common.ui.TableDecorator;
+import org.apache.directory.studio.openldap.common.ui.model.DisallowFeatureEnum;
+import org.apache.directory.studio.openldap.config.editor.dialogs.DnValueDialog;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * A decorator for the Dn table.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DnDecorator extends TableDecorator<DnWrapper>
+{
+ /**
+ * Create a new instance of DnDecorator
+ * @param parentShell The parent Shell
+ */
+ public DnDecorator( Shell parentShell )
+ {
+ setDialog( new DnValueDialog( parentShell ) );
+ }
+
+ /**
+ * Construct the label for an DisallowFeature.
+ *
+ */
+ public String getText( Object element )
+ {
+ if ( element instanceof DisallowFeatureEnum )
+ {
+ String disallowFeature = ( ( DisallowFeatureEnum ) element ).toString();
+
+ return disallowFeature;
+ }
+
+ return super.getText( element );
+ };
+
+
+ /**
+ * Get the image. We have none
+ *
+ * {@inheritDoc}
+ */
+ public Image getImage( Object element )
+ {
+ return null;
+ };
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compare( DnWrapper e1, DnWrapper e2 )
+ {
+ if ( e1 != null )
+ {
+ if ( e2 == null )
+ {
+ return 1;
+ }
+ else
+ {
+ return e1.compareTo( e2 );
+ }
+ }
+ else
+ {
+ if ( e2 == null )
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ }
+}
Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnWrapper.java?rev=1690182&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnWrapper.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/DnWrapper.java Thu Jul 9 22:35:42 2015
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.openldap.config.editor.wrappers;
+
+
+import org.apache.directory.api.ldap.model.name.Dn;
+
+/**
+ * A wrapper for DNs.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DnWrapper implements Cloneable, Comparable<DnWrapper>
+{
+ /** The interned DN */
+ private Dn dn;
+
+ /**
+ * Build a DnWrapper from a String containing the DN
+ *
+ * @param dn The DN to store
+ */
+ public DnWrapper( Dn dn )
+ {
+ this.dn = dn;
+ }
+
+
+ /**
+ * @return the dn
+ */
+ public Dn getDn()
+ {
+ return dn;
+ }
+
+
+ /**
+ * @param dn the dn to set
+ */
+ public void setDn( Dn dn )
+ {
+ this.dn = dn;
+ }
+
+
+ /**
+ * @see Object#clone()
+ */
+ public DnWrapper clone()
+ {
+ // No need to clone, DN is immutable
+ return this;
+ }
+
+
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return dn.hashCode();
+ }
+
+
+ /**
+ * @see Object#equals()
+ */
+ public boolean equals( Object that )
+ {
+ if ( that == this )
+ {
+ return true;
+ }
+
+ if ( ! ( that instanceof DnWrapper ) )
+ {
+ return false;
+ }
+
+ return compareTo( (DnWrapper)that ) == 0;
+ }
+
+
+ /**
+ * @see Comparable#compareTo()
+ */
+ public int compareTo( DnWrapper that )
+ {
+ if ( that == null )
+ {
+ return 1;
+ }
+
+ if ( dn.equals( that.dn ) )
+ {
+ return 0;
+ }
+
+ if ( dn.isDescendantOf( that.dn ) )
+ {
+ return 1;
+ }
+ else if ( that.dn.isDescendantOf( dn ) )
+ {
+ return -1;
+ }
+ else
+ {
+ // Find the common ancestor, if any
+ int upperBound = Math.min( dn.size(), that.dn.size() );
+ int result = 0;
+
+ for ( int i = 0; i < upperBound; i++ )
+ {
+ result = dn.getRdn( i ).compareTo( that.dn.getRdn( i ) );
+
+ if ( result != 0 )
+ {
+ return result;
+ }
+ }
+ // We have exhausted one of the DN
+ if ( dn.size() > upperBound )
+ {
+ return 1;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ return dn.toString();
+ }
+}