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.common.ui.widgets.TableWidget.java

License:Apache License

/**
 * This method is called when the 'Delete' button is clicked.
 */// www .  j av a  2s .co  m
private void deleteElement() {
    StructuredSelection selection = (StructuredSelection) elementTableViewer.getSelection();

    if (!selection.isEmpty()) {
        // If the table is ordered, we need to decrement the prefix of all the following elements
        if (isOrdered) {
            int selectedPosition = elementTableViewer.getTable().getSelectionIndex();

            for (int i = selectedPosition + 1; i < elements.size(); i++) {
                E nextElement = elements.get(i);
                ((OrderedElement) nextElement).decrementPrefix();
                elements.set(i - 1, nextElement);
            }

            elements.remove(elements.size() - 1);
        } else {
            int selectedPosition = elementTableViewer.getTable().getSelectionIndex();
            elements.remove(selectedPosition);
        }

        elementTableViewer.refresh();
        notifyListeners();
    }
}

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

License:Apache License

/**
 * This method is called when the 'Up...' button is clicked
 *///from   w w  w . j  av a 2  s  . co  m
private void upElement() {
    StructuredSelection selection = (StructuredSelection) elementTableViewer.getSelection();

    if (!selection.isEmpty()) {
        // Get the line the selected element is in. We will move it up 
        int selectionLine = elementTableViewer.getTable().getSelectionIndex();

        // The selected element
        E selectedElement = (E) selection.getFirstElement();

        // Decrease the prefix
        ((OrderedElement) selectedElement).decrementPrefix();

        // Just swap the elements which is just before with the selected one
        E previousElement = getElements().get(selectionLine - 1);

        // Increase the prefix
        ((OrderedElement) previousElement).incrementPrefix();

        elements.remove(selectionLine - 1);
        elements.add(selectionLine, previousElement);

        // Refresh the table now
        elementTableViewer.refresh();
        elementTableViewer.setSelection(new StructuredSelection(selectedElement));

        notifyListeners();
    }
}

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

License:Apache License

/**
 * This method is called when the 'Down...' button is clicked
 * or the table viewer is double-clicked.
 *//*www  .j a  v  a 2  s. c om*/
private void downElement() {
    StructuredSelection selection = (StructuredSelection) elementTableViewer.getSelection();

    if (!selection.isEmpty()) {
        // Get the line the selected element is in. We will move it down 
        int selectionLine = elementTableViewer.getTable().getSelectionIndex();

        // The selected element
        E selectedElement = (E) selection.getFirstElement();

        // Increase the prefix
        ((OrderedElement) selectedElement).incrementPrefix();

        // Just swap the elements which is just after with the selected one
        E previousElement = getElements().get(selectionLine + 1);

        // Decrease the prefix
        ((OrderedElement) previousElement).decrementPrefix();

        elements.remove(selectionLine + 1);
        elements.add(selectionLine, previousElement);

        // refresh the table now
        elementTableViewer.refresh();
        elementTableViewer.setSelection(new StructuredSelection(selectedElement));

        notifyListeners();
    }
}

From source file:org.apache.directory.studio.connection.ui.wizards.ExportCertificateWizardPage.java

License:Apache License

/**
 * Gets the certificate export format.// www .jav  a2  s .  c  o m
 *
 * @return the certificate export format
 */
public CertificateExportFormat getCertificateExportFormat() {
    StructuredSelection selection = (StructuredSelection) formatComboViewer.getSelection();

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

    // Default format
    return CertificateExportFormat.DER;
}

From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.preferences.BinaryAttributesAndSyntaxesPreferencePage.java

License:Apache License

private void editAttribute() {
    StructuredSelection sel = (StructuredSelection) attributeViewer.getSelection();
    if (!sel.isEmpty()) {
        BinaryAttribute attribute = (BinaryAttribute) sel.getFirstElement();
        AttributeDialog dialog = new AttributeDialog(getShell(), attribute, attributeNamesAndOids);
        if (dialog.open() == AttributeValueEditorDialog.OK) {
            int index = attributeList.indexOf(attribute);
            attributeList.set(index, dialog.getAttribute());
            attributeViewer.refresh();/*from  w w  w .j  a v  a  2 s.  c  o  m*/
        }
    }
}

From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.preferences.BinaryAttributesAndSyntaxesPreferencePage.java

License:Apache License

private void editSyntax() {
    StructuredSelection sel = (StructuredSelection) syntaxViewer.getSelection();
    if (!sel.isEmpty()) {
        BinarySyntax syntax = (BinarySyntax) sel.getFirstElement();
        SyntaxDialog dialog = new SyntaxDialog(getShell(), syntax, syntaxOids);
        if (dialog.open() == SyntaxValueEditorDialog.OK) {
            int index = syntaxList.indexOf(syntax);
            syntaxList.set(index, dialog.getSyntax());
            syntaxViewer.refresh();//  w ww  . j  av  a2 s .c  o m
        }
    }
}

From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.preferences.ValueEditorsPreferencePage.java

License:Apache License

private void editAttribute() {
    StructuredSelection sel = (StructuredSelection) attributeViewer.getSelection();
    if (!sel.isEmpty()) {
        AttributeValueEditorRelation relation = (AttributeValueEditorRelation) sel.getFirstElement();
        AttributeValueEditorDialog dialog = new AttributeValueEditorDialog(getShell(), relation,
                class2ValueEditorExtensionMap, attributeTypesAndOids);
        if (dialog.open() == AttributeValueEditorDialog.OK) {
            int index = attributeList.indexOf(relation);
            attributeList.set(index, dialog.getRelation());
            attributeViewer.refresh();/* ww w  .ja  va 2 s.co m*/
        }
    }
}

From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.preferences.ValueEditorsPreferencePage.java

License:Apache License

private void editSyntax() {
    StructuredSelection sel = (StructuredSelection) syntaxViewer.getSelection();
    if (!sel.isEmpty()) {
        SyntaxValueEditorRelation relation = (SyntaxValueEditorRelation) sel.getFirstElement();
        SyntaxValueEditorDialog dialog = new SyntaxValueEditorDialog(getShell(), relation,
                class2ValueEditorExtensionMap, syntaxDescsAndOids);
        if (dialog.open() == SyntaxValueEditorDialog.OK) {
            int index = syntaxList.indexOf(relation);
            syntaxList.set(index, dialog.getRelation());
            syntaxViewer.refresh();//w  ww. j  a v a 2s  .co m
        }
    }
}

From source file:org.apache.directory.studio.ldapbrowser.ui.actions.EntryEditorMenuManager.java

License:Apache License

/**
 * Gets the currently selected entry./*from w  w  w.ja  va 2  s . c om*/
 *
 * @return
 *      the currently selected entry
 */
private IEntry getCurrentSelection() {
    StructuredSelection structuredSelection = (StructuredSelection) selectionProvider.getSelection();
    if (!structuredSelection.isEmpty()) {
        Object selection = structuredSelection.getFirstElement();
        if (selection instanceof IEntry) {
            return (IEntry) selection;
        } else if (selection instanceof ISearchResult) {
            return ((ISearchResult) selection).getEntry();
        } else if (selection instanceof IBookmark) {
            return ((IBookmark) selection).getEntry();
        }
    }

    return null;
}

From source file:org.apache.directory.studio.ldapservers.actions.OpenConfigurationAction.java

License:Apache License

/**
 * {@inheritDoc}//from   ww w  .j ava2 s  . c  o  m
 */
public void run() {
    if (view != null) {
        // Getting the selection
        StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection();
        if ((!selection.isEmpty()) && (selection.size() == 1)) {
            // Getting the server
            LdapServer server = (LdapServer) selection.getFirstElement();

            // Creating and scheduling the job to start the server
            StudioLdapServerJob job = new StudioLdapServerJob(new OpenConfigurationLdapServerRunnable(server));
            job.schedule();
        }
    }
}