Package org.chromium.debug.ui.DialogUtils

Examples of org.chromium.debug.ui.DialogUtils.Scope


    updater = new Updater();
  }

  WizardLogic create(final List<? extends ScriptTargetMapping> targetList,
      final ErrorPositionHighlighter positionHighlighter) {
    Scope scope = updater.rootScope();

    final boolean skipSingleTargetSelection = true;

    // Wizard logic is described from the first page toward the last pages.

    final PageImpl<PushChangesWizard.ChooseVmPageElements> chooseVmPage =
        pageSet.getChooseVmPage();

    // A value corresponding to selected VMs on 'choose vm' page.
    final ValueSource<List<ScriptTargetMapping>> selectedVmInput =
        new ValueSource<List<ScriptTargetMapping>>() {
      private final ChooseVmControl.Logic chooseVmControl =
          chooseVmPage.getPageElements().getChooseVm();
      {
        chooseVmControl.setData(targetList);
        chooseVmControl.selectAll();
        final ValueSource<?> thisSource = this;
        ChooseVmControl.Logic.Listener listener = new ChooseVmControl.Logic.Listener() {
          public void checkStateChanged() {
            updater.reportChanged(thisSource);
            updater.update();
          }
        };
        chooseVmControl.addListener(listener);
      }
      public List<ScriptTargetMapping> getValue() {
        return chooseVmControl.getSelected();
      }
    };
    updater.addSource(scope, selectedVmInput);


    final ValueProcessor<? extends List<Optional<PushChangesPlan>>> selectedChangePlansValue =
        createProcessor(new Gettable<List<Optional<PushChangesPlan>>>() {
      @Override
      public List<Optional<PushChangesPlan>> getValue() {
        List<ScriptTargetMapping> input = selectedVmInput.getValue();
        List<Optional<PushChangesPlan>> result =
            new ArrayList<DialogUtils.Optional<PushChangesPlan>>(input.size());
        for (ScriptTargetMapping mapping : input) {
          Optional<PushChangesPlan> optionalPlan;
          try {
            PushChangesPlan plan = PushChangesPlan.create(mapping);
            optionalPlan = createOptional(plan);
          } catch (RuntimeException e) {
            // TODO: have more specific exception types to catch.
            optionalPlan = createErrorOptional(new Message(
                Messages.WizardLogicBuilder_FAILED_TO_GET,
                MessagePriority.BLOCKING_PROBLEM));
          }
          result.add(optionalPlan);
        }
        return result;
      }
    });
    updater.addSource(scope, selectedChangePlansValue);
    updater.addConsumer(scope, selectedChangePlansValue);
    updater.addDependency(selectedChangePlansValue, selectedVmInput);


    // A derived value of selected VMs list; the list is non-empty or the value is error.
    final ValueProcessor<? extends Optional<List<PushChangesPlan>>> nonEmptySelectedPlansValue =
        createProcessor(new Gettable<Optional<List<PushChangesPlan>>>() {
      public Optional<List<PushChangesPlan>> getValue() {
        List<Optional<PushChangesPlan>> planList = selectedChangePlansValue.getValue();
        if (planList.isEmpty()) {
          return createErrorOptional(
              new Message(Messages.WizardLogicBuilder_CHOOSE_VM, MessagePriority.BLOCKING_INFO));
        }
        List<Message> errorMessages = new LinkedList<Message>();
        List<PushChangesPlan> result = new ArrayList<PushChangesPlan>(planList.size());
        for (Optional<PushChangesPlan> optionalPlan : planList) {
          if (optionalPlan.isNormal()) {
            result.add(optionalPlan.getNormal());
          } else {
            errorMessages.addAll(optionalPlan.errorMessages());
          }
        }
        if (errorMessages.isEmpty()) {
          return createOptional(result);
        } else {
          return createErrorOptional(new HashSet<Message>(errorMessages));
        }
      }
    });
    updater.addSource(scope, nonEmptySelectedPlansValue);
    updater.addConsumer(scope, nonEmptySelectedPlansValue);
    updater.addDependency(nonEmptySelectedPlansValue, selectedChangePlansValue);


    // A condition value for up-coming fork between 'single vm' and 'multiple vm' paths.
    Gettable<? extends Optional<? extends Boolean>> singleVmSelectedExpression = handleErrors(
        new NormalExpression<Boolean>() {
          @Calculate
          public Boolean calculate(List<PushChangesPlan> selectedVm) {
            return selectedVm.size() == 1;
          }
          @DependencyGetter
          public ValueSource<? extends Optional<List<PushChangesPlan>>> getSelectVmSource() {
            return nonEmptySelectedPlansValue;
          }
        });

    // A switch between 2 paths: 'single vm' and 'multiple vm'.
    OptionalSwitcher<Boolean> singleVmSelectedSwitch =
        scope.addOptionalSwitch(singleVmSelectedExpression);

    final PreviewAndOptionPath singleVmPath =
        createSingleVmPath(chooseVmPage, singleVmSelectedSwitch, nonEmptySelectedPlansValue);
    final PreviewAndOptionPath multipleVmPath =
        createMultipleVmPath(chooseVmPage, singleVmSelectedSwitch, nonEmptySelectedPlansValue);
View Full Code Here


    // All logic is inside a dedicated scope, which gets enabled only when user chooses exactly
    // one VM on a previous page. The scope enablement is synchronized with these pages becoming
    // available to user.
    ScopeEnabler scopeEnabler = new NextPageEnabler(basePage, v8PreviewPage);
    Scope scope = switcher.addScope(Boolean.TRUE, scopeEnabler);

    // A value of the single vm, that must be always available within this scope.
    final ValueProcessor<PushChangesPlan> singlePlanValue =
        createProcessor(new Gettable<PushChangesPlan>() {
      public PushChangesPlan getValue() {
View Full Code Here

    PageImpl<PageElements> multipleVmStubPage = pageSet.getMultipleVmStubPage();

    ScopeEnabler scopeEnabler =
        new NextPageEnabler(basePage, multipleVmStubPage);

    Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler);

    final ValueProcessor<Optional<? extends FinisherDelegate>> wizardFinisher =
        createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() {
          @Calculate
          public FinisherDelegate calculate(List<PushChangesPlan> selectedVm) {
View Full Code Here

   * (to better deal with various states and transitions of dialog).
   */
  static Handle buildDialogLogic(final DialogImpl.Elements elements,
      final DialogImpl.DialogPreferencesStore dialogPreferencesStore, final Value uiValue) {
    final Updater updater = new Updater();
    Scope rootScope = updater.rootScope();

    // A global dialog warning collection (those warnings that are not tied to the primary
    // result value).
    List<ValueSource<String>> warningSources = new ArrayList<ValueSource<String>>(2);

    // 'Property expression' editor raw value.
    final ValueSource<String> propertyExpressionEditorValue = new ValueSource<String>() {
      private final Text textElement = elements.getExpressionText();
      {
        String text = dialogPreferencesStore.getExpressionText();
        textElement.setText(text);
        // Select all expression but a first dot.
        int selectionStart = text.startsWith(".") ? 1 : 0; //$NON-NLS-1$
        textElement.setSelection(selectionStart, text.length());
        addModifyListener(textElement, this, updater);
      }
      public String getValue() {
        return textElement.getText();
      }
    };
    updater.addSource(rootScope, propertyExpressionEditorValue);

    // A preview context value. It is constant but optional (so it's passed via updater).
    final ValueSource<Optional<DialogLogic.PreviewContext>> evaluatorValue =
        createConstant(PreviewContext.build(uiValue), updater);

    // Property expression parsed as Expression. Parse errors are kept in Optional.
    final ValueProcessor<Optional<DialogLogic.Expression>> parsedPropertyExpressionValue =
      createProcessor(new Gettable<Optional<DialogLogic.Expression>>() {
        @Override
        public Optional<DialogLogic.Expression> getValue() {
          return parseExpression(propertyExpressionEditorValue.getValue());
        }
      });
    updater.addConsumer(rootScope, parsedPropertyExpressionValue);
    updater.addSource(rootScope, parsedPropertyExpressionValue);
    updater.addDependency(parsedPropertyExpressionValue, propertyExpressionEditorValue);


    // 'Show preview' check box value.
    final ValueSource<Boolean> previewCheckBoxValue = new ValueSource<Boolean>() {
      private final Button checkBox = elements.getPreviewCheckBox();
      {
        checkBox.setSelection(dialogPreferencesStore.getPreviewCheck());
        addModifyListener(checkBox, this, updater);
      }
      @Override
      public Boolean getValue() {
        return checkBox.getSelection();
      }
    };

    // A conditional block that holds optional preview section.
    Switcher<Boolean> checkerSwitch = rootScope.addSwitch(previewCheckBoxValue);

    PreviewSwitchOutput switchBlockOutput = fillShowPreviewSwitch(checkerSwitch, updater,
        rootScope, elements, evaluatorValue, parsedPropertyExpressionValue);

    // Preview block may emit warning.
View Full Code Here

      Updater updater, Scope scope, final DialogImpl.Elements elements,
      ValueSource<Optional<DialogLogic.PreviewContext>> evaluatorValue,
      ValueProcessor<Optional<DialogLogic.Expression>> parsedPropertyNameValue) {

    // Switch branch that corresponds to enabled preview.
    Scope checkerScope = switcher.addScope(Boolean.TRUE, new ScopeEnabler() {
      @Override
      public void setEnabled(boolean enabled, boolean recursive) {
        elements.getPreviewDisplay().setEnabled(enabled);
      }
    });
View Full Code Here

   * (to better deal with various states and transitions of dialog).
   */
  static Handle buildDialogLogic(final DialogImpl.Elements elements,
      final DialogImpl.DialogPreferencesStore dialogPreferencesStore, final Value uiValue) {
    final Updater updater = new Updater();
    Scope rootScope = updater.rootScope();

    // A global dialog warning collection (those warnings that are not tied to the primary
    // result value).
    List<ValueSource<String>> warningSources = new ArrayList<ValueSource<String>>(2);

    // 'Property expression' editor raw value.
    final ValueSource<String> propertyExpressionEditorValue = new ValueSource<String>() {
      private final Text textElement = elements.getExpressionText();
      {
        String text = dialogPreferencesStore.getExpressionText();
        textElement.setText(text);
        // Select all expression but a first dot.
        int selectionStart = text.startsWith(".") ? 1 : 0; //$NON-NLS-1$
        textElement.setSelection(selectionStart, text.length());
        addModifyListener(textElement, this, updater);
      }
      public String getValue() {
        return textElement.getText();
      }
    };
    updater.addSource(rootScope, propertyExpressionEditorValue);

    // A preview context value. It is constant but optional (so it's passed via updater).
    final ValueSource<Optional<DialogLogic.PreviewContext>> evaluatorValue =
        createConstant(PreviewContext.build(uiValue), updater);

    // Property expression parsed as Expression. Parse errors are kept in Optional.
    final ValueProcessor<Optional<DialogLogic.Expression>> parsedPropertyExpressionValue =
      createProcessor(new Gettable<Optional<DialogLogic.Expression>>() {
        @Override
        public Optional<DialogLogic.Expression> getValue() {
          return parseExpression(propertyExpressionEditorValue.getValue());
        }
      });
    updater.addConsumer(rootScope, parsedPropertyExpressionValue);
    updater.addSource(rootScope, parsedPropertyExpressionValue);
    updater.addDependency(parsedPropertyExpressionValue, propertyExpressionEditorValue);


    // 'Show preview' check box value.
    final ValueSource<Boolean> previewCheckBoxValue = new ValueSource<Boolean>() {
      private final Button checkBox = elements.getPreviewCheckBox();
      {
        checkBox.setSelection(dialogPreferencesStore.getPreviewCheck());
        addModifyListener(checkBox, this, updater);
      }
      @Override
      public Boolean getValue() {
        return checkBox.getSelection();
      }
    };

    // A conditional block that holds optional preview section.
    Switcher<Boolean> checkerSwitch = rootScope.addSwitch(previewCheckBoxValue);

    PreviewSwitchOutput switchBlockOutput = fillShowPreviewSwitch(checkerSwitch, updater,
        rootScope, elements, evaluatorValue, parsedPropertyExpressionValue);

    // Preview block may emit warning.
View Full Code Here

      Updater updater, Scope scope, final DialogImpl.Elements elements,
      ValueSource<Optional<DialogLogic.PreviewContext>> evaluatorValue,
      ValueProcessor<Optional<DialogLogic.Expression>> parsedPropertyNameValue) {

    // Switch branch that corresponds to enabled preview.
    Scope checkerScope = switcher.addScope(Boolean.TRUE, new ScopeEnabler() {
      @Override
      public void setEnabled(boolean enabled, boolean recursive) {
        elements.getPreviewDisplay().setEnabled(enabled);
      }
    });
View Full Code Here

    updater = new Updater();
  }

  WizardLogic create(final List<? extends ScriptTargetMapping> targetList) {
    Scope scope = updater.rootScope();

    final boolean skipSingleTargetSelection = true;

    // Wizard logic is described from the first page toward the last pages.

    final PageImpl<PushChangesWizard.ChooseVmPageElements> chooseVmPage =
        pageSet.getChooseVmPage();

    // A value corresponding to selected VMs on 'choose vm' page.
    final ValueSource<List<ScriptTargetMapping>> selectedVmInput =
        new ValueSource<List<ScriptTargetMapping>>() {
      private final ChooseVmControl.Logic chooseVmControl =
          chooseVmPage.getPageElements().getChooseVm();
      {
        chooseVmControl.setData(targetList);
        chooseVmControl.selectAll();
        final ValueSource<?> thisSource = this;
        ChooseVmControl.Logic.Listener listener = new ChooseVmControl.Logic.Listener() {
          public void checkStateChanged() {
            updater.reportChanged(thisSource);
            updater.update();
          }
        };
        chooseVmControl.addListener(listener);
      }
      public List<ScriptTargetMapping> getValue() {
        return chooseVmControl.getSelected();
      }
    };
    updater.addSource(scope, selectedVmInput);


    final ValueProcessor<? extends List<Optional<PushChangesPlan>>> selectedChangePlansValue =
        createProcessor(new Gettable<List<Optional<PushChangesPlan>>>() {
      @Override
      public List<Optional<PushChangesPlan>> getValue() {
        List<ScriptTargetMapping> input = selectedVmInput.getValue();
        List<Optional<PushChangesPlan>> result =
            new ArrayList<DialogUtils.Optional<PushChangesPlan>>(input.size());
        for (ScriptTargetMapping mapping : input) {
          Optional<PushChangesPlan> optionalPlan;
          try {
            PushChangesPlan plan = PushChangesPlan.create(mapping);
            optionalPlan = createOptional(plan);
          } catch (RuntimeException e) {
            // TODO: have more specific exception types to catch.
            optionalPlan = createErrorOptional(new Message(
                "Failed to get script source from a file. See log for details.",
                MessagePriority.BLOCKING_PROBLEM));
          }
          result.add(optionalPlan);
        }
        return result;
      }
    });
    updater.addSource(scope, selectedChangePlansValue);
    updater.addConsumer(scope, selectedChangePlansValue);
    updater.addDependency(selectedChangePlansValue, selectedVmInput);


    // A derived value of selected VMs list; the list is non-empty or the value is error.
    final ValueProcessor<? extends Optional<List<PushChangesPlan>>> nonEmptySelectedPlansValue =
        createProcessor(new Gettable<Optional<List<PushChangesPlan>>>() {
      public Optional<List<PushChangesPlan>> getValue() {
        List<Optional<PushChangesPlan>> planList = selectedChangePlansValue.getValue();
        if (planList.isEmpty()) {
          return createErrorOptional(
              new Message("Choose at least one VM", MessagePriority.BLOCKING_INFO));
        }
        List<Message> errorMessages = new LinkedList<Message>();
        List<PushChangesPlan> result = new ArrayList<PushChangesPlan>(planList.size());
        for (Optional<PushChangesPlan> optionalPlan : planList) {
          if (optionalPlan.isNormal()) {
            result.add(optionalPlan.getNormal());
          } else {
            errorMessages.addAll(optionalPlan.errorMessages());
          }
        }
        if (errorMessages.isEmpty()) {
          return createOptional(result);
        } else {
          return createErrorOptional(new HashSet<Message>(errorMessages));
        }
      }
    });
    updater.addSource(scope, nonEmptySelectedPlansValue);
    updater.addConsumer(scope, nonEmptySelectedPlansValue);
    updater.addDependency(nonEmptySelectedPlansValue, selectedChangePlansValue);


    // A condition value for up-coming fork between 'single vm' and 'multiple vm' paths.
    Gettable<? extends Optional<? extends Boolean>> singleVmSelectedExpression = handleErrors(
        new NormalExpression<Boolean>() {
          @Calculate
          public Boolean calculate(List<PushChangesPlan> selectedVm) {
            return selectedVm.size() == 1;
          }
          @DependencyGetter
          public ValueSource<? extends Optional<List<PushChangesPlan>>> getSelectVmSource() {
            return nonEmptySelectedPlansValue;
          }
        });

    // A switch between 2 paths: 'single vm' and 'multiple vm'.
    OptionalSwitcher<Boolean> singleVmSelectedSwitch =
        scope.addOptionalSwitch(singleVmSelectedExpression);

    final PreviewAndOptionPath singleVmPath =
        createSingleVmPath(chooseVmPage, singleVmSelectedSwitch, nonEmptySelectedPlansValue);
    final PreviewAndOptionPath multipleVmPath =
        createMultipleVmPath(chooseVmPage, singleVmSelectedSwitch, nonEmptySelectedPlansValue);
View Full Code Here

    // All logic is inside a dedicated scope, which gets enabled only when user chooses exactly
    // one VM on a previous page. The scope enablement is synchronized with these pages becoming
    // available to user.
    ScopeEnabler scopeEnabler = new NextPageEnabler(basePage, v8PreviewPage);
    Scope scope = switcher.addScope(Boolean.TRUE, scopeEnabler);

    // A value of the single vm, that must be always available within this scope.
    final ValueProcessor<PushChangesPlan> singlePlanValue =
        createProcessor(new Gettable<PushChangesPlan>() {
      public PushChangesPlan getValue() {
View Full Code Here

    PageImpl<PageElements> multipleVmStubPage = pageSet.getMultipleVmStubPage();

    ScopeEnabler scopeEnabler =
        new NextPageEnabler(basePage, multipleVmStubPage);

    Scope scope = switcher.addScope(Boolean.FALSE, scopeEnabler);

    final ValueProcessor<Optional<? extends FinisherDelegate>> wizardFinisher =
        createProcessor(handleErrors(new NormalExpression<FinisherDelegate>() {
          @Calculate
          public FinisherDelegate calculate(List<PushChangesPlan> selectedVm) {
View Full Code Here

TOP

Related Classes of org.chromium.debug.ui.DialogUtils.Scope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.