@@ -657,57 +657,68 @@ private void openModule(ISelection selection) {
657657 *
658658 * @param selection
659659 * the selection
660+ * @return whether configuration was successful
660661 */
661- private void newModule (ISelection selection ) {
662- if (mConfigurable ) {
663- boolean openOnAdd = CheckstyleUIPluginPrefs
664- .getBoolean (CheckstyleUIPluginPrefs .PREF_OPEN_MODULE_EDITOR );
665-
666- Iterator <?> iter = ((IStructuredSelection ) selection ).iterator ();
667- while (iter .hasNext ()) {
668- Object selectedElement = iter .next ();
669- if (selectedElement instanceof RuleGroupMetadata ) {
670- // if group is selected add all modules from this group
671- List <RuleMetadata > rules = ((RuleGroupMetadata ) selectedElement ).getRuleMetadata ();
672-
673- IStructuredSelection allRulesOfGroupSelection = new StructuredSelection (rules );
674- newModule (allRulesOfGroupSelection );
675- } else if (selectedElement instanceof RuleMetadata ) {
676-
677- RuleMetadata metadata = (RuleMetadata ) selectedElement ;
678-
679- // check if the module is a singleton and already
680- // configured
681- if (metadata .isSingleton () && isAlreadyConfigured (metadata )) {
682- return ;
683- }
662+ private boolean newModule (ISelection selection ) {
663+ if (!mConfigurable ) {
664+ return true ;
665+ }
666+ boolean openOnAdd = CheckstyleUIPluginPrefs
667+ .getBoolean (CheckstyleUIPluginPrefs .PREF_OPEN_MODULE_EDITOR );
668+
669+ Iterator <?> iter = ((IStructuredSelection ) selection ).iterator ();
670+ while (iter .hasNext ()) {
671+ Object selectedElement = iter .next ();
672+ if (selectedElement instanceof RuleGroupMetadata ) {
673+ // if group is selected add all modules from this group
674+ List <RuleMetadata > rules = ((RuleGroupMetadata ) selectedElement ).getRuleMetadata ();
675+
676+ IStructuredSelection allRulesOfGroupSelection = new StructuredSelection (rules );
677+ if (!newModule (allRulesOfGroupSelection )) {
678+ return false ;
679+ }
680+ } else if (selectedElement instanceof RuleMetadata ) {
681+
682+ RuleMetadata metadata = (RuleMetadata ) selectedElement ;
683+
684+ // check if the module is a singleton and already
685+ // configured
686+ if (metadata .isSingleton () && isAlreadyConfigured (metadata )) {
687+ return true ;
688+ }
684689
685- Module workingCopy = new Module (metadata , false );
690+ Module workingCopy = new Module (metadata , false );
686691
687- if (openOnAdd ) {
692+ if (openOnAdd ) {
688693
689- RuleConfigurationEditDialog dialog = new RuleConfigurationEditDialog (getShell (),
690- workingCopy , !mConfigurable ,
691- Messages .CheckConfigurationConfigureDialog_titleNewModule );
692- if (mConfigurable && Window .OK == dialog .open ()) {
694+ RuleConfigurationEditDialog dialog = new RuleConfigurationEditDialog (getShell (),
695+ workingCopy , !mConfigurable ,
696+ Messages .CheckConfigurationConfigureDialog_titleNewModule );
697+ if (mConfigurable ) {
698+ int dialogResult = dialog .open ();
699+ if (Window .OK == dialogResult ) {
693700 mModules .add (workingCopy );
694701 mIsDirty = true ;
695702 mTableViewer .refresh (true );
696703 refreshTableViewerState ();
697704 mTreeViewer .refresh ();
698705 mTreeViewer .getTree ().forceFocus ();
699706 }
700- } else {
701- mModules .add (workingCopy );
702- mIsDirty = true ;
703- mTableViewer .refresh (true );
704- refreshTableViewerState ();
705- mTreeViewer .refresh ();
707+ if (Window .CANCEL == dialogResult ) {
708+ // stop showing more dialogs and also don't add any further rules
709+ return false ;
710+ }
706711 }
712+ } else {
713+ mModules .add (workingCopy );
714+ mIsDirty = true ;
715+ mTableViewer .refresh (true );
716+ refreshTableViewerState ();
717+ mTreeViewer .refresh ();
707718 }
708719 }
709720 }
710-
721+ return true ;
711722 }
712723
713724 /**
0 commit comments