Example usage for org.eclipse.jface.viewers StructuredSelection toList

List of usage examples for org.eclipse.jface.viewers StructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection toList.

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:org.jboss.tools.windup.ui.internal.launch.OptionsRulesTab.java

License:Open Source License

private void createCustomRulesButtonBar(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = new Button(container, SWT.PUSH);
    addButton.setText(Messages.windupAdd);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override//from   w w  w  .j av a 2  s.  co  m
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell());
            String directory = dialog.open();
            if (directory != null) {
                if (!configuration.getUserRulesDirectories().contains(directory)) {
                    configuration.getUserRulesDirectories().add(directory);
                    reloadCustomRules();
                }
            }
        }
    });

    Button removeButton = new Button(container, SWT.PUSH);
    removeButton.setText(Messages.windupRemove);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) rulesDirectoryViewer.getSelection();
            if (!ss.isEmpty()) {
                @SuppressWarnings("unchecked")
                List<String> paths = (List<String>) ss.toList();
                configuration.getUserRulesDirectories().removeAll(paths);
                reloadCustomRules();
            }
        }
    });
}

From source file:org.jboss.tools.windup.ui.internal.launch.OptionsRulesTab.java

License:Open Source License

private void createOptionsButtonBar(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = new Button(container, SWT.PUSH);
    addButton.setText(Messages.windupAdd);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override//from  www  . j a v  a  2  s . c o m
        public void widgetSelected(SelectionEvent e) {
            if (configurationOptions == null) {
                ProgressBar progress = new ProgressBar(parent.getShell(), SWT.HORIZONTAL | SWT.INDETERMINATE);
                progress.setLayoutData(new GridData(GridData.FILL_BOTH));
                OptionsRulesTab.this.configurationOptions = WindupService.getWindupConfigurationOptions();
                progress.dispose();
            }
            OptionsDialog dialog = new OptionsDialog(parent.getShell(), configurationOptions);
            if (dialog.open() == IDialogConstants.OK_ID) {
                String option = dialog.getOption();
                String value = dialog.getValue();
                Pair pair = WindupFactory.eINSTANCE.createPair();
                pair.setKey(option);
                pair.setValue(value);
                configuration.getOptions().add(pair);
                reloadOptions();
            }
        }
    });

    Button removeButton = new Button(container, SWT.PUSH);
    removeButton.setText(Messages.windupRemove);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) optionsViewer.getSelection();
            if (!ss.isEmpty()) {
                @SuppressWarnings("unchecked")
                List<Pair> options = (List<Pair>) ss.toList();
                configuration.getOptions().removeAll(options);
                reloadOptions();
            }
        }
    });
}

From source file:org.jboss.tools.windup.ui.internal.launch.OptionsTab.java

License:Open Source License

private void createOptionsButtonBar(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = new Button(container, SWT.PUSH);
    addButton.setText(Messages.windupAdd);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override/*from w  ww.  j  a  v  a 2 s .c om*/
        public void widgetSelected(SelectionEvent e) {
            OptionsDialog dialog = new OptionsDialog(parent.getShell(), modelService, optionsService,
                    configuration);
            if (dialog.open() == IDialogConstants.OK_ID) {
                OptionDescription option = dialog.getSelectedOption();
                String value = dialog.getSelectedOptionValue();
                if (!value.isEmpty()) {
                    Pair pair = WindupFactory.eINSTANCE.createPair();
                    pair.setKey(option.getName());
                    pair.setValue(value);
                    configuration.getOptions().add(pair);
                    if (IOptionKeys.outputOption.equals(option.getName())) {
                        configuration.setOutputLocation(value);
                    }
                }
                reloadOptions();
            }
        }
    });

    Button removeButton = new Button(container, SWT.PUSH);
    removeButton.setText(Messages.windupRemove);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) optionsViewer.getSelection();
            if (!ss.isEmpty()) {
                @SuppressWarnings("unchecked")
                List<Pair> options = (List<Pair>) ss.toList();
                configuration.getOptions().removeAll(options);
                for (Pair option : options) {
                    if (IOptionKeys.outputOption.equals(option.getKey())) {
                        configuration.setOutputLocation(modelService.getDefaultOutputLocation(configuration));
                    }
                }
                reloadOptions();
            }
        }
    });
}

From source file:org.jboss.tools.windup.ui.internal.launch.RulesTab.java

License:Open Source License

private void createCustomRulesButtonBar(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = new Button(container, SWT.PUSH);
    addButton.setText("Add..."); //$NON-NLS-1$
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override//from ww  w  .j  a  v a 2  s. co  m
        public void widgetSelected(SelectionEvent e) {
            FilteredListDialog dialog = new FilteredListDialog(parent.getShell(), new LabelProvider() {
                @Override
                public String getText(Object element) {
                    CustomRuleProvider provider = (CustomRuleProvider) element;
                    StringBuilder builder = new StringBuilder();
                    String parsedRulesetId = XMLRulesetModelUtil.getRulesetId(provider.getLocationURI());
                    if (parsedRulesetId != null && !parsedRulesetId.isEmpty()) {
                        builder.append(parsedRulesetId);
                        builder.append(" - "); //$NON-NLS-1$
                    }
                    builder.append(provider.getLocationURI());
                    return builder.toString();
                }

                @Override
                public Image getImage(Object element) {
                    return WindupUIPlugin.getDefault().getImageRegistry().get(WindupUIPlugin.IMG_RULE_SET);
                }
            });
            dialog.setMultipleSelection(true);
            dialog.setMessage(Messages.selectExistingRepositories);

            //modelService.cleanCustomRuleRepositories(configuration);

            List<CustomRuleProvider> providers = Lists
                    .newArrayList(modelService.getModel().getCustomRuleRepositories());
            providers = providers.stream()
                    .filter(p -> !configuration.getUserRulesDirectories().contains(p.getLocationURI()))
                    .collect(Collectors.toList());
            dialog.setElements(providers.stream().toArray(CustomRuleProvider[]::new));
            dialog.setTitle(Messages.selectRepositories);
            dialog.setHelpAvailable(false);
            dialog.create();
            if (dialog.open() == Window.OK) {
                Object[] selected = (Object[]) dialog.getResult();
                if (selected.length > 0) {
                    List<String> rulesets = Lists.newArrayList();

                    // TODO: Temporary - see https://tree.taiga.io/project/rdruss-jboss-migration-windup-v3/task/884
                    selected = new Object[] { selected[0] };
                    //modelService.write(() -> configuration.getUserRulesDirectories().clear());
                    // 

                    Arrays.stream(selected)
                            .forEach(p -> rulesets.add(((CustomRuleProvider) p).getLocationURI()));
                    modelService.write(() -> {
                        configuration.getUserRulesDirectories().addAll(rulesets);
                    });
                    reload();
                }
            }
        }
    });

    removeButton = new Button(container, SWT.PUSH);
    removeButton.setText(Messages.windupRemove);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection ss = (StructuredSelection) rulesRepositoryViewer.getSelection();
            if (!ss.isEmpty()) {
                @SuppressWarnings("unchecked")
                List<CustomRuleProvider> providers = (List<CustomRuleProvider>) ss.toList();
                List<String> paths = providers.stream().map(p -> p.getLocationURI())
                        .collect(Collectors.toList());
                modelService.write(() -> {
                    configuration.getUserRulesDirectories().removeAll(paths);
                });
                reloadCustomRules();
            }
        }
    });

    rulesRepositoryViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            removeButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    removeButton.setEnabled(false);
}

From source file:org.jboss.tools.windup.ui.internal.launch.WindupInputTab.java

License:Open Source License

private void createProjectsButtonBar(Composite parent, TableViewer table) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = new Button(container, SWT.PUSH);
    addButton.setText(Messages.windupAdd);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override// ww  w.  java 2  s .c  om
        public void widgetSelected(SelectionEvent e) {
            List<IProject> projects = Lists
                    .newArrayList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
            projects.removeAll(Lists.newArrayList(getCurrentProjects(configuration)));
            FilteredListDialog dialog = new FilteredListDialog(parent.getShell(), new WorkbenchLabelProvider());
            dialog.setMultipleSelection(true);
            dialog.setMessage(Messages.windupProjectsSelect);
            dialog.setElements(projects.toArray(new IProject[projects.size()]));
            dialog.setTitle(Messages.windupProjects);
            dialog.setHelpAvailable(false);
            dialog.create();
            if (dialog.open() == Window.OK) {
                Object[] selected = (Object[]) dialog.getResult();
                if (selected.length > 0) {
                    List<IProject> newProjects = Lists.newArrayList();
                    Arrays.stream(selected).forEach(p -> newProjects.add((IProject) p));
                    modelService.createInput(configuration, newProjects);
                    reloadProjectsTable();
                }
            }
            updateLaunchConfigurationDialog();
        }
    });

    Button removeButton = new Button(container, SWT.PUSH);
    removeButton.setText(Messages.windupRemove);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = projectsTable.getSelection();
            if (!selection.isEmpty()) {
                StructuredSelection ss = (StructuredSelection) selection;
                List<IProject> projects = (List<IProject>) ss.toList();
                modelService.deleteInput(configuration, projects);
                modelService.synch(configuration);
                reloadProjectsTable();
                reloadPackagesTable();
            }
        }
    });
}

From source file:org.jboss.tools.windup.ui.internal.launch.WindupInputTab.java

License:Open Source License

private void createPackagesButtonBar(Composite parent, TableViewer table) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(container);

    Button addButton = new Button(container, SWT.PUSH);
    addButton.setText(Messages.windupAdd);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override//  w  w w .ja v  a2 s  .c om
        public void widgetSelected(SelectionEvent e) {
            FilteredListDialog dialog = new FilteredListDialog(parent.getShell(), new WorkbenchLabelProvider());
            dialog.setMultipleSelection(true);
            dialog.setMessage(Messages.windupPackagesSelect);
            dialog.setElements(computePackages(configuration));
            dialog.setTitle(Messages.windupPackages);
            dialog.setHelpAvailable(false);
            dialog.create();
            if (dialog.open() == Window.OK) {
                Object[] selected = (Object[]) dialog.getResult();
                if (selected.length > 0) {
                    List<IPackageFragment> packages = Lists.newArrayList();
                    Arrays.stream(selected).forEach(p -> packages.add((IPackageFragment) p));
                    modelService.addPackages(configuration, packages);
                    reloadPackagesTable();
                }
            }
        }
    });

    Button removeButton = new Button(container, SWT.PUSH);
    removeButton.setText(Messages.windupRemove);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(removeButton);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = table.getSelection();
            if (!selection.isEmpty()) {
                StructuredSelection ss = (StructuredSelection) selection;
                modelService.removePackages(configuration, (List<IPackageFragment>) ss.toList());
                reloadPackagesTable();
            }
        }
    });
}

From source file:org.obeonetwork.dsl.environment.binding.dialect.ui.editor.BindingTreeEditor.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w w w .jav a2s  .  com*/
 * 
 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createPartControl(final Composite parent) {
    this.setUpUndoRedoActionHandler();

    this.sashForm = new SashForm(parent, SWT.VERTICAL);
    this.sashForm.setSashWidth(3);

    parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    this.editorManager = new BindingTreeEditorManager(this.getEditingDomain(), this.accessor);
    final BindingTreeSemanticSupport treeSemanticSupport = new BindingTreeSemanticSupport(this.getBindingInfo(),
            this.editorManager);
    this.treeMapper = new BindingTreeMapper(this.sashForm, treeSemanticSupport);
    this.treeMapper.getLeftTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                final StructuredSelection strSelection = (StructuredSelection) event.getSelection();
                @SuppressWarnings("unchecked")
                final Collection<DBoundElement> selectedElements = strSelection.toList();
                BindingTreeEditor.this.populateLTRMappingDetails(selectedElements);
            }
        }
    });
    this.treeMapper.getRightTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                final StructuredSelection strSelection = (StructuredSelection) event.getSelection();
                @SuppressWarnings("unchecked")
                final Collection<DBoundElement> selectedElements = strSelection.toList();
                BindingTreeEditor.this.populateRTLMappingDetails(selectedElements);
            }
        }
    });

    final TreeDataProvider treeDataProvider = new TreeDataProvider(this.getBindingInfo());
    final DBoundElement left = treeDataProvider.getLeftRoot();
    final DBoundElement right = treeDataProvider.getRightRoot();
    final List<DBindingEdge> edges = treeDataProvider.getEdges();

    this.treeMapper.setInput(new TreeRoot(left), new TreeRoot(right), edges);

    this.createBindingGroupDetails(this.sashForm);
    this.grpDetailsLTR.setText(this.getBindingDetailsLabel(left, right));
    this.grpDetailsRTL.setText(this.getBindingDetailsLabel(right, left));

    this.sashForm.setWeights(new int[] { 70, 30 });

    // Expand the first levels on the two trees
    this.treeMapper.getLeftTreeViewer().expandToLevel(2);
    this.treeMapper.getRightTreeViewer().expandToLevel(2);

    this.revealBoundElements(edges);
}

From source file:org.openntf.bootlegger.action.BootleggerAction.java

License:Open Source License

private void processSelection(ExecutionEvent event) {

    this.desProject = null;

    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof StructuredSelection) {

        StructuredSelection ss = (StructuredSelection) selection;

        IProject project = null;//  w  ww  .ja  v  a2  s . c o  m

        List<?> list = ss.toList();

        // Check to determine first project
        for (Object o : list) {

            if (o instanceof IFile) {

                IFile file = (IFile) o;

                if (project == null) {
                    project = file.getProject();
                }

            }

        }

        // if we found the project, assign the this.desProject
        if (project != null) {

            if (DominoResourcesPlugin.isDominoDesignerProject(project)) {
                try {
                    this.desProject = DominoResourcesPlugin.getDominoDesignerProject(project);
                } catch (NsfException e) {
                    BootleggerUtil.logError(e.getMessage());
                }
            }

        } else {
            // If we can't figure out the project then it is no good
            return;
        }

        // Add files that belong to that project
        for (Object o : list) {

            if (o instanceof IFile) {

                IFile file = (IFile) o;

                if (file.getProject() == project) {
                    filesTofilter.add(file);
                }

            }

        }

    }

}

From source file:org.openntf.swiper.action.FilterMetadataAction.java

License:Open Source License

private void processSelection(ExecutionEvent event) {

    this.desProject = null;

    ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof StructuredSelection) {

        StructuredSelection ss = (StructuredSelection) selection;

        IProject project = null;/*from  ww  w . j a  va 2 s. c om*/

        List<?> list = ss.toList();

        // Check to determine first project
        for (Object o : list) {

            if (o instanceof IFile) {

                IFile file = (IFile) o;

                if (project == null) {
                    project = file.getProject();
                }

            }

        }

        // if we found the project, assign the this.desProject
        if (project != null) {

            if (DominoResourcesPlugin.isDominoDesignerProject(project)) {
                try {
                    this.desProject = DominoResourcesPlugin.getDominoDesignerProject(project);
                } catch (NsfException e) {
                    SwiperUtil.logError(e.getMessage());
                }
            }

        } else {
            // If we can't figure out the project then it is no good
            return;
        }

        // Add files that belong to that project
        for (Object o : list) {

            if (o instanceof IFile) {

                IFile file = (IFile) o;

                if (file.getProject() == project) {
                    filesTofilter.add(file);
                }

            }

        }

    }

}

From source file:org.opentravel.schemas.navigation.DoubleClickSelection.java

License:Apache License

public DoubleClickSelection(StructuredSelection selection) {
    super(selection.toList());
}