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

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

Introduction

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

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:org.apache.directory.studio.openldap.common.ui.widgets.BooleanWithDefaultWidget.java

License:Apache License

/**
 * Creates the widget.// ww  w  . j  a  va 2  s . c  om
 *
 * @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]));
}

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

License:Apache License

/**
 * Updates the state of the overlays table buttons.
 *//* www . j  a  v a  2 s  . c  om*/
private void updateOverlaysTableButtonsState() {
    StructuredSelection selection = (StructuredSelection) overlaysTableViewer.getSelection();

    editOverlayButton.setEnabled(!selection.isEmpty());
    deleteOverlayButton.setEnabled(!selection.isEmpty());
}

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

License:Apache License

/**
 * Updates the state of the replication consumers table buttons.
 *///from w  w  w  .j a  v  a2  s  .  c o  m
private void updateReplicationConsumersTableButtonsState() {
    StructuredSelection selection = (StructuredSelection) replicationConsumersTableViewer.getSelection();

    editReplicationConsumerButton.setEnabled(!selection.isEmpty());
    deleteReplicationConsumerButton.setEnabled(!selection.isEmpty());
}

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

License:Apache License

/**
 * Action launched when the edit overlay button is clicked, or
 * when the overlays table viewer is double-clicked.
 */// w w w. ja  v a 2  s  .  co  m
private void editOverlayButtonAction() {
    StructuredSelection selection = (StructuredSelection) overlaysTableViewer.getSelection();

    if (!selection.isEmpty()) {
        OlcOverlayConfig selectedOverlay = (OlcOverlayConfig) selection.getFirstElement();

        OverlayDialog dialog = new OverlayDialog(addOverlayButton.getShell());
        dialog.setBrowserConnection(browserConnection);
        dialog.setOverlay(selectedOverlay);

        if (dialog.open() == OverlayDialog.OK) {
            refreshOverlaysTableViewer();
            setEditorDirty();
        }
    }
}

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

License:Apache License

/**
 * Action launched when the delete overlay button is clicked.
 *//*  w w  w .  j  ava  2  s  .  c om*/
private void deleteOverlayButtonAction() {
    StructuredSelection selection = (StructuredSelection) overlaysTableViewer.getSelection();

    if (!selection.isEmpty()) {
        OlcOverlayConfig overlay = (OlcOverlayConfig) selection.getFirstElement();

        if (MessageDialog.openConfirm(overlaysTableViewer.getControl().getShell(), "Delete Overlay?",
                NLS.bind("Are you sure you want to delete the ''{0}'' overlay?", getOverlayText(overlay)))) {
            if ((databaseWrapper != null) && (databaseWrapper.getDatabase() != null)) {
                databaseWrapper.getDatabase().removeOverlay(overlay);
                refreshOverlaysTableViewer();
                setEditorDirty();
            }
        }
    }
}

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.
 *//*ww w.  j av a  2s . 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.
 *//*www .  j a  va2 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.
 *//*  w w w .  jav a 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.
 *//* w  w w .  j a v  a2  s.  co m*/
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 www.  ja  v a  2s.c o  m*/
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();
        }
    }
}