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.DeleteSchemaElementAction.java

License:Apache License

/**
 * {@inheritDoc}/*from   www .ja va  2 s .c o  m*/
 */
public void run() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();

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

        int count = selection.size();

        if (count == 1) {
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof AttributeTypeWrapper) {
                message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteAttributeType")); //$NON-NLS-1$
            } else if (firstElement instanceof ObjectClassWrapper) {
                message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteObjectClass")); //$NON-NLS-1$
            } else if (firstElement instanceof SchemaWrapper) {
                message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteSchema")); //$NON-NLS-1$
            } else {
                message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteItem")); //$NON-NLS-1$
            }
        } else {
            message.append(NLS.bind(Messages.getString("DeleteSchemaElementAction.SureDeleteItems"), //$NON-NLS-1$
                    new Object[] { count }));
        }

        // Showing the confirmation window
        if (MessageDialog.openConfirm(viewer.getControl().getShell(),
                Messages.getString("DeleteSchemaElementAction.DeleteTitle"), message.toString())) //$NON-NLS-1$
        {
            Map<String, Schema> schemasMap = new HashMap<String, Schema>();
            List<SchemaObject> schemaObjectsList = new ArrayList<SchemaObject>();

            for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
                Object selectedItem = iterator.next();
                if (selectedItem instanceof SchemaWrapper) {
                    Schema schema = ((SchemaWrapper) selectedItem).getSchema();
                    schemasMap.put(Strings.toLowerCase(schema.getSchemaName()), schema);
                } else if (selectedItem instanceof AttributeTypeWrapper) {
                    AttributeType at = ((AttributeTypeWrapper) selectedItem).getAttributeType();
                    schemaObjectsList.add(at);
                } else if (selectedItem instanceof ObjectClassWrapper) {
                    ObjectClass oc = ((ObjectClassWrapper) selectedItem).getObjectClass();
                    schemaObjectsList.add(oc);
                }
            }

            SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
            // Removing schema objects
            for (SchemaObject schemaObject : schemaObjectsList) {
                if (!schemasMap.containsKey(Strings.toLowerCase(schemaObject.getSchemaName()))) {
                    // If the schema object is not part of deleted schema, we need to delete it.
                    // But, we don't delete schema objects that are part of a deleted schema, since
                    // deleting the schema will also delete this schema object.
                    if (schemaObject instanceof AttributeType) {
                        schemaHandler.removeAttributeType((AttributeType) schemaObject);
                    } else if (schemaObject instanceof ObjectClass) {
                        schemaHandler.removeObjectClass((ObjectClass) schemaObject);
                    }
                }
            }

            // Removing schemas
            for (Schema schema : schemasMap.values()) {
                schemaHandler.removeSchema(schema);
            }
        }
    }
}

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

License:Apache License

/**
 * {@inheritDoc}/*www  .  j  a v  a2 s .  c  o m*/
 */
public void run() {
    List<Project> selectedProjects = new ArrayList<Project>();
    // Getting the selection
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() > 0)) {
        for (Iterator<?> i = selection.iterator(); i.hasNext();) {
            selectedProjects.add(((ProjectWrapper) i.next()).getProject());
        }
    }

    // Instantiates and initializes the wizard
    ExportProjectsWizard wizard = new ExportProjectsWizard();
    wizard.setSelectedProjects(selectedProjects.toArray(new Project[0]));
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            wizard);
    dialog.create();
    dialog.open();
}

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

License:Apache License

/**
 * {@inheritDoc}//w ww.j ava2  s .c  o m
 */
public void run() {
    List<Schema> selectedSchemas = new ArrayList<Schema>();
    // Getting the selection
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() > 0)) {
        for (Iterator<?> i = selection.iterator(); i.hasNext();) {
            Object o = i.next();
            if (o instanceof SchemaWrapper) {
                selectedSchemas.add(((SchemaWrapper) o).getSchema());
            }
        }
    }

    // Instantiates and initializes the wizard
    ExportSchemasAsOpenLdapWizard wizard = new ExportSchemasAsOpenLdapWizard();
    wizard.setSelectedSchemas(selectedSchemas.toArray(new Schema[0]));
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            wizard);
    dialog.create();
    dialog.open();
}

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

License:Apache License

/**
 * {@inheritDoc}/*  w  w w .  ja  v  a  2s  .com*/
 */
public void run() {
    List<Schema> selectedSchemas = new ArrayList<Schema>();
    // Getting the selection
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() > 0)) {
        for (Iterator<?> i = selection.iterator(); i.hasNext();) {
            Object o = i.next();
            if (o instanceof SchemaWrapper) {
                selectedSchemas.add(((SchemaWrapper) o).getSchema());
            }
        }
    }

    // Instantiates and initializes the wizard
    ExportSchemasAsXmlWizard wizard = new ExportSchemasAsXmlWizard();
    wizard.setSelectedSchemas(selectedSchemas.toArray(new Schema[0]));
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            wizard);
    dialog.create();
    dialog.open();
}

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

License:Apache License

/**
 * {@inheritDoc}//from   w w  w  . ja va 2  s  .com
 */
public void run() {
    List<Schema> selectedSchemas = new ArrayList<Schema>();
    // Getting the selection
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() > 0)) {
        for (Iterator<?> i = selection.iterator(); i.hasNext();) {
            Object o = i.next();
            if (o instanceof SchemaWrapper) {
                selectedSchemas.add(((SchemaWrapper) o).getSchema());
            }
        }
    }

    // Instantiates and initializes the wizard
    ExportSchemasForADSWizard wizard = new ExportSchemasForADSWizard();
    wizard.setSelectedSchemas(selectedSchemas.toArray(new Schema[0]));
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            wizard);
    dialog.create();
    dialog.open();
}

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

License:Apache License

/**
 * {@inheritDoc}/*from  www .j  a  va 2  s. c o  m*/
 */
public void run() {
    // Getting the selection
    Schema selectedSchema = null;

    int presentation = Activator.getDefault().getPreferenceStore()
            .getInt(PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION);
    if (presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT) {
        StructuredSelection selection = (StructuredSelection) viewer.getSelection();
        if ((!selection.isEmpty()) && (selection.size() == 1)) {
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof SchemaWrapper) {
                selectedSchema = ((SchemaWrapper) firstElement).getSchema();
            } else if (firstElement instanceof Folder) {
                selectedSchema = ((SchemaWrapper) ((Folder) firstElement).getParent()).getSchema();
            } else if (firstElement instanceof AttributeTypeWrapper) {
                TreeNode parent = ((AttributeTypeWrapper) firstElement).getParent();

                if (parent instanceof Folder) {
                    selectedSchema = ((SchemaWrapper) ((Folder) parent).getParent()).getSchema();

                } else if (parent instanceof SchemaWrapper) {
                    selectedSchema = ((SchemaWrapper) parent).getSchema();
                }
            } else if (firstElement instanceof ObjectClassWrapper) {
                TreeNode parent = ((ObjectClassWrapper) firstElement).getParent();

                if (parent instanceof Folder) {
                    selectedSchema = ((SchemaWrapper) ((Folder) parent).getParent()).getSchema();
                } else if (parent instanceof SchemaWrapper) {
                    selectedSchema = ((SchemaWrapper) parent).getSchema();
                }
            }
        }
    }

    // Instantiates and initializes the wizard
    NewAttributeTypeWizard wizard = new NewAttributeTypeWizard();
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    wizard.setSelectedSchema(selectedSchema);
    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            wizard);
    dialog.create();
    dialog.open();
}

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

License:Apache License

/**
 * {@inheritDoc}/*from   w w  w  .  j a  v a  2  s . c  om*/
 */
public void run() {
    // Getting the selection
    Schema selectedSchema = null;

    int presentation = Activator.getDefault().getPreferenceStore()
            .getInt(PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION);
    if (presentation == PluginConstants.PREFS_SCHEMA_VIEW_SCHEMA_PRESENTATION_FLAT) {
        StructuredSelection selection = (StructuredSelection) viewer.getSelection();
        if ((!selection.isEmpty()) && (selection.size() == 1)) {
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof SchemaWrapper) {
                selectedSchema = ((SchemaWrapper) firstElement).getSchema();
            } else if (firstElement instanceof Folder) {
                selectedSchema = ((SchemaWrapper) ((Folder) firstElement).getParent()).getSchema();
            } else if (firstElement instanceof AttributeTypeWrapper) {
                TreeNode parent = ((AttributeTypeWrapper) firstElement).getParent();

                if (parent instanceof Folder) {
                    selectedSchema = ((SchemaWrapper) ((Folder) parent).getParent()).getSchema();

                } else if (parent instanceof SchemaWrapper) {
                    selectedSchema = ((SchemaWrapper) parent).getSchema();
                }
            } else if (firstElement instanceof ObjectClassWrapper) {
                TreeNode parent = ((ObjectClassWrapper) firstElement).getParent();

                if (parent instanceof Folder) {
                    selectedSchema = ((SchemaWrapper) ((Folder) parent).getParent()).getSchema();
                } else if (parent instanceof SchemaWrapper) {
                    selectedSchema = ((SchemaWrapper) parent).getSchema();
                }
            }
        }
    }

    // Instantiates and initializes the wizard
    NewObjectClassWizard wizard = new NewObjectClassWizard();
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    wizard.setSelectedSchema(selectedSchema);
    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            wizard);
    dialog.create();
    dialog.open();
}

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

License:Apache License

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

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

License:Apache License

/**
 * {@inheritDoc}/*w  w  w . ja v  a  2 s . co  m*/
 */
public void run() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() == 1)) {
        projectsHandler.openProject(((ProjectWrapper) selection.getFirstElement()).getProject());
    }

}

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

License:Apache License

/**
 * {@inheritDoc}/*from w w  w  . j  a  v  a  2  s  .c  om*/
 */
public void run() {
    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
    if ((!selection.isEmpty()) && (selection.size() == 1)) {
        Project project = ((ProjectWrapper) selection.getFirstElement()).getProject();
        RenameProjectDialog dialog = new RenameProjectDialog(project.getName());
        if (dialog.open() == Dialog.OK) {
            projectsHandler.renameProject(project, dialog.getNewName());
        }
    }
}