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.openldap.config.editor.databases.DatabasesDetailsPage.java

License:Apache License

/**
 * Action launched when the edit replication consumer button is clicked, or
 * when the replication consumers table viewer is double-clicked.
 *//*from w w w .  j  a  v  a2s. c o  m*/
private void editReplicationConsumerButtonAction() {
    StructuredSelection selection = (StructuredSelection) replicationConsumersTableViewer.getSelection();

    if (!selection.isEmpty()) {
        // Getting the raw SyncRepl value
        String syncReplValue = (String) selection.getFirstElement();
        String syncReplValueWithoutOrderingPrefix = syncReplValue;

        // Getting the ordering prefix (if it exists)
        int orderingPrefix = OpenLdapConfigurationPluginUtils.getOrderingPrefix(syncReplValue);

        // If an ordering prefix was found, lets remove it before parsing the string
        if (orderingPrefix > 0) {
            syncReplValueWithoutOrderingPrefix = OpenLdapConfigurationPluginUtils
                    .stripOrderingPrefix(syncReplValue);
        }

        // Parsing the SyncRepl value
        SyncReplParser parser = new SyncReplParser();
        try {
            SyncRepl syncRepl = parser.parse(syncReplValueWithoutOrderingPrefix);

            // Opening a replication consumer dialog
            ReplicationConsumerDialog dialog = new ReplicationConsumerDialog(
                    addReplicationConsumerButton.getShell(), syncRepl, browserConnection);

            if (dialog.open() == OverlayDialog.OK) {
                if ((databaseWrapper != null) && (databaseWrapper.getDatabase() != null)) {
                    String newSyncReplValue = dialog.getSyncRepl().toString();

                    // Add back the ordering prefix if it was present
                    if (orderingPrefix > 0) {
                        newSyncReplValue = "{" + orderingPrefix + "}" + newSyncReplValue;
                    }

                    OlcDatabaseConfig databaseConfig = databaseWrapper.getDatabase();
                    List<String> newOlcSyncrepls = databaseConfig.getOlcSyncrepl();
                    newOlcSyncrepls.remove(syncReplValue);
                    newOlcSyncrepls.add(newSyncReplValue);
                    databaseConfig.setOlcSyncrepl(newOlcSyncrepls);
                    refreshReplicationConsumersTableViewer();
                    replicationConsumersTableViewer.setSelection(new StructuredSelection(newSyncReplValue));
                    setEditorDirty();
                }
            }
        } catch (SyncReplParserException e) {
            CommonUIUtils.openErrorDialog(NLS.bind(
                    "The replication consumer definition could not be read correctly.\nThe following error occured:\n {0}",
                    e));
        }
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.databases.DatabasesDetailsPage.java

License:Apache License

/**
 * Action launched when the delete replication consumer button is clicked.
 */// w  w  w.j  a  va  2  s  .  c  o m
private void deleteReplicationConsumerButtonAction() {
    StructuredSelection selection = (StructuredSelection) replicationConsumersTableViewer.getSelection();

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

        if (MessageDialog.openConfirm(overlaysTableViewer.getControl().getShell(), "Delete Overlay?",
                NLS.bind("Are you sure you want to delete the ''{0}'' replication consumer ?",
                        getReplicationConsumerText(syncReplValue)))) {

            if (databaseWrapper != null) {
                OlcDatabaseConfig databaseConfig = databaseWrapper.getDatabase();

                if (databaseConfig != null) {
                    List<String> newOlcSynrepls = databaseConfig.getOlcSyncrepl();
                    newOlcSynrepls.remove(syncReplValue);
                    databaseConfig.setOlcSyncrepl(newOlcSynrepls);
                    refreshReplicationConsumersTableViewer();
                    setEditorDirty();
                }
            }
        }
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.databases.DatabasesMasterDetailsBlock.java

License:Apache License

/**
 * This method is called when the 'Delete' button is clicked.
 *///from www  .  java  2  s  .co m
private void deleteSelectedDatabase() {
    StructuredSelection selection = (StructuredSelection) databaseTableViewer.getSelection();

    if (!selection.isEmpty()) {
        DatabaseWrapper databaseWrapper = (DatabaseWrapper) selection.getFirstElement();
        OlcDatabaseConfig database = databaseWrapper.getDatabase();

        if (MessageDialog.openConfirm(page.getManagedForm().getForm().getShell(), "Confirm Delete",
                NLS.bind("Are you sure you want to delete database ''{0} ({1})''?",
                        OpenLdapConfigurationPluginUtils.stripOrderingPrefix(database.getOlcDatabase()),
                        getSuffixValue(database)))) {
            databaseWrappers.remove(databaseWrapper);
            setEditorDirty();
        }
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.databases.DatabasesMasterDetailsBlock.java

License:Apache License

/**
 * This method is called when the 'Up' button is clicked.
 *//* ww  w  .  ja  v  a 2  s.com*/
private void moveSelectedDatabaseUp() {
    StructuredSelection selection = (StructuredSelection) databaseTableViewer.getSelection();

    if (!selection.isEmpty()) {
        OlcDatabaseConfig selectedDatabase = ((DatabaseWrapper) selection.getFirstElement()).getDatabase();
        int selectedDatabaseOrderingPrefix = OpenLdapConfigurationPluginUtils
                .getOrderingPrefix(selectedDatabase.getOlcDatabase());
        String selectedDatabaseName = OpenLdapConfigurationPluginUtils
                .stripOrderingPrefix(selectedDatabase.getOlcDatabase());

        OlcDatabaseConfig swapDatabase = findPreviousDatabase(selectedDatabaseOrderingPrefix);

        if (swapDatabase != null) {
            int swapDatabaseOrderingPrefix = OpenLdapConfigurationPluginUtils
                    .getOrderingPrefix(swapDatabase.getOlcDatabase());
            String swapDatabaseName = OpenLdapConfigurationPluginUtils
                    .stripOrderingPrefix(swapDatabase.getOlcDatabase());

            selectedDatabase.setOlcDatabase("{" + swapDatabaseOrderingPrefix + "}" + selectedDatabaseName);
            swapDatabase.setOlcDatabase("{" + selectedDatabaseOrderingPrefix + "}" + swapDatabaseName);

            databaseTableViewer.refresh();
            refreshButtonStates();
            setEditorDirty();
        }
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.databases.DatabasesMasterDetailsBlock.java

License:Apache License

/**
 * This method is called when the 'Down' button is clicked.
 *//*from ww w .  j  a v a 2s  .  c om*/
private void moveSelectedDatabaseDown() {
    StructuredSelection selection = (StructuredSelection) databaseTableViewer.getSelection();

    if (!selection.isEmpty()) {
        OlcDatabaseConfig selectedDatabase = ((DatabaseWrapper) selection.getFirstElement()).getDatabase();
        int selectedDatabaseOrderingPrefix = OpenLdapConfigurationPluginUtils
                .getOrderingPrefix(selectedDatabase.getOlcDatabase());
        String selectedDatabaseName = OpenLdapConfigurationPluginUtils
                .stripOrderingPrefix(selectedDatabase.getOlcDatabase());

        OlcDatabaseConfig swapDatabase = findNextDatabase(selectedDatabaseOrderingPrefix);

        if (swapDatabase != null) {
            int swapDatabaseOrderingPrefix = OpenLdapConfigurationPluginUtils
                    .getOrderingPrefix(swapDatabase.getOlcDatabase());
            String swapDatabaseName = OpenLdapConfigurationPluginUtils
                    .stripOrderingPrefix(swapDatabase.getOlcDatabase());

            selectedDatabase.setOlcDatabase("{" + swapDatabaseOrderingPrefix + "}" + selectedDatabaseName);
            swapDatabase.setOlcDatabase("{" + selectedDatabaseOrderingPrefix + "}" + swapDatabaseName);

            databaseTableViewer.refresh();
            refreshButtonStates();
            setEditorDirty();
        }
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.databases.DatabasesMasterDetailsBlock.java

License:Apache License

/**
 * Update the button according to the content of the table. If we have
 * no Database, we just enable the Add button. If we only have one Database,
 * we don't enable the Add and Delete buttons. We also enable the Up and
 * Down button accordingly to the selected database : if it's the first one,
 * the Up butto is disabled, if it's the last one, the Down button is
 * disabled./*from   w  ww  .  j  a  va2  s  . c  o  m*/
 */
private void refreshButtonStates() {
    // Getting the selection of the table viewer
    StructuredSelection selection = (StructuredSelection) databaseTableViewer.getSelection();

    if (!selection.isEmpty()) {
        OlcDatabaseConfig database = ((DatabaseWrapper) selection.getFirstElement()).getDatabase();

        deleteButton.setEnabled(true);
        upButton.setEnabled(getMinOrderingValue() != OpenLdapConfigurationPluginUtils
                .getOrderingPrefix(database.getOlcDatabase()));
        downButton.setEnabled(getMaxOrderingValue() != OpenLdapConfigurationPluginUtils
                .getOrderingPrefix(database.getOlcDatabase()));
    } else {
        deleteButton.setEnabled(false);
        upButton.setEnabled(false);
        downButton.setEnabled(false);
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.dialogs.overlays.MemberOfOverlayConfigurationBlock.java

License:Apache License

/**
 * Gets the selected dangling reference behavior.
 *
 * @return the selected dangling reference behavior
 *///from   w  w  w . ja  v a2  s . c  o m
private OlcMemberOfDanglingReferenceBehaviorEnum getSelectedDanglingReferenceBehavior() {
    StructuredSelection selection = (StructuredSelection) danglingReferenceBehaviorComboViewer.getSelection();

    if ((selection != null) && (!selection.isEmpty())) {
        Object firstElement = selection.getFirstElement();

        if (firstElement instanceof OlcMemberOfDanglingReferenceBehaviorEnum) {
            return (OlcMemberOfDanglingReferenceBehaviorEnum) firstElement;
        } else {
            return null;
        }
    }

    return null;
}

From source file:org.apache.directory.studio.openldap.config.editor.dialogs.overlays.MemberOfOverlayConfigurationBlock.java

License:Apache License

/**
 * Gets the selected dangling reference error code.
 *
 * @return the selected dangling reference error code
 *//*from w w w  . j  av a2s .  c  o  m*/
private ResultCodeEnum getSelectedDanglingReferenceErrorCode() {
    StructuredSelection selection = (StructuredSelection) danglingReferenceErrorCodeComboViewer.getSelection();

    if ((selection != null) && (!selection.isEmpty())) {
        Object firstElement = selection.getFirstElement();

        if (firstElement instanceof ResultCodeEnum) {
            return (ResultCodeEnum) firstElement;
        } else {
            return null;
        }
    }

    return null;
}

From source file:org.apache.directory.studio.openldap.config.editor.dialogs.overlays.RewriteRemapOverlayConfigurationBlock.java

License:Apache License

/**
 * Action launched when the edit mapping button is clicked, or
 * when the value sorts table viewer is double-clicked.
 *//*from  ww  w  .  j  ava 2s.c o  m*/
private void editMappingButtonAction() {
    StructuredSelection selection = (StructuredSelection) mappingsTableViewer.getSelection();

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

        RwmMappingDialog dialog = new RwmMappingDialog(addMappingButton.getShell(), browserConnection,
                selectedMapping);
        if (dialog.open() == AttributeDialog.OK) {
            String value = dialog.getValue();

            int index = mappings.indexOf(selectedMapping);
            mappings.remove(selectedMapping);
            mappings.add(index, value);
            mappingsTableViewer.refresh();
            mappingsTableViewer.setSelection(new StructuredSelection(value));
        }
    }
}

From source file:org.apache.directory.studio.openldap.config.editor.dialogs.overlays.ValueSortingOverlayConfigurationBlock.java

License:Apache License

/**
 * Action launched when the edit value sort button is clicked, or
 * when the value sorts table viewer is double-clicked.
 *///from ww  w .  j  a va 2s . c  o m
private void editValueSortButtonAction() {
    StructuredSelection selection = (StructuredSelection) valueSortsTableViewer.getSelection();

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

        ValueSortingValueDialog dialog = new ValueSortingValueDialog(addValueSortButton.getShell(),
                browserConnection, selectedValueSort);
        if (dialog.open() == AttributeDialog.OK) {
            String value = dialog.getValue();

            int index = valueSorts.indexOf(selectedValueSort);
            valueSorts.remove(selectedValueSort);
            valueSorts.add(index, value);
            valueSortsTableViewer.refresh();
            valueSortsTableViewer.setSelection(new StructuredSelection(value));
        }
    }
}