diff --git a/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/NewStepsSelectWizardPage.java b/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/NewStepsSelectWizardPage.java index 3d0b4e7..94c6a7a 100644 --- a/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/NewStepsSelectWizardPage.java +++ b/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/NewStepsSelectWizardPage.java @@ -50,23 +50,67 @@ public void createControl(Composite parent) { Tree tree = new Tree(composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - tree.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + tree.setLayoutData(new GridData(GridData.FILL_BOTH)); + + TreeItem selectAllItem = new TreeItem(tree, SWT.NONE); + selectAllItem.setText(WizardsMessages.GenerateStepsCheckboxAllScenarios); + selectAllItem.setChecked(false); + for (NewStep step : steps()) { - TreeItem item = new TreeItem(tree, SWT.NONE); + TreeItem item = new TreeItem(selectAllItem, SWT.NONE); item.setData(step); item.setText(step.asString()); item.setChecked(false); } - tree.setSize(100, 100); + selectAllItem.setExpanded(true); + tree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TreeItem item = (TreeItem) e.item; NewStep step = (NewStep) item.getData(); - if ( item.getChecked() ) { - selectedSteps.add(step); + + if (item.getParentItem() != null) { + // Leaf item selected + + if (item.getChecked()) { + selectedSteps.add(step); + + TreeItem selectAllItem = item.getParentItem(); + TreeItem[] childItems = selectAllItem.getItems(); + + boolean allChecked = true; + // Verify if "All Scenarios" checkbox needs selection + for (int i = 0; i < childItems.length; i++) { + if(!childItems[i].getChecked()) { + allChecked = false; + break; + } + } + + selectAllItem.setChecked(allChecked); + } else { + selectedSteps.remove(step); + + // Uncheck "All Scenarios" checkbox + item.getParentItem().setChecked(false); + } } else { - selectedSteps.remove(step); + // Root item selected + + TreeItem[] childItems = item.getItems(); + TreeItem child = null; + + for (int i = 0; i < childItems.length; i++) { + child = childItems[i]; + + if (item.getChecked()) { + selectedSteps.add((NewStep) child.getData()); + } else { + selectedSteps.remove((NewStep) child.getData()); + } + child.setChecked(item.getChecked()); + } } } }); diff --git a/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/WizardsMessages.java b/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/WizardsMessages.java index 1bb9010..dddc8d4 100644 --- a/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/WizardsMessages.java +++ b/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/WizardsMessages.java @@ -20,6 +20,7 @@ public class WizardsMessages extends NLS { public static String NewStoryWizardPageFileName; public static String NewStoryWizardPageFileExtension; public static String NewStoryWizardPageInitialContents; + public static String GenerateStepsCheckboxAllScenarios; static { // initialize resource bundle diff --git a/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/wizardsMessages.properties b/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/wizardsMessages.properties index fa8cbaa..3ad3dc6 100644 --- a/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/wizardsMessages.properties +++ b/org.jbehave.eclipse/src/org/jbehave/eclipse/wizards/wizardsMessages.properties @@ -1,6 +1,7 @@ GenerateStepsPageTitle=Generate Steps GenerateStepsPageDescription=This wizard generate stubs for missing steps GenerateStepsPageName=generateStepsPage +GenerateStepsCheckboxAllScenarios=All Scenarios NewStepsWizardTitle=Steps NewStepsWizardPageName=newStepsPage NewStepsWizardPageTitle=Steps