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:edu.utexas.cs.orc.orceclipse.project.EnableOrcNature.java

License:Open Source License

/**
 * Executes the add Orc nature action.// w  w w  .  j  a va 2  s. co  m
 *
 * @param event An event containing event parameters, the event trigger, and
 *            the application context. Must not be <code>null</code>.
 * @return the result of the execution. Reserved for future use, must be
 *         <code>null</code>.
 * @throws ExecutionException if an exception occurred during execution.
 */
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection ss = (IStructuredSelection) selection;

        for (final Iterator<?> selnIter = ss.iterator(); selnIter.hasNext();) {
            final Object currSelnElem = selnIter.next();

            IProject project = null;
            if (currSelnElem instanceof IProject) {
                project = (IProject) currSelnElem;
            } else if (currSelnElem instanceof IJavaProject) {
                project = ((IJavaProject) currSelnElem).getProject();
            } else if (currSelnElem instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) currSelnElem).getAdapter(IProject.class);
            }

            if (project != null) {
                try {
                    if (project.getNature(JavaCore.NATURE_ID) != null) {
                        MessageDialog.openError(null, Messages.EnableOrcNature_AlreadyJavaErrorTitle,
                                Messages.EnableOrcNature_AlreadJavaErrorMessage);
                        return null;
                    }
                } catch (final CoreException e) {
                    /* This is OK, it means we don't have Java nature */
                }
                try {
                    OrcNature.addToProject(project);
                } catch (final CoreException e) {
                    throw new ExecutionException("Failure when setting project nature for project: " + project, //$NON-NLS-1$
                            e);
                }
            }
        }
    }

    return null;
}

From source file:era.foss.erf.exporter.RifExportWizard.java

License:Open Source License

/**
 * Gets the white checked input resources.
 * /* w  ww.  j a  v a2 s.  co m*/
 * @param selection the selection
 * @return the white checked input resources
 */
private List<IFile> getWhiteCheckedInputResources(IStructuredSelection selection) {
    List<IFile> erfFileList = new ArrayList<IFile>();
    Iterator<?> fileIter = selection.iterator();
    while (fileIter.hasNext()) {
        // check if selected element is a file
        Object file = fileIter.next();
        if (file instanceof IFile) {
            try {
                if (((IFile) file).getContentDescription().getContentType().getId()
                        .equals("era.foss.erf.ErfContentType")) {
                    erfFileList.add((IFile) file);
                }
            } catch (CoreException e) {
            }
        }
    }
    return erfFileList;
}

From source file:es.cv.gvcase.emf.ui.common.dialogs.FeatureEditorDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite contents = (Composite) super.createDialogArea(parent);

    GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
    contentsGridLayout.numColumns = 3;//from   ww  w.j a va 2s  . c  o  m

    GridData contentsGridData = (GridData) contents.getLayoutData();
    contentsGridData.horizontalAlignment = SWT.FILL;
    contentsGridData.verticalAlignment = SWT.FILL;

    Text patternText = null;

    if (choiceOfValues != null) {
        Group filterGroupComposite = new Group(contents, SWT.NONE);
        filterGroupComposite.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_group"));
        filterGroupComposite.setLayout(new GridLayout(2, false));
        filterGroupComposite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 3, 1));

        Label label = new Label(filterGroupComposite, SWT.NONE);
        label.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_label"));

        patternText = new Text(filterGroupComposite, SWT.BORDER);
        patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }

    Composite choiceComposite = new Composite(contents, SWT.NONE);
    {
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        choiceComposite.setLayoutData(data);

        GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        choiceComposite.setLayout(layout);
    }

    Label choiceLabel = new Label(choiceComposite, SWT.NONE);
    choiceLabel.setText(choiceOfValues == null ? EMFEditUIPlugin.INSTANCE.getString("_UI_Value_label")
            : EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_label"));
    GridData choiceLabelGridData = new GridData();
    choiceLabelGridData.verticalAlignment = SWT.FILL;
    choiceLabelGridData.horizontalAlignment = SWT.FILL;
    choiceLabel.setLayoutData(choiceLabelGridData);

    final Tree choiceTree = choiceOfValues == null ? null : new Tree(choiceComposite, SWT.MULTI | SWT.BORDER);
    if (choiceTree != null) {
        GridData choiceTtreeGridData = new GridData();
        choiceTtreeGridData.widthHint = Display.getCurrent().getBounds().width / 5;
        choiceTtreeGridData.heightHint = Display.getCurrent().getBounds().height / 3;
        choiceTtreeGridData.verticalAlignment = SWT.FILL;
        choiceTtreeGridData.horizontalAlignment = SWT.FILL;
        choiceTtreeGridData.grabExcessHorizontalSpace = true;
        choiceTtreeGridData.grabExcessVerticalSpace = true;
        choiceTree.setLayoutData(choiceTtreeGridData);
    }

    final TreeViewer choiceTreeViewer = choiceOfValues == null ? null : new TreeViewer(choiceTree);
    if (choiceTreeViewer != null) {
        choiceTreeViewer.setContentProvider(contentProvider);
        choiceTreeViewer.setLabelProvider(labelProvider);
        final PatternFilter filter = new PatternFilter() {
            @Override
            protected boolean isParentMatch(Viewer viewer, Object element) {
                return viewer instanceof AbstractTreeViewer && super.isParentMatch(viewer, element);
            }
        };
        choiceTreeViewer.addFilter(filter);
        assert patternText != null;
        patternText.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                filter.setPattern(((Text) e.widget).getText());
                choiceTreeViewer.refresh();
            }
        });
        choiceTreeViewer.setInput(choiceOfValues);

        choiceTreeViewer.expandToLevel(2);
    }

    // We use multi even for a single line because we want to respond to the
    // enter key.
    //
    int style = multiLine ? SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER : SWT.MULTI | SWT.BORDER;
    final Text choiceText = choiceOfValues == null ? new Text(choiceComposite, style) : null;
    if (choiceText != null) {
        GridData choiceTextGridData = new GridData();
        choiceTextGridData.widthHint = Display.getCurrent().getBounds().width / 5;
        choiceTextGridData.verticalAlignment = SWT.BEGINNING;
        choiceTextGridData.horizontalAlignment = SWT.FILL;
        choiceTextGridData.grabExcessHorizontalSpace = true;
        if (multiLine) {
            choiceTextGridData.verticalAlignment = SWT.FILL;
            choiceTextGridData.grabExcessVerticalSpace = true;
        }
        choiceText.setLayoutData(choiceTextGridData);
    }

    Composite controlButtons = new Composite(contents, SWT.NONE);
    GridData controlButtonsGridData = new GridData();
    controlButtonsGridData.verticalAlignment = SWT.FILL;
    controlButtonsGridData.horizontalAlignment = SWT.FILL;
    controlButtons.setLayoutData(controlButtonsGridData);

    GridLayout controlsButtonGridLayout = new GridLayout();
    controlButtons.setLayout(controlsButtonGridLayout);

    new Label(controlButtons, SWT.NONE);

    final Button addButton = new Button(controlButtons, SWT.PUSH);
    addButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Add_label"));
    GridData addButtonGridData = new GridData();
    addButtonGridData.verticalAlignment = SWT.FILL;
    addButtonGridData.horizontalAlignment = SWT.FILL;
    addButton.setLayoutData(addButtonGridData);

    final Button removeButton = new Button(controlButtons, SWT.PUSH);
    removeButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Remove_label"));
    GridData removeButtonGridData = new GridData();
    removeButtonGridData.verticalAlignment = SWT.FILL;
    removeButtonGridData.horizontalAlignment = SWT.FILL;
    removeButton.setLayoutData(removeButtonGridData);

    Label spaceLabel = new Label(controlButtons, SWT.NONE);
    GridData spaceLabelGridData = new GridData();
    spaceLabelGridData.verticalSpan = 2;
    spaceLabel.setLayoutData(spaceLabelGridData);

    final Button upButton = new Button(controlButtons, SWT.PUSH);
    upButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Up_label"));
    GridData upButtonGridData = new GridData();
    upButtonGridData.verticalAlignment = SWT.FILL;
    upButtonGridData.horizontalAlignment = SWT.FILL;
    upButton.setLayoutData(upButtonGridData);

    final Button downButton = new Button(controlButtons, SWT.PUSH);
    downButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Down_label"));
    GridData downButtonGridData = new GridData();
    downButtonGridData.verticalAlignment = SWT.FILL;
    downButtonGridData.horizontalAlignment = SWT.FILL;
    downButton.setLayoutData(downButtonGridData);

    Composite featureComposite = new Composite(contents, SWT.NONE);
    {
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.horizontalAlignment = SWT.END;
        featureComposite.setLayoutData(data);

        GridLayout layout = new GridLayout();
        data.horizontalAlignment = SWT.FILL;
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 1;
        featureComposite.setLayout(layout);
    }

    Label featureLabel = new Label(featureComposite, SWT.NONE);
    featureLabel.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Feature_label"));
    GridData featureLabelGridData = new GridData();
    featureLabelGridData.horizontalSpan = 2;
    featureLabelGridData.horizontalAlignment = SWT.FILL;
    featureLabelGridData.verticalAlignment = SWT.FILL;
    featureLabel.setLayoutData(featureLabelGridData);

    final Tree featureTree = new Tree(featureComposite, SWT.MULTI | SWT.BORDER);
    GridData featureTreeGridData = new GridData();
    featureTreeGridData.widthHint = Display.getCurrent().getBounds().width / 5;
    featureTreeGridData.heightHint = Display.getCurrent().getBounds().height / 3;
    featureTreeGridData.verticalAlignment = SWT.FILL;
    featureTreeGridData.horizontalAlignment = SWT.FILL;
    featureTreeGridData.grabExcessHorizontalSpace = true;
    featureTreeGridData.grabExcessVerticalSpace = true;
    featureTree.setLayoutData(featureTreeGridData);

    final TreeViewer featureTreeViewer = new TreeViewer(featureTree);
    featureTreeViewer.setContentProvider(contentProvider);
    featureTreeViewer.setLabelProvider(labelProvider);
    if (values != null) {
        featureTreeViewer.setInput(values);
        if (!values.getChildren().isEmpty()) {
            featureTreeViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
        }
    } else {
        featureTreeViewer.setInput(currentValues);
        if (!currentValues.isEmpty()) {
            featureTreeViewer.setSelection(new StructuredSelection(currentValues.get(0)));
        }
    }
    featureTreeViewer.expandToLevel(2);

    if (choiceTreeViewer != null) {
        choiceTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (addButton.isEnabled()) {
                    addButton.notifyListeners(SWT.Selection, null);
                }
            }
        });

        featureTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                if (removeButton.isEnabled()) {
                    removeButton.notifyListeners(SWT.Selection, null);
                }
            }
        });
    }

    if (choiceText != null) {
        choiceText.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent event) {
                if (!multiLine && (event.character == '\r' || event.character == '\n')) {
                    try {
                        Object value = EcoreUtil.createFromString((EDataType) eClassifier,
                                choiceText.getText());
                        if (values != null) {
                            values.getChildren().add(value);
                        } else {
                            currentValues.add(value);
                        }
                        choiceText.setText("");
                        featureTreeViewer.setSelection(new StructuredSelection(value));
                        event.doit = false;
                    } catch (RuntimeException exception) {
                        // Ignore
                    }
                } else if (event.character == '\33') {
                    choiceText.setText("");
                    event.doit = false;
                }
            }
        });
    }

    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTreeViewer.getSelection();
            int minIndex = 0;
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                if (values != null) {
                    int index = values.getChildren().indexOf(value);
                    values.getChildren().move(Math.max(index - 1, minIndex++), value);
                } else {
                    int index = currentValues.indexOf(value);
                    currentValues.remove(value);
                    currentValues.add(Math.max(index - 1, minIndex++), value);
                }
            }
            featureTreeViewer.refresh();
            featureTreeViewer.expandToLevel(2);
            featureTreeViewer.setSelection(selection);
        }
    });

    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTreeViewer.getSelection();
            int maxIndex = 0;
            if (values != null) {
                maxIndex = values.getChildren().size();
            } else {
                maxIndex = currentValues.size();
            }
            maxIndex = maxIndex - selection.size();
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                if (values != null) {
                    int index = values.getChildren().indexOf(value);
                    values.getChildren().move(Math.min(index + 1, maxIndex++), value);
                } else {
                    int index = currentValues.indexOf(value);
                    currentValues.remove(value);
                    currentValues.add(Math.min(index + 1, maxIndex++), value);
                }
            }
            featureTreeViewer.refresh();
            featureTreeViewer.expandToLevel(2);
            featureTreeViewer.setSelection(selection);
        }
    });

    addButton.addSelectionListener(new SelectionAdapter() {
        // event is null when choiceTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (choiceTreeViewer != null) {
                IStructuredSelection selection = (IStructuredSelection) choiceTreeViewer.getSelection();
                for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                    Object value = i.next();
                    if (!eClassifier.isInstance(value)) {
                        continue;
                    }
                    if (values != null) {
                        if (!values.getChildren().contains(value)) {
                            values.getChildren().add(value);
                        }
                    } else {
                        if (!currentValues.contains(value)) {
                            currentValues.add(value);
                        }
                    }
                }
                featureTreeViewer.refresh();
                featureTreeViewer.expandToLevel(2);
                featureTreeViewer.setSelection(selection);
            } else if (choiceText != null) {
                try {
                    Object value = EcoreUtil.createFromString((EDataType) eClassifier, choiceText.getText());
                    if (values != null) {
                        values.getChildren().add(value);
                    } else {
                        currentValues.add(value);
                    }
                    choiceText.setText("");
                    featureTreeViewer.refresh(value);
                    featureTreeViewer.setSelection(new StructuredSelection(value));
                } catch (RuntimeException exception) {
                    // Ignore
                }
            }
        }
    });

    removeButton.addSelectionListener(new SelectionAdapter() {
        // event is null when featureTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTreeViewer.getSelection();
            Object firstValue = null;
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                if (!eClassifier.isInstance(value)) {
                    continue;
                }
                if (firstValue == null) {
                    firstValue = value;
                }
                if (values != null) {
                    values.getChildren().remove(value);
                } else {
                    currentValues.remove(value);
                }
            }

            if (values != null) {
                if (!values.getChildren().isEmpty()) {
                    featureTreeViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
                }
            } else {
                if (!currentValues.isEmpty()) {
                    featureTreeViewer.setSelection(new StructuredSelection(currentValues.get(0)));
                }
            }

            if (choiceTreeViewer != null) {
                choiceTreeViewer.refresh();
                choiceTreeViewer.expandToLevel(2);
                featureTreeViewer.refresh();
                featureTreeViewer.expandToLevel(2);
                choiceTreeViewer.setSelection(selection);
            } else if (choiceText != null) {
                if (firstValue != null) {
                    String value = EcoreUtil.convertToString((EDataType) eClassifier, firstValue);
                    choiceText.setText(value);
                }
            }
        }
    });

    return contents;
}

From source file:es.cv.gvcase.emf.ui.common.dialogs.SelectMultipleValuesDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite contents = (Composite) super.createDialogArea(parent);

    GridLayout contentsGridLayout = (GridLayout) contents.getLayout();
    contentsGridLayout.numColumns = 3;//from w ww  .  j a v  a2 s.com

    GridData contentsGridData = (GridData) contents.getLayoutData();
    contentsGridData.horizontalAlignment = SWT.FILL;
    contentsGridData.verticalAlignment = SWT.FILL;

    Composite choiceComposite = new Composite(contents, SWT.NONE);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.horizontalAlignment = SWT.END;
    choiceComposite.setLayoutData(data);
    GridLayout layout = new GridLayout();
    data.horizontalAlignment = SWT.FILL;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 1;
    choiceComposite.setLayout(layout);

    Label choiceLabel = new Label(choiceComposite, SWT.NONE);
    choiceLabel.setText("Available values:");
    data = new GridData();
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    choiceLabel.setLayoutData(data);

    Composite filterGroupComposite = new Composite(choiceComposite, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    filterGroupComposite.setLayout(layout);
    data = new GridData(SWT.FILL, SWT.DEFAULT, true, false, 3, 1);
    filterGroupComposite.setLayoutData(data);

    Label label = new Label(filterGroupComposite, SWT.NONE);
    label.setText("Filter " + EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_label"));

    Text patternText = new Text(filterGroupComposite, SWT.BORDER);
    patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Table choiceTable = new Table(choiceComposite, SWT.MULTI | SWT.BORDER);
    data = new GridData();
    data.widthHint = Display.getCurrent().getBounds().width / 10;
    data.heightHint = Display.getCurrent().getBounds().height / 6;
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    choiceTable.setLayoutData(data);

    final TableViewer choiceTableViewer = new TableViewer(choiceTable);
    choiceTableViewer.setContentProvider(new AdapterFactoryContentProvider(new AdapterFactoryImpl()));
    choiceTableViewer.setLabelProvider(labelProvider);
    final PatternFilter filter = new PatternFilter() {
        @Override
        protected boolean isParentMatch(Viewer viewer, Object element) {
            return viewer instanceof AbstractTreeViewer && super.isParentMatch(viewer, element);
        }
    };
    choiceTableViewer.addFilter(filter);
    patternText.addListener(SWT.Modify, new Listener() {
        public void handleEvent(final Event e) {
            ISWTUpdater updater = new ISWTUpdater() {
                public void execute() {
                    filter.setPattern(((Text) e.widget).getText());
                    choiceTableViewer.refresh();
                }
            };
            searchAsynchUpdater.addExecution(e, updater);
        }
    });
    choiceTableViewer.setComparator(new ViewerComparator() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            String s1 = SelectMultipleValuesDialog.this.labelProvider.getText(e1);
            String s2 = SelectMultipleValuesDialog.this.labelProvider.getText(e2);
            return s1.compareToIgnoreCase(s2);
        }
    });
    choiceTableViewer.setInput(choices);

    Composite controlButtons = new Composite(contents, SWT.NONE);
    data = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_FILL);
    controlButtons.setLayoutData(data);

    layout = new GridLayout();
    controlButtons.setLayout(layout);

    new Label(controlButtons, SWT.NONE);

    final Button addButton = new Button(controlButtons, SWT.PUSH);
    addButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Add_label"));
    data = new GridData();
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    addButton.setLayoutData(data);

    final Button removeButton = new Button(controlButtons, SWT.PUSH);
    removeButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Remove_label"));
    data = new GridData();
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    removeButton.setLayoutData(data);

    Label spaceLabel = new Label(controlButtons, SWT.NONE);
    data = new GridData();
    data.verticalSpan = 2;
    spaceLabel.setLayoutData(data);

    final Button upButton = new Button(controlButtons, SWT.PUSH);
    upButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Up_label"));
    data = new GridData();
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    upButton.setLayoutData(data);

    Button downButton = new Button(controlButtons, SWT.PUSH);
    downButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Down_label"));
    data = new GridData();
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    downButton.setLayoutData(data);

    Composite featureComposite = new Composite(contents, SWT.NONE);
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.horizontalAlignment = SWT.END;
    featureComposite.setLayoutData(data);
    layout = new GridLayout();
    data.horizontalAlignment = SWT.FILL;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 1;
    featureComposite.setLayout(layout);

    Label featureLabel = new Label(featureComposite, SWT.NONE);
    featureLabel.setText("Selected values:");
    data = new GridData();
    data.horizontalSpan = 2;
    data.horizontalAlignment = SWT.FILL;
    data.verticalAlignment = SWT.FILL;
    featureLabel.setLayoutData(data);

    Table featureTable = new Table(featureComposite, SWT.MULTI | SWT.BORDER);
    data = new GridData();
    data.widthHint = Display.getCurrent().getBounds().width / 10;
    data.heightHint = Display.getCurrent().getBounds().height / 6;
    data.verticalAlignment = SWT.FILL;
    data.horizontalAlignment = SWT.FILL;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    featureTable.setLayoutData(data);

    final TableViewer featureTableViewer = new TableViewer(featureTable);
    featureTableViewer.setContentProvider(contentProvider);
    featureTableViewer.setLabelProvider(labelProvider);
    featureTableViewer.setInput(values);
    if (!values.getChildren().isEmpty()) {
        featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
    }

    choiceTableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (addButton.isEnabled()) {
                addButton.notifyListeners(SWT.Selection, null);
            }
        }
    });

    featureTableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (removeButton.isEnabled()) {
                removeButton.notifyListeners(SWT.Selection, null);
            }
        }
    });

    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTableViewer.getSelection();
            int minIndex = 0;
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                int index = values.getChildren().indexOf(value);
                values.getChildren().move(Math.max(index - 1, minIndex++), value);
            }
        }
    });

    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTableViewer.getSelection();
            int maxIndex = values.getChildren().size() - selection.size();
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                int index = values.getChildren().indexOf(value);
                values.getChildren().move(Math.min(index + 1, maxIndex++), value);
            }
        }
    });

    addButton.addSelectionListener(new SelectionAdapter() {
        // event is null when choiceTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            Object value = null;
            IStructuredSelection selection = (IStructuredSelection) choiceTableViewer.getSelection();
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                value = i.next();
                if (!values.getChildren().contains(value)) {
                    values.getChildren().add(value);
                    choices.getChildren().remove(value);
                }
            }
            choiceTableViewer.refresh();
            featureTableViewer.refresh();
            if (value != null) {
                featureTableViewer.setSelection(new StructuredSelection(value));
            }
        }
    });

    removeButton.addSelectionListener(new SelectionAdapter() {
        // event is null when featureTableViewer is double clicked
        @Override
        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (IStructuredSelection) featureTableViewer.getSelection();
            Object firstValue = null;
            for (Iterator<?> i = selection.iterator(); i.hasNext();) {
                Object value = i.next();
                if (firstValue == null) {
                    firstValue = value;
                }
                values.getChildren().remove(value);
                choices.getChildren().add(value);
            }

            choiceTableViewer.refresh();
            if (!values.getChildren().isEmpty()) {
                featureTableViewer.setSelection(new StructuredSelection(values.getChildren().get(0)));
            }

            choiceTableViewer.setSelection(selection);
        }
    });

    return contents;
}

From source file:es.cv.gvcase.mdt.common.actions.DuplicateActionFilterProvider.java

License:Open Source License

/**
 * Finds my editing domain by adating the current selection to
 * <code>EObject</code>./* w  ww .java2  s  . c  o  m*/
 */
protected TransactionalEditingDomain getEditingDomain(Object target) {

    TransactionalEditingDomain result = null;
    IStructuredSelection selection = getStructuredSelection();

    if (selection != null && !selection.isEmpty()) {

        for (Iterator i = selection.iterator(); i.hasNext() && result == null;) {
            Object next = i.next();

            if (next instanceof IAdaptable) {
                EObject element = (EObject) ((IAdaptable) next).getAdapter(EObject.class);

                if (element != null) {
                    result = TransactionUtil.getEditingDomain(element);
                }
            }
        }
    }

    return result;
}

From source file:es.sidelab.pascaline.cdtinterface.launch.FreePascalApplicationLaunchShortcut.java

License:Open Source License

/**
 * Gets the owning project(s) of the selected object(s) if any
 * @param selection the current selection
 * @return a list of projects - may be empty
 *//*from  www  .  j  a  v  a2s .  c o  m*/
public static List<IProject> getProjectsFromSelection(ISelection selection) {
    List<IProject> projects = new ArrayList<IProject>();

    if (selection != null && !selection.isEmpty()) {
        if (selection instanceof ITextSelection) {

            IWorkbenchWindow activeWindow = CDebugUIPlugin.getActiveWorkbenchWindow();
            IWorkbenchPage wpage = activeWindow.getActivePage();
            if (wpage != null) {
                IEditorPart ep = wpage.getActiveEditor();
                if (ep != null) {
                    IEditorInput editorInput = ep.getEditorInput();
                    if (editorInput instanceof IFileEditorInput) {
                        IFile file = ((IFileEditorInput) editorInput).getFile();
                        if (file != null) {
                            projects.add(file.getProject());
                        }
                    }
                }
            }
        } else if (selection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;

            for (Iterator<?> iter = structuredSelection.iterator(); iter.hasNext();) {
                Object element = (Object) iter.next();
                if (element != null) {

                    if (element instanceof ICProject) {
                        projects.add(((ICProject) element).getProject());
                    } else if (element instanceof IResource) {
                        projects.add(((IResource) element).getProject());
                    } else if (element instanceof ICElement) {
                        ICElement unit = (ICElement) element;

                        // Get parent of the Element until we reach the owner project.
                        while (unit != null && !(unit instanceof ICProject))
                            unit = unit.getParent();

                        if (unit != null) {
                            projects.add(((ICProject) unit).getProject());
                        }
                    } else if (element instanceof IAdaptable) {
                        Object adapter = ((IAdaptable) element).getAdapter(IResource.class);
                        if (adapter != null && adapter instanceof IResource) {
                            projects.add(((IResource) adapter).getProject());
                        } else {
                            adapter = ((IAdaptable) element).getAdapter(ICProject.class);
                            if (adapter != null && adapter instanceof ICProject) {
                                projects.add(((ICProject) adapter).getProject());
                            }
                        }
                    }
                }
            }
        }
    }
    return projects;
}

From source file:es.uah.aut.srg.micobs.library.ui.handlers.UpdateRemoteModelFile.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    if (!(HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection)) {
        return null;
    }//from w w w.java 2  s.co  m

    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);

    MCommonLibrary library = null;

    final Set<MCommonPackageVersionedItem> itemsToUpdate = new HashSet<MCommonPackageVersionedItem>();

    for (Iterator<?> i = selection.iterator(); i.hasNext();) {
        Object object = i.next();
        if (object instanceof MCommonLibrary) {
            itemsToUpdate.addAll(getVersionedItems((MCommonLibrary) object));
            library = (MCommonLibrary) object;
        } else if (object instanceof MCommonPackage) {
            itemsToUpdate.addAll(getVersionedItems((MCommonPackage) object));
            library = (MCommonLibrary) EcoreUtil.getRootContainer((EObject) object);
        } else if (object instanceof MCommonPackageItem) {
            MCommonPackageItem item = (MCommonPackageItem) object;
            itemsToUpdate.addAll(item.getVersionedItems());
            library = (MCommonLibrary) EcoreUtil.getRootContainer((EObject) object);
        } else if (object instanceof MCommonPackageVersionedItem) {
            itemsToUpdate.add((MCommonPackageVersionedItem) object);
            library = (MCommonLibrary) EcoreUtil.getRootContainer((EObject) object);
        }
    }

    final BasicDiagnostic diagnostics = new BasicDiagnostic(MICOBSPlugin.INSTANCE.getSymbolicName(), 0,
            "Updating Remote Files", null);

    String libraryID = LibraryAdapterFactory.getAdapterFactory().getLibraryID(library.eClass().getName());
    LibraryAdapter adapter = LibraryAdapterFactory.getAdapterFactory().getAdapter(libraryID);
    if (adapter == null) {
        CheckingDiagnostic diag = CheckingDiagnostic.createError(MICOBSPlugin.INSTANCE.getString(
                "_UI_UnknownLibraryError_message", new Object[] { library.eClass().getName() }), library);
        diagnostics.add(diag);

    }
    final ILibraryManager manager = (ILibraryManager) adapter.adapt(ILibraryManager.class);

    if (manager == null) {
        CheckingDiagnostic diag = CheckingDiagnostic.createError(MICOBSPlugin.INSTANCE.getString(
                "_UI_LibraryInstallError_message", new Object[] { library.eClass().getName() }), library);
        diagnostics.add(diag);
    }

    if (diagnostics.getSeverity() != Diagnostic.OK) {
        DiagnosticDialog.open(HandlerUtil.getActiveShell(event),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Title"),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Message"), diagnostics);
        return null;
    }

    try {
        new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, true,
                new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {

                        monitor.beginTask("Updating Remote Files", 100); //$NON-NLS-1$   

                        int step = 100 / itemsToUpdate.size();

                        for (MCommonPackageVersionedItem versionedItem : itemsToUpdate) {
                            if (monitor.isCanceled()) {
                                break;
                            }
                            monitor.worked(step);

                            if (versionedItem.getRemoteModelURI() == null) {
                                continue;
                            }

                            MCommonPackageElement element;

                            try {
                                element = manager.getElement(versionedItem);
                            } catch (LibraryManagerException e) {
                                MICOBSPlugin.INSTANCE.log(e);
                                throw new InvocationTargetException(e);
                            }

                            String remoteModelURI = versionedItem.getRemoteModelURI();
                            String localModelURI = versionedItem.getLocalModelURI();
                            String modelFileExtension = remoteModelURI
                                    .substring(remoteModelURI.lastIndexOf(".") + 1, remoteModelURI.length());

                            File tmp = null;
                            try {
                                tmp = SVNUtil.loadRemoteFileOnTmp(remoteModelURI, "model",
                                        "." + modelFileExtension, monitor);
                            } catch (CoreException e) {
                                diagnostics.add(CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_ModelElementLoading",
                                                new Object[] { remoteModelURI }),
                                        versionedItem));
                                continue;
                            } catch (IOException e) {
                                diagnostics.add(CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_SavingTmp"), versionedItem));
                                continue;
                            }

                            File destFile = null;
                            String destString = null;

                            URI resourceURI = URI.createURI(localModelURI, true);

                            try {
                                destFile = FileConverter.platformPluginURItoFile(resourceURI);
                                destString = destFile.getAbsolutePath();
                                manager.removeElement(element.eClass(), element.getUri(), element.getVersion());
                            } catch (Throwable e) {
                                CheckingDiagnostic diag = CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERR_ResourceUnloadProblem"),
                                        versionedItem);
                                diagnostics.add(diag);
                                continue;
                            }

                            try {
                                if (destFile.isFile()) {
                                    destFile.setWritable(true);
                                    destFile.delete();
                                }
                                FileHelper.copyBinaryFile(tmp.getAbsolutePath(), destString);
                                destFile.setWritable(false);
                            } catch (IOException e) {
                                CheckingDiagnostic diag = CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_CopyingFileToLibrary"),
                                        versionedItem);
                                diagnostics.add(diag);
                                continue;
                            }

                            MCommonPackageVersionedItem newVersionedItem = null;

                            try {
                                newVersionedItem = manager.putElement(resourceURI);
                            } catch (Throwable e) {
                                CheckingDiagnostic diag = CheckingDiagnostic.createError(
                                        MICOBSPlugin.INSTANCE.getString("_ERROR_CopyingFileToLibrary"),
                                        versionedItem);
                                diagnostics.add(diag);
                                continue;
                            }

                            for (Iterator<EStructuralFeature> f = versionedItem.eClass()
                                    .getEAllStructuralFeatures().iterator(); f.hasNext();) {
                                EStructuralFeature feature = f.next();
                                if (feature != commonPackage.eINSTANCE
                                        .getMCommonPackageVersionedItem_LocalModelURI()
                                        && versionedItem.eGet(feature) != null) {
                                    newVersionedItem.eSet(feature, versionedItem.eGet(feature));
                                }
                            }
                        }
                        try {
                            manager.saveLibrary();
                        } catch (IOException e) {
                            MICOBSPlugin.INSTANCE.log(e);
                            throw new InvocationTargetException(e);
                        }

                        monitor.done();

                    }
                });

    } catch (InvocationTargetException e) {
        MICOBSPlugin.INSTANCE.log(e);
        return false;
    } catch (InterruptedException e) {
        MICOBSPlugin.INSTANCE.log(e);
        return false;
    }

    if (diagnostics.getSeverity() != Diagnostic.OK) {
        DiagnosticDialog.open(HandlerUtil.getActiveShell(event),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Title"),
                MICOBSPlugin.INSTANCE.getString("_UI_updateRemoteModelFileError_Message"), diagnostics);
    }

    return null;
}

From source file:es.uah.aut.srg.micobs.library.ui.handlers.UploadToLibraryHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection selectionList = (IStructuredSelection) selection;

        Shell parentShell = HandlerUtil.getActiveShell(event);

        // We have to open the library like this because we later want to
        // save it. Otherwise, the proper way is to use a platform URI

        ILibraryManager libraryManager;/* w  ww.java  2  s .  c  o  m*/
        try {
            libraryManager = getLibraryManager();
        } catch (LibraryManagerException e) {
            throw new ExecutionException(e.getMessage());
        }

        for (Iterator<?> i = selectionList.iterator(); i.hasNext();) {
            Object object = i.next();
            if (object instanceof IResource) {
                IResource resource = (IResource) object;

                URI resourceURI = URI.createPlatformResourceURI(resource.getFullPath().toPortableString(),
                        true);
                String resourceExtension = resource.getFileExtension();

                ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                ISVNLocalResource svnContainer = null;
                if (resource.getParent() != null
                        && resource.getParent().getName()
                                .matches(MICOBSPlugin.INSTANCE.getString("_MICOBSProject_models_foldername"))
                        && resource.getParent().getParent() != null) {
                    svnContainer = SVNWorkspaceRoot.getSVNResourceFor(resource.getParent().getParent());
                } else if (resource.getParent() != null) {
                    svnContainer = SVNWorkspaceRoot.getSVNResourceFor(resource.getParent());
                } else if (resource.getProject() != null) {
                    svnContainer = SVNWorkspaceRoot.getSVNResourceFor(resource.getProject());
                }
                String remoteModelURI = null;
                String repositoryFolderURI = null;
                if (svnResource != null && svnResource.getUrl() != null) {
                    remoteModelURI = svnResource.getUrl().toString();
                }
                if (svnContainer != null && svnContainer.getUrl() != null) {
                    repositoryFolderURI = svnContainer.getUrl().toString();
                }

                ResourceSet resourceSet = new ResourceSetImpl();
                Resource emfResource = resourceSet.getResource(resourceURI, true);
                final MCommonPackageFile packageFile = (MCommonPackageFile) emfResource.getContents().get(0);

                if (!checkPackageFile(packageFile)) {
                    MessageDialog.openError(parentShell, "Wrong file type", "This is not a valid MICOBS file");
                    return null;
                }

                Diagnostic diagnostic = MICOBSUtilProvider.getMICOBSUtil().validateResource(emfResource,
                        getModelAdapterFactory(packageFile));

                if (diagnostic.getSeverity() != Diagnostic.OK) {
                    handleDiagnostic(diagnostic);
                    return null;
                }

                String elementClassifier = packageFile.getElement().eClass().getName();
                String elementURI = packageFile.getElement().getUri();
                String elementVersion = packageFile.getElement().getVersion();

                MCommonPackageVersionedItem oldItem = null;
                MCommonPackageElement oldElement = null;

                try {
                    if ((oldElement = getLibraryManager().getElement(packageFile.getElement().eClass(),
                            elementURI, elementVersion)) != null) {
                        // There was a previous element with the same name!
                        oldItem = getLibraryManager().getVersionedItem(oldElement);
                        if (MessageDialog.openQuestion(parentShell, "Item previously exists!",
                                "Item with the same URI <" + elementURI + "> and version <" + elementVersion
                                        + "> previously exists. Overwrite?")) {
                            try {
                                getLibraryManager().removeElement(oldElement.eClass(), elementURI,
                                        elementVersion);
                            } catch (LibraryManagerException e) {
                                MessageDialog.openError(parentShell, "Remove Element",
                                        "Error when removing the element");
                                return null;
                            }
                        } else {
                            return null;
                        }
                    }
                    if (packageFile.getElement() instanceof MCommonPackageReferencingElement) {
                        // It is a referencing element, we have to check if there is a
                        // previously loaded item in the library that points to the same element
                        MCommonPackageElement referencedElement = ((MCommonPackageReferencingElement) packageFile
                                .getElement()).getReferencedElement();
                        IReferencingLibraryManager manager = (IReferencingLibraryManager) getLibraryManager();
                        MCommonPackageElement referencingElement = null;
                        if ((referencingElement = manager.getReferencingElement(referencedElement,
                                packageFile.getElement().eClass())) != null) {
                            // There was a previous element pointing to the same reference
                            if (MessageDialog.openQuestion(parentShell, "Previously referenced item!",
                                    "An item pointing to the element "
                                            + MICOBSStringHelper.getInstance().getElementName(referencedElement)
                                            + " previously exists. Overwrite?")) {
                                try {
                                    getLibraryManager().removeElement(referencingElement.eClass(),
                                            referencingElement.getUri(), referencingElement.getVersion());
                                } catch (LibraryManagerException e) {
                                    MessageDialog.openError(parentShell, "Remove Element",
                                            "Error when removing the element");
                                    return null;
                                }
                            } else {
                                return null;
                            }
                        }
                    } else if (packageFile.getElement() instanceof MCommonPackageParametricReferencingElement) {
                        // It is a referencing element, we have to check if there is a
                        // previously loaded item in the library that points to the same element
                        MCommonPackageElement referencedElement = ((MCommonPackageParametricReferencingElement) packageFile
                                .getElement()).getReferencedElement();
                        MCommonPackageElement parameterElement = ((MCommonPackageParametricReferencingElement) packageFile
                                .getElement()).getParameterElement();

                        IParametricReferencingLibraryManager manager = (IParametricReferencingLibraryManager) getLibraryManager();

                        MCommonPackageElement referencingElement = null;
                        if ((referencingElement = manager.getParametricReferencingElement(referencedElement,
                                parameterElement, packageFile.getElement().eClass())) != null) {
                            // There was a previous element pointing to the same reference
                            if (MessageDialog.openQuestion(parentShell, "Previously referenced item!",
                                    "An item pointing to the element "
                                            + MICOBSStringHelper.getInstance().getElementName(referencedElement)
                                            + " with parameter "
                                            + MICOBSStringHelper.getInstance().getElementName(parameterElement)
                                            + " previously exists. Overwrite?")) {
                                try {
                                    getLibraryManager().removeElement(referencingElement.eClass(),
                                            referencingElement.getUri(), referencingElement.getVersion());
                                } catch (LibraryManagerException e) {
                                    MessageDialog.openError(parentShell, "Remove Element",
                                            "Error when removing the element");
                                    return null;
                                }
                            } else {
                                return null;
                            }
                        }
                    }
                } catch (LibraryManagerException e) {
                    throw new ExecutionException(e.getMessage());
                }

                // Now I have to copy the file

                IPath path = resource.getLocation();

                IPath destPath = libraryManager.getPlugin().getStateLocation()
                        .append(ILibraryManager.LIBRARY_FOLDER);
                destPath = destPath.append(ILibraryManager.PACKAGES_FOLDER);
                destPath = destPath.append(StringHelper.toLowerDefString(packageFile.getPackage().getUri()));

                destPath = destPath.append(UUID
                        .nameUUIDFromBytes(StringHelper
                                .toLowerDefString(elementClassifier, elementURI, elementVersion).getBytes())
                        .toString() + "." + resourceExtension);

                File destFile = new File(destPath.toOSString());

                try {
                    if (destFile.isFile()) {
                        destFile.setWritable(true);
                        destFile.delete();
                    }
                    FileHelper.copyBinaryFile(path, destPath.toOSString());
                    destFile.setWritable(false);

                } catch (IOException e) {
                    throw new ExecutionException(e.toString());
                }

                URI modelURI;
                try {
                    modelURI = URI.createPlatformPluginURI(getLibraryManager().getPlugin().getBundle()
                            .getSymbolicName() + "/" + ILibraryManager.LIBRARY_FOLDER + "/"
                            + ILibraryManager.PACKAGES_FOLDER + "/"
                            + StringHelper.toLowerDefString(packageFile.getPackage().getUri()) + "/"
                            + UUID.nameUUIDFromBytes(StringHelper
                                    .toLowerDefString(elementClassifier, elementURI, elementVersion).getBytes())
                                    .toString()
                            + "." + resourceExtension, true);
                } catch (LibraryManagerException e) {
                    throw new ExecutionException(e.toString());
                }

                MCommonPackageVersionedItem newItem;
                try {
                    newItem = getLibraryManager().putElement(modelURI);
                } catch (LibraryManagerException e) {
                    MessageDialog.openError(parentShell, "Add Element", e.getMessage());
                    return null;
                }
                if (remoteModelURI != null) {
                    newItem.setRemoteModelURI(remoteModelURI);
                }
                if (repositoryFolderURI != null) {
                    newItem.setRepositoryFolderURI(repositoryFolderURI);
                }
                if (oldItem != null) {
                    for (Iterator<EStructuralFeature> f = oldItem.eClass().getEAllStructuralFeatures()
                            .iterator(); f.hasNext();) {
                        EStructuralFeature feature = f.next();
                        if (feature != commonPackage.eINSTANCE.getMCommonPackageVersionedItem_LocalModelURI()
                                && feature != commonPackage.eINSTANCE.getMCommonPackageVersionedItem_Version()
                                && feature != commonPackage.eINSTANCE
                                        .getMCommonPackageVersionedItem_RemoteModelURI()
                                && feature != commonPackage.eINSTANCE
                                        .getMCommonPackageVersionedItem_RepositoryFolderURI()
                                && oldItem.eGet(feature) != null) {
                            newItem.eSet(feature, oldItem.eGet(feature));
                        }
                    }
                }
            }
        }
        try {
            getLibraryManager().saveLibrary();
        } catch (IOException e) {
            throw new ExecutionException(e.getMessage());
        } catch (LibraryManagerException e) {
            throw new ExecutionException(e.getMessage());
        }
    }
    return null;
}

From source file:etomica.plugin.editors.eclipse.EtomicaPropertyViewer.java

License:Open Source License

/**
 * Reset the selected properties to their default values.
 *///from w  w w. j a v  a2  s.c  o m
public void resetProperties() {
    // Determine the selection
    IStructuredSelection selection = (IStructuredSelection) getSelection();

    // Iterate over entries and reset them
    Iterator itr = selection.iterator();
    while (itr.hasNext())
        ((IPropertySheetEntry) itr.next()).resetPropertyValue();
}

From source file:eu.artist.migration.ct.gui.rcp2gwt.dialog.GUICloudifierDialog.java

License:Open Source License

/**
 * This method renders the widgets for selecting available component model generators.
 * @param container Composite where placing these widgets
 *//*from  w w w  . j  av  a 2s .c om*/
private void createGUICloudifierSelector(Composite container) {
    Label lbtFirstName = new Label(container, SWT.NONE);
    lbtFirstName.setText("Select abstractor types");

    lvCloudifier = new ListViewer(container);
    lvCloudifier.setContentProvider(ArrayContentProvider.getInstance());
    lvCloudifier.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof Cloudifiers) {
                Cloudifiers generator = (Cloudifiers) element;
                return generator.getLabel();
            }
            return super.getText(element);
        }
    });

    Cloudifiers cmTypes[] = Cloudifiers.values();
    lvCloudifier.setInput(cmTypes);

    lvCloudifier.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectedCloudifiers.clear();
            Iterator abstractors = selection.iterator();
            while (abstractors.hasNext()) {
                Cloudifiers abstractor = (Cloudifiers) abstractors.next();
                selectedCloudifiers.add(abstractor);
            }
            validate();
        }
    });
}