List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationMasterDetailsBlock.java
License:Apache License
/** * This method is called when the 'Delete' button is clicked. *///from ww w .jav a 2 s. c o m private void deleteSelectedConsumer() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { ReplConsumerBean consumer = (ReplConsumerBean) selection.getFirstElement(); if (MessageDialog.openConfirm(page.getManagedForm().getForm().getShell(), "Confirm Delete", NLS.bind("Are you sure you want to delete replication consumer ''{0}''?", consumer.getReplConsumerId()))) { page.getConfigBean().getDirectoryServiceBean().getLdapServerBean().getReplConsumers() .remove(consumer); setEditorDirty(); } } }
From source file:org.apache.directory.studio.common.ui.widgets.TableWidget.java
License:Apache License
/** * This method is called when the 'Edit...' button is clicked * or the table viewer is double-clicked. *///ww w . ja v a 2 s. c o m private void editElement() { StructuredSelection selection = (StructuredSelection) elementTableViewer.getSelection(); if (!selection.isEmpty()) { AddEditDialog<E> dialog = decorator.getDialog(); dialog.setEdit(); E selectedElement = (E) selection.getFirstElement(); int editPosition = elementTableViewer.getTable().getSelectionIndex(); dialog.setEditedElement(selectedElement); dialog.setSelectedPosition(editPosition); // Open the element dialog, with the selected index if (decorator.getDialog().open() == Dialog.OK) { E newElement = dialog.getEditedElement(); if (!isOrdered) { // Check to see if the modified element does not already exist if (elements.contains(newElement)) { // Remove the original element elements.remove(selectedElement); // Replace the existing element with the new one elements.remove(newElement); int pos = 0; for (E element : elements) { if (decorator.compare(element, newElement) > 0) { break; } else { pos++; } } elements.add(pos, newElement); } else { // We will remove the modified element, and replace it with the new element // Replace the old element by the new one elements.remove(editPosition); elements.add(editPosition, newElement); } } else { // Remove the original element elements.remove(selectedElement); elements.add(editPosition, newElement); } elementTableViewer.refresh(); elementTableViewer.setSelection(new StructuredSelection(newElement.toString())); 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 . ja v a 2 s.c o 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. *//*from w w w.jav 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.//from w w w . j a v a2 s .co 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 av 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();/*from w w w. j a v a 2s . co 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();//from ww w. j a 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();/*from w w w. jav a 2s.c o m*/ } } }
From source file:org.apache.directory.studio.ldapbrowser.ui.actions.EntryEditorMenuManager.java
License:Apache License
/** * Gets the currently selected entry.//w w w .java2s . c o m * * @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; }