| 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.createConstant; |
| 8 import static org.chromium.debug.ui.DialogUtils.createErrorOptional; | 8 import static org.chromium.debug.ui.DialogUtils.createErrorOptional; |
| 9 import static org.chromium.debug.ui.DialogUtils.createOptional; | 9 import static org.chromium.debug.ui.DialogUtils.createOptional; |
| 10 import static org.chromium.debug.ui.DialogUtils.createProcessor; | 10 import static org.chromium.debug.ui.DialogUtils.createProcessor; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 import org.chromium.debug.ui.DialogUtils.ValueSource; | 34 import org.chromium.debug.ui.DialogUtils.ValueSource; |
| 35 import org.chromium.debug.ui.WizardUtils.LogicBasedWizard; | 35 import org.chromium.debug.ui.WizardUtils.LogicBasedWizard; |
| 36 import org.chromium.debug.ui.WizardUtils.NextPageEnabler; | 36 import org.chromium.debug.ui.WizardUtils.NextPageEnabler; |
| 37 import org.chromium.debug.ui.WizardUtils.PageElements; | 37 import org.chromium.debug.ui.WizardUtils.PageElements; |
| 38 import org.chromium.debug.ui.WizardUtils.PageImpl; | 38 import org.chromium.debug.ui.WizardUtils.PageImpl; |
| 39 import org.chromium.debug.ui.WizardUtils.PageListener; | 39 import org.chromium.debug.ui.WizardUtils.PageListener; |
| 40 import org.chromium.debug.ui.WizardUtils.WizardFinishController; | 40 import org.chromium.debug.ui.WizardUtils.WizardFinishController; |
| 41 import org.chromium.debug.ui.WizardUtils.WizardFinisher; | 41 import org.chromium.debug.ui.WizardUtils.WizardFinisher; |
| 42 import org.chromium.debug.ui.WizardUtils.WizardLogic; | 42 import org.chromium.debug.ui.WizardUtils.WizardLogic; |
| 43 import org.chromium.debug.ui.actions.ChooseVmControl; | 43 import org.chromium.debug.ui.actions.ChooseVmControl; |
| 44 import org.chromium.debug.ui.liveedit.LiveEditDiffViewer.Input; |
| 44 import org.chromium.debug.ui.liveedit.PushChangesWizard.FinisherDelegate; | 45 import org.chromium.debug.ui.liveedit.PushChangesWizard.FinisherDelegate; |
| 46 import org.chromium.sdk.TextStreamPosition; |
| 45 import org.chromium.sdk.UpdatableScript.ChangeDescription; | 47 import org.chromium.sdk.UpdatableScript.ChangeDescription; |
| 48 import org.chromium.sdk.UpdatableScript.CompileErrorFailure; |
| 49 import org.eclipse.osgi.util.NLS; |
| 46 | 50 |
| 47 /** | 51 /** |
| 48 * Creates Updater-based logic implementation of the wizard. It is responsible f
or proper data | 52 * Creates Updater-based logic implementation of the wizard. It is responsible f
or proper data |
| 49 * manipulation and view control updates. | 53 * manipulation and view control updates. |
| 50 * <p> | 54 * <p> |
| 51 * The wizard pages are arranged in graph with one fork:<br> | 55 * The wizard pages are arranged in graph with one fork:<br> |
| 52 * 'choose vm' -> | 56 * 'choose vm' -> |
| 53 * <ul> | 57 * <ul> |
| 54 * <li>[single vm path] -> 'textual preview' -> 'v8 preview' | 58 * <li>[single vm path] -> 'textual preview' -> 'v8 preview' |
| 55 * <li>[multiple vm path] -> 'multiple vm stub' | 59 * <li>[multiple vm path] -> 'multiple vm stub' |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 List<Optional<PushChangesPlan>> result = | 113 List<Optional<PushChangesPlan>> result = |
| 110 new ArrayList<DialogUtils.Optional<PushChangesPlan>>(input.size()); | 114 new ArrayList<DialogUtils.Optional<PushChangesPlan>>(input.size()); |
| 111 for (ScriptTargetMapping mapping : input) { | 115 for (ScriptTargetMapping mapping : input) { |
| 112 Optional<PushChangesPlan> optionalPlan; | 116 Optional<PushChangesPlan> optionalPlan; |
| 113 try { | 117 try { |
| 114 PushChangesPlan plan = PushChangesPlan.create(mapping); | 118 PushChangesPlan plan = PushChangesPlan.create(mapping); |
| 115 optionalPlan = createOptional(plan); | 119 optionalPlan = createOptional(plan); |
| 116 } catch (RuntimeException e) { | 120 } catch (RuntimeException e) { |
| 117 // TODO: have more specific exception types to catch. | 121 // TODO: have more specific exception types to catch. |
| 118 optionalPlan = createErrorOptional(new Message( | 122 optionalPlan = createErrorOptional(new Message( |
| 119 "Failed to get script source from a file. See log for details.", | 123 Messages.WizardLogicBuilder_FAILED_TO_GET, |
| 120 MessagePriority.BLOCKING_PROBLEM)); | 124 MessagePriority.BLOCKING_PROBLEM)); |
| 121 } | 125 } |
| 122 result.add(optionalPlan); | 126 result.add(optionalPlan); |
| 123 } | 127 } |
| 124 return result; | 128 return result; |
| 125 } | 129 } |
| 126 }); | 130 }); |
| 127 updater.addSource(scope, selectedChangePlansValue); | 131 updater.addSource(scope, selectedChangePlansValue); |
| 128 updater.addConsumer(scope, selectedChangePlansValue); | 132 updater.addConsumer(scope, selectedChangePlansValue); |
| 129 updater.addDependency(selectedChangePlansValue, selectedVmInput); | 133 updater.addDependency(selectedChangePlansValue, selectedVmInput); |
| 130 | 134 |
| 131 | 135 |
| 132 // A derived value of selected VMs list; the list is non-empty or the value
is error. | 136 // A derived value of selected VMs list; the list is non-empty or the value
is error. |
| 133 final ValueProcessor<? extends Optional<List<PushChangesPlan>>> nonEmptySele
ctedPlansValue = | 137 final ValueProcessor<? extends Optional<List<PushChangesPlan>>> nonEmptySele
ctedPlansValue = |
| 134 createProcessor(new Gettable<Optional<List<PushChangesPlan>>>() { | 138 createProcessor(new Gettable<Optional<List<PushChangesPlan>>>() { |
| 135 public Optional<List<PushChangesPlan>> getValue() { | 139 public Optional<List<PushChangesPlan>> getValue() { |
| 136 List<Optional<PushChangesPlan>> planList = selectedChangePlansValue.getV
alue(); | 140 List<Optional<PushChangesPlan>> planList = selectedChangePlansValue.getV
alue(); |
| 137 if (planList.isEmpty()) { | 141 if (planList.isEmpty()) { |
| 138 return createErrorOptional( | 142 return createErrorOptional( |
| 139 new Message("Choose at least one VM", MessagePriority.BLOCKING_INF
O)); | 143 new Message(Messages.WizardLogicBuilder_CHOOSE_VM, MessagePriority
.BLOCKING_INFO)); |
| 140 } | 144 } |
| 141 List<Message> errorMessages = new LinkedList<Message>(); | 145 List<Message> errorMessages = new LinkedList<Message>(); |
| 142 List<PushChangesPlan> result = new ArrayList<PushChangesPlan>(planList.s
ize()); | 146 List<PushChangesPlan> result = new ArrayList<PushChangesPlan>(planList.s
ize()); |
| 143 for (Optional<PushChangesPlan> optionalPlan : planList) { | 147 for (Optional<PushChangesPlan> optionalPlan : planList) { |
| 144 if (optionalPlan.isNormal()) { | 148 if (optionalPlan.isNormal()) { |
| 145 result.add(optionalPlan.getNormal()); | 149 result.add(optionalPlan.getNormal()); |
| 146 } else { | 150 } else { |
| 147 errorMessages.addAll(optionalPlan.errorMessages()); | 151 errorMessages.addAll(optionalPlan.errorMessages()); |
| 148 } | 152 } |
| 149 } | 153 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 }); | 280 }); |
| 277 | 281 |
| 278 // Parses raw preview value and converts it into a form suitable for the vie
wer; also handles | 282 // Parses raw preview value and converts it into a form suitable for the vie
wer; also handles |
| 279 // errors that become warnings. | 283 // errors that become warnings. |
| 280 final ValueProcessor<Optional<? extends LiveEditDiffViewer.Input>> previewVa
lue = | 284 final ValueProcessor<Optional<? extends LiveEditDiffViewer.Input>> previewVa
lue = |
| 281 createProcessor(handleErrors( | 285 createProcessor(handleErrors( |
| 282 new NormalExpression<LiveEditDiffViewer.Input>() { | 286 new NormalExpression<LiveEditDiffViewer.Input>() { |
| 283 @Calculate | 287 @Calculate |
| 284 public Optional<? extends LiveEditDiffViewer.Input> calculate( | 288 public Optional<? extends LiveEditDiffViewer.Input> calculate( |
| 285 PreviewLoader.Data previewRawResultParam) { | 289 PreviewLoader.Data previewRawResultParam) { |
| 286 PushChangesPlan changesPlan = singlePlanValue.getValue(); | 290 final PushChangesPlan changesPlan = singlePlanValue.getValue(); |
| 287 ChangeDescription changeDescription = previewRawResultParam.getCha
ngeDescription(); | 291 |
| 288 Optional<LiveEditDiffViewer.Input> result; | 292 return previewRawResultParam.accept( |
| 289 if (changeDescription == null) { | 293 new PreviewLoader.Data.Visitor<Optional<LiveEditDiffViewer.Inp
ut>>() { |
| 290 result = createOptional(null); | 294 @Override |
| 291 } else { | 295 public Optional<LiveEditDiffViewer.Input> visitSuccess( |
| 292 try { | 296 ChangeDescription changeDescription) { |
| 297 if (changeDescription == null) { |
| 298 return createOptional(null); |
| 299 } else { |
| 300 try { |
| 301 LiveEditDiffViewer.Input viewerInput = |
| 302 PushResultParser.createViewerInput(changeDescription,
changesPlan, true); |
| 303 return createOptional(viewerInput); |
| 304 } catch (RuntimeException e) { |
| 305 ChromiumDebugPlugin.log(e); |
| 306 String messageText = |
| 307 NLS.bind(Messages.WizardLogicBuilder_ERROR_GETTING_PRE
VIEW, e.toString()); |
| 308 return createErrorOptional( |
| 309 new Message(messageText, MessagePriority.WARNING)); |
| 310 } |
| 311 } |
| 312 } |
| 313 |
| 314 @Override |
| 315 public Optional<Input> visitCompileError(CompileErrorFailure com
pileError) { |
| 293 LiveEditDiffViewer.Input viewerInput = | 316 LiveEditDiffViewer.Input viewerInput = |
| 294 PushResultParser.createViewerInput(changeDescription, chan
gesPlan, true); | 317 PushResultParser.createCompileErrorViewerInput(compileErro
r, changesPlan, |
| 295 result = createOptional(viewerInput); | 318 true); |
| 296 } catch (RuntimeException e) { | 319 return createOptional(viewerInput); |
| 297 ChromiumDebugPlugin.log(e); | |
| 298 result = createErrorOptional(new Message( | |
| 299 "Error in getting preview: " + e.toString(), MessagePriori
ty.WARNING)); | |
| 300 } | 320 } |
| 301 } | 321 }); |
| 302 return result; | |
| 303 } | 322 } |
| 304 @DependencyGetter | 323 @DependencyGetter |
| 305 public ValueSource<Optional<PreviewLoader.Data>> | 324 public ValueSource<Optional<PreviewLoader.Data>> |
| 306 previewRawResultValueSource() { | 325 previewRawResultValueSource() { |
| 307 return previewRawResultValue; | 326 return previewRawResultValue; |
| 308 } | 327 } |
| 309 })); | 328 })); |
| 310 | 329 |
| 311 | 330 |
| 312 | 331 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 328 v8PreviewPage.getPageElements().getPreviewViewer().setInput(viewerInput)
; | 347 v8PreviewPage.getPageElements().getPreviewViewer().setInput(viewerInput)
; |
| 329 } | 348 } |
| 330 }; | 349 }; |
| 331 updater.addConsumer(scope, v8PreviewInputSetter); | 350 updater.addConsumer(scope, v8PreviewInputSetter); |
| 332 updater.addDependency(v8PreviewInputSetter, previewValue); | 351 updater.addDependency(v8PreviewInputSetter, previewValue); |
| 333 | 352 |
| 334 // A warning generator that collects them from v8 preview loader. | 353 // A warning generator that collects them from v8 preview loader. |
| 335 final ValueProcessor<Optional<Void>> warningValue = createProcessor( | 354 final ValueProcessor<Optional<Void>> warningValue = createProcessor( |
| 336 new Gettable<Optional<Void>>() { | 355 new Gettable<Optional<Void>>() { |
| 337 public Optional<Void> getValue() { | 356 public Optional<Void> getValue() { |
| 338 Optional<?> previewResult = previewValue.getValue(); | 357 Optional<PreviewLoader.Data> previewResult = previewRawResultValue.getVa
lue(); |
| 339 if (previewResult.isNormal()) { | 358 if (previewResult.isNormal()) { |
| 340 return createOptional(null); | 359 PreviewLoader.Data data = previewResult.getNormal(); |
| 360 return data.accept(new PreviewLoader.Data.Visitor<Optional<Void>>() { |
| 361 @Override public Optional<Void> visitSuccess(ChangeDescription chang
eDescription) { |
| 362 return createOptional(null); |
| 363 } |
| 364 @Override |
| 365 public Optional<Void> visitCompileError(CompileErrorFailure compileE
rror) { |
| 366 TextStreamPosition start = compileError.getStartPosition(); |
| 367 String messageString = NLS.bind(Messages.WizardLogicBuilder_COMPIL
E_ERROR_AT, |
| 368 new Object[] { compileError.getCompilerMessage(), |
| 369 start.getLine(), start.getColumn() }); |
| 370 return createErrorOptional( |
| 371 new Message(messageString, MessagePriority.BLOCKING_PROBLEM)); |
| 372 } |
| 373 }); |
| 341 } else { | 374 } else { |
| 342 return createErrorOptional(previewResult.errorMessages()); | 375 return createErrorOptional(previewResult.errorMessages()); |
| 343 } | 376 } |
| 344 } | 377 } |
| 345 }); | 378 }); |
| 346 updater.addConsumer(scope, warningValue); | 379 updater.addConsumer(scope, warningValue); |
| 347 updater.addSource(scope, warningValue); | 380 updater.addSource(scope, warningValue); |
| 348 updater.addDependency(warningValue, previewValue); | 381 updater.addDependency(warningValue, previewRawResultValue); |
| 349 | 382 |
| 350 // A finisher delegate source, that does not actually depend on most of the
code above. | 383 // A finisher delegate source, that does not actually depend on most of the
code above. |
| 351 final ValueProcessor<? extends Optional<FinisherDelegate>> wizardFinisher = | 384 final ValueProcessor<? extends Optional<FinisherDelegate>> wizardFinisher = |
| 352 createProcessor(( | 385 createProcessor(( |
| 353 new Gettable<Optional<FinisherDelegate>>() { | 386 new Gettable<Optional<FinisherDelegate>>() { |
| 354 public Optional<FinisherDelegate> getValue() { | 387 public Optional<FinisherDelegate> getValue() { |
| 355 FinisherDelegate finisher = | 388 FinisherDelegate finisher = |
| 356 new PushChangesWizard.SingleVmFinisher(singlePlanValue.getValue(
)); | 389 new PushChangesWizard.SingleVmFinisher(singlePlanValue.getValue(
)); |
| 357 return createOptional(finisher); | 390 return createOptional(finisher); |
| 358 } | 391 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 385 | 418 |
| 386 ScopeEnabler scopeEnabler = | 419 ScopeEnabler scopeEnabler = |
| 387 new NextPageEnabler(basePage, multipleVmStubPage); | 420 new NextPageEnabler(basePage, multipleVmStubPage); |
| 388 | 421 |
| 389 Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler); | 422 Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler); |
| 390 | 423 |
| 391 final ValueProcessor<Optional<? extends FinisherDelegate>> wizardFinisher = | 424 final ValueProcessor<Optional<? extends FinisherDelegate>> wizardFinisher = |
| 392 createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() { | 425 createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() { |
| 393 @Calculate | 426 @Calculate |
| 394 public FinisherDelegate calculate(List<PushChangesPlan> selectedVm) { | 427 public FinisherDelegate calculate(List<PushChangesPlan> selectedVm) { |
| 395 return new PushChangesWizard.MultipleVmFinisher(selectedVmValue.getV
alue().getNormal()); | 428 return new PushChangesWizard.MultipleVmFinisher( |
| 429 selectedVmValue.getValue().getNormal()); |
| 396 } | 430 } |
| 397 @DependencyGetter | 431 @DependencyGetter |
| 398 public ValueSource<? extends Optional<? extends List<PushChangesPlan>>
> | 432 public ValueSource<? extends Optional<? extends List<PushChangesPlan>>
> |
| 399 getSelectVmSource() { | 433 getSelectVmSource() { |
| 400 return selectedVmValue; | 434 return selectedVmValue; |
| 401 } | 435 } |
| 402 })); | 436 })); |
| 403 updater.addSource(scope, wizardFinisher); | 437 updater.addSource(scope, wizardFinisher); |
| 404 updater.addConsumer(scope, wizardFinisher); | 438 updater.addConsumer(scope, wizardFinisher); |
| 405 updater.addDependency(wizardFinisher, selectedVmValue); | 439 updater.addDependency(wizardFinisher, selectedVmValue); |
| 406 | 440 |
| 407 final ValueSource<Optional<Void>> warningValue = | 441 final ValueSource<Optional<Void>> warningValue = |
| 408 createConstant(createOptional((Void) null), updater); | 442 createConstant(createOptional((Void) null), updater); |
| 409 | 443 |
| 410 return new PreviewAndOptionPath() { | 444 return new PreviewAndOptionPath() { |
| 411 public ValueSource<? extends Optional<? extends FinisherDelegate>> | 445 public ValueSource<? extends Optional<? extends FinisherDelegate>> |
| 412 getFinisherDelegateValue() { | 446 getFinisherDelegateValue() { |
| 413 return wizardFinisher; | 447 return wizardFinisher; |
| 414 } | 448 } |
| 415 public ValueSource<Optional<Void>> getWarningValue() { | 449 public ValueSource<Optional<Void>> getWarningValue() { |
| 416 return warningValue; | 450 return warningValue; |
| 417 } | 451 } |
| 418 }; | 452 }; |
| 419 } | 453 } |
| 420 } | 454 } |
| OLD | NEW |