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.config.editor.dialogs.ReplicationConsumerDialog.java

License:Apache License

/**
 * Gets the scope.//www. j ava  2s. co m
 *
 * @return the scope
 */
private Scope getScope() {
    StructuredSelection selection = (StructuredSelection) scopeComboViewer.getSelection();

    if ((selection != null) && (!selection.isEmpty())) {
        return (Scope) selection.getFirstElement();
    }

    return null;
}

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

License:Apache License

/**
 * Gets the sync data./*from w  w  w  . j a  v  a 2 s .  co  m*/
 *
 * @return the sync data
 */
private SyncData getSyncData() {
    if (enableDeltaSyncReplCheckbox.getSelection()) {
        StructuredSelection selection = (StructuredSelection) syncDataComboViewer.getSelection();

        if ((selection != null) && (!selection.isEmpty())) {
            return (SyncData) selection.getFirstElement();
        }
    }

    return null;
}

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

License:Apache License

/**
 * Gets the selected SASL mechanism.//  w  w w. j a  v a  2s. com
 *
 * @return the selected SASL mechanism
 */
private String getSaslMechanism() {
    StructuredSelection selection = (StructuredSelection) saslMechanismComboViewer.getSelection();

    if ((selection != null) && (!selection.isEmpty())) {
        return ((SaslMechanism) selection.getFirstElement()).getValue();
    }

    return null;
}

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

License:Apache License

/**
 * Gets the selected sort method.//from  w w  w . j a v  a  2s.com
 *
 * @return the selected sort method
 */
private OlcRwmMapValueTypeEnum getSelectedType() {
    StructuredSelection selection = (StructuredSelection) typeComboViewer.getSelection();

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

    return null;
}

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

License:Apache License

/**
 * Gets the selected sort method.//w ww .j a  v a2  s.  co  m
 *
 * @return the selected sort method
 */
private Object getSelectedSortMethod() {
    StructuredSelection selection = (StructuredSelection) sortMethodComboViewer.getSelection();

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

    return null;
}

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

License:Apache License

/**
 * Gets the selected secondary sort method.
 *
 * @return the selected secondary sort method
 *///from  w w w. j  a  va2s. c  om
private Object getSelectedSecondarySortMethod() {
    StructuredSelection selection = (StructuredSelection) secondarySortMethodComboViewer.getSelection();

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

    return null;
}

From source file:org.apache.directory.studio.openldap.config.model.widgets.LockDetectWidget.java

License:Apache License

/**
 * Creates the widget.//  w  w  w.ja v a2  s.  c  o  m
 * 
 * @param parent the parent
 * @param toolkit the toolkit
 */
public void createWidget(Composite parent, FormToolkit toolkit) {
    // Combo
    comboViewer = new ComboViewer(parent);
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof NoneObject) {
                return "(No value)";
            } else if (element instanceof OlcBdbConfigLockDetectEnum) {
                OlcBdbConfigLockDetectEnum lockDetect = (OlcBdbConfigLockDetectEnum) element;

                switch (lockDetect) {
                case OLDEST:
                    return "Oldest";
                case YOUNGEST:
                    return "Youngest";
                case FEWEST:
                    return "Fewest";
                case RANDOM:
                    return "Random";
                case DEFAULT:
                    return "Default";
                }
            }

            return super.getText(element);
        }
    });
    comboViewer.addSelectionChangedListener(event -> {
        value = null;

        StructuredSelection selection = (StructuredSelection) comboViewer.getSelection();

        if (!selection.isEmpty()) {
            Object selectedObject = selection.getFirstElement();

            if (selectedObject instanceof OlcBdbConfigLockDetectEnum) {
                value = (OlcBdbConfigLockDetectEnum) selectedObject;
            }
        }

        notifyListeners();
    });
    comboViewer.setInput(comboViewerValues);
    comboViewer.setSelection(new StructuredSelection(comboViewerValues[0]));
}

From source file:org.apache.directory.studio.schemaeditor.controller.actions.CloseProjectAction.java

License:Apache License

/**
 * Enables or disables the Action./*from   w ww  . jav  a 2  s  .com*/
 */
private void enableDisable() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() == 1)) {
        setEnabled(((ProjectWrapper) selection.getFirstElement()).getProject().getState()
                .equals(ProjectState.OPEN));
    } else {
        setEnabled(false);
    }
}

From source file:org.apache.directory.studio.schemaeditor.controller.actions.CloseProjectAction.java

License:Apache License

/**
 * {@inheritDoc}//from   w w  w . ja va  2s  .  c  o m
 */
public void run() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() == 1)) {
        projectsHandler.closeProject(((ProjectWrapper) selection.getFirstElement()).getProject());
    }

}

From source file:org.apache.directory.studio.schemaeditor.controller.actions.DeleteProjectAction.java

License:Apache License

/**
 * {@inheritDoc}/*from  www .ja v  a2  s  .c o  m*/
 */
public void run() {
    ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler();
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();

    if (!selection.isEmpty()) {
        StringBuilder title = new StringBuilder();
        StringBuilder message = new StringBuilder();

        int count = selection.size();

        if (count <= 5) {
            if (count == 1) {
                // Only 1 project to delete
                title.append(Messages.getString("DeleteProjectAction.DeleteProjectTitle")); //$NON-NLS-1$
                message.append(Messages.getString("DeleteProjectAction.SureDeleteFollowingProject")); //$NON-NLS-1$
            } else {
                // Between 2 to 5 projects to delete
                title.append(Messages.getString("DeleteProjectAction.DeleteProjectsTitle")); //$NON-NLS-1$
                message.append(Messages.getString("DeleteProjectAction.SureDeleteFollowingProjects")); //$NON-NLS-1$
            }

            // Appending the projects names
            for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
                message.append(ConnectionCoreConstants.LINE_SEPARATOR);
                message.append("  - "); //$NON-NLS-1$
                message.append(((ProjectWrapper) iterator.next()).getProject().getName());
            }
        } else {
            // More than 5 projects to delete
            title.append(Messages.getString("DeleteProjectAction.DeleteProjectsTitle")); //$NON-NLS-1$
            message.append(Messages.getString("DeleteProjectAction.SureDeleteSelectedProjects")); //$NON-NLS-1$
        }

        // Showing the confirmation window
        if (MessageDialog.openConfirm(viewer.getControl().getShell(), title.toString(), message.toString())) {
            for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
                ProjectWrapper wrapper = (ProjectWrapper) iterator.next();
                Project project = wrapper.getProject();

                if (project.getState() == ProjectState.OPEN) {
                    // Closing the project before removing it. 
                    projectsHandler.closeProject(project);
                }

                projectsHandler.removeProject(project);
            }
        }
    }
}