OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.debug.ui.liveedit; | 5 package org.chromium.debug.ui.liveedit; |
6 | 6 |
7 import static org.chromium.debug.ui.DialogUtils.createConstant; | 7 import static org.chromium.debug.ui.DialogUtils.*; |
8 import static org.chromium.debug.ui.DialogUtils.createErrorOptional; | |
9 import static org.chromium.debug.ui.DialogUtils.createOptional; | |
10 import static org.chromium.debug.ui.DialogUtils.createOptionalProcessor; | |
11 import static org.chromium.debug.ui.DialogUtils.createProcessor; | |
12 import static org.chromium.debug.ui.DialogUtils.dependencies; | |
13 import static org.chromium.debug.ui.DialogUtils.handleErrors; | |
14 import static org.chromium.debug.ui.DialogUtils.handleErrorsAddNew; | |
15 | 8 |
16 import java.util.List; | 9 import java.util.List; |
17 | 10 |
18 import org.chromium.debug.core.ChromiumDebugPlugin; | 11 import org.chromium.debug.core.ChromiumDebugPlugin; |
19 import org.chromium.debug.core.util.ScriptTargetMapping; | 12 import org.chromium.debug.core.util.ScriptTargetMapping; |
20 import org.chromium.debug.ui.DialogUtils.Gettable; | 13 import org.chromium.debug.ui.DialogUtils.*; |
21 import org.chromium.debug.ui.DialogUtils.Message; | |
22 import org.chromium.debug.ui.DialogUtils.MessagePriority; | |
23 import org.chromium.debug.ui.DialogUtils.NormalExpression; | |
24 import org.chromium.debug.ui.DialogUtils.Optional; | 14 import org.chromium.debug.ui.DialogUtils.Optional; |
25 import org.chromium.debug.ui.DialogUtils.OptionalSwitcher; | |
26 import org.chromium.debug.ui.DialogUtils.Scope; | |
27 import org.chromium.debug.ui.DialogUtils.ScopeEnabler; | |
28 import org.chromium.debug.ui.DialogUtils.Updater; | |
29 import org.chromium.debug.ui.DialogUtils.ValueConsumer; | |
30 import org.chromium.debug.ui.DialogUtils.ValueProcessor; | 15 import org.chromium.debug.ui.DialogUtils.ValueProcessor; |
31 import org.chromium.debug.ui.DialogUtils.ValueSource; | 16 import org.chromium.debug.ui.DialogUtils.ValueSource; |
32 import org.chromium.debug.ui.WizardUtils.LogicBasedWizard; | 17 import org.chromium.debug.ui.WizardUtils.LogicBasedWizard; |
33 import org.chromium.debug.ui.WizardUtils.NextPageEnabler; | 18 import org.chromium.debug.ui.WizardUtils.NextPageEnabler; |
34 import org.chromium.debug.ui.WizardUtils.PageElements; | 19 import org.chromium.debug.ui.WizardUtils.PageElements; |
35 import org.chromium.debug.ui.WizardUtils.PageImpl; | 20 import org.chromium.debug.ui.WizardUtils.PageImpl; |
36 import org.chromium.debug.ui.WizardUtils.PageListener; | 21 import org.chromium.debug.ui.WizardUtils.PageListener; |
37 import org.chromium.debug.ui.WizardUtils.WizardFinishController; | 22 import org.chromium.debug.ui.WizardUtils.WizardFinishController; |
38 import org.chromium.debug.ui.WizardUtils.WizardFinisher; | 23 import org.chromium.debug.ui.WizardUtils.WizardFinisher; |
39 import org.chromium.debug.ui.WizardUtils.WizardLogic; | 24 import org.chromium.debug.ui.WizardUtils.WizardLogic; |
40 import org.chromium.debug.ui.actions.ChooseVmControl; | 25 import org.chromium.debug.ui.actions.ChooseVmControl; |
41 import org.chromium.debug.ui.actions.CompareChangesAction; | 26 import org.chromium.debug.ui.actions.CompareChangesAction; |
42 import org.chromium.debug.ui.liveedit.PushChangesWizard.FinisherDelegate; | 27 import org.chromium.debug.ui.liveedit.PushChangesWizard.FinisherDelegate; |
28 import org.chromium.sdk.UpdatableScript; | |
43 import org.chromium.sdk.UpdatableScript.ChangeDescription; | 29 import org.chromium.sdk.UpdatableScript.ChangeDescription; |
44 import org.eclipse.compare.structuremergeviewer.DiffNode; | 30 import org.eclipse.compare.structuremergeviewer.DiffNode; |
45 import org.eclipse.core.runtime.NullProgressMonitor; | 31 import org.eclipse.core.runtime.NullProgressMonitor; |
46 | 32 |
47 /** | 33 /** |
48 * Creates Updater-based logic implementation of the wizard. It is responsible f or proper data | 34 * Creates Updater-based logic implementation of the wizard. It is responsible f or proper data |
49 * manipulation and view control updates. | 35 * manipulation and view control updates. |
50 * <p> | 36 * <p> |
51 * The wizard pages are arranged in graph with one fork:<br> | 37 * The wizard pages are arranged in graph with one fork:<br> |
52 * 'choose vm' -> | 38 * 'choose vm' -> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 return createOptional(vmList); | 97 return createOptional(vmList); |
112 } | 98 } |
113 } | 99 } |
114 }); | 100 }); |
115 updater.addSource(scope, selectedVmValue); | 101 updater.addSource(scope, selectedVmValue); |
116 updater.addConsumer(scope, selectedVmValue); | 102 updater.addConsumer(scope, selectedVmValue); |
117 updater.addDependency(selectedVmValue, selectedVmInput); | 103 updater.addDependency(selectedVmValue, selectedVmInput); |
118 | 104 |
119 | 105 |
120 // A condition value for up-coming fork between 'single vm' and 'multiple vm ' paths. | 106 // A condition value for up-coming fork between 'single vm' and 'multiple vm ' paths. |
121 Gettable<? extends Optional<Boolean>> singleVmSelectedExpression = handleErr ors( | 107 Gettable<? extends Optional<? extends Boolean>> singleVmSelectedExpression = handleErrors( |
122 new NormalExpression<Boolean>() { | 108 new NormalExpression<Boolean>() { |
123 public Boolean calculate() { | 109 @Calculate |
124 return selectedVmValue.getValue().getNormal().size() == 1; | 110 public Boolean calculate(List<ScriptTargetMapping> selectedVm) { |
111 return selectedVm.size() == 1; | |
125 } | 112 } |
126 }, | 113 @DependencyGetter |
127 dependencies(selectedVmValue)); | 114 public ValueSource<? extends Optional<List<ScriptTargetMapping>>> getS electVmSource() { |
115 return selectedVmValue; | |
116 } | |
117 }); | |
128 | 118 |
129 // A switch between 2 paths: 'single vm' and 'multiple vm'. | 119 // A switch between 2 paths: 'single vm' and 'multiple vm'. |
130 OptionalSwitcher<Boolean> singleVmSelectedSwitch = | 120 OptionalSwitcher<Boolean> singleVmSelectedSwitch = |
131 scope.addOptionalSwitch(singleVmSelectedExpression); | 121 scope.addOptionalSwitch(singleVmSelectedExpression); |
132 | 122 |
133 final PreviewAndOptionPath singleVmPath = | 123 final PreviewAndOptionPath singleVmPath = |
134 createSingleVmPath(chooseVmPage, singleVmSelectedSwitch, selectedVmValue ); | 124 createSingleVmPath(chooseVmPage, singleVmSelectedSwitch, selectedVmValue ); |
135 final PreviewAndOptionPath multipleVmPath = | 125 final PreviewAndOptionPath multipleVmPath = |
136 createMultipleVmPath(chooseVmPage, singleVmSelectedSwitch, selectedVmVal ue); | 126 createMultipleVmPath(chooseVmPage, singleVmSelectedSwitch, selectedVmVal ue); |
137 | 127 |
138 // 2 merges for output values of 2 paths. Only the value from active path is effective. | 128 // 2 merges for output values of 2 paths. Only the value from active path is effective. |
139 final ValueSource<? extends Optional<? extends FinisherDelegate>> wizardFini sherDelegateValue = | 129 final ValueSource<? extends Optional<? extends FinisherDelegate>> wizardFini sherDelegateValue = |
140 singleVmSelectedSwitch.createOptionalMerge(singleVmPath.getFinisherDeleg ateValue(), | 130 singleVmSelectedSwitch.createOptionalMerge(singleVmPath.getFinisherDeleg ateValue(), |
141 multipleVmPath.getFinisherDelegateValue()); | 131 multipleVmPath.getFinisherDelegateValue()); |
142 | 132 |
143 ValueSource<? extends Optional<Void>> warningValue = | 133 ValueSource<? extends Optional<? extends Void>> warningValue = |
144 singleVmSelectedSwitch.createOptionalMerge(singleVmPath.getWarningValue( ), | 134 singleVmSelectedSwitch.createOptionalMerge(singleVmPath.getWarningValue( ), |
145 multipleVmPath.getWarningValue()); | 135 multipleVmPath.getWarningValue()); |
146 | 136 |
147 | 137 |
148 // A simple value converter that wraps wizard delegate as UI-aware wizard fi nisher. | 138 // A simple value converter that wraps wizard delegate as UI-aware wizard fi nisher. |
149 ValueProcessor<Optional<WizardFinisher>> finisherValue = | 139 ValueProcessor<Optional<? extends WizardFinisher>> finisherValue = |
150 createOptionalProcessor(new NormalExpression<WizardFinisher>() { | 140 createProcessor(handleErrors(new NormalExpression<WizardFinisher>() { |
151 public WizardFinisher calculate() { | 141 @Calculate |
152 return new PushChangesWizard.FinisherImpl( | 142 public WizardFinisher calculate(FinisherDelegate finisherDelegate) { |
153 wizardFinisherDelegateValue.getValue().getNormal()); | 143 return new PushChangesWizard.FinisherImpl(finisherDelegate); |
154 } | 144 } |
155 }, | 145 @DependencyGetter |
156 dependencies(wizardFinisherDelegateValue)); | 146 public ValueSource<? extends Optional<? extends FinisherDelegate>> getWizardFinisherDelegateSource() { |
apavlov
2011/02/01 18:05:37
line too long
Peter Rybin
2011/02/01 19:28:04
Done.
| |
147 return wizardFinisherDelegateValue; | |
148 } | |
149 })); | |
157 updater.addConsumer(scope, finisherValue); | 150 updater.addConsumer(scope, finisherValue); |
158 updater.addSource(scope, finisherValue); | 151 updater.addSource(scope, finisherValue); |
159 updater.addDependency(finisherValue, wizardFinisherDelegateValue); | 152 updater.addDependency(finisherValue, wizardFinisherDelegateValue); |
160 | 153 |
161 // A controller that ties finisher value and other warnings to a wizard UI. | 154 // A controller that ties finisher value and other warnings to a wizard UI. |
162 WizardFinishController finishController = | 155 WizardFinishController finishController = |
163 new WizardFinishController(finisherValue, warningValue, wizardImpl); | 156 new WizardFinishController(finisherValue, warningValue, wizardImpl); |
164 updater.addConsumer(scope, finishController); | 157 updater.addConsumer(scope, finishController); |
165 updater.addDependency(finishController, wizardFinisherDelegateValue); | 158 updater.addDependency(finishController, wizardFinisherDelegateValue); |
166 updater.addDependency(finishController, warningValue); | 159 updater.addDependency(finishController, warningValue); |
(...skipping 10 matching lines...) Expand all Loading... | |
177 } | 170 } |
178 }; | 171 }; |
179 } | 172 } |
180 | 173 |
181 /** | 174 /** |
182 * An internal interface that defines a uniform output of preview path. The pr eview path | 175 * An internal interface that defines a uniform output of preview path. The pr eview path |
183 * is responsible for returning finisher (which may carry error messages) and it also may | 176 * is responsible for returning finisher (which may carry error messages) and it also may |
184 * return additional warning messages. | 177 * return additional warning messages. |
185 */ | 178 */ |
186 private interface PreviewAndOptionPath { | 179 private interface PreviewAndOptionPath { |
187 ValueSource<? extends Optional<FinisherDelegate>> getFinisherDelegateValue() ; | 180 ValueSource<? extends Optional<? extends FinisherDelegate>> getFinisherDeleg ateValue(); |
188 ValueSource<Optional<Void>> getWarningValue(); | 181 ValueSource<Optional<Void>> getWarningValue(); |
189 } | 182 } |
190 | 183 |
191 /** | 184 /** |
192 * Creates a 'single vm' page path in wizard. User sees it after choosing exac tly one VM. | 185 * Creates a 'single vm' page path in wizard. User sees it after choosing exac tly one VM. |
193 * It consists of 2 pages, 'textual preview' and 'v8 preview'. | 186 * It consists of 2 pages, 'textual preview' and 'v8 preview'. |
194 */ | 187 */ |
195 private PreviewAndOptionPath createSingleVmPath(PageImpl<?> basePage, | 188 private PreviewAndOptionPath createSingleVmPath(PageImpl<?> basePage, |
196 OptionalSwitcher<Boolean> switcher, | 189 OptionalSwitcher<Boolean> switcher, |
197 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>> selectedVmValue) { | 190 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>> selectedVmValue) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 234 |
242 // previewRawResultValue is trigged only when page is actually visible to us er. | 235 // previewRawResultValue is trigged only when page is actually visible to us er. |
243 v8PreviewPage.addListener(new PageListener() { | 236 v8PreviewPage.addListener(new PageListener() { |
244 public void onSetVisible(boolean visible) { | 237 public void onSetVisible(boolean visible) { |
245 previewRawResultValue.setActive(visible); | 238 previewRawResultValue.setActive(visible); |
246 } | 239 } |
247 }); | 240 }); |
248 | 241 |
249 // Parses raw preview value and converts it into a form suitable for the vie wer; also handles | 242 // Parses raw preview value and converts it into a form suitable for the vie wer; also handles |
250 // errors that become warnings. | 243 // errors that become warnings. |
251 final ValueProcessor<Optional<LiveEditDiffViewer.Input>> previewValue = | 244 // final ValueProcessor<Optional<LiveEditDiffViewer.Input>> previewValue = |
apavlov
2011/02/01 18:05:37
can we refrain from committing commented code?
Peter Rybin
2011/02/01 19:28:04
Done.
| |
252 createProcessor(handleErrorsAddNew( | 245 // createProcessor(handleErrorsAddNew( |
253 new NormalExpression<Optional<LiveEditDiffViewer.Input>>() { | 246 // new NormalExpression<Optional<LiveEditDiffViewer.Input>>() { |
254 public Optional<LiveEditDiffViewer.Input> calculate() { | 247 // public Optional<LiveEditDiffViewer.Input> calculate() { |
255 ScriptTargetMapping filePair = singleVmValue.getValue(); | 248 // ScriptTargetMapping filePair = singleVmValue.getValue(); |
256 ChangeDescription changeDescription = previewRawResultValue.getValue ().getNormal(); | 249 // ChangeDescription changeDescription = previewRawResultValue.getVal ue().getNormal(); |
257 Optional<LiveEditDiffViewer.Input> result; | 250 // Optional<LiveEditDiffViewer.Input> result; |
258 if (changeDescription == null) { | 251 // if (changeDescription == null) { |
259 result = createOptional(null); | 252 // result = createOptional(null); |
260 } else { | 253 // } else { |
261 try { | 254 // try { |
262 LiveEditDiffViewer.Input viewerInput = | 255 // LiveEditDiffViewer.Input viewerInput = |
263 PushResultParser.createViewerInput(changeDescription, filePa ir, true); | 256 // PushResultParser.createViewerInput(changeDescription, file Pair, true); |
264 result = createOptional(viewerInput); | 257 // result = createOptional(viewerInput); |
265 } catch (RuntimeException e) { | 258 // } catch (RuntimeException e) { |
266 ChromiumDebugPlugin.log(e); | 259 // ChromiumDebugPlugin.log(e); |
267 result = createErrorOptional(new Message( | 260 // result = createErrorOptional(new Message( |
268 "Error in getting preview: " + e.toString(), MessagePriority .WARNING)); | 261 // "Error in getting preview: " + e.toString(), MessagePriori ty.WARNING)); |
262 // } | |
263 // } | |
264 // return result; | |
265 // } | |
266 // }, | |
267 // dependencies(previewRawResultValue))); | |
268 | |
269 | |
270 | |
271 final ValueProcessor<Optional<? extends LiveEditDiffViewer.Input>> previewVa lue = | |
272 createProcessor(handleErrors( | |
273 new NormalExpression<LiveEditDiffViewer.Input>() { | |
274 @Calculate | |
275 public Optional<? extends LiveEditDiffViewer.Input> calculate(Change Description previewRawResultParam) { | |
apavlov
2011/02/01 18:05:37
line too long
Peter Rybin
2011/02/01 19:28:04
Done.
| |
276 ScriptTargetMapping filePair = singleVmValue.getValue(); | |
277 ChangeDescription changeDescription = previewRawResultParam; | |
278 Optional<LiveEditDiffViewer.Input> result; | |
279 if (changeDescription == null) { | |
280 result = createOptional(null); | |
281 } else { | |
282 try { | |
283 LiveEditDiffViewer.Input viewerInput = | |
284 PushResultParser.createViewerInput(changeDescription, file Pair, true); | |
285 result = createOptional(viewerInput); | |
286 } catch (RuntimeException e) { | |
287 ChromiumDebugPlugin.log(e); | |
288 result = createErrorOptional(new Message( | |
289 "Error in getting preview: " + e.toString(), MessagePriori ty.WARNING)); | |
290 } | |
269 } | 291 } |
292 return result; | |
270 } | 293 } |
271 return result; | 294 @DependencyGetter |
272 } | 295 public ValueSource<Optional<UpdatableScript.ChangeDescription>> prev iewRawResultValueSource() { |
apavlov
2011/02/01 18:05:37
line too long
Peter Rybin
2011/02/01 19:28:04
Done.
| |
273 }, | 296 return previewRawResultValue; |
274 dependencies(previewRawResultValue))); | 297 } |
298 })); | |
299 | |
300 | |
301 | |
275 updater.addConsumer(scope, previewValue); | 302 updater.addConsumer(scope, previewValue); |
276 updater.addSource(scope, previewValue); | 303 updater.addSource(scope, previewValue); |
277 updater.addDependency(previewValue, previewRawResultValue); | 304 updater.addDependency(previewValue, previewRawResultValue); |
278 updater.addDependency(previewValue, singleVmValue); | 305 updater.addDependency(previewValue, singleVmValue); |
279 | 306 |
280 // A simple consumer that sets preview data to the viewer. | 307 // A simple consumer that sets preview data to the viewer. |
281 ValueConsumer v8PreviewInputSetter = new ValueConsumer() { | 308 ValueConsumer v8PreviewInputSetter = new ValueConsumer() { |
282 public void update(Updater updater) { | 309 public void update(Updater updater) { |
283 Optional<LiveEditDiffViewer.Input> previewOptional = previewValue.getVal ue(); | 310 Optional<? extends LiveEditDiffViewer.Input> previewOptional = previewVa lue.getValue(); |
284 LiveEditDiffViewer.Input viewerInput; | 311 LiveEditDiffViewer.Input viewerInput; |
285 if (previewOptional.isNormal()) { | 312 if (previewOptional.isNormal()) { |
286 viewerInput = previewOptional.getNormal(); | 313 viewerInput = previewOptional.getNormal(); |
287 } else { | 314 } else { |
288 viewerInput = null; | 315 viewerInput = null; |
289 } | 316 } |
290 v8PreviewPage.getPageElements().getPreviewViewer().setInput(viewerInput) ; | 317 v8PreviewPage.getPageElements().getPreviewViewer().setInput(viewerInput) ; |
291 } | 318 } |
292 }; | 319 }; |
293 updater.addConsumer(scope, v8PreviewInputSetter); | 320 updater.addConsumer(scope, v8PreviewInputSetter); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 OptionalSwitcher<Boolean> switcher, | 370 OptionalSwitcher<Boolean> switcher, |
344 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>> selectedVmValue) { | 371 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>> selectedVmValue) { |
345 | 372 |
346 PageImpl<PageElements> multipleVmStubPage = pageSet.getMultipleVmStubPage(); | 373 PageImpl<PageElements> multipleVmStubPage = pageSet.getMultipleVmStubPage(); |
347 | 374 |
348 ScopeEnabler scopeEnabler = | 375 ScopeEnabler scopeEnabler = |
349 new NextPageEnabler(basePage, multipleVmStubPage); | 376 new NextPageEnabler(basePage, multipleVmStubPage); |
350 | 377 |
351 Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler); | 378 Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler); |
352 | 379 |
353 final ValueProcessor<? extends Optional<FinisherDelegate>> wizardFinisher = | 380 final ValueProcessor<Optional<? extends FinisherDelegate>> wizardFinisher = |
354 createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() { | 381 createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() { |
355 public FinisherDelegate calculate() { | 382 @Calculate |
383 public FinisherDelegate calculate(List<ScriptTargetMapping> selectedVm ) { | |
356 return new PushChangesWizard.MultipleVmFinisher(selectedVmValue.getV alue().getNormal()); | 384 return new PushChangesWizard.MultipleVmFinisher(selectedVmValue.getV alue().getNormal()); |
357 } | 385 } |
358 }, dependencies(selectedVmValue))); | 386 @DependencyGetter |
387 public ValueSource<? extends Optional<? extends List<ScriptTargetMappi ng>>> getSelectVmSource() { | |
apavlov
2011/02/01 18:05:37
line too long
Peter Rybin
2011/02/01 19:28:04
Done.
| |
388 return selectedVmValue; | |
389 } | |
390 })); | |
359 updater.addSource(scope, wizardFinisher); | 391 updater.addSource(scope, wizardFinisher); |
360 updater.addConsumer(scope, wizardFinisher); | 392 updater.addConsumer(scope, wizardFinisher); |
361 updater.addDependency(wizardFinisher, selectedVmValue); | 393 updater.addDependency(wizardFinisher, selectedVmValue); |
362 | 394 |
363 final ValueSource<Optional<Void>> warningValue = | 395 final ValueSource<Optional<Void>> warningValue = |
364 createConstant(createOptional((Void) null), updater); | 396 createConstant(createOptional((Void) null), updater); |
365 | 397 |
366 return new PreviewAndOptionPath() { | 398 return new PreviewAndOptionPath() { |
367 public ValueSource<? extends Optional<FinisherDelegate>> getFinisherDelega teValue() { | 399 public ValueSource<? extends Optional<? extends FinisherDelegate>> getFini sherDelegateValue() { |
368 return wizardFinisher; | 400 return wizardFinisher; |
369 } | 401 } |
370 public ValueSource<Optional<Void>> getWarningValue() { | 402 public ValueSource<Optional<Void>> getWarningValue() { |
371 return warningValue; | 403 return warningValue; |
372 } | 404 } |
373 }; | 405 }; |
374 } | 406 } |
375 } | 407 } |
OLD | NEW |