Example usage for org.eclipse.jface.viewers IStructuredSelection iterator

List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection iterator.

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:eu.geclipse.jsdl.ui.adapters.jsdl.ResourcesTypeAdapter.java

License:Open Source License

protected void performDelete(final TableViewer viewer) {

    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    if (structSelection != null) {

        Iterator<?> it = structSelection.iterator();

        /*//from  www  . ja  v  a 2  s . c  o m
         * Iterate over the selections and delete them from the model.
         */
        while (it.hasNext()) {

            Object feature = it.next();

            try {
                /* Delete only Multi-Valued Elements */

                if (!this.adapterRefreshed) {

                    /*
                     * Check the instance of the Selection.
                     */
                    if (feature instanceof String) {

                        /*
                         * If this feature is an instance of String then, this 
                         * is a CandidateHosts instance. Therefore, remove the
                         * CandidataHosts instance.
                         */

                        this.candidateHosts.getHostName().remove(feature);

                        if (this.candidateHosts.getHostName().size() == 0) {

                            EcoreUtil.remove(this.candidateHosts);

                            checkResourcesElement();

                        }
                    }

                    /*
                     * Then this is a FileSystem instance, so we have to remove
                     * the instance from the parent( ResourceType ) object.
                     */
                    else {
                        this.resourcesType.getFileSystem().remove(feature);
                        if (this.resourcesType.getFileSystem().size() == 0) {
                            EcoreUtil.remove(this.fileSystemType);
                            checkResourcesElement();

                        }

                    }

                    contentChanged();

                } else {
                    viewer.remove(feature);
                }

            } //end try
            catch (Exception e) {
                Activator.logException(e);
            }

            /*
             * Refresh the table viewer and notify the editor that the page content has
             * changed.
             */
            viewer.refresh();

        } // end While

    } // end_if

}

From source file:eu.geclipse.jsdl.ui.adapters.posix.PosixApplicationTypeAdapter.java

License:Open Source License

protected void performDelete(final TableViewer viewer) {

    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    Iterator<?> it = structSelection.iterator();

    /*/*from  w  ww .  ja va2s.  c  o  m*/
     * Iterate over the selections and delete them from the model.
     */
    while (it.hasNext()) {

        Object feature = it.next();

        if (feature instanceof ArgumentType) {

            ArgumentType argument = (ArgumentType) feature;

            try {
                EcoreUtil.remove(argument);

            } catch (Exception e) {
                Activator.logException(e);
            }

        } //end ArgumentType
        else if (feature instanceof EnvironmentType) {
            EnvironmentType environment = (EnvironmentType) feature;

            try {
                EcoreUtil.remove(environment);
                viewer.setInput(this.posixApplicationType.getEnvironment());
            } catch (Exception e) {
                Activator.logException(e);
            }

        } // end EnvironmentType
    }

    viewer.refresh();
    contentChanged();

}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.CandidateHostsSection.java

License:Open Source License

protected void performDelete(final TableViewer viewer) {

    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    if (structSelection != null) {

        Iterator<?> it = structSelection.iterator();

        /*//ww w. java  2 s  .c  o m
         * Iterate over the selections and delete them from the model.
         */
        while (it.hasNext()) {

            Object feature = it.next();

            try {
                /* Delete only Multi-Valued Elements */

                if (!this.adapterRefreshed) {

                    /*
                     * Check the instance of the Selection.
                     */
                    if (feature instanceof String) {

                        /*
                         * If this feature is an instance of String then, this 
                         * is a CandidateHosts instance. Therefore, remove the
                         * CandidataHosts instance.
                         */

                        this.candidateHosts.getHostName().remove(feature);

                        if (this.candidateHosts.getHostName().size() == 0) {

                            EcoreUtil.remove(this.candidateHosts);

                            checkResourcesElement();

                        }
                    }

                    contentChanged();
                } else {
                    viewer.remove(feature);
                }

            } //end try
            catch (Exception e) {
                Activator.logException(e);
            }

            /*
             * Refresh the table viewer and notify the editor that the page content has
             * changed.
             */
            viewer.refresh();

        } // end While

    } // end_if

}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.DataStageInSection.java

License:Open Source License

/**
 * Delete the selected Element in the TableViewer. The selected element must
 * be of type: {@link DataStagingType}//from ww  w  .  j  av a  2 s . com
 * 
 * If the selected DataStage element is a data-staged POSIX Input / Output / Error element, then 
 * the respective element in the POSIX Application section will also be deleted. 
 */
protected void performDelete(final TableViewer viewer) {

    /* Get the table viewer selection.  */
    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    Iterator<?> it = structSelection.iterator();

    /*
     * Get the JSDL Posix Element in order to check if the staged item to be deleted has any association with
     * it - that is if the staged item to be deleted is reported in one of the Input | Output | Error elements. 
     */

    POSIXApplicationType posixApplicationType = null;
    TreeIterator<EObject> iterator = this.jobDefinitionType.eAllContents();

    while (iterator.hasNext()) {

        EObject testType = iterator.next();

        if (testType instanceof POSIXApplicationType) {
            posixApplicationType = (POSIXApplicationType) testType;

        }

    }

    /*
     * Iterate over the selections and delete them from the model.
     */
    while (it.hasNext()) {

        /* Get the First Element of the selection. */
        Object feature = it.next();

        /* Cast the first element to DataStageingType */
        DataStagingType selectedDataStage = (DataStagingType) feature;

        /* Remove the selected DataStage object from it's container (JobDescription) */
        try {
            if (null != posixApplicationType) {
                if ((null != posixApplicationType.getOutput()) && (posixApplicationType.getOutput().getValue()
                        .equals(selectedDataStage.getFileName()))) {
                    posixApplicationType.setOutput(null);
                } else if ((null != posixApplicationType.getInput()) && (posixApplicationType.getInput()
                        .getValue().equals(selectedDataStage.getFileName()))) {
                    posixApplicationType.setInput(null);
                } else {
                    if (null != posixApplicationType.getError()) {
                        posixApplicationType.setError(null);
                    }
                }
            }
            EcoreUtil.remove(selectedDataStage);
        } catch (Exception e) {
            Activator.logException(e);

        } // end while

        /* Refresh the viewer and notify the editor that the page content has 
         * changed. */
        viewer.refresh();
        contentChanged();

    } //end iterator

}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.DataStageOutSection.java

License:Open Source License

/**
 * Delete the selected Element in the TableViewer. The selected element must
 * be of type: {@link DataStagingType}//from ww  w  .  j a v a  2s  . co  m
 * 
 */
protected void performDelete(final TableViewer viewer) {

    /* Get the table viewer selection.  */
    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    /*
     * Get the JSDL Posix Element in order to check if the staged item to be deleted has any association with
     * it - that is if the staged item to be deleted is reported in one of the Input | Output | Error elements. 
     */

    POSIXApplicationType posixApplicationType = null;
    TreeIterator<EObject> iterator = this.jobDefinitionType.eAllContents();

    while (iterator.hasNext()) {

        EObject testType = iterator.next();

        if (testType instanceof POSIXApplicationType) {
            posixApplicationType = (POSIXApplicationType) testType;

        }

    }

    Iterator<?> it = structSelection.iterator();

    /*
     * Iterate over the selections and delete them from the model.
     */
    while (it.hasNext()) {

        /* Get the First Element of the selection. */
        Object feature = it.next();

        /* Cast the first element to DataStageingType */
        DataStagingType selectedDataStage = (DataStagingType) feature;

        /* Remove the selected DataStage object from it's container (JobDescription) */
        try {
            if (null != posixApplicationType) {
                if ((null != posixApplicationType.getOutput()) && (posixApplicationType.getOutput().getValue()
                        .equals(selectedDataStage.getFileName()))) {
                    posixApplicationType.setOutput(null);
                } else if ((null != posixApplicationType.getInput()) && (posixApplicationType.getInput()
                        .getValue().equals(selectedDataStage.getFileName()))) {
                    posixApplicationType.setInput(null);
                } else {
                    if (null != posixApplicationType.getError()) {
                        posixApplicationType.setError(null);
                    }
                }
            }
            EcoreUtil.remove(selectedDataStage);
        } catch (Exception e) {
            Activator.logException(e);

        } // end while

        /* Refresh the viewer and notify the editor that the page content has 
         * changed. */
        viewer.refresh();
        contentChanged();

    } //end iterator

}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.FileSystemSection.java

License:Open Source License

protected void performDelete(final TableViewer viewer) {

    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    Iterator<?> it = structSelection.iterator();

    /*/*from   w  w  w.j av  a  2 s.  c om*/
     * Iterate over the selections and delete them from the model.
     */
    while (it.hasNext()) {

        Object feature = it.next();

        if (feature instanceof FileSystemType) {

            FileSystemType argument = (FileSystemType) feature;

            try {
                EcoreUtil.remove(argument);

            } catch (Exception e) {
                Activator.logException(e);
            }

        } //end ArgumentType
    }

    viewer.refresh();
    contentChanged();

}

From source file:eu.geclipse.jsdl.ui.internal.pages.sections.JobIdentificationSection.java

License:Open Source License

protected void performDelete(final TableViewer viewer) {

    IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection();

    if (structSelection != null) {
        Iterator<?> it = structSelection.iterator();
        /*//w  w  w. java2s  .  c  om
         * Iterate over the selections and delete them from the model.
         */
        while (it.hasNext()) {
            Object feature = it.next();
            try {
                /* Delete only Multi-Valued Elements */
                if (!this.adapterRefreshed) {
                    /*
                     * Check the instance of the Selection.
                     */
                    if (feature instanceof String) {
                        /*
                         * If this feature is an instance of String then, this is a
                         * CandidateHosts instance. Therefore, remove the CandidataHosts
                         * instance.
                         */
                        if (viewer == this.annotationsViewer) {
                            this.jobIdentificationType.getJobAnnotation().remove(feature);
                        } else {
                            this.jobIdentificationType.getJobProject().remove(feature);
                        }
                    }
                    contentChanged();
                } else {
                    viewer.remove(feature);
                }
            } // end try
            catch (Exception e) {
                Activator.logException(e);
            }
            /*
             * Refresh the table viewer and notify the editor that the page content
             * has changed.
             */
            viewer.refresh();
        } // end While
    } // end_if

}

From source file:eu.geclipse.jsdl.ui.internal.wizards.JSDLExactValueTab.java

License:Open Source License

@Override
protected void handleRemoveButtonSelected() {
    IStructuredSelection sel = (IStructuredSelection) this.table.getSelection();
    this.table.getControl().setRedraw(false);
    for (Iterator<?> i = sel.iterator(); i.hasNext();) {
        ValueWithEpsilon var = (ValueWithEpsilon) i.next();
        this.table.remove(var);
    }/*  w w w . jav a2s .  c  om*/
    this.table.getControl().setRedraw(true);
    // updateAppendReplace();
    updateLaunchConfigurationDialog();
}

From source file:eu.geclipse.jsdl.ui.internal.wizards.JSDLRangesTab.java

License:Open Source License

@Override
protected void handleRemoveButtonSelected() {
    IStructuredSelection sel = (IStructuredSelection) this.table.getSelection();
    this.table.getControl().setRedraw(false);
    for (Iterator<?> i = sel.iterator(); i.hasNext();) {
        Range var = (Range) i.next();
        this.table.remove(var);
    }/*from w ww .j  av a2s.  co m*/
    this.table.getControl().setRedraw(true);
    // updateAppendReplace();
    updateLaunchConfigurationDialog();
}

From source file:eu.geclipse.jsdl.ui.internal.wizards.MultipleArgumentList.java

License:Open Source License

@Override
protected void handleRemoveButtonSelected() {
    IStructuredSelection sel = (IStructuredSelection) this.table.getSelection();
    this.table.getControl().setRedraw(false);
    for (Iterator<?> i = sel.iterator(); i.hasNext();) {
        String var = (String) i.next();
        this.table.remove(var);
    }/*  ww w .  j a  v a2 s  .co m*/
    this.table.getControl().setRedraw(true);
    updateLaunchConfigurationDialog();
}