List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionsMasterDetailsBlock.java
License:Apache License
/** * Add listeners to UI fields./*ww w . j ava2s. c om*/ */ private void addListeners() { viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { viewer.refresh(); // Getting the selection of the table viewer StructuredSelection selection = (StructuredSelection) viewer.getSelection(); // Delete button is enabled when something is selected deleteButton.setEnabled(!selection.isEmpty()); // Delete button is not enabled in the case of the system partition if (!selection.isEmpty()) { PartitionWrapper partitionWrapper = (PartitionWrapper) selection.getFirstElement(); if (PartitionsPage.isSystemPartition(partitionWrapper.getPartition())) { deleteButton.setEnabled(false); } } } }); addButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addNewPartition(); } }); deleteButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { deleteSelectedPartition(); } }); }
From source file:org.apache.directory.studio.apacheds.configuration.editor.PartitionsMasterDetailsBlock.java
License:Apache License
/** * This method is called when the 'Delete' button is clicked. *///from ww w .j av a 2 s .co m private void deleteSelectedPartition() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { PartitionWrapper partitionWrapper = (PartitionWrapper) selection.getFirstElement(); PartitionBean partition = partitionWrapper.getPartition(); if (!PartitionsPage.isSystemPartition(partition)) { if (MessageDialog.openConfirm(page.getManagedForm().getForm().getShell(), Messages.getString("PartitionsMasterDetailsBlock.ConfirmDelete"), //$NON-NLS-1$ NLS.bind(Messages.getString("PartitionsMasterDetailsBlock.AreYouSureDeletePartition"), //$NON-NLS-1$ partition.getPartitionId(), partition.getPartitionSuffix()))) { partitionWrappers.remove(partitionWrapper); setEditorDirty(); } } } }
From source file:org.apache.directory.studio.apacheds.configuration.editor.PasswordPoliciesMasterDetailsBlock.java
License:Apache License
/** * Add listeners to UI fields./*from w w w. j av a 2s.co m*/ */ private void addListeners() { viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { viewer.refresh(); // Getting the selection of the table viewer StructuredSelection selection = (StructuredSelection) viewer.getSelection(); // Delete button is enabled when something is selected deleteButton.setEnabled(!selection.isEmpty()); // Delete button is not enabled in the case of the system partition if (!selection.isEmpty()) { PasswordPolicyBean passwordPolicy = (PasswordPolicyBean) selection.getFirstElement(); if (PasswordPoliciesPage.isDefaultPasswordPolicy(passwordPolicy)) { deleteButton.setEnabled(false); } } } }); addButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addNewPasswordPolicy(); } }); deleteButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { deleteSelectedPasswordPolicy(); } }); }
From source file:org.apache.directory.studio.apacheds.configuration.editor.PasswordPoliciesMasterDetailsBlock.java
License:Apache License
/** * This method is called when the 'Delete' button is clicked. */// w w w. j ava 2s .co m private void deleteSelectedPasswordPolicy() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { PasswordPolicyBean passwordPolicy = (PasswordPolicyBean) selection.getFirstElement(); if (!PasswordPoliciesPage.isDefaultPasswordPolicy(passwordPolicy)) { if (MessageDialog.openConfirm(page.getManagedForm().getForm().getShell(), Messages.getString("PasswordPoliciesMasterDetailsBlock.ConfirmDelete"), //$NON-NLS-1$ NLS.bind( Messages.getString( "PasswordPoliciesMasterDetailsBlock.AreYouSureDeletePasswordPolicy"), //$NON-NLS-1$ passwordPolicy.getPwdId()))) { getAuthenticationInterceptor().removePasswordPolicies(passwordPolicy); setEditorDirty(); } } } }
From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationDetailsPage.java
License:Apache License
/** * Opens an attribute dialog with the selected attribute in the attributes table viewer. *//*w ww . ja v a2 s . co m*/ private void editSelectedAttribute() { StructuredSelection selection = (StructuredSelection) attributesTableViewer.getSelection(); if (!selection.isEmpty()) { String attribute = (String) selection.getFirstElement(); AttributeDialog dialog = new AttributeDialog(addAttributeButton.getShell()); dialog.setEditedElement(new StringValueWrapper(attribute, false)); dialog.setAttributeNamesAndOids(attributeLoader.getAttributeNamesAndOids()); if (AttributeDialog.OK == dialog.open()) { attributesList.remove(attribute); String newAttribute = dialog.getEditedElement().getValue(); if (!attributesList.contains(newAttribute)) { attributesList.add(newAttribute); } attributesTableViewer.refresh(); attributesTableViewer.setSelection(new StructuredSelection(newAttribute)); masterDetailsBlock.setEditorDirty(); } } }
From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationDetailsPage.java
License:Apache License
/** * Deletes the selected index in the indexes table viewer. *//* ww w . j ava2 s . c om*/ private void deleteSelectedAttribute() { StructuredSelection selection = (StructuredSelection) attributesTableViewer.getSelection(); if (!selection.isEmpty()) { String attribute = (String) selection.getFirstElement(); attributesList.remove(attribute); attributesTableViewer.refresh(); masterDetailsBlock.setEditorDirty(); } }
From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationMasterDetailsBlock.java
License:Apache License
/** * Add listeners to UI fields./*from w w w. j a va 2s .co m*/ */ private void addListeners() { viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { viewer.refresh(); // Getting the selection of the table viewer StructuredSelection selection = (StructuredSelection) viewer.getSelection(); // Delete button is enabled when something is selected deleteButton.setEnabled(!selection.isEmpty()); } }); addButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addNewConsumer(); } }); deleteButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { deleteSelectedConsumer(); } }); }
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.j a v a 2 s. com 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 'Add...' button is clicked. *//*from w w w .j av a 2 s . c o m*/ private void addElement() { AddEditDialog<E> dialog = decorator.getDialog(); dialog.setAdd(); dialog.addNewElement(); dialog.setElements(elements); // Inject the position if we have a selected value StructuredSelection selection = (StructuredSelection) elementTableViewer.getSelection(); int insertionPos = elements.size(); if (!selection.isEmpty()) { insertionPos = elementTableViewer.getTable().getSelectionIndex(); } // Open the Dialog, and process the addition if it went fine if (decorator.getDialog().open() == Dialog.OK) { E newElement = decorator.getDialog().getEditedElement(); if (!elements.contains(newElement)) { String elementStr = newElement.toString(); int pos = 0; if (isOrdered) { // The table is ordered, insert the element at the right position ((OrderedElement) newElement).setPrefix(insertionPos); elements.add(insertionPos, newElement); // Move up the following elements for (int i = insertionPos + 1; i < elements.size(); i++) { E element = elements.get(i); ((OrderedElement) element).incrementPrefix(); } } else { if (selection.isEmpty()) { // no selected element, add at the end pos = elements.size(); } else { pos = elementTableViewer.getTable().getSelectionIndex() + 1; } elements.add(pos, newElement); } elementTableViewer.refresh(); elementTableViewer.setSelection(new StructuredSelection(elementStr)); } notifyListeners(); } }
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. *///from w ww . jav a 2 s. c om 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(); } } }