Skip to content

Commit e5d5415

Browse files
committed
Clean up wizard.
1 parent 4fa226c commit e5d5415

File tree

1 file changed

+79
-83
lines changed

1 file changed

+79
-83
lines changed

edu.cuny.hunter.streamrefactoring.ui/src/edu/cuny/hunter/streamrefactoring/ui/wizards/OptimizeStreamRefactoringWizard.java

Lines changed: 79 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
2121
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
2222
import org.eclipse.swt.SWT;
23-
import org.eclipse.swt.events.ModifyEvent;
24-
import org.eclipse.swt.events.ModifyListener;
2523
import org.eclipse.swt.events.SelectionAdapter;
2624
import org.eclipse.swt.events.SelectionEvent;
2725
import org.eclipse.swt.layout.GridData;
@@ -45,40 +43,76 @@ public class OptimizeStreamRefactoringWizard extends RefactoringWizard {
4543

4644
private static class OptimizeStreamsInputPage extends UserInputWizardPage {
4745

48-
public static final String PAGE_NAME = "OptimizeStreamsInputPage"; //$NON-NLS-1$
49-
5046
private static final String DESCRIPTION = Messages.Name;
5147

5248
private static final String DIALOG_SETTING_SECTION = "OptimizeStreams"; //$NON-NLS-1$
5349

54-
private static final String USE_IMPLICIT_ENTRY_POINTS = "useImplicitEntryPoints"; //$NON-NLS-1$
50+
private static final String K_FOR_STREAMS = "kForStreams"; //$NON-NLS-1$
5551

56-
private static final String USE_IMPLICIT_TEST_ENTRY_POINTS = "useImplicitTestEntryPoints"; //$NON-NLS-1$
52+
public static final String PAGE_NAME = "OptimizeStreamsInputPage"; //$NON-NLS-1$
5753

58-
private static final String USE_IMPLICIT_JMH_ENTRY_POINTS = "useImplicitJMHEntryPoints"; //$NON-NLS-1$
54+
private static final String USE_IMPLICIT_ENTRY_POINTS = "useImplicitEntryPoints"; //$NON-NLS-1$
5955

6056
private static final String USE_IMPLICIT_JAVAFX_ENTRY_POINTS = "useImplicitJavaFXEntryPoints"; //$NON-NLS-1$
6157

62-
private static final String K_FOR_STREAMS = "kForStreams"; //$NON-NLS-1$
58+
private static final String USE_IMPLICIT_JMH_ENTRY_POINTS = "useImplicitJMHEntryPoints"; //$NON-NLS-1$
6359

64-
IDialogSettings settings;
60+
private static final String USE_IMPLICIT_TEST_ENTRY_POINTS = "useImplicitTestEntryPoints"; //$NON-NLS-1$
6561

6662
private OptimizeStreamsRefactoringProcessor processor;
6763

64+
IDialogSettings settings;
65+
6866
public OptimizeStreamsInputPage() {
6967
super(PAGE_NAME);
70-
setDescription(DESCRIPTION);
68+
this.setDescription(DESCRIPTION);
69+
}
70+
71+
private void addBooleanButton(String text, String key, Consumer<Boolean> valueConsumer, Composite result) {
72+
Button button = new Button(result, SWT.CHECK);
73+
button.setText(text);
74+
boolean value = this.settings.getBoolean(key);
75+
valueConsumer.accept(value);
76+
button.setSelection(value);
77+
button.addSelectionListener(new SelectionAdapter() {
78+
@Override
79+
public void widgetSelected(SelectionEvent e) {
80+
boolean selection = ((Button) e.widget).getSelection();
81+
OptimizeStreamsInputPage.this.settings.put(key, selection);
82+
valueConsumer.accept(selection);
83+
}
84+
});
85+
}
86+
87+
private void addIntegerButton(String text, String key, Consumer<Integer> valueConsumer, Composite result) {
88+
Label label = new Label(result, SWT.HORIZONTAL);
89+
label.setText(text);
90+
91+
Text textBox = new Text(result, SWT.SINGLE);
92+
int value = this.settings.getInt(key);
93+
valueConsumer.accept(value);
94+
textBox.setText(String.valueOf(value));
95+
textBox.addModifyListener(event -> {
96+
int selection;
97+
try {
98+
selection = Integer.parseInt(((Text) event.widget).getText());
99+
} catch (NumberFormatException e) {
100+
return;
101+
}
102+
OptimizeStreamsInputPage.this.settings.put(key, selection);
103+
valueConsumer.accept(selection);
104+
});
71105
}
72106

73107
@Override
74108
public void createControl(Composite parent) {
75-
ProcessorBasedRefactoring processorBasedRefactoring = (ProcessorBasedRefactoring) getRefactoring();
109+
ProcessorBasedRefactoring processorBasedRefactoring = (ProcessorBasedRefactoring) this.getRefactoring();
76110
RefactoringProcessor refactoringProcessor = processorBasedRefactoring.getProcessor();
77111
this.setProcessor((OptimizeStreamsRefactoringProcessor) refactoringProcessor);
78112
this.loadSettings();
79113

80114
Composite result = new Composite(parent, SWT.NONE);
81-
setControl(result);
115+
this.setControl(result);
82116
GridLayout layout = new GridLayout();
83117
layout.numColumns = 1;
84118
result.setLayout(layout);
@@ -91,105 +125,67 @@ public void createControl(Composite parent) {
91125
separator.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
92126

93127
// set up buttons.
94-
addBooleanButton("Automatically discover standard entry points (main methods).", USE_IMPLICIT_ENTRY_POINTS,
95-
this.getProcessor()::setUseImplicitEntrypoints, result);
96-
addBooleanButton("Automatically discover test-based entry points (JUnit).", USE_IMPLICIT_TEST_ENTRY_POINTS,
97-
this.getProcessor()::setUseImplicitTestEntrypoints, result);
98-
addBooleanButton("Automatically discover benchmark entry points (JMH).", USE_IMPLICIT_JMH_ENTRY_POINTS,
128+
this.addBooleanButton("Automatically discover standard entry points (main methods).",
129+
USE_IMPLICIT_ENTRY_POINTS, this.getProcessor()::setUseImplicitEntrypoints, result);
130+
this.addBooleanButton("Automatically discover test-based entry points (JUnit).",
131+
USE_IMPLICIT_TEST_ENTRY_POINTS, this.getProcessor()::setUseImplicitTestEntrypoints, result);
132+
this.addBooleanButton("Automatically discover benchmark entry points (JMH).", USE_IMPLICIT_JMH_ENTRY_POINTS,
99133
this.getProcessor()::setUseImplicitBenchmarkEntrypoints, result);
100-
addBooleanButton("Automatically discover GUI entry points (JavaFX).", USE_IMPLICIT_JAVAFX_ENTRY_POINTS,
134+
this.addBooleanButton("Automatically discover GUI entry points (JavaFX).", USE_IMPLICIT_JAVAFX_ENTRY_POINTS,
101135
this.getProcessor()::setUseImplicitJavaFXEntrypoints, result);
102136

103137
Composite compositeForIntegerButton = new Composite(result, SWT.NONE);
104138
GridLayout layoutForIntegerButton = new GridLayout(2, false);
105139

106140
compositeForIntegerButton.setLayout(layoutForIntegerButton);
107141

108-
addIntegerButton("k value to use for streams for kCFA: ", K_FOR_STREAMS,
142+
this.addIntegerButton("k value to use for streams for kCFA: ", K_FOR_STREAMS,
109143
this.getProcessor()::setNForStreams, compositeForIntegerButton);
110144

111-
updateStatus();
145+
this.updateStatus();
112146
Dialog.applyDialogFont(result);
113-
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), "optimize_streams_wizard_page_context");
147+
PlatformUI.getWorkbench().getHelpSystem().setHelp(this.getControl(),
148+
"optimize_streams_wizard_page_context");
114149
}
115150

116-
private void addBooleanButton(String text, String key, Consumer<Boolean> valueConsumer, Composite result) {
117-
Button button = new Button(result, SWT.CHECK);
118-
button.setText(text);
119-
boolean value = settings.getBoolean(key);
120-
valueConsumer.accept(value);
121-
button.setSelection(value);
122-
button.addSelectionListener(new SelectionAdapter() {
123-
@Override
124-
public void widgetSelected(SelectionEvent e) {
125-
boolean selection = ((Button) e.widget).getSelection();
126-
settings.put(key, selection);
127-
valueConsumer.accept(selection);
128-
}
129-
});
130-
}
131-
132-
private void addIntegerButton(String text, String key, Consumer<Integer> valueConsumer, Composite result) {
133-
Label label = new Label(result, SWT.HORIZONTAL);
134-
label.setText(text);
135-
136-
Text textBox = new Text(result, SWT.SINGLE);
137-
int value = settings.getInt(key);
138-
valueConsumer.accept(value);
139-
textBox.setText(String.valueOf(value));
140-
textBox.addModifyListener(new ModifyListener() {
141-
142-
@Override
143-
public void modifyText(ModifyEvent event) {
144-
int selection;
145-
try {
146-
selection = Integer.parseInt(((Text) event.widget).getText());
147-
} catch (NumberFormatException e) {
148-
return;
149-
}
150-
settings.put(key, selection);
151-
valueConsumer.accept(selection);
152-
}
153-
});
151+
private OptimizeStreamsRefactoringProcessor getProcessor() {
152+
return this.processor;
154153
}
155154

156155
private void loadSettings() {
157-
settings = getDialogSettings().getSection(DIALOG_SETTING_SECTION);
158-
if (settings == null) {
159-
settings = getDialogSettings().addNewSection(DIALOG_SETTING_SECTION);
160-
settings.put(USE_IMPLICIT_ENTRY_POINTS, this.getProcessor().getUseImplicitEntrypoints());
161-
settings.put(USE_IMPLICIT_TEST_ENTRY_POINTS, this.getProcessor().getUseImplicitTestEntrypoints());
162-
settings.put(USE_IMPLICIT_JMH_ENTRY_POINTS, this.getProcessor().getUseImplicitBenchmarkEntrypoints());
163-
settings.put(USE_IMPLICIT_JAVAFX_ENTRY_POINTS,
156+
this.settings = this.getDialogSettings().getSection(DIALOG_SETTING_SECTION);
157+
if (this.settings == null) {
158+
this.settings = this.getDialogSettings().addNewSection(DIALOG_SETTING_SECTION);
159+
this.settings.put(USE_IMPLICIT_ENTRY_POINTS, this.getProcessor().getUseImplicitEntrypoints());
160+
this.settings.put(USE_IMPLICIT_TEST_ENTRY_POINTS, this.getProcessor().getUseImplicitTestEntrypoints());
161+
this.settings.put(USE_IMPLICIT_JMH_ENTRY_POINTS,
162+
this.getProcessor().getUseImplicitBenchmarkEntrypoints());
163+
this.settings.put(USE_IMPLICIT_JAVAFX_ENTRY_POINTS,
164164
this.getProcessor().getUseImplicitBenchmarkEntrypoints());
165-
settings.put(K_FOR_STREAMS, this.getProcessor().getNForStreams());
165+
this.settings.put(K_FOR_STREAMS, this.getProcessor().getNForStreams());
166166
}
167-
processor.setUseImplicitEntrypoints(settings.getBoolean(USE_IMPLICIT_ENTRY_POINTS));
168-
processor.setUseImplicitTestEntrypoints(settings.getBoolean(USE_IMPLICIT_TEST_ENTRY_POINTS));
169-
processor.setUseImplicitBenchmarkEntrypoints(settings.getBoolean(USE_IMPLICIT_JMH_ENTRY_POINTS));
170-
processor.setUseImplicitJavaFXEntrypoints(settings.getBoolean(USE_IMPLICIT_JAVAFX_ENTRY_POINTS));
167+
this.processor.setUseImplicitEntrypoints(this.settings.getBoolean(USE_IMPLICIT_ENTRY_POINTS));
168+
this.processor.setUseImplicitTestEntrypoints(this.settings.getBoolean(USE_IMPLICIT_TEST_ENTRY_POINTS));
169+
this.processor.setUseImplicitBenchmarkEntrypoints(this.settings.getBoolean(USE_IMPLICIT_JMH_ENTRY_POINTS));
170+
this.processor.setUseImplicitJavaFXEntrypoints(this.settings.getBoolean(USE_IMPLICIT_JAVAFX_ENTRY_POINTS));
171171

172172
int value;
173173
try {
174-
value = settings.getInt(K_FOR_STREAMS);
174+
value = this.settings.getInt(K_FOR_STREAMS);
175175
} catch (NumberFormatException e) {
176-
settings.put(K_FOR_STREAMS, this.getProcessor().getNForStreams());
177-
value = settings.getInt(K_FOR_STREAMS);
176+
this.settings.put(K_FOR_STREAMS, this.getProcessor().getNForStreams());
177+
value = this.settings.getInt(K_FOR_STREAMS);
178178
}
179-
processor.setNForStreams(value);
180-
}
181-
182-
private void updateStatus() {
183-
setPageComplete(true);
184-
}
185-
186-
private OptimizeStreamsRefactoringProcessor getProcessor() {
187-
return processor;
179+
this.processor.setNForStreams(value);
188180
}
189181

190182
private void setProcessor(OptimizeStreamsRefactoringProcessor processor) {
191183
this.processor = processor;
192184
}
185+
186+
private void updateStatus() {
187+
this.setPageComplete(true);
188+
}
193189
}
194190

195191
public static void startRefactoring(IJavaProject[] javaProjects, Shell shell, Optional<IProgressMonitor> monitor)

0 commit comments

Comments
 (0)