Search in sources :

Example 1 with ISonarLintProject

use of org.sonarlint.eclipse.core.resource.ISonarLintProject in project sonarlint-eclipse by SonarSource.

the class ProjectsSelectionWizardPage method doCreateControl.

@Override
protected void doCreateControl(Composite container) {
    projectsViewer = new TableViewer(container, SWT.MULTI | SWT.BORDER);
    projectsViewer.addSelectionChangedListener(event -> updateButtonsState());
    projectsViewer.setContentProvider(new ArrayContentProvider());
    projectsViewer.setLabelProvider(new SonarLintProjectLabelProvider());
    projectsViewer.setInput(new ArrayList<>(model.getEclipseProjects()));
    projectsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    var dataBindingContext = new DataBindingContext();
    observableInput = ViewersObservables.observeInput(projectsViewer);
    projectsBinding = dataBindingContext.bindValue(observableInput, BeanProperties.value(ProjectBindingModel.class, ProjectBindingModel.PROPERTY_PROJECTS).observe(model), new UpdateValueStrategy().setBeforeSetValidator(new MandatoryProjectsValidator("You must select at least one project")), null);
    ControlDecorationSupport.create(projectsBinding, SWT.LEFT | SWT.TOP);
    WizardPageSupport.create(this, dataBindingContext);
    var btnAddProject = new Button(container, SWT.NONE);
    btnAddProject.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addSonarLintProjectsAction();
        }
    });
    btnAddProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnAddProject.setText("Add...");
    btnRemove = new Button(container, SWT.NONE);
    btnRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            var newInput = new ArrayList<ISonarLintProject>((List) projectsViewer.getInput());
            newInput.removeAll(getSelectedElements());
            observableInput.setValue(newInput);
        }
    });
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    btnRemove.setText("Remove");
    updateButtonsState();
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) Button(org.eclipse.swt.widgets.Button) ISonarLintProject(org.sonarlint.eclipse.core.resource.ISonarLintProject) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 ISonarLintProject (org.sonarlint.eclipse.core.resource.ISonarLintProject)1