Example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement

List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection getFirstElement.

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:org.apache.directory.studio.apacheds.configuration.editor.LdapLdapsServersPage.java

License:Apache License

/**
 * Gets the selected hashing method./* w  ww  .j av  a 2  s.c o m*/
 *
 * @return the selected hashing method
 */
private LdapSecurityConstants getSelectedHashingMethod() {
    StructuredSelection selection = (StructuredSelection) hashingMethodComboViewer.getSelection();

    if (!selection.isEmpty()) {
        return (LdapSecurityConstants) selection.getFirstElement();
    }

    return null;
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.LdapLdapsServersPage.java

License:Apache License

/**
 * Gets the first SASL realms Table //from ww  w. j a  va 2 s. co m
 *
 * @return the first Enabled Protocols Table
 */
private String getSelectedSaslRealms() {
    StructuredSelection selection = (StructuredSelection) saslRealmsTableViewer.getSelection();

    if (!selection.isEmpty()) {
        return (String) selection.getFirstElement();
    }

    return null;
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionDetailsPage.java

License:Apache License

/**
 * Opens an indexed dialog with the selected index in the indexes table viewer.
 *//*from w w  w . j  ava 2  s  .c  om*/
private void editSelectedIndex() {
    StructuredSelection selection = (StructuredSelection) indexesTableViewer.getSelection();
    if (!selection.isEmpty()) {
        PartitionType partitionType = (PartitionType) ((StructuredSelection) partitionTypeComboViewer
                .getSelection()).getFirstElement();

        if (partitionType != null) {
            IndexBean editedIndex = null;

            // JDBM partition
            if (partitionType == PartitionType.JDBM) {
                // Getting the selected JDBM index
                JdbmIndexBean index = (JdbmIndexBean) selection.getFirstElement();

                // Creating a JDBM dialog
                JdbmIndexDialog dialog = new JdbmIndexDialog(index);

                if (JdbmIndexDialog.OK == dialog.open() && dialog.isDirty()) {
                    editedIndex = index;
                }
            }
            // Mavibot Partition
            else if (partitionType == PartitionType.MAVIBOT) {
                // Getting the selected Mavibot index
                MavibotIndexBean index = (MavibotIndexBean) selection.getFirstElement();

                // Creating a Mavibot dialog
                MavibotIndexDialog dialog = new MavibotIndexDialog(index);

                if (MavibotIndexDialog.OK == dialog.open() && dialog.isDirty()) {
                    editedIndex = index;
                }
            }

            // Checking the new index
            if (editedIndex != null) {
                indexesTableViewer.refresh();
                masterDetailsBlock.setEditorDirty();
            }
        }
    }
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionDetailsPage.java

License:Apache License

/**
 * Opens a Context Entry Dialog with the selected Attribute Value Object in the
 * Context Entry Table Viewer.//from   w  w  w .j a  v  a  2 s  .  co  m
 */
private void editSelectedContextEntry() {
    StructuredSelection selection = (StructuredSelection) contextEntryTableViewer.getSelection();
    if (!selection.isEmpty()) {
        AttributeValueObject attributeValueObject = (AttributeValueObject) selection.getFirstElement();

        String oldId = attributeValueObject.getAttribute();
        String oldValue = attributeValueObject.getValue();

        AttributeValueDialog dialog = new AttributeValueDialog(attributeValueObject);
        if (AttributeValueDialog.OK == dialog.open() && dialog.isDirty()) {
            Attribute attribute = contextEntry.get(oldId);
            if (attribute != null) {
                attribute.remove(oldValue);
            }

            AttributeValueObject newAttributeValueObject = dialog.getAttributeValueObject();
            attribute = contextEntry.get(newAttributeValueObject.getAttribute());

            if (attribute != null) {
                try {
                    attribute.add(newAttributeValueObject.getValue());
                } catch (LdapInvalidAttributeValueException liave) {
                    // Will never occur
                }
            } else {
                try {
                    contextEntry.put(new DefaultAttribute(newAttributeValueObject.getAttribute(),
                            newAttributeValueObject.getValue()));
                } catch (LdapException e) {
                    // Will never occur
                }
            }

            contextEntryTableViewer.refresh();
            resizeContextEntryTableColumnsToFit();
            masterDetailsBlock.setEditorDirty();
            //                dirty = true; TODO
            commit(true);
        }
    }
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionsMasterDetailsBlock.java

License:Apache License

/**
 * Add listeners to UI fields./*from   w w w.java 2 s.co m*/
 */
private void addListeners() {
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            viewer.refresh();

            // Getting the selection of the table viewer
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();

            // Delete button is enabled when something is selected
            deleteButton.setEnabled(!selection.isEmpty());

            // Delete button is not enabled in the case of the system partition
            if (!selection.isEmpty()) {
                PartitionWrapper partitionWrapper = (PartitionWrapper) selection.getFirstElement();
                if (PartitionsPage.isSystemPartition(partitionWrapper.getPartition())) {
                    deleteButton.setEnabled(false);
                }
            }
        }
    });

    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewPartition();
        }
    });

    deleteButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            deleteSelectedPartition();
        }
    });
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionsMasterDetailsBlock.java

License:Apache License

/**
 * This method is called when the 'Delete' button is clicked.
 *//*w w w  .  j  a  v  a  2  s . com*/
private void deleteSelectedPartition() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();

    if (!selection.isEmpty()) {
        PartitionWrapper partitionWrapper = (PartitionWrapper) selection.getFirstElement();

        PartitionBean partition = partitionWrapper.getPartition();

        if (!PartitionsPage.isSystemPartition(partition)) {
            if (MessageDialog.openConfirm(page.getManagedForm().getForm().getShell(),
                    Messages.getString("PartitionsMasterDetailsBlock.ConfirmDelete"), //$NON-NLS-1$
                    NLS.bind(Messages.getString("PartitionsMasterDetailsBlock.AreYouSureDeletePartition"), //$NON-NLS-1$
                            partition.getPartitionId(), partition.getPartitionSuffix()))) {
                partitionWrappers.remove(partitionWrapper);
                setEditorDirty();
            }
        }
    }
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.PasswordPoliciesMasterDetailsBlock.java

License:Apache License

/**
 * Add listeners to UI fields.//from   w w  w  .  j  av  a 2 s .  c  o m
 */
private void addListeners() {
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            viewer.refresh();

            // Getting the selection of the table viewer
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();

            // Delete button is enabled when something is selected
            deleteButton.setEnabled(!selection.isEmpty());

            // Delete button is not enabled in the case of the system partition
            if (!selection.isEmpty()) {
                PasswordPolicyBean passwordPolicy = (PasswordPolicyBean) selection.getFirstElement();
                if (PasswordPoliciesPage.isDefaultPasswordPolicy(passwordPolicy)) {
                    deleteButton.setEnabled(false);
                }
            }
        }
    });

    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewPasswordPolicy();
        }
    });

    deleteButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            deleteSelectedPasswordPolicy();
        }
    });
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.PasswordPoliciesMasterDetailsBlock.java

License:Apache License

/**
 * This method is called when the 'Delete' button is clicked.
 *///  www  .ja v a  2 s.  com
private void deleteSelectedPasswordPolicy() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if (!selection.isEmpty()) {
        PasswordPolicyBean passwordPolicy = (PasswordPolicyBean) selection.getFirstElement();
        if (!PasswordPoliciesPage.isDefaultPasswordPolicy(passwordPolicy)) {
            if (MessageDialog.openConfirm(page.getManagedForm().getForm().getShell(),
                    Messages.getString("PasswordPoliciesMasterDetailsBlock.ConfirmDelete"), //$NON-NLS-1$
                    NLS.bind(
                            Messages.getString(
                                    "PasswordPoliciesMasterDetailsBlock.AreYouSureDeletePasswordPolicy"), //$NON-NLS-1$
                            passwordPolicy.getPwdId()))) {
                getAuthenticationInterceptor().removePasswordPolicies(passwordPolicy);
                setEditorDirty();
            }
        }
    }
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationDetailsPage.java

License:Apache License

/**
 * Opens an attribute dialog with the selected attribute in the attributes table viewer.
 *//*  w w w.  j  a  va2 s.  co m*/
private void editSelectedAttribute() {
    StructuredSelection selection = (StructuredSelection) attributesTableViewer.getSelection();

    if (!selection.isEmpty()) {
        String attribute = (String) selection.getFirstElement();

        AttributeDialog dialog = new AttributeDialog(addAttributeButton.getShell());
        dialog.setEditedElement(new StringValueWrapper(attribute, false));
        dialog.setAttributeNamesAndOids(attributeLoader.getAttributeNamesAndOids());

        if (AttributeDialog.OK == dialog.open()) {
            attributesList.remove(attribute);

            String newAttribute = dialog.getEditedElement().getValue();

            if (!attributesList.contains(newAttribute)) {
                attributesList.add(newAttribute);
            }

            attributesTableViewer.refresh();
            attributesTableViewer.setSelection(new StructuredSelection(newAttribute));
            masterDetailsBlock.setEditorDirty();
        }
    }
}

From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationDetailsPage.java

License:Apache License

/**
 * Deletes the selected index in the indexes table viewer.
 *//*from   ww  w.  j  a  va  2  s  .  c  om*/
private void deleteSelectedAttribute() {
    StructuredSelection selection = (StructuredSelection) attributesTableViewer.getSelection();

    if (!selection.isEmpty()) {
        String attribute = (String) selection.getFirstElement();

        attributesList.remove(attribute);
        attributesTableViewer.refresh();
        masterDetailsBlock.setEditorDirty();
    }
}