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/03/24 20:24:45 UTC
svn commit: r1668963 [2/4] - in /directory/studio/trunk/plugins: ./
openldap.common.ui/ openldap.common.ui/.settings/
openldap.common.ui/META-INF/ openldap.common.ui/src/
openldap.common.ui/src/main/ openldap.common.ui/src/main/java/
openldap.common.ui...
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsDialog.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsDialog.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/dialogs/UnixPermissionsDialog.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,414 @@
+/*
+ * 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.common.ui.dialogs;
+
+
+import java.text.ParseException;
+
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.eclipse.jface.dialogs.Dialog;
+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.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+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.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * The UnixPermissionsDialog is used to edit a Unix Permissions value. Unix
+ * permissions are stored using 3 sets of permissions for 3 different entities :
+ *
+ * <ul>
+ * <li>users</li>
+ * <li>group</li>
+ * <li>other</li>
+ * </ul>
+ *
+ * with the following permissions :
+ *
+ * <ul>
+ * <li>read</li>
+ * <li>write</li>
+ * <li>execute</li>
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UnixPermissionsDialog extends Dialog
+{
+ /** The octal value */
+ private String value;
+
+ // UI widgets
+ private Button ownerReadCheckbox;
+ private Button ownerWriteCheckbox;
+ private Button ownerExecuteCheckbox;
+ private Button groupReadCheckbox;
+ private Button groupWriteCheckbox;
+ private Button groupExecuteCheckbox;
+ private Button othersReadCheckbox;
+ private Button othersWriteCheckbox;
+ private Button othersExecuteCheckbox;
+ private Text octalNotationText;
+
+ // The octal verifier only accepts values between 0 and 7.
+ private VerifyListener octalNotationTextVerifyListener = new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-7]*" ) ) //$NON-NLS-1$
+ {
+ e.doit = false;
+ }
+ }
+ };
+
+
+ private ModifyListener octalNotationTextModifyListener = new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ resetChecboxSelection();
+
+ try
+ {
+ UnixPermissions perm = new UnixPermissions( octalNotationText.getText() );
+
+ removeListeners();
+ setCheckboxesValue( perm );
+ addListeners();
+ }
+ catch ( ParseException e1 )
+ {
+ // Nothing to do
+ }
+ }
+ };
+
+
+ private SelectionListener checkboxSelectionListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ UnixPermissions perm = new UnixPermissions();
+
+ perm.setOwnerRead( ownerReadCheckbox.getSelection() );
+ perm.setOwnerWrite( ownerWriteCheckbox.getSelection() );
+ perm.setOwnerExecute( ownerExecuteCheckbox.getSelection() );
+ perm.setGroupRead( groupReadCheckbox.getSelection() );
+ perm.setGroupWrite( groupWriteCheckbox.getSelection() );
+ perm.setGroupExecute( groupExecuteCheckbox.getSelection() );
+ perm.setOthersRead( othersReadCheckbox.getSelection() );
+ perm.setOthersWrite( othersWriteCheckbox.getSelection() );
+ perm.setOthersExecute( othersExecuteCheckbox.getSelection() );
+
+ removeListeners();
+ setOctalValue( perm );
+ addListeners();
+ }
+ };
+
+
+ /**
+ * Creates a new instance of UnixPermissionsDialog.
+ *
+ * @param parentShell the parent shell
+ */
+ public UnixPermissionsDialog( Shell parentShell )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ }
+
+
+ /**
+ * Creates a new instance of UnixPermissionsDialog.
+ *
+ * @param parentShell the parent shell
+ * @param value the initial value
+ */
+ public UnixPermissionsDialog( Shell parentShell, String value )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ this.value = value;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( "Unix Permissions Dialog" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void okPressed()
+ {
+ try
+ {
+ UnixPermissions perm = new UnixPermissions( octalNotationText.getText() );
+ value = perm.getOctalValue();
+ }
+ catch ( ParseException e )
+ {
+ value = "0000";
+ }
+
+ super.okPressed();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ composite.setLayoutData( gd );
+
+ createPermissionsArea( composite );
+ createOctalNotationArea( composite );
+
+ initialize();
+
+ addListeners();
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ /**
+ * Initializes the dialog with the initial value
+ */
+ private void initialize()
+ {
+ if ( value != null )
+ {
+ try
+ {
+ UnixPermissions perm = new UnixPermissions( value );
+
+ setCheckboxesValue( perm );
+ setOctalValue( perm );
+ }
+ catch ( ParseException e )
+ {
+ resetChecboxSelection();
+ setOctalValue( new UnixPermissions() );
+ }
+ }
+ else
+ {
+ resetChecboxSelection();
+ setOctalValue( new UnixPermissions() );
+ }
+ }
+
+
+ /**
+ * Sets the checkboxes value.
+ *
+ * @param perm the Unix permissions
+ */
+ private void setCheckboxesValue( UnixPermissions perm )
+ {
+ ownerReadCheckbox.setSelection( perm.isOwnerRead() );
+ ownerWriteCheckbox.setSelection( perm.isOwnerWrite() );
+ ownerExecuteCheckbox.setSelection( perm.isOwnerExecute() );
+ groupReadCheckbox.setSelection( perm.isGroupRead() );
+ groupWriteCheckbox.setSelection( perm.isGroupWrite() );
+ groupExecuteCheckbox.setSelection( perm.isGroupExecute() );
+ othersReadCheckbox.setSelection( perm.isOthersRead() );
+ othersWriteCheckbox.setSelection( perm.isOthersWrite() );
+ othersExecuteCheckbox.setSelection( perm.isOthersExecute() );
+ }
+
+
+ /**
+ * Sets the octal value.
+ *
+ * @param perm the Unix permissions
+ */
+ private void setOctalValue( UnixPermissions perm )
+ {
+ octalNotationText.setText( perm.getOctalValue() );
+ }
+
+
+ /**
+ * Resets the checkbox selection
+ */
+ private void resetChecboxSelection()
+ {
+ ownerReadCheckbox.setSelection( false );
+ ownerWriteCheckbox.setSelection( false );
+ ownerExecuteCheckbox.setSelection( false );
+ groupReadCheckbox.setSelection( false );
+ groupWriteCheckbox.setSelection( false );
+ groupExecuteCheckbox.setSelection( false );
+ othersReadCheckbox.setSelection( false );
+ othersWriteCheckbox.setSelection( false );
+ othersExecuteCheckbox.setSelection( false );
+ }
+
+
+ /**
+ * Creates the permissions area.
+ *
+ * @param parent the parent composite
+ */
+ private void createPermissionsArea( Composite parent )
+ {
+ Group symbolicNotationGroup = BaseWidgetUtils.createGroup( parent, "Permissions", 1 );
+ symbolicNotationGroup.setLayout( new GridLayout( 2, false ) );
+
+ BaseWidgetUtils.createLabel( symbolicNotationGroup, "Owner:", 1 );
+ Composite ownerComposite = BaseWidgetUtils.createColumnContainer( symbolicNotationGroup, 3, true, 1 );
+ ownerReadCheckbox = BaseWidgetUtils.createCheckbox( ownerComposite, "Read", 1 );
+ ownerWriteCheckbox = BaseWidgetUtils.createCheckbox( ownerComposite, "Write", 1 );
+ ownerExecuteCheckbox = BaseWidgetUtils.createCheckbox( ownerComposite, "Execute", 1 );
+
+ BaseWidgetUtils.createLabel( symbolicNotationGroup, "Group:", 1 );
+ Composite groupComposite = BaseWidgetUtils.createColumnContainer( symbolicNotationGroup, 3, true, 1 );
+ groupReadCheckbox = BaseWidgetUtils.createCheckbox( groupComposite, "Read", 1 );
+ groupWriteCheckbox = BaseWidgetUtils.createCheckbox( groupComposite, "Write", 1 );
+ groupExecuteCheckbox = BaseWidgetUtils.createCheckbox( groupComposite, "Execute", 1 );
+
+ BaseWidgetUtils.createLabel( symbolicNotationGroup, "Others:", 1 );
+ Composite othersComposite = BaseWidgetUtils.createColumnContainer( symbolicNotationGroup, 3, true, 1 );
+ othersReadCheckbox = BaseWidgetUtils.createCheckbox( othersComposite, "Read", 1 );
+ othersWriteCheckbox = BaseWidgetUtils.createCheckbox( othersComposite, "Write", 1 );
+ othersExecuteCheckbox = BaseWidgetUtils.createCheckbox( othersComposite, "Execute", 1 );
+ }
+
+
+ /**
+ * Creates the octal notation area.
+ *
+ * @param parent the parent composite
+ */
+ private void createOctalNotationArea( Composite parent )
+ {
+ Group octalNotationGroup = BaseWidgetUtils.createGroup( parent, "Octal Notation", 1 );
+ octalNotationText = BaseWidgetUtils.createText( octalNotationGroup, "0000", 1 );
+ octalNotationText.setTextLimit( 4 );
+ }
+
+
+ /**
+ * Adds listeners.
+ */
+ private void addListeners()
+ {
+ ownerReadCheckbox.addSelectionListener( checkboxSelectionListener );
+ ownerWriteCheckbox.addSelectionListener( checkboxSelectionListener );
+ ownerExecuteCheckbox.addSelectionListener( checkboxSelectionListener );
+ groupReadCheckbox.addSelectionListener( checkboxSelectionListener );
+ groupWriteCheckbox.addSelectionListener( checkboxSelectionListener );
+ groupExecuteCheckbox.addSelectionListener( checkboxSelectionListener );
+ othersReadCheckbox.addSelectionListener( checkboxSelectionListener );
+ othersWriteCheckbox.addSelectionListener( checkboxSelectionListener );
+ othersExecuteCheckbox.addSelectionListener( checkboxSelectionListener );
+ octalNotationText.addVerifyListener( octalNotationTextVerifyListener );
+ octalNotationText.addModifyListener( octalNotationTextModifyListener );
+ }
+
+
+ /**
+ * Remove listeners.
+ */
+ private void removeListeners()
+ {
+ ownerReadCheckbox.removeSelectionListener( checkboxSelectionListener );
+ ownerWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
+ ownerExecuteCheckbox.removeSelectionListener( checkboxSelectionListener );
+ groupReadCheckbox.removeSelectionListener( checkboxSelectionListener );
+ groupWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
+ groupExecuteCheckbox.removeSelectionListener( checkboxSelectionListener );
+ othersReadCheckbox.removeSelectionListener( checkboxSelectionListener );
+ othersWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
+ othersExecuteCheckbox.removeSelectionListener( checkboxSelectionListener );
+ octalNotationText.removeVerifyListener( octalNotationTextVerifyListener );
+ octalNotationText.removeModifyListener( octalNotationTextModifyListener );
+ }
+
+
+ /**
+ * Gets the symbolic value (no type included).
+ *
+ * @return the symbolic value
+ */
+ public String getSymbolicValue()
+ {
+
+ UnixPermissions perm = null;
+ try
+ {
+ perm = new UnixPermissions( value );
+ }
+ catch ( ParseException e )
+ {
+ perm = new UnixPermissions();
+ }
+
+ return perm.getSymbolicValue();
+ }
+
+
+ /**
+ * Gets the octal value.
+ *
+ * @return the octal value
+ */
+ public String getOctalValue()
+ {
+ return value;
+ }
+
+
+ /**
+ * Gets the decimal value.
+ *
+ * @return the decimal value
+ */
+ public String getDecimalValue()
+ {
+ return "" + Integer.parseInt( value, 8 );
+ }
+}
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages.properties?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages.properties (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages.properties Tue Mar 24 19:24:44 2015
@@ -0,0 +1,18 @@
+# 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.
+
+OpenLdapCommonUiPlugin.UnableGetPluginProperties=Unable to get the plugin properties.
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_de.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_de.properties?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_de.properties (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_de.properties Tue Mar 24 19:24:44 2015
@@ -0,0 +1,18 @@
+# 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.
+
+OpenLdapCommonUiPlugin.UnableGetPluginProperties=Plugin Eigenschaften k\u00F6nnen nicht gefunden werden.
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_fr.properties
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_fr.properties?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_fr.properties (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/messages_fr.properties Tue Mar 24 19:24:44 2015
@@ -0,0 +1,18 @@
+# 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.
+
+OpenLdapCommonUiPlugin.UnableGetPluginProperties=Impossible de r\u00E9cup\u00E9rer les propri\u00E9t\u00E9s du plugin
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/BooleanWithDefaultWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/BooleanWithDefaultWidget.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/BooleanWithDefaultWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/BooleanWithDefaultWidget.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,259 @@
+/*
+ * 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.common.ui.widgets;
+
+
+import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+
+public class BooleanWithDefaultWidget extends BrowserWidget
+{
+ /** The combo viewer's values */
+ private Object[] comboViewerValues = new Object[]
+ {
+ BooleanValue.DEFAULT,
+ BooleanValue.TRUE,
+ BooleanValue.FALSE
+ };
+
+ // The default value
+ private Boolean defaultValue;
+
+ // The value
+ private Boolean value;
+
+ // UI widgets
+ private ComboViewer comboViewer;
+
+
+ /**
+ * Creates a new instance of BooleanWithDefaultWidget.
+ */
+ public BooleanWithDefaultWidget()
+ {
+ }
+
+
+ /**
+ * Creates a new instance of BooleanWithDefaultWidget.
+ *
+ * @param defaultValue the default value
+ */
+ public BooleanWithDefaultWidget( boolean defaultValue )
+ {
+ this.defaultValue = defaultValue;
+ }
+
+
+ /**
+ * Creates a new instance of BooleanWithDefaultWidget.
+ *
+ * @param defaultValue the default value
+ */
+ public BooleanWithDefaultWidget( Boolean defaultValue )
+ {
+ this.defaultValue = defaultValue;
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent composite
+ */
+ public void create( Composite parent )
+ {
+ create( parent, null );
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent composite
+ */
+ public void create( Composite parent, FormToolkit toolkit )
+ {
+ comboViewer = new ComboViewer( parent );
+ comboViewer.setContentProvider( new ArrayContentProvider() );
+ comboViewer.setLabelProvider( new LabelProvider()
+ {
+ public String getText( Object element )
+ {
+ if ( element instanceof BooleanValue )
+ {
+ BooleanValue booleanValue = ( BooleanValue ) element;
+
+ switch ( booleanValue )
+ {
+ case DEFAULT:
+ if ( defaultValue != null )
+ {
+ if ( defaultValue.booleanValue() )
+ {
+ return NLS.bind( "Default value ({0})", "true" );
+ }
+ else
+ {
+ return NLS.bind( "Default value ({0})", "false" );
+ }
+ }
+ else
+ {
+ return "Default value";
+ }
+ case TRUE:
+ return "True";
+ case FALSE:
+ return "False";
+ }
+ }
+
+ return super.getText( element );
+ }
+ } );
+ comboViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ value = null;
+
+ StructuredSelection selection = ( StructuredSelection ) comboViewer.getSelection();
+
+ if ( !selection.isEmpty() )
+ {
+ BooleanValue booleanValue = ( BooleanValue ) selection.getFirstElement();
+
+ switch ( booleanValue )
+ {
+ case DEFAULT:
+ value = null;
+ break;
+ case TRUE:
+ value = new Boolean( true );
+ break;
+ case FALSE:
+ value = new Boolean( false );
+ break;
+ }
+ }
+
+ notifyListeners();
+ }
+ } );
+ comboViewer.setInput( comboViewerValues );
+ comboViewer.setSelection( new StructuredSelection( comboViewerValues[0] ) );
+ }
+
+
+ /**
+ * Returns the primary control associated with this widget.
+ *
+ * @return the primary control associated with this widget.
+ */
+ public Control getControl()
+ {
+ return comboViewer.getControl();
+ }
+
+
+ /**
+ * Sets the value.
+ *
+ * @param s the value
+ */
+ public void setValue( Boolean value )
+ {
+ this.value = value;
+
+ if ( value != null )
+ {
+ if ( value.booleanValue() )
+ {
+ comboViewer.setSelection( new StructuredSelection( comboViewerValues[1] ) );
+ }
+ else
+ {
+ comboViewer.setSelection( new StructuredSelection( comboViewerValues[2] ) );
+ }
+ }
+ else
+ {
+ comboViewer.setSelection( new StructuredSelection( comboViewerValues[0] ) );
+ }
+ }
+
+
+ /**
+ * Gets the value.
+ *
+ * @return the value
+ */
+ public Boolean getValue()
+ {
+ return value;
+ }
+
+
+ /**
+ * Disposes all created SWT widgets.
+ */
+ public void dispose()
+ {
+ if ( ( comboViewer != null ) && ( comboViewer.getControl() != null )
+ && ( !comboViewer.getControl().isDisposed() ) )
+ {
+ comboViewer.getControl().dispose();
+ }
+ }
+
+
+ /**
+ * Sets the enabled state of the widget.
+ *
+ * @param enabled true to enable the widget, false to disable the widget
+ */
+ public void setEnabled( boolean enabled )
+ {
+ if ( ( comboViewer != null ) && ( comboViewer.getControl() != null )
+ && ( !comboViewer.getControl().isDisposed() ) )
+ {
+ comboViewer.getControl().setEnabled( enabled );
+ }
+ }
+
+ /**
+ * This enum represents the various values available.
+ */
+ enum BooleanValue
+ {
+ DEFAULT, TRUE, FALSE
+ }
+}
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/DirectoryBrowserWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/DirectoryBrowserWidget.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/DirectoryBrowserWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/DirectoryBrowserWidget.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,235 @@
+/*
+ * 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.common.ui.widgets;
+
+
+import java.io.File;
+
+import org.apache.directory.studio.common.ui.HistoryUtils;
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget;
+import org.apache.directory.studio.ldapbrowser.common.widgets.Messages;
+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.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+import org.apache.directory.studio.openldap.common.ui.OpenLdapCommonUiConstants;
+import org.apache.directory.studio.openldap.common.ui.OpenLdapCommonUiPlugin;
+
+
+/**
+ * The DirectoryBrowserWidget provides a combo with a history of recently
+ * used directory and a browse button to open the directory browser.
+ */
+public class DirectoryBrowserWidget extends BrowserWidget
+{
+ /** The combo with the history of recently used directories */
+ protected Combo directoryCombo;
+
+ /** The button to launch the file browser */
+ protected Button browseButton;
+
+ /** The title */
+ protected String title;
+
+
+ /**
+ * Creates a new instance of DirectoryBrowserWidget.
+ *
+ * @param title The title
+ */
+ public DirectoryBrowserWidget( String title )
+ {
+ this.title = title;
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent
+ */
+ public void createWidget( Composite parent )
+ {
+ createWidget( parent, null );
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent
+ * @param toolkit the toolkit
+ */
+ public void createWidget( Composite parent, FormToolkit toolkit )
+ {
+ // Combo
+ directoryCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+ if ( toolkit != null )
+ {
+ toolkit.adapt( directoryCombo );
+ }
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.widthHint = 50;
+ directoryCombo.setLayoutData( gd );
+ directoryCombo.setVisibleItemCount( 20 );
+ directoryCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ notifyListeners();
+ }
+ } );
+
+ // Button
+ if ( toolkit != null )
+ {
+ browseButton = toolkit.createButton( parent,
+ Messages.getString( "FileBrowserWidget.BrowseButton" ), SWT.PUSH ); //$NON-NLS-1$
+ }
+ else
+ {
+ browseButton = BaseWidgetUtils.createButton( parent,
+ Messages.getString( "FileBrowserWidget.BrowseButton" ), 1 ); //$NON-NLS-1$
+ }
+ browseButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent event )
+ {
+ DirectoryDialog directoryDialog = new DirectoryDialog( browseButton.getShell() );
+ directoryDialog.setText( title );
+
+ File file = new File( directoryCombo.getText() );
+ if ( file.isFile() )
+ {
+ directoryDialog.setFilterPath( file.getParent() );
+ }
+ else if ( file.isDirectory() )
+ {
+ directoryDialog.setFilterPath( file.getPath() );
+ }
+ else
+ {
+ directoryDialog.setFilterPath( BrowserCommonActivator.getDefault().getDialogSettings().get(
+ BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH ) );
+ }
+
+ String returnedFileName = directoryDialog.open();
+ if ( returnedFileName != null )
+ {
+ directoryCombo.setText( returnedFileName );
+ File file2 = new File( returnedFileName );
+ BrowserCommonActivator.getDefault().getDialogSettings().put(
+ BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH, file2.getParent() );
+ }
+ }
+ } );
+
+ loadDialogSettings();
+ }
+
+
+ /**
+ * Gets the directory path.
+ *
+ * @return the directory path or <code>null</code>
+ */
+ public String getDirectoryPath()
+ {
+ String directoryPath = directoryCombo.getText();
+
+ if ( ( directoryPath != null ) && ( !"".equals( directoryPath ) ) )
+ {
+ return directoryPath;
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Sets the directory path.
+ *
+ * @param directoryPath the directory path
+ */
+ public void setDirectoryPath( String directoryPath )
+ {
+ if ( directoryPath == null )
+ {
+ directoryCombo.setText( "" );
+ }
+ else
+ {
+ directoryCombo.setText( directoryPath );
+ }
+ }
+
+
+ /**
+ * Saves dialog settings.
+ */
+ public void loadDialogSettings()
+ {
+ String[] history = HistoryUtils.load( OpenLdapCommonUiPlugin.getDefault().getDialogSettings(),
+ OpenLdapCommonUiConstants.DIALOGSETTING_KEY_DIRECTORY_HISTORY );
+ directoryCombo.setItems( history );
+ }
+
+
+ /**
+ * Saves dialog settings.
+ */
+ public void saveDialogSettings()
+ {
+ HistoryUtils.save( OpenLdapCommonUiPlugin.getDefault().getDialogSettings(),
+ OpenLdapCommonUiConstants.DIALOGSETTING_KEY_DIRECTORY_HISTORY, directoryCombo.getText() );
+ }
+
+
+ /**
+ * Sets the focus.
+ */
+ public void setFocus()
+ {
+ directoryCombo.setFocus();
+ }
+
+
+ /**
+ * Enables or disables the widget.
+ *
+ * @param b true to enable the widget, false otherwise
+ */
+ public void setEnabled( boolean b )
+ {
+ directoryCombo.setEnabled( b );
+ browseButton.setEnabled( b );
+ }
+}
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/EntryWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/EntryWidget.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/EntryWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/EntryWidget.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,466 @@
+/*
+ * 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.common.ui.widgets;
+
+
+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.HistoryUtils;
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.connection.ui.RunnableContextRunner;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.dialogs.SelectEntryDialog;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget;
+import org.apache.directory.studio.ldapbrowser.common.widgets.search.Messages;
+import org.apache.directory.studio.ldapbrowser.core.jobs.ReadEntryRunnable;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
+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.ui.forms.widgets.FormToolkit;
+
+
+/**
+ * The EntryWidget could be used to select an entry.
+ * It is composed
+ * <ul>
+ * <li>a combo to manually enter an Dn or to choose one from
+ * the history
+ * <li>an up button to switch to the parent's Dn
+ * <li>a browse button to open a {@link SelectEntryDialog}
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryWidget extends BrowserWidget
+{
+ /** The connection. */
+ private IBrowserConnection browserConnection;
+
+ /** The flag to show the "None" checkbox or not */
+ private boolean showNoneCheckbox;
+
+ /** The selected Dn. */
+ private Dn dn;
+
+ /** The enabled state */
+ private boolean enabled = true;
+
+ // UI widgets
+ private Composite composite;
+ private Button noneCheckbox;
+ private Combo dnCombo;
+ private Button entryBrowseButton;
+
+ // Listeners
+ private SelectionAdapter noneCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ noneCheckboxSelected( noneCheckbox.getSelection() );
+ notifyListeners();
+ }
+ };
+ private ModifyListener dnComboListener = new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ try
+ {
+ dn = new Dn( dnCombo.getText() );
+ }
+ catch ( LdapInvalidDnException e1 )
+ {
+ dn = null;
+ }
+
+ internalSetEnabled();
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter entryBrowseButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ if ( browserConnection != null )
+ {
+ // get root entry
+ IEntry rootEntry = browserConnection.getRootDSE();
+
+ // get initial entry
+ IEntry entry = rootEntry;
+ if ( dn != null && dn.size() > 0 )
+ {
+ entry = browserConnection.getEntryFromCache( dn );
+ if ( entry == null )
+ {
+ ReadEntryRunnable runnable = new ReadEntryRunnable( browserConnection, dn );
+ RunnableContextRunner.execute( runnable, null, true );
+ entry = runnable.getReadEntry();
+ }
+ }
+
+ // open dialog
+ SelectEntryDialog dialog = new SelectEntryDialog( entryBrowseButton.getShell(), Messages
+ .getString( "EntryWidget.SelectDN" ), rootEntry, entry ); //$NON-NLS-1$
+ dialog.open();
+ IEntry selectedEntry = dialog.getSelectedEntry();
+
+ // get selected Dn
+ if ( selectedEntry != null )
+ {
+ dn = selectedEntry.getDn();
+ dnChanged();
+ internalSetEnabled();
+ notifyListeners();
+ }
+ }
+ }
+ };
+
+
+ /**
+ * Creates a new instance of EntryWidget.
+ */
+ public EntryWidget()
+ {
+ this.browserConnection = null;
+ this.dn = null;
+ }
+
+
+ /**
+ * Creates a new instance of EntryWidget.
+ *
+ * @param browserConnection the connection
+ */
+ public EntryWidget( IBrowserConnection browserConnection )
+ {
+ this.browserConnection = browserConnection;
+ }
+
+
+ /**
+ * Creates a new instance of EntryWidget.
+ *
+ * @param browserConnection the connection
+ * @param dn the initial Dn
+ */
+ public EntryWidget( IBrowserConnection browserConnection, Dn dn )
+ {
+ this.browserConnection = browserConnection;
+ this.dn = dn;
+ }
+
+
+ /**
+ * Creates a new instance of EntryWidget.
+ *
+ * @param browserConnection the connection
+ * @param dn the initial Dn
+ * @param showNoneButton the flag to show the "None" checkbox
+ */
+ public EntryWidget( IBrowserConnection browserConnection, Dn dn, boolean showNoneCheckbox )
+ {
+ this.browserConnection = browserConnection;
+ this.dn = dn;
+ this.showNoneCheckbox = showNoneCheckbox;
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent
+ */
+ public void createWidget( Composite parent )
+ {
+ createWidget( parent, null );
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent
+ * @param toolkit the toolkit
+ */
+ public void createWidget( Composite parent, FormToolkit toolkit )
+ {
+ // Composite
+ if ( toolkit != null )
+ {
+ composite = toolkit.createComposite( parent );
+ }
+ else
+ {
+ composite = new Composite( parent, SWT.NONE );
+ }
+ GridLayout compositeGridLayout = new GridLayout( getNumberOfColumnsForComposite(), false );
+ compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
+ compositeGridLayout.verticalSpacing = 0;
+ composite.setLayout( compositeGridLayout );
+
+ // None Checbox
+ if ( showNoneCheckbox )
+ {
+ if ( toolkit != null )
+ {
+ noneCheckbox = toolkit.createButton( composite, "None", SWT.CHECK );
+ }
+ else
+ {
+ noneCheckbox = BaseWidgetUtils.createCheckbox( composite, "None", 1 );
+ }
+ }
+
+ // Dn combo
+ dnCombo = BaseWidgetUtils.createCombo( composite, new String[0], -1, 1 );
+ if ( toolkit != null )
+ {
+ toolkit.adapt( dnCombo );
+ }
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = 1;
+ gd.widthHint = 50;
+ dnCombo.setLayoutData( gd );
+
+ // Dn history
+ String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(),
+ BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY );
+ dnCombo.setItems( history );
+
+ // Browse button
+ if ( toolkit != null )
+ {
+ entryBrowseButton = toolkit.createButton( composite,
+ Messages.getString( "EntryWidget.BrowseButton" ), SWT.PUSH ); //$NON-NLS-1$
+ }
+ else
+ {
+ entryBrowseButton = BaseWidgetUtils.createButton( composite,
+ Messages.getString( "EntryWidget.BrowseButton" ), 1 ); //$NON-NLS-1$
+
+ }
+
+ dnChanged();
+ internalSetEnabled();
+ addListeners();
+ }
+
+
+ /**
+ * Adds the listeners
+ */
+ private void addListeners()
+ {
+ if ( showNoneCheckbox )
+ {
+ noneCheckbox.addSelectionListener( noneCheckboxListener );
+ }
+
+ dnCombo.addModifyListener( dnComboListener );
+ entryBrowseButton.addSelectionListener( entryBrowseButtonListener );
+ }
+
+
+ /**
+ * Removes the listeners
+ */
+ private void removeListeners()
+ {
+ if ( showNoneCheckbox )
+ {
+ noneCheckbox.removeSelectionListener( noneCheckboxListener );
+ }
+
+ dnCombo.removeModifyListener( dnComboListener );
+ entryBrowseButton.removeSelectionListener( entryBrowseButtonListener );
+ }
+
+
+ /**
+ * Gets the number of columns for the composite.
+ *
+ * @return the number of columns for the composite
+ */
+ private int getNumberOfColumnsForComposite()
+ {
+ if ( showNoneCheckbox )
+ {
+ return 3;
+ }
+ else
+ {
+ return 2;
+ }
+ }
+
+
+ /**
+ * Notifies that the Dn has been changed.
+ */
+ private void dnChanged()
+ {
+ if ( dnCombo != null && entryBrowseButton != null )
+ {
+ if ( showNoneCheckbox )
+ {
+ boolean noneSelected = ( dn == null );
+ noneCheckbox.setSelection( noneSelected );
+ noneCheckboxSelected( noneSelected );
+ }
+
+ dnCombo.setText( dn != null ? dn.getName() : "" ); //$NON-NLS-1$
+ }
+ }
+
+
+ /**
+ * This method is called when the "None" checkbox is clicked.
+ */
+ private void noneCheckboxSelected( boolean state )
+ {
+ dnCombo.setEnabled( !state );
+ entryBrowseButton.setEnabled( !state );
+ }
+
+
+ /**
+ * Sets the enabled state of the widget.
+ *
+ * @param b true to enable the widget, false to disable the widget
+ */
+ public void setEnabled( boolean enabled )
+ {
+ this.enabled = enabled;
+
+ if ( enabled )
+ {
+ this.dnChanged();
+ }
+
+ internalSetEnabled();
+ }
+
+
+ /**
+ * Internal set enabled.
+ */
+ private void internalSetEnabled()
+ {
+ if ( showNoneCheckbox )
+ {
+ noneCheckbox.setEnabled( enabled );
+
+ if ( dn == null )
+ {
+ dnCombo.setEnabled( false );
+ entryBrowseButton.setEnabled( false );
+ }
+ else
+ {
+ dnCombo.setEnabled( enabled );
+ entryBrowseButton.setEnabled( ( browserConnection != null ) && enabled );
+ }
+ }
+ else
+ {
+ dnCombo.setEnabled( enabled );
+ entryBrowseButton.setEnabled( ( browserConnection != null ) && enabled );
+ }
+ }
+
+
+ /**
+ * Saves dialog settings.
+ */
+ public void saveDialogSettings()
+ {
+ HistoryUtils.save( BrowserCommonActivator.getDefault().getDialogSettings(),
+ BrowserCommonConstants.DIALOGSETTING_KEY_DN_HISTORY, this.dnCombo.getText() );
+ }
+
+
+ /**
+ * Gets the Dn or <code>null</code> if the Dn isn't valid.
+ *
+ * @return the Dn or <code>null</code> if the Dn isn't valid
+ */
+ public Dn getDn()
+ {
+ if ( showNoneCheckbox && noneCheckbox.getSelection() )
+ {
+ return null;
+ }
+
+ return dn;
+ }
+
+
+ /**
+ * Gets the browser connection.
+ *
+ * @return the browser connection
+ */
+ public IBrowserConnection getBrowserConnection()
+ {
+ return browserConnection;
+ }
+
+
+ /**
+ * Sets the input.
+ *
+ * @param dn the Dn
+ */
+ public void setInput( Dn dn )
+ {
+ if ( this.dn != dn )
+ {
+ this.dn = dn;
+ removeListeners();
+ dnChanged();
+ addListeners();
+ }
+ }
+
+
+ /**
+ * Returns the primary control associated with this widget.
+ *
+ * @return the primary control associated with this widget.
+ */
+ public Control getControl()
+ {
+ return composite;
+ }
+}
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/FileBrowserWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/FileBrowserWidget.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/FileBrowserWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/FileBrowserWidget.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,171 @@
+/*
+ * 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.common.ui.widgets;
+
+
+import java.io.File;
+
+import org.apache.directory.studio.common.ui.HistoryUtils;
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
+import org.apache.directory.studio.ldapbrowser.common.widgets.Messages;
+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.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+
+/**
+ * The DirectoryBrowserWidget provides a combo with a history of recently
+ * used directory and a browse button to open the directory browser.
+ */
+public class FileBrowserWidget extends org.apache.directory.studio.ldapbrowser.common.widgets.FileBrowserWidget
+{
+ /**
+ * Creates a new instance of FileBrowserWidget.
+ *
+ * @param title The title
+ * @param extensions The valid file extensions
+ * @param type The type, one of {@link #TYPE_OPEN} or {@link #TYPE_SAVE}
+ */
+ public FileBrowserWidget( String title, String[] extensions, int type )
+ {
+ super( title, extensions, type );
+ }
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent
+ * @param toolkit the toolkit
+ */
+ public void createWidget( Composite parent, FormToolkit toolkit )
+ {
+ // Combo
+ fileCombo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+ if ( toolkit != null )
+ {
+ toolkit.adapt( fileCombo );
+ }
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.widthHint = 50;
+ fileCombo.setLayoutData( gd );
+ fileCombo.setVisibleItemCount( 20 );
+ fileCombo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ notifyListeners();
+ }
+ } );
+
+ // Button
+ if ( toolkit != null )
+ {
+ browseButton = toolkit.createButton( parent,
+ Messages.getString( "FileBrowserWidget.BrowseButton" ), SWT.PUSH ); //$NON-NLS-1$
+ }
+ else
+ {
+ browseButton = BaseWidgetUtils.createButton( parent,
+ Messages.getString( "FileBrowserWidget.BrowseButton" ), 1 ); //$NON-NLS-1$
+ }
+ browseButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent event )
+ {
+ FileDialog fileDialog = new FileDialog( browseButton.getShell(), type );
+ fileDialog.setText( title );
+
+ fileDialog.setFilterExtensions( extensions );
+
+ File file = new File( fileCombo.getText() );
+ if ( file.isFile() )
+ {
+ fileDialog.setFilterPath( file.getParent() );
+ fileDialog.setFileName( file.getName() );
+ }
+ else if ( file.isDirectory() )
+ {
+ fileDialog.setFilterPath( file.getPath() );
+ }
+ else
+ {
+ fileDialog.setFilterPath( BrowserCommonActivator.getDefault().getDialogSettings().get(
+ BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH ) );
+ }
+
+ String returnedFileName = fileDialog.open();
+ if ( returnedFileName != null )
+ {
+ fileCombo.setText( returnedFileName );
+ File file2 = new File( returnedFileName );
+ BrowserCommonActivator.getDefault().getDialogSettings().put(
+ BrowserCommonConstants.DIALOGSETTING_KEY_RECENT_FILE_PATH, file2.getParent() );
+ }
+ }
+ } );
+
+ // file history
+ String[] history = HistoryUtils.load( BrowserCommonActivator.getDefault().getDialogSettings(),
+ BrowserCommonConstants.DIALOGSETTING_KEY_FILE_HISTORY );
+ fileCombo.setItems( history );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getFilename()
+ {
+ String filename = fileCombo.getText();
+
+ if ( ( filename != null ) && ( !"".equals( filename ) ) )
+ {
+ return filename;
+ }
+
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setFilename( String filename )
+ {
+ if ( filename == null )
+ {
+ fileCombo.setText( filename );
+ }
+ else
+ {
+ fileCombo.setText( filename );
+ }
+ }
+}
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperation.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperation.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperation.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperation.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,132 @@
+/*
+ * 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.common.ui.widgets;
+
+
+/**
+ * This enums represents the various access log operation.
+ */
+public enum LogOperation
+{
+ WRITES("writes"),
+ ADD("add"),
+ DELETE("delete"),
+ MODIFY("modify"),
+ MODIFY_RDN("modrdn"),
+ READS("reads"),
+ COMPARE("compare"),
+ SEARCH("search"),
+ SESSION("session"),
+ ABANDON("abandon"),
+ BIND("bind"),
+ UNBIND("unbind"),
+ ALL("all");
+
+ /** The value */
+ protected String value;
+
+
+ /**
+ * Creates a new instance of LogOperation.
+ *
+ * @param value the value
+ */
+ private LogOperation( String value )
+ {
+ this.value = value;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString()
+ {
+ return value;
+ }
+
+
+ /**
+ * Gets the log operation corresponding to the given string.
+ *
+ * @param s the string
+ * @return the corresponding log operation
+ */
+ public static LogOperation fromString( String s )
+ {
+ if ( s != null )
+ {
+ if ( s.equalsIgnoreCase( WRITES.value ) )
+ {
+ return WRITES;
+ }
+ else if ( s.equalsIgnoreCase( ADD.value ) )
+ {
+ return ADD;
+ }
+ else if ( s.equalsIgnoreCase( DELETE.value ) )
+ {
+ return DELETE;
+ }
+ else if ( s.equalsIgnoreCase( MODIFY.value ) )
+ {
+ return MODIFY;
+ }
+ else if ( s.equalsIgnoreCase( MODIFY_RDN.value ) )
+ {
+ return MODIFY_RDN;
+ }
+ else if ( s.equalsIgnoreCase( READS.value ) )
+ {
+ return READS;
+ }
+ else if ( s.equalsIgnoreCase( COMPARE.value ) )
+ {
+ return COMPARE;
+ }
+ else if ( s.equalsIgnoreCase( SEARCH.value ) )
+ {
+ return SEARCH;
+ }
+ else if ( s.equalsIgnoreCase( SESSION.value ) )
+ {
+ return SESSION;
+ }
+ else if ( s.equalsIgnoreCase( ABANDON.value ) )
+ {
+ return ABANDON;
+ }
+ else if ( s.equalsIgnoreCase( BIND.value ) )
+ {
+ return BIND;
+ }
+ else if ( s.equalsIgnoreCase( UNBIND.value ) )
+ {
+ return UNBIND;
+ }
+ else if ( s.equalsIgnoreCase( ALL.value ) )
+ {
+ return ALL;
+ }
+ }
+
+ return null;
+ }
+}
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperationsWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperationsWidget.java?rev=1668963&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperationsWidget.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/widgets/LogOperationsWidget.java Tue Mar 24 19:24:44 2015
@@ -0,0 +1,617 @@
+/*
+ * 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.common.ui.widgets;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget;
+import org.eclipse.swt.SWT;
+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.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+
+public class LogOperationsWidget extends BrowserWidget
+{
+ // UI widgets
+ private Composite composite;
+ private Composite writeOperationsComposite;
+ private Composite readOperationsComposite;
+ private Composite sessionOperationsComposite;
+ private Button allOperationsCheckbox;
+ private Button writeOperationsCheckbox;
+ private Button addOperationCheckbox;
+ private Button deleteOperationCheckbox;
+ private Button modifyOperationCheckbox;
+ private Button modifyRdnOperationCheckbox;
+ private Button readOperationsCheckbox;
+ private Button compareOperationCheckbox;
+ private Button searchOperationCheckbox;
+ private Button sessionOperationsCheckbox;
+ private Button abandonOperationCheckbox;
+ private Button bindOperationCheckbox;
+ private Button unbindOperationCheckbox;
+
+ // Listeners
+ private SelectionAdapter allOperationsCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ allOperationsCheckboxesSetSelection( allOperationsCheckbox.getSelection() );
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter writeOperationsCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ writeOperationsCheckboxesSetSelection( writeOperationsCheckbox.getSelection() );
+ checkAllOperationsCheckboxSelectionState();
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter writeOperationCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ checkWriteOperationsCheckboxSelectionState();
+ checkAllOperationsCheckboxSelectionState();
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter readOperationsCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ readOperationsCheckboxesSetSelection( readOperationsCheckbox.getSelection() );
+ checkAllOperationsCheckboxSelectionState();
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter readOperationCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ checkReadOperationsCheckboxSelectionState();
+ checkAllOperationsCheckboxSelectionState();
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter sessionOperationsCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ sessionOperationsCheckboxesSetSelection( sessionOperationsCheckbox.getSelection() );
+ checkAllOperationsCheckboxSelectionState();
+ notifyListeners();
+ }
+ };
+ private SelectionAdapter sessionOperationCheckboxListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ checkSessionOperationsCheckboxSelectionState();
+ checkAllOperationsCheckboxSelectionState();
+ notifyListeners();
+ }
+ };
+
+
+ /**
+ * Creates the widget.
+ *
+ * @param parent the parent composite
+ */
+ public void create( Composite parent )
+ {
+ // Creating the widget base composite
+ composite = new Composite( parent, SWT.NONE );
+ GridLayout compositeGridLayout = new GridLayout( 3, true );
+ compositeGridLayout.marginHeight = compositeGridLayout.marginWidth = 0;
+ compositeGridLayout.verticalSpacing = compositeGridLayout.horizontalSpacing = 0;
+ composite.setLayout( compositeGridLayout );
+
+ // All Operations Checkbox
+ allOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "All operations", 3 );
+
+ // Write Operations Checkbox
+ writeOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "Read operations", 1 );
+
+ // Read Operations Checkbox
+ readOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "Write operations", 1 );
+
+ // Session Operations Checkbox
+ sessionOperationsCheckbox = BaseWidgetUtils.createCheckbox( composite, "Session operations", 1 );
+
+ // Write Operations Composite
+ writeOperationsComposite = new Composite( composite, SWT.NONE );
+ GridLayout writeOperationsCompositeGridLayout = new GridLayout( 2, false );
+ writeOperationsCompositeGridLayout.marginHeight = writeOperationsCompositeGridLayout.marginWidth = 0;
+ writeOperationsCompositeGridLayout.verticalSpacing = writeOperationsCompositeGridLayout.horizontalSpacing = 0;
+ writeOperationsComposite.setLayout( writeOperationsCompositeGridLayout );
+ writeOperationsComposite.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
+
+ // Read Operations Composite
+ readOperationsComposite = new Composite( composite, SWT.NONE );
+ GridLayout readOperationsCompositeGridLayout = new GridLayout( 2, false );
+ readOperationsCompositeGridLayout.marginHeight = readOperationsCompositeGridLayout.marginWidth = 0;
+ readOperationsCompositeGridLayout.verticalSpacing = readOperationsCompositeGridLayout.horizontalSpacing = 0;
+ readOperationsComposite.setLayout( readOperationsCompositeGridLayout );
+ readOperationsComposite.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
+
+ // Session Operations Composite
+ sessionOperationsComposite = new Composite( composite, SWT.NONE );
+ GridLayout sessionOperationsCompositeGridLayout = new GridLayout( 2, false );
+ sessionOperationsCompositeGridLayout.marginHeight = sessionOperationsCompositeGridLayout.marginWidth = 0;
+ sessionOperationsCompositeGridLayout.verticalSpacing = sessionOperationsCompositeGridLayout.horizontalSpacing = 0;
+ sessionOperationsComposite.setLayout( sessionOperationsCompositeGridLayout );
+ sessionOperationsComposite.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false ) );
+
+ // Add Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
+ addOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Add", 1 );
+
+ // Delete Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
+ deleteOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Delete", 1 );
+
+ // Modify Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
+ modifyOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Modify", 1 );
+
+ // Modify RDN Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( writeOperationsComposite, 1 );
+ modifyRdnOperationCheckbox = BaseWidgetUtils.createCheckbox( writeOperationsComposite, "Modify RDN", 1 );
+
+ // Compare Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( readOperationsComposite, 1 );
+ compareOperationCheckbox = BaseWidgetUtils.createCheckbox( readOperationsComposite, "Compare", 1 );
+
+ // Search Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( readOperationsComposite, 1 );
+ searchOperationCheckbox = BaseWidgetUtils.createCheckbox( readOperationsComposite, "Search", 1 );
+
+ // Abandon Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( sessionOperationsComposite, 1 );
+ abandonOperationCheckbox = BaseWidgetUtils.createCheckbox( sessionOperationsComposite, "Abandon", 1 );
+
+ // Bind Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( sessionOperationsComposite, 1 );
+ bindOperationCheckbox = BaseWidgetUtils.createCheckbox( sessionOperationsComposite, "Bind", 1 );
+
+ // Unbind Operation Checkbox
+ BaseWidgetUtils.createRadioIndent( sessionOperationsComposite, 1 );
+ unbindOperationCheckbox = BaseWidgetUtils.createCheckbox( sessionOperationsComposite, "Unbind", 1 );
+
+ // Adding the listeners to the UI widgets
+ addListeners();
+ }
+
+
+ /**
+ * Returns the associated composite.
+ *
+ * @return the composite
+ */
+ public void adapt( FormToolkit toolkit )
+ {
+ if ( toolkit != null )
+ {
+ toolkit.adapt( composite );
+ toolkit.adapt( writeOperationsComposite );
+ toolkit.adapt( readOperationsComposite );
+ toolkit.adapt( sessionOperationsComposite );
+ }
+ }
+
+
+ /**
+ * Returns the primary control associated with this widget.
+ *
+ * @return the primary control associated with this widget.
+ */
+ public Control getControl()
+ {
+ return composite;
+ }
+
+
+ /**
+ * Adds the listeners to the UI widgets.
+ */
+ private void addListeners()
+ {
+ allOperationsCheckbox.addSelectionListener( allOperationsCheckboxListener );
+ writeOperationsCheckbox.addSelectionListener( writeOperationsCheckboxListener );
+ addOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
+ deleteOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
+ modifyOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
+ modifyRdnOperationCheckbox.addSelectionListener( writeOperationCheckboxListener );
+ readOperationsCheckbox.addSelectionListener( readOperationsCheckboxListener );
+ compareOperationCheckbox.addSelectionListener( readOperationCheckboxListener );
+ searchOperationCheckbox.addSelectionListener( readOperationCheckboxListener );
+ sessionOperationsCheckbox.addSelectionListener( sessionOperationsCheckboxListener );
+ abandonOperationCheckbox.addSelectionListener( sessionOperationCheckboxListener );
+ bindOperationCheckbox.addSelectionListener( sessionOperationCheckboxListener );
+ unbindOperationCheckbox.addSelectionListener( sessionOperationCheckboxListener );
+ }
+
+
+ /**
+ * Sets the selection for all operations checkboxes.
+ *
+ * @param selection the selection
+ */
+ private void allOperationsCheckboxesSetSelection( boolean selection )
+ {
+ allOperationsCheckbox.setGrayed( false );
+ allOperationsCheckbox.setSelection( selection );
+ writeOperationsCheckboxesSetSelection( selection );
+ readOperationsCheckboxesSetSelection( selection );
+ sessionOperationsCheckboxesSetSelection( selection );
+ }
+
+
+ /**
+ * Sets the selection for the 'Write' operations checkboxes.
+ *
+ * @param selection the selection
+ */
+ private void writeOperationsCheckboxesSetSelection( boolean selection )
+ {
+ writeOperationsCheckbox.setGrayed( false );
+ writeOperationsCheckbox.setSelection( selection );
+ addOperationCheckbox.setSelection( selection );
+ deleteOperationCheckbox.setSelection( selection );
+ modifyOperationCheckbox.setSelection( selection );
+ modifyRdnOperationCheckbox.setSelection( selection );
+ }
+
+
+ /**
+ * Sets the selection for the 'Read' operations checkboxes.
+ *
+ * @param selection the selection
+ */
+ private void readOperationsCheckboxesSetSelection( boolean selection )
+ {
+ readOperationsCheckbox.setGrayed( false );
+ readOperationsCheckbox.setSelection( selection );
+ compareOperationCheckbox.setSelection( selection );
+ searchOperationCheckbox.setSelection( selection );
+ }
+
+
+ /**
+ * Sets the selection for the 'Session' operations checkboxes.
+ *
+ * @param selection the selection
+ */
+ private void sessionOperationsCheckboxesSetSelection( boolean selection )
+ {
+ sessionOperationsCheckbox.setGrayed( false );
+ sessionOperationsCheckbox.setSelection( selection );
+ abandonOperationCheckbox.setSelection( selection );
+ bindOperationCheckbox.setSelection( selection );
+ unbindOperationCheckbox.setSelection( selection );
+ }
+
+
+ /**
+ * Verifies the selection state for the 'All Operations' checkbox.
+ */
+ private void checkAllOperationsCheckboxSelectionState()
+ {
+ boolean atLeastOneSelected = addOperationCheckbox.getSelection()
+ || deleteOperationCheckbox.getSelection() || modifyOperationCheckbox.getSelection()
+ || modifyRdnOperationCheckbox.getSelection() || compareOperationCheckbox.getSelection()
+ || searchOperationCheckbox.getSelection() || abandonOperationCheckbox.getSelection()
+ || bindOperationCheckbox.getSelection() || unbindOperationCheckbox.getSelection();
+ boolean allSelected = addOperationCheckbox.getSelection()
+ && deleteOperationCheckbox.getSelection() && modifyOperationCheckbox.getSelection()
+ && modifyRdnOperationCheckbox.getSelection() && compareOperationCheckbox.getSelection()
+ && searchOperationCheckbox.getSelection() && abandonOperationCheckbox.getSelection()
+ && bindOperationCheckbox.getSelection() && unbindOperationCheckbox.getSelection();
+ allOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
+ allOperationsCheckbox.setSelection( atLeastOneSelected );
+ }
+
+
+ /**
+ * Verifies the selection state for the 'Write Operations' checkbox.
+ */
+ private void checkWriteOperationsCheckboxSelectionState()
+ {
+ boolean atLeastOneSelected = isChecked( addOperationCheckbox )
+ || isChecked( deleteOperationCheckbox ) || isChecked( modifyOperationCheckbox )
+ || isChecked( modifyRdnOperationCheckbox );
+ boolean allSelected = isChecked( addOperationCheckbox )
+ && isChecked( deleteOperationCheckbox ) && isChecked( modifyOperationCheckbox )
+ && isChecked( modifyRdnOperationCheckbox );
+ writeOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
+ writeOperationsCheckbox.setSelection( atLeastOneSelected );
+ }
+
+
+ /**
+ * Verifies the selection state for the 'Read Operations' checkbox.
+ */
+ private void checkReadOperationsCheckboxSelectionState()
+ {
+ boolean atLeastOneSelected = isChecked( compareOperationCheckbox )
+ || isChecked( searchOperationCheckbox );
+ boolean allSelected = isChecked( compareOperationCheckbox )
+ && isChecked( searchOperationCheckbox );
+ readOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
+ readOperationsCheckbox.setSelection( atLeastOneSelected );
+ }
+
+
+ /**
+ * Verifies the selection state for the 'Session Operations' checkbox.
+ */
+ private void checkSessionOperationsCheckboxSelectionState()
+ {
+ boolean atLeastOneSelected = isChecked( abandonOperationCheckbox )
+ || isChecked( bindOperationCheckbox ) || isChecked( unbindOperationCheckbox );
+ boolean allSelected = isChecked( abandonOperationCheckbox )
+ && isChecked( bindOperationCheckbox ) && isChecked( unbindOperationCheckbox );
+ sessionOperationsCheckbox.setGrayed( atLeastOneSelected && !allSelected );
+ sessionOperationsCheckbox.setSelection( atLeastOneSelected );
+ }
+
+
+ /**
+ * Sets the input.
+ *
+ * @param operationsList the operations list
+ */
+ public void setInput( List<LogOperation> operationsList )
+ {
+ // Reset all checkboxes
+ resetAllCheckboxes();
+
+ // Select checkboxes according to the log operations list
+ if ( operationsList != null )
+ {
+ for ( LogOperation logOperation : operationsList )
+ {
+ switch ( logOperation )
+ {
+ case ALL:
+ allOperationsCheckbox.setSelection( true );
+ allOperationsCheckboxesSetSelection( true );
+ break;
+ case WRITES:
+ writeOperationsCheckbox.setSelection( true );
+ writeOperationsCheckboxesSetSelection( true );
+ break;
+ case ADD:
+ addOperationCheckbox.setSelection( true );
+ break;
+ case DELETE:
+ deleteOperationCheckbox.setSelection( true );
+ break;
+ case MODIFY:
+ modifyOperationCheckbox.setSelection( true );
+ break;
+ case MODIFY_RDN:
+ modifyRdnOperationCheckbox.setSelection( true );
+ break;
+ case READS:
+ readOperationsCheckbox.setSelection( true );
+ readOperationsCheckboxesSetSelection( true );
+ break;
+ case COMPARE:
+ compareOperationCheckbox.setSelection( true );
+ break;
+ case SEARCH:
+ searchOperationCheckbox.setSelection( true );
+ break;
+ case SESSION:
+ sessionOperationsCheckbox.setSelection( true );
+ sessionOperationsCheckboxesSetSelection( true );
+ break;
+ case ABANDON:
+ abandonOperationCheckbox.setSelection( true );
+ break;
+ case BIND:
+ bindOperationCheckbox.setSelection( true );
+ break;
+ case UNBIND:
+ unbindOperationCheckbox.setSelection( true );
+ break;
+ }
+ }
+ }
+
+ // Check hierarchical checkboxes
+ checkWriteOperationsCheckboxSelectionState();
+ checkReadOperationsCheckboxSelectionState();
+ checkSessionOperationsCheckboxSelectionState();
+ checkAllOperationsCheckboxSelectionState();
+ }
+
+
+ /**
+ * Resets all checkboxes.
+ */
+ private void resetAllCheckboxes()
+ {
+ allOperationsCheckbox.setSelection( false );
+ allOperationsCheckbox.setGrayed( false );
+ writeOperationsCheckbox.setSelection( false );
+ writeOperationsCheckbox.setGrayed( false );
+ addOperationCheckbox.setSelection( false );
+ addOperationCheckbox.setGrayed( false );
+ deleteOperationCheckbox.setSelection( false );
+ deleteOperationCheckbox.setGrayed( false );
+ modifyOperationCheckbox.setSelection( false );
+ modifyOperationCheckbox.setGrayed( false );
+ readOperationsCheckbox.setSelection( false );
+ readOperationsCheckbox.setGrayed( false );
+ compareOperationCheckbox.setSelection( false );
+ compareOperationCheckbox.setGrayed( false );
+ searchOperationCheckbox.setSelection( false );
+ searchOperationCheckbox.setGrayed( false );
+ sessionOperationsCheckbox.setSelection( false );
+ sessionOperationsCheckbox.setGrayed( false );
+ abandonOperationCheckbox.setSelection( false );
+ abandonOperationCheckbox.setGrayed( false );
+ bindOperationCheckbox.setSelection( false );
+ bindOperationCheckbox.setGrayed( false );
+ unbindOperationCheckbox.setSelection( false );
+ unbindOperationCheckbox.setGrayed( false );
+ }
+
+
+ /**
+ * Returns the list of selected operations.
+ *
+ * @return the list of selected operations
+ */
+ public List<LogOperation> getSelectedOperationsList()
+ {
+ List<LogOperation> logOperations = new ArrayList<LogOperation>();
+
+ // All operations
+ if ( isChecked( allOperationsCheckbox ) )
+ {
+ logOperations.add( LogOperation.ALL );
+ }
+ else
+ {
+ // Write operations
+ if ( isChecked( writeOperationsCheckbox ) )
+ {
+ logOperations.add( LogOperation.WRITES );
+ }
+ else
+ {
+ // Add operation
+ if ( isChecked( addOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.ADD );
+ }
+
+ // Delete operation
+ if ( isChecked( deleteOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.DELETE );
+ }
+
+ // Modify operation
+ if ( isChecked( modifyOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.MODIFY );
+ }
+
+ // Modify RDN operation
+ if ( isChecked( modifyRdnOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.MODIFY_RDN );
+ }
+ }
+
+ // Read operations
+ if ( isChecked( readOperationsCheckbox ) )
+ {
+ logOperations.add( LogOperation.READS );
+ }
+ else
+ {
+ // Compare operation
+ if ( isChecked( compareOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.COMPARE );
+ }
+
+ // Search operation
+ if ( isChecked( searchOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.SEARCH );
+ }
+ }
+
+ // Session operations
+ if ( isChecked( sessionOperationsCheckbox ) )
+ {
+ logOperations.add( LogOperation.SESSION );
+ }
+ else
+ {
+ // Abandon operation
+ if ( isChecked( abandonOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.ABANDON );
+ }
+
+ // Bind operation
+ if ( isChecked( bindOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.BIND );
+ }
+
+ // Unbind operation
+ if ( isChecked( unbindOperationCheckbox ) )
+ {
+ logOperations.add( LogOperation.UNBIND );
+ }
+ }
+ }
+
+ return logOperations;
+ }
+
+
+ /**
+ * Indicates if a checkbox is checked ('selected' and not 'grayed').
+ *
+ * @param checkbox the checkbox
+ * @return <code>true</code> if the checkbox is checked
+ * <code>false</code> if not.
+ */
+ private boolean isChecked( Button checkbox )
+ {
+ return ( ( checkbox != null ) && ( !checkbox.isDisposed() ) && ( checkbox.getSelection() ) && ( !checkbox
+ .getGrayed() ) );
+ }
+
+
+ /**
+ * Disposes all created SWT widgets.
+ */
+ public void dispose()
+ {
+ // Composite
+ if ( ( composite != null ) && ( !composite.isDisposed() ) )
+ {
+ composite.dispose();
+ }
+ }
+}