Search in sources :

Example 1 with RuleSetViewModel

use of ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel in project eclipse-pmd by acanda.

the class PMDPropertyPageController method addRuleSetConfiguration.

public void addRuleSetConfiguration(final Shell shell) {
    final AddRuleSetConfigurationWizard wizard = new AddRuleSetConfigurationWizard(project);
    final WizardDialog dialog = new WizardDialog(shell, wizard);
    dialog.setPageSize(300, SWT.DEFAULT);
    final int result = dialog.open();
    if (result == Window.OK && wizard.getRuleSetModel() != null) {
        final RuleSetViewModel viewModel = toViewModel(wizard.getRuleSetModel(), project);
        model.addRuleSet(viewModel);
        final HashSet<RuleSetViewModel> activeConfigs = new HashSet<>(model.getActiveRuleSets());
        activeConfigs.add(viewModel);
        model.setActiveRuleSets(activeConfigs);
    }
}
Also used : RuleSetViewModel(ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel) AddRuleSetConfigurationWizard(ch.acanda.eclipse.pmd.wizard.AddRuleSetConfigurationWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) HashSet(java.util.HashSet)

Example 2 with RuleSetViewModel

use of ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel in project eclipse-pmd by acanda.

the class PMDPropertyPageControllerTest method removeSelectedConfigurations.

/**
 * Verifies that {@link PMDPropertyPageController#removeSelectedConfigurations()} updates the view model correctly.
 */
@Test
public void removeSelectedConfigurations() {
    final PMDPropertyPageController controller = new PMDPropertyPageController();
    final PMDPropertyPageViewModel model = controller.getModel();
    final IProject project = mock(IProject.class);
    model.setInitialState(true, ImmutableSortedSet.<RuleSetModel>of(), project);
    final ImmutableList<RuleSetViewModel> ruleSets = createRuleSets();
    model.setRuleSets(ruleSets);
    model.setActiveRuleSets(ruleSets.subList(0, 2));
    model.setSelectedRuleSets(ruleSets.subList(1, 3));
    controller.removeSelectedConfigurations();
    assertEquals("ruleSets", "[A, D]", toNameString(model.getRuleSets()));
    assertEquals("activeRuleSets", "[A]", toNameString(model.getActiveRuleSets()));
    assertEquals("selectedRuleSets", "[]", toNameString(model.getSelectedRuleSets()));
}
Also used : RuleSetViewModel(ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 3 with RuleSetViewModel

use of ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel in project eclipse-pmd by acanda.

the class PMDPropertyPageControllerTest method removeSelectedConfigurationsWithoutSelection.

/**
 * Verifies that {@link PMDPropertyPageController#removeSelectedConfigurations()} updates the view model correctly
 * when none of the rule sets are selected.
 */
@Test
public void removeSelectedConfigurationsWithoutSelection() {
    final PMDPropertyPageController controller = new PMDPropertyPageController();
    final PMDPropertyPageViewModel model = controller.getModel();
    final IProject project = mock(IProject.class);
    model.setInitialState(true, ImmutableSortedSet.<RuleSetModel>of(), project);
    final ImmutableList<RuleSetViewModel> ruleSets = createRuleSets();
    model.setRuleSets(ruleSets);
    model.setActiveRuleSets(ruleSets.subList(0, 2));
    model.setSelectedRuleSets(ImmutableList.<RuleSetViewModel>of());
    controller.removeSelectedConfigurations();
    assertEquals("ruleSets", "[A, B, C, D]", toNameString(model.getRuleSets()));
    assertEquals("activeRuleSets", "[A, B]", toNameString(model.getActiveRuleSets()));
    assertEquals("selectedRuleSets", "[]", toNameString(model.getSelectedRuleSets()));
}
Also used : RuleSetViewModel(ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

RuleSetViewModel (ch.acanda.eclipse.pmd.properties.PMDPropertyPageViewModel.RuleSetViewModel)3 IProject (org.eclipse.core.resources.IProject)2 Test (org.junit.Test)2 AddRuleSetConfigurationWizard (ch.acanda.eclipse.pmd.wizard.AddRuleSetConfigurationWizard)1 HashSet (java.util.HashSet)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1