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.schemaeditor.controller.actions.RenameSchemaElementAction.java

License:Apache License

/**
 * {@inheritDoc}//  w ww  . ja  v  a  2  s.c om
 */
public void run() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() == 1)) {
        Object selectedElement = selection.getFirstElement();

        // Saving all dirty editors before processing the renaming
        if (EditorsUtils.saveAllDirtyEditors()) {
            // SCHEMA
            if (selectedElement instanceof SchemaWrapper) {
                Schema schema = ((SchemaWrapper) selectedElement).getSchema();

                RenameSchemaDialog dialog = new RenameSchemaDialog(schema.getSchemaName());
                if (dialog.open() == RenameSchemaDialog.OK) {
                    Activator.getDefault().getSchemaHandler().renameSchema(schema, dialog.getNewName());
                }
            }
            // ATTRIBUTE TYPE
            else if (selectedElement instanceof AttributeTypeWrapper) {
                MutableAttributeType attributeType = (MutableAttributeType) ((AttributeTypeWrapper) selectedElement)
                        .getAttributeType();

                RenameAttributeTypeDialog dialog = new RenameAttributeTypeDialog(attributeType.getNames());
                if (dialog.open() == RenameAttributeTypeDialog.OK) {
                    MutableAttributeType modifiedAttributeType = PluginUtils.getClone(attributeType);
                    modifiedAttributeType.setNames(dialog.getAliases());
                    Activator.getDefault().getSchemaHandler().modifyAttributeType(attributeType,
                            modifiedAttributeType);
                }
            }
            // OBJECT CLASS
            else if (selectedElement instanceof ObjectClassWrapper) {
                MutableObjectClass objectClass = (MutableObjectClass) ((ObjectClassWrapper) selectedElement)
                        .getObjectClass();

                RenameObjectClassDialog dialog = new RenameObjectClassDialog(objectClass.getNames());
                if (dialog.open() == RenameObjectClassDialog.OK) {
                    ObjectClass modifiedObjectClass = PluginUtils.getClone(objectClass);
                    modifiedObjectClass.setNames(dialog.getAliases());
                    Activator.getDefault().getSchemaHandler().modifyObjectClass(objectClass,
                            modifiedObjectClass);
                }
            }
        }
    }
}

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

License:Apache License

/**
 * Initializes the DoubleClickListener.//from  ww w .j av a2  s. com
 */
private void initDoubleClickListener() {
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();

            if ((!selection.isEmpty()) && (selection.size() == 1)) {
                Project project = ((ProjectWrapper) selection.getFirstElement()).getProject();
                if (project.getState().equals(ProjectState.CLOSED)) {
                    projectsHandler.openProject(project);
                }
            }
        }
    });
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w w . ja va2  s  .  c  om*/
 */
protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    composite.setLayout(layout);

    Label chooseLabel = new Label(composite, SWT.NONE);
    chooseLabel.setText(Messages.getString("AttributeTypeSelectionDialog.ChooseAType")); //$NON-NLS-1$
    chooseLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    searchText = new Text(composite, SWT.BORDER | SWT.SEARCH);
    searchText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    searchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setSearchInput(searchText.getText());
        }
    });
    searchText.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                attributeTypesTable.setFocus();
            }
        }
    });

    Label matchingLabel = new Label(composite, SWT.NONE);
    matchingLabel.setText(Messages.getString("AttributeTypeSelectionDialog.MatchingTypes")); //$NON-NLS-1$
    matchingLabel.setLayoutData(new GridData(SWT.FILL, SWT.None, true, false));

    attributeTypesTable = new Table(composite,
            SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 148;
    gridData.minimumHeight = 148;
    gridData.widthHint = 350;
    gridData.minimumWidth = 350;
    attributeTypesTable.setLayoutData(gridData);
    attributeTypesTable.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent e) {
            if (attributeTypesTable.getSelectionIndex() != -1) {
                okPressed();
            }
        }
    });

    attributeTypesTableViewer = new TableViewer(attributeTypesTable);
    attributeTypesTableViewer
            .setContentProvider(new AttributeTypeSelectionDialogContentProvider(hiddenAttributeTypes));
    attributeTypesTableViewer
            .setLabelProvider(new DecoratingLabelProvider(new AttributeTypeSelectionDialogLabelProvider(),
                    Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
    attributeTypesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) attributeTypesTableViewer.getSelection();
            if (selection.isEmpty()) {
                if ((chooseButton != null) && (!chooseButton.isDisposed())) {
                    chooseButton.setEnabled(false);
                }
                schemaIconLabel
                        .setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16));
                schemaNameLabel.setText(""); //$NON-NLS-1$
            } else {
                if ((chooseButton != null) && (!chooseButton.isDisposed())) {
                    chooseButton.setEnabled(true);
                }
                schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_SCHEMA));
                schemaNameLabel.setText(((AttributeType) selection.getFirstElement()).getSchemaName());
            }
        }
    });

    // Schema Composite
    Composite schemaComposite = new Composite(composite, SWT.BORDER);
    schemaComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    GridLayout schemaCompositeGridLayout = new GridLayout(2, false);
    schemaCompositeGridLayout.horizontalSpacing = 0;
    schemaCompositeGridLayout.verticalSpacing = 0;
    schemaCompositeGridLayout.marginWidth = 2;
    schemaCompositeGridLayout.marginHeight = 2;
    schemaComposite.setLayout(schemaCompositeGridLayout);

    // Schema Icon Label
    schemaIconLabel = new Label(schemaComposite, SWT.NONE);
    GridData schemaIconLabelGridData = new GridData(SWT.NONE, SWT.BOTTOM, false, false);
    schemaIconLabelGridData.widthHint = 18;
    schemaIconLabelGridData.heightHint = 16;
    schemaIconLabel.setLayoutData(schemaIconLabelGridData);
    schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16));

    // Schema Name Label
    schemaNameLabel = new Label(schemaComposite, SWT.NONE);
    schemaNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
    schemaNameLabel.setText(""); //$NON-NLS-1$

    // We need to force the input to load the complete list of attribute types
    setSearchInput(""); //$NON-NLS-1$

    return composite;
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w  w  .j  a v a  2 s .co  m*/
 */
protected void createButtonsForButtonBar(Composite parent) {
    chooseButton = createButton(parent, IDialogConstants.OK_ID,
            Messages.getString("AttributeTypeSelectionDialog.Choose"), true); //$NON-NLS-1$
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);

    StructuredSelection selection = (StructuredSelection) attributeTypesTableViewer.getSelection();
    if (selection.isEmpty()) {
        if ((chooseButton != null) && (!chooseButton.isDisposed())) {
            chooseButton.setEnabled(false);
        }
    } else {
        if ((chooseButton != null) && (!chooseButton.isDisposed())) {
            chooseButton.setEnabled(true);
        }
    }
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog.java

License:Apache License

/**
 * {@inheritDoc}//w ww .ja v  a2s  .c om
 */
protected void okPressed() {
    StructuredSelection selection = (StructuredSelection) attributeTypesTableViewer.getSelection();
    if (selection.isEmpty()) {
        MessageDialog.openError(getShell(), Messages.getString("AttributeTypeSelectionDialog.InvalidSelection"), //$NON-NLS-1$
                Messages.getString("AttributeTypeSelectionDialog.MustChooseType")); //$NON-NLS-1$
        return;
    } else {
        selectedAttributeType = (AttributeType) selection.getFirstElement();
    }

    super.okPressed();
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w w. jav  a  2 s .  c  o  m*/
 */
protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, false);
    composite.setLayout(layout);

    Label chooseLabel = new Label(composite, SWT.NONE);
    chooseLabel.setText(Messages.getString("ObjectClassSelectionDialog.ChooseClass")); //$NON-NLS-1$
    chooseLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    searchText = new Text(composite, SWT.BORDER | SWT.SEARCH);
    searchText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    searchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setSearchInput(searchText.getText());
        }
    });
    searchText.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                objectClassesTable.setFocus();
            }
        }
    });

    Label matchingLabel = new Label(composite, SWT.NONE);
    matchingLabel.setText(Messages.getString("ObjectClassSelectionDialog.MatchingClasses")); //$NON-NLS-1$
    matchingLabel.setLayoutData(new GridData(SWT.FILL, SWT.None, true, false));

    objectClassesTable = new Table(composite,
            SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 148;
    gridData.minimumHeight = 148;
    gridData.widthHint = 350;
    gridData.minimumWidth = 350;
    objectClassesTable.setLayoutData(gridData);
    objectClassesTable.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent e) {
            if (objectClassesTable.getSelectionIndex() != -1) {
                okPressed();
            }
        }
    });

    objectClassesTableViewer = new TableViewer(objectClassesTable);
    objectClassesTableViewer
            .setContentProvider(new ObjectClassSelectionDialogContentProvider(hiddenObjectClasses));
    objectClassesTableViewer
            .setLabelProvider(new DecoratingLabelProvider(new ObjectClassSelectionDialogLabelProvider(),
                    Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
    objectClassesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) objectClassesTableViewer.getSelection();
            if (selection.isEmpty()) {
                if ((chooseButton != null) && (!chooseButton.isDisposed())) {
                    chooseButton.setEnabled(false);
                }
                schemaIconLabel
                        .setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16));
                schemaNameLabel.setText(""); //$NON-NLS-1$
            } else {
                if ((chooseButton != null) && (!chooseButton.isDisposed())) {
                    chooseButton.setEnabled(true);
                }
                schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_SCHEMA));
                schemaNameLabel.setText(((ObjectClass) selection.getFirstElement()).getSchemaName());
            }
        }
    });

    // Schema Composite
    Composite schemaComposite = new Composite(composite, SWT.BORDER);
    schemaComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    GridLayout schemaCompositeGridLayout = new GridLayout(2, false);
    schemaCompositeGridLayout.horizontalSpacing = 0;
    schemaCompositeGridLayout.verticalSpacing = 0;
    schemaCompositeGridLayout.marginWidth = 2;
    schemaCompositeGridLayout.marginHeight = 2;
    schemaComposite.setLayout(schemaCompositeGridLayout);

    // Schema Icon Label
    schemaIconLabel = new Label(schemaComposite, SWT.NONE);
    GridData schemaIconLabelGridData = new GridData(SWT.NONE, SWT.BOTTOM, false, false);
    schemaIconLabelGridData.widthHint = 18;
    schemaIconLabelGridData.heightHint = 16;
    schemaIconLabel.setLayoutData(schemaIconLabelGridData);
    schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16));

    // Schema Name Label
    schemaNameLabel = new Label(schemaComposite, SWT.NONE);
    schemaNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
    schemaNameLabel.setText(""); //$NON-NLS-1$

    // We need to force the input to load the complete list of attribute types
    setSearchInput(""); //$NON-NLS-1$

    return composite;
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog.java

License:Apache License

/**
 * {@inheritDoc}//from   w ww  .j  av  a 2 s. c o  m
 */
protected void createButtonsForButtonBar(Composite parent) {
    chooseButton = createButton(parent, IDialogConstants.OK_ID,
            Messages.getString("ObjectClassSelectionDialog.Choose"), true); //$NON-NLS-1$
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);

    StructuredSelection selection = (StructuredSelection) objectClassesTableViewer.getSelection();
    if (selection.isEmpty()) {
        if ((chooseButton != null) && (!chooseButton.isDisposed())) {
            chooseButton.setEnabled(false);
        }
    } else {
        if ((chooseButton != null) && (!chooseButton.isDisposed())) {
            chooseButton.setEnabled(true);
        }
    }
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog.java

License:Apache License

/**
 * {@inheritDoc}//  w  ww  .j ava2 s  . co m
 */
protected void okPressed() {
    StructuredSelection selection = (StructuredSelection) objectClassesTableViewer.getSelection();

    if (selection.isEmpty()) {
        MessageDialog.openError(getShell(), Messages.getString("ObjectClassSelectionDialog.InvalidSelection"), //$NON-NLS-1$
                Messages.getString("ObjectClassSelectionDialog.MustChooseClass")); //$NON-NLS-1$
        return;
    } else {
        selectedObjectClass = (ObjectClass) selection.getFirstElement();
    }

    super.okPressed();
}

From source file:org.apache.directory.studio.schemaeditor.view.views.SearchView.java

License:Apache License

/**
 * Open the editor associated with the current selection in the table.
 *//* www  .jav  a2s  .co  m*/
private void openEditor() {
    if (Activator.getDefault().getSchemaHandler() != null) {
        StructuredSelection selection = (StructuredSelection) resultsTableViewer.getSelection();

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

            IEditorInput input = null;
            String editorId = null;

            // Here is the double clicked item
            if (item instanceof AttributeType) {
                input = new AttributeTypeEditorInput((AttributeType) item);
                editorId = AttributeTypeEditor.ID;
            } else if (item instanceof ObjectClass) {
                input = new ObjectClassEditorInput((MutableObjectClass) item);
                editorId = ObjectClassEditor.ID;
            }

            // Let's open the editor
            if (input != null) {
                try {
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input,
                            editorId);
                } catch (PartInitException exception) {
                    PluginUtils.logError(Messages.getString("SearchView.ErrorOpeningEditor"), exception); //$NON-NLS-1$
                    ViewUtils.displayErrorMessageDialog(Messages.getString("SearchView.Error"), //$NON-NLS-1$
                            Messages.getString("SearchView.ErrorOpeningEditor")); //$NON-NLS-1$
                }
            }
        }
    }
}

From source file:org.apache.directory.studio.schemaeditor.view.wizards.NewAttributeTypeContentWizardPage.java

License:Apache License

/**
 * Gets the usage value.//from w  w  w. j a  v a  2  s. c  o m
 *
 * @return
 *      the usage value
 */
public UsageEnum getUsageValue() {
    StructuredSelection selection = (StructuredSelection) usageComboViewer.getSelection();
    if (!selection.isEmpty()) {
        String selectedUsage = (String) selection.getFirstElement();
        if (selectedUsage.equals(Messages.getString("NewAttributeTypeContentWizardPage.DirectoryOperation"))) //$NON-NLS-1$
        {
            return UsageEnum.DIRECTORY_OPERATION;
        } else if (selectedUsage
                .equals(Messages.getString("NewAttributeTypeContentWizardPage.DistributedOperation"))) //$NON-NLS-1$
        {
            return UsageEnum.DISTRIBUTED_OPERATION;
        } else if (selectedUsage.equals(Messages.getString("NewAttributeTypeContentWizardPage.DSAOperation"))) //$NON-NLS-1$
        {
            return UsageEnum.DSA_OPERATION;
        } else if (selectedUsage
                .equals(Messages.getString("NewAttributeTypeContentWizardPage.UserApplications"))) //$NON-NLS-1$
        {
            return UsageEnum.USER_APPLICATIONS;
        } else {
            return UsageEnum.USER_APPLICATIONS;
        }
    } else {
        return UsageEnum.USER_APPLICATIONS;
    }
}