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>> |
| 147 getWizardFinisherDelegateSource() { |
| 148 return wizardFinisherDelegateValue; |
| 149 } |
| 150 })); |
157 updater.addConsumer(scope, finisherValue); | 151 updater.addConsumer(scope, finisherValue); |
158 updater.addSource(scope, finisherValue); | 152 updater.addSource(scope, finisherValue); |
159 updater.addDependency(finisherValue, wizardFinisherDelegateValue); | 153 updater.addDependency(finisherValue, wizardFinisherDelegateValue); |
160 | 154 |
161 // A controller that ties finisher value and other warnings to a wizard UI. | 155 // A controller that ties finisher value and other warnings to a wizard UI. |
162 WizardFinishController finishController = | 156 WizardFinishController finishController = |
163 new WizardFinishController(finisherValue, warningValue, wizardImpl); | 157 new WizardFinishController(finisherValue, warningValue, wizardImpl); |
164 updater.addConsumer(scope, finishController); | 158 updater.addConsumer(scope, finishController); |
165 updater.addDependency(finishController, wizardFinisherDelegateValue); | 159 updater.addDependency(finishController, wizardFinisherDelegateValue); |
166 updater.addDependency(finishController, warningValue); | 160 updater.addDependency(finishController, warningValue); |
(...skipping 10 matching lines...) Expand all Loading... |
177 } | 171 } |
178 }; | 172 }; |
179 } | 173 } |
180 | 174 |
181 /** | 175 /** |
182 * An internal interface that defines a uniform output of preview path. The pr
eview path | 176 * 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 | 177 * is responsible for returning finisher (which may carry error messages) and
it also may |
184 * return additional warning messages. | 178 * return additional warning messages. |
185 */ | 179 */ |
186 private interface PreviewAndOptionPath { | 180 private interface PreviewAndOptionPath { |
187 ValueSource<? extends Optional<FinisherDelegate>> getFinisherDelegateValue()
; | 181 ValueSource<? extends Optional<? extends FinisherDelegate>> getFinisherDeleg
ateValue(); |
188 ValueSource<Optional<Void>> getWarningValue(); | 182 ValueSource<Optional<Void>> getWarningValue(); |
189 } | 183 } |
190 | 184 |
191 /** | 185 /** |
192 * Creates a 'single vm' page path in wizard. User sees it after choosing exac
tly one VM. | 186 * 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'. | 187 * It consists of 2 pages, 'textual preview' and 'v8 preview'. |
194 */ | 188 */ |
195 private PreviewAndOptionPath createSingleVmPath(PageImpl<?> basePage, | 189 private PreviewAndOptionPath createSingleVmPath(PageImpl<?> basePage, |
196 OptionalSwitcher<Boolean> switcher, | 190 OptionalSwitcher<Boolean> switcher, |
197 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>>
selectedVmValue) { | 191 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>>
selectedVmValue) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 235 |
242 // previewRawResultValue is trigged only when page is actually visible to us
er. | 236 // previewRawResultValue is trigged only when page is actually visible to us
er. |
243 v8PreviewPage.addListener(new PageListener() { | 237 v8PreviewPage.addListener(new PageListener() { |
244 public void onSetVisible(boolean visible) { | 238 public void onSetVisible(boolean visible) { |
245 previewRawResultValue.setActive(visible); | 239 previewRawResultValue.setActive(visible); |
246 } | 240 } |
247 }); | 241 }); |
248 | 242 |
249 // Parses raw preview value and converts it into a form suitable for the vie
wer; also handles | 243 // Parses raw preview value and converts it into a form suitable for the vie
wer; also handles |
250 // errors that become warnings. | 244 // errors that become warnings. |
251 final ValueProcessor<Optional<LiveEditDiffViewer.Input>> previewValue = | 245 final ValueProcessor<Optional<? extends LiveEditDiffViewer.Input>> previewVa
lue = |
252 createProcessor(handleErrorsAddNew( | 246 createProcessor(handleErrors( |
253 new NormalExpression<Optional<LiveEditDiffViewer.Input>>() { | 247 new NormalExpression<LiveEditDiffViewer.Input>() { |
254 public Optional<LiveEditDiffViewer.Input> calculate() { | 248 @Calculate |
255 ScriptTargetMapping filePair = singleVmValue.getValue(); | 249 public Optional<? extends LiveEditDiffViewer.Input> calculate( |
256 ChangeDescription changeDescription = previewRawResultValue.getValue
().getNormal(); | 250 ChangeDescription previewRawResultParam) { |
257 Optional<LiveEditDiffViewer.Input> result; | 251 ScriptTargetMapping filePair = singleVmValue.getValue(); |
258 if (changeDescription == null) { | 252 ChangeDescription changeDescription = previewRawResultParam; |
259 result = createOptional(null); | 253 Optional<LiveEditDiffViewer.Input> result; |
260 } else { | 254 if (changeDescription == null) { |
261 try { | 255 result = createOptional(null); |
262 LiveEditDiffViewer.Input viewerInput = | 256 } else { |
263 PushResultParser.createViewerInput(changeDescription, filePa
ir, true); | 257 try { |
264 result = createOptional(viewerInput); | 258 LiveEditDiffViewer.Input viewerInput = |
265 } catch (RuntimeException e) { | 259 PushResultParser.createViewerInput(changeDescription, file
Pair, true); |
266 ChromiumDebugPlugin.log(e); | 260 result = createOptional(viewerInput); |
267 result = createErrorOptional(new Message( | 261 } catch (RuntimeException e) { |
268 "Error in getting preview: " + e.toString(), MessagePriority
.WARNING)); | 262 ChromiumDebugPlugin.log(e); |
| 263 result = createErrorOptional(new Message( |
| 264 "Error in getting preview: " + e.toString(), MessagePriori
ty.WARNING)); |
| 265 } |
269 } | 266 } |
| 267 return result; |
270 } | 268 } |
271 return result; | 269 @DependencyGetter |
272 } | 270 public ValueSource<Optional<UpdatableScript.ChangeDescription>> |
273 }, | 271 previewRawResultValueSource() { |
274 dependencies(previewRawResultValue))); | 272 return previewRawResultValue; |
| 273 } |
| 274 })); |
| 275 |
| 276 |
| 277 |
275 updater.addConsumer(scope, previewValue); | 278 updater.addConsumer(scope, previewValue); |
276 updater.addSource(scope, previewValue); | 279 updater.addSource(scope, previewValue); |
277 updater.addDependency(previewValue, previewRawResultValue); | 280 updater.addDependency(previewValue, previewRawResultValue); |
278 updater.addDependency(previewValue, singleVmValue); | 281 updater.addDependency(previewValue, singleVmValue); |
279 | 282 |
280 // A simple consumer that sets preview data to the viewer. | 283 // A simple consumer that sets preview data to the viewer. |
281 ValueConsumer v8PreviewInputSetter = new ValueConsumer() { | 284 ValueConsumer v8PreviewInputSetter = new ValueConsumer() { |
282 public void update(Updater updater) { | 285 public void update(Updater updater) { |
283 Optional<LiveEditDiffViewer.Input> previewOptional = previewValue.getVal
ue(); | 286 Optional<? extends LiveEditDiffViewer.Input> previewOptional = previewVa
lue.getValue(); |
284 LiveEditDiffViewer.Input viewerInput; | 287 LiveEditDiffViewer.Input viewerInput; |
285 if (previewOptional.isNormal()) { | 288 if (previewOptional.isNormal()) { |
286 viewerInput = previewOptional.getNormal(); | 289 viewerInput = previewOptional.getNormal(); |
287 } else { | 290 } else { |
288 viewerInput = null; | 291 viewerInput = null; |
289 } | 292 } |
290 v8PreviewPage.getPageElements().getPreviewViewer().setInput(viewerInput)
; | 293 v8PreviewPage.getPageElements().getPreviewViewer().setInput(viewerInput)
; |
291 } | 294 } |
292 }; | 295 }; |
293 updater.addConsumer(scope, v8PreviewInputSetter); | 296 updater.addConsumer(scope, v8PreviewInputSetter); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 OptionalSwitcher<Boolean> switcher, | 346 OptionalSwitcher<Boolean> switcher, |
344 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>>
selectedVmValue) { | 347 final ValueSource<? extends Optional<? extends List<ScriptTargetMapping>>>
selectedVmValue) { |
345 | 348 |
346 PageImpl<PageElements> multipleVmStubPage = pageSet.getMultipleVmStubPage(); | 349 PageImpl<PageElements> multipleVmStubPage = pageSet.getMultipleVmStubPage(); |
347 | 350 |
348 ScopeEnabler scopeEnabler = | 351 ScopeEnabler scopeEnabler = |
349 new NextPageEnabler(basePage, multipleVmStubPage); | 352 new NextPageEnabler(basePage, multipleVmStubPage); |
350 | 353 |
351 Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler); | 354 Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler); |
352 | 355 |
353 final ValueProcessor<? extends Optional<FinisherDelegate>> wizardFinisher = | 356 final ValueProcessor<Optional<? extends FinisherDelegate>> wizardFinisher = |
354 createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() { | 357 createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() { |
355 public FinisherDelegate calculate() { | 358 @Calculate |
| 359 public FinisherDelegate calculate(List<ScriptTargetMapping> selectedVm
) { |
356 return new PushChangesWizard.MultipleVmFinisher(selectedVmValue.getV
alue().getNormal()); | 360 return new PushChangesWizard.MultipleVmFinisher(selectedVmValue.getV
alue().getNormal()); |
357 } | 361 } |
358 }, dependencies(selectedVmValue))); | 362 @DependencyGetter |
| 363 public ValueSource<? extends Optional<? extends List<ScriptTargetMappi
ng>>> |
| 364 getSelectVmSource() { |
| 365 return selectedVmValue; |
| 366 } |
| 367 })); |
359 updater.addSource(scope, wizardFinisher); | 368 updater.addSource(scope, wizardFinisher); |
360 updater.addConsumer(scope, wizardFinisher); | 369 updater.addConsumer(scope, wizardFinisher); |
361 updater.addDependency(wizardFinisher, selectedVmValue); | 370 updater.addDependency(wizardFinisher, selectedVmValue); |
362 | 371 |
363 final ValueSource<Optional<Void>> warningValue = | 372 final ValueSource<Optional<Void>> warningValue = |
364 createConstant(createOptional((Void) null), updater); | 373 createConstant(createOptional((Void) null), updater); |
365 | 374 |
366 return new PreviewAndOptionPath() { | 375 return new PreviewAndOptionPath() { |
367 public ValueSource<? extends Optional<FinisherDelegate>> getFinisherDelega
teValue() { | 376 public ValueSource<? extends Optional<? extends FinisherDelegate>> |
| 377 getFinisherDelegateValue() { |
368 return wizardFinisher; | 378 return wizardFinisher; |
369 } | 379 } |
370 public ValueSource<Optional<Void>> getWarningValue() { | 380 public ValueSource<Optional<Void>> getWarningValue() { |
371 return warningValue; | 381 return warningValue; |
372 } | 382 } |
373 }; | 383 }; |
374 } | 384 } |
375 } | 385 } |
OLD | NEW |