1515
1616import java .util .ArrayList ;
1717import java .util .HashMap ;
18+ import java .util .List ;
1819import java .util .Map ;
1920
2021import org .eclipse .swt .SWT ;
@@ -66,6 +67,7 @@ public void widgetSelected(SelectionEvent e) {
6667 Text text = (Text )e .widget ;
6768 fOverlayStore .setValue (fStringInputs .get (text ), text .getText ());
6869 };
70+ private List <SelectionListener > fMasterSlaveListeners = new ArrayList <>();
6971
7072
7173
@@ -118,7 +120,7 @@ public Control createControl(Composite composite) {
118120 addCheckBox (initialFoldingGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_innerTypes , PreferenceConstants .EDITOR_FOLDING_INNERTYPES , 0 );
119121 addCheckBox (initialFoldingGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_methods , PreferenceConstants .EDITOR_FOLDING_METHODS , 0 );
120122 addCheckBox (initialFoldingGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_imports , PreferenceConstants .EDITOR_FOLDING_IMPORTS , 0 );
121- addCheckBox (initialFoldingGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_customRegions , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGIONS_ENABLED , 0 );
123+ Button initiallyFoldCustomRegions = addCheckBox (initialFoldingGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_customRegions , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGIONS_ENABLED , 0 );
122124
123125 Group extendedFoldingGroup = new Group (outer , SWT .NONE );
124126 GridLayout extendedFoldingLayout = new GridLayout (1 , false );
@@ -141,13 +143,31 @@ public Control createControl(Composite composite) {
141143 customRegionGroup .setLayout (customRegionLayout );
142144 customRegionGroup .setText (FoldingMessages .DefaultJavaFoldingPreferenceBlock_custom_region_title );
143145
144- addCheckBox (customRegionGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_customRegionsEnabled , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGIONS_ENABLED , 0 , 2 );
145- addStringInput (customRegionGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_customRegionStart , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGION_START );
146- addStringInput (customRegionGroup , FoldingMessages .defaultJavaFoldingPreferenceBlock_customRegionEnd , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGION_END );
146+ Button customRegionsEnabled = addCheckBox (customRegionGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_customRegionsEnabled , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGIONS_ENABLED , 0 , 2 );
147+ Text customRegionTextStart = addStringInput (customRegionGroup , FoldingMessages .DefaultJavaFoldingPreferenceBlock_customRegionStart , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGION_START );
148+ Text customRegionTextEnd = addStringInput (customRegionGroup , FoldingMessages .defaultJavaFoldingPreferenceBlock_customRegionEnd , PreferenceConstants .EDITOR_FOLDING_CUSTOM_REGION_END );
149+ addDependency (customRegionsEnabled , initiallyFoldCustomRegions );
150+ addDependency (customRegionsEnabled , customRegionTextStart );
151+ addDependency (customRegionsEnabled , customRegionTextEnd );
147152
148153 return outer ;
149154 }
150155
156+ private void addDependency (Button master , Control slave ) {
157+ slave .setEnabled (fOverlayStore .getBoolean (fCheckBoxes .get (master )));
158+ SelectionListener listener = new SelectionListener () {
159+ @ Override
160+ public void widgetSelected (SelectionEvent e ) {
161+ slave .setEnabled (master .getSelection ());
162+ }
163+
164+ @ Override
165+ public void widgetDefaultSelected (SelectionEvent e ) {}
166+ };
167+ master .addSelectionListener (listener );
168+ fMasterSlaveListeners .add (listener );
169+ }
170+
151171 private Button addCheckBox (Composite parent , String label , String key , int indentation ) {
152172 return addCheckBox (parent , label , key , indentation , 1 );
153173 }
@@ -167,7 +187,7 @@ private Button addCheckBox(Composite parent, String label, String key, int inden
167187 return checkBox ;
168188 }
169189
170- private void addStringInput (Composite parent , String label , String key ) {
190+ private Text addStringInput (Composite parent , String label , String key ) {
171191 Label labelElement = new Label (parent , SWT .LEFT );
172192 labelElement .setText (label );
173193 GridData labelGridData = new GridData (GridData .HORIZONTAL_ALIGN_BEGINNING );
@@ -185,11 +205,13 @@ private void addStringInput(Composite parent, String label, String key) {
185205 textInput .setLayoutData (textGridData );
186206
187207 fStringInputs .put (textInput , key );
208+ return textInput ;
188209 }
189210
190211 private void initializeFields () {
191212 fCheckBoxes .forEach ((b , key ) -> b .setSelection (fOverlayStore .getBoolean (key )));
192213 fStringInputs .forEach ((text , key ) -> text .setText (fOverlayStore .getString (key )));
214+ fMasterSlaveListeners .forEach (listener -> listener .widgetSelected (null ));
193215 }
194216
195217 /*
0 commit comments