Package org.chromium.debug.ui.DialogUtils

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


  WizardLogicBuilder(PushChangesWizard.PageSet pageSet, LogicBasedWizard wizardImpl) {
    this.pageSet = pageSet;
    this.wizardImpl = wizardImpl;

    updater = new Updater();
  }
View Full Code Here


   * Builds an updater-based dialog logic. This is more a function-style programming inside
   * (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.
    warningSources.add(switchBlockOutput.warningSource());

    // 'Add watch expression' check box value.
    final ValueSource<Boolean> addWatchExpressionValue = new ValueSource<Boolean>() {
      private final Button checkBox = elements.getAddWatchCheckBox();
      {
        checkBox.setSelection(dialogPreferencesStore.getAddWatchExpression());
        addModifyListener(checkBox, this, updater);
      }
      @Override
      public Boolean getValue() {
        return checkBox.getSelection();
      }
    };
    updater.addSource(rootScope, addWatchExpressionValue);

    // An OK button implementation that do set property in remote VM.
    final ValueProcessor<Optional<? extends Runnable>> okRunnable = createProcessor(handleErrors(
        new NormalExpression<Runnable>() {
          @Calculate
          public Runnable calculate(DialogLogic.PreviewContext previewContext,
              DialogLogic.Expression expression) {
            return new OkRunnable(elements.getParentShell(), expression, previewContext,
                addWatchExpressionValue.getValue());
          }

          @DependencyGetter
          public ValueSource<Optional<DialogLogic.PreviewContext>> previewContextSource() {
            return evaluatorValue;
          }

          @DependencyGetter
          public ValueSource<Optional<DialogLogic.Expression>> parsedPropertyExpressionSource() {
            return parsedPropertyExpressionValue;
          }
        })
    );
    updater.addSource(rootScope, okRunnable);
    updater.addConsumer(rootScope, okRunnable);
    updater.addDependency(okRunnable, evaluatorValue);
    updater.addDependency(okRunnable, parsedPropertyExpressionValue);
    updater.addDependency(okRunnable, addWatchExpressionValue);

    final OkButtonControl<Runnable> okButtonControl =
        new OkButtonControl<Runnable>(okRunnable, warningSources, elements);
    updater.addConsumer(rootScope, okButtonControl);
    updater.addDependency(okButtonControl, okButtonControl.getDependencies());

    return new Handle() {
      @Override
      public void updateAll() {
        updater.updateAll();
      }
      @Override
      public Runnable getOkRunnable() {
        return okButtonControl.getNormalValue();
      }
View Full Code Here

   * Builds an updater-based dialog logic. This is more a function-style programming inside
   * (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.
    warningSources.add(switchBlockOutput.warningSource());

    // 'Add watch expression' check box value.
    final ValueSource<Boolean> addWatchExpressionValue = new ValueSource<Boolean>() {
      private final Button checkBox = elements.getAddWatchCheckBox();
      {
        checkBox.setSelection(dialogPreferencesStore.getAddWatchExpression());
        addModifyListener(checkBox, this, updater);
      }
      @Override
      public Boolean getValue() {
        return checkBox.getSelection();
      }
    };
    updater.addSource(rootScope, addWatchExpressionValue);

    // An OK button implementation that do set property in remote VM.
    final ValueProcessor<Optional<? extends Runnable>> okRunnable = createProcessor(handleErrors(
        new NormalExpression<Runnable>() {
          @Calculate
          public Runnable calculate(DialogLogic.PreviewContext previewContext,
              DialogLogic.Expression expression) {
            return new OkRunnable(elements.getParentShell(), expression, previewContext,
                addWatchExpressionValue.getValue());
          }

          @DependencyGetter
          public ValueSource<Optional<DialogLogic.PreviewContext>> previewContextSource() {
            return evaluatorValue;
          }

          @DependencyGetter
          public ValueSource<Optional<DialogLogic.Expression>> parsedPropertyExpressionSource() {
            return parsedPropertyExpressionValue;
          }
        })
    );
    updater.addSource(rootScope, okRunnable);
    updater.addConsumer(rootScope, okRunnable);
    updater.addDependency(okRunnable, evaluatorValue);
    updater.addDependency(okRunnable, parsedPropertyExpressionValue);
    updater.addDependency(okRunnable, addWatchExpressionValue);

    final OkButtonControl<Runnable> okButtonControl =
        new OkButtonControl<Runnable>(okRunnable, warningSources, elements);
    updater.addConsumer(rootScope, okButtonControl);
    updater.addDependency(okButtonControl, okButtonControl.getDependencies());

    return new Handle() {
      @Override
      public void updateAll() {
        updater.updateAll();
      }
      @Override
      public Runnable getOkRunnable() {
        return okButtonControl.getNormalValue();
      }
View Full Code Here

  private static Logic createLogic(final Elements elements) {
    // The logic is Updater-based.
    // Presented path of several visible segments influences whether 'more' or 'less'
    // buttons enabled.
    final Updater updater = new Updater();

    final AccuratenessControl.PathLabel pathElement = elements.getPathLabel();
    final ValueSource<Integer> visiblePartSource = new ValueSource<Integer>() {
      @Override
      public Integer getValue() {
        return pathElement.getVisiblePartSize();
      }
    };

    updater.addSource(updater.rootScope(), visiblePartSource);

    // Wraps button as ValueConsumer.
    abstract class ButtonController implements ValueConsumer {
      private final Button button;

      ButtonController(Button button) {
        this.button = button;

        button.addSelectionListener(new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            int size = pathElement.getVisiblePartSize();
            if (!isEnabled(size)) {
              return;
            }
            int newSize = getNewValue(size);
            pathElement.setVisiblePart(newSize);
            updater.reportChanged(visiblePartSource);
            updater.update();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
          }
        });
      }

      @Override
      public void update(Updater updater) {
        int size = pathElement.getVisiblePartSize();
        boolean enabled = isEnabled(size);
        button.setEnabled(enabled);
      }

      // Defines button logic.
      protected abstract boolean isEnabled(int visiblePartSize);

      // Defines button logic.
      protected abstract int getNewValue(int currentValue);
    }

    ValueConsumer lessController = new ButtonController(elements.getLessButton()) {
      @Override
      protected boolean isEnabled(int visiblePartSize) {
        return visiblePartSize > 1;
      }

      @Override
      protected int getNewValue(int currentValue) {
        return currentValue - 1;
      }
    };

    updater.addConsumer(updater.rootScope(), lessController);
    updater.addDependency(lessController, visiblePartSource);

    final int size = elements.getPathLabel().size();
    ValueConsumer moreController = new ButtonController(elements.getMoreButton()) {
      @Override
      protected boolean isEnabled(int visiblePartSize) {
        return visiblePartSize < size;
      }

      @Override
      protected int getNewValue(int currentValue) {
        return currentValue + 1;
      }
    };

    updater.addConsumer(updater.rootScope(), moreController);
    updater.addDependency(moreController, visiblePartSource);

    return new Logic() {
      @Override
      public int getAccuratenessValue() {
        return elements.getPathLabel().getVisiblePartSize();
      }
      @Override
      public void updateAll() {
        updater.updateAll();
      }
    };
  }
View Full Code Here

  WizardLogicBuilder(PushChangesWizard.PageSet pageSet, LogicBasedWizard wizardImpl) {
    this.pageSet = pageSet;
    this.wizardImpl = wizardImpl;

    updater = new Updater();
  }
View Full Code Here

  abstract void updateAll();

  static SourceNameMapperContainerDialogLogic create(
      final Elements elements, final ISourceLookupDirector director,
      final PresetFieldValues initialParams) {
    final Updater updater = new Updater();
    Scope rootScope = updater.rootScope();

    final List<ValueSource<String>> warningSources = new ArrayList<ValueSource<String>>(2);

    // Represents value entered as prefix.
    final ValueSource<String> prefixEditor = new ValueSource<String>() {
      public String getValue() {
        return elements.getPrefixField().getText();
      }
      {
        if (initialParams != null) {
          elements.getPrefixField().setText(initialParams.getPrefix());
        }
        final ValueSource<String> updatableThis = this;
        ModifyListener listener = new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            updater.reportChanged(updatableThis);
            updater.update();
          }
        };
        elements.getPrefixField().addModifyListener(listener);
      }
    };
    updater.addSource(rootScope, prefixEditor);

    // Represents prefix value after it has been validated.
    final ValueProcessor<Optional<String>> prefixValue = new ExpressionProcessor<String>(
        Collections.<ValueSource<? extends Optional<?>>>emptyList()) {
      @Override
      protected Optional<String> calculateNormal() {
        String prefix = prefixEditor.getValue();
        Optional<String> result;
        if (prefix == null || prefix.length() == 0) {
          return createErrorOptional(new Message(
              Messages.SourceNameMapperContainerDialog_ENTER_PREFIX,
              MessagePriority.BLOCKING_INFO));
        } else {
          return createOptional(prefix);
        }
      }
    };
    updater.addSource(rootScope, prefixValue);
    updater.addConsumer(rootScope, prefixValue);
    updater.addDependency(prefixValue, prefixEditor);

    // Represents possible warning about prefix value having no trailing slash.
    ValueProcessor<String> noSlashWarning = new ValueProcessor<String>() {
      public void update(Updater updater) {
        Optional<String> prefix = prefixValue.getValue();
        String result;
        if (prefix.isNormal() && !prefix.getNormal().endsWith("/")) { //$NON-NLS-1$
          result = Messages.SourceNameMapperContainerDialog_PREFIX_NORMALLY_ENDS;
        } else {
          result = null;
        }
        setCurrentValue(result);
        updater.reportChanged(this);
      }
    };
    updater.addSource(rootScope, noSlashWarning);
    updater.addConsumer(rootScope, noSlashWarning);
    updater.addDependency(noSlashWarning, prefixValue);
    warningSources.add(noSlashWarning);

    // Represents prefix rule example printer.
    ValueConsumer prefixExample = new ValueConsumer() {
      public void update(Updater updater) {
        Optional<String> prefix = prefixValue.getValue();
        String line1;
        String line2;
        if (prefix.isNormal()) {
          String sampleFileName = Messages.SourceNameMapperContainerDialog_SAMPLE_FILE_NAME;
          line1 = NLS.bind(Messages.SourceNameMapperContainerDialog_EXAMPLE_1,
              prefix.getNormal() + sampleFileName);
          line2 = NLS.bind(Messages.SourceNameMapperContainerDialog_EXAMPLE_2, sampleFileName);
        } else {
          line1 = ""; //$NON-NLS-1$
          line2 = ""; //$NON-NLS-1$
        }
        elements.getPrefixExampleLine1Label().setText(line1);
        elements.getPrefixExampleLine2Label().setText(line2);
      }
    };
    updater.addConsumer(rootScope, prefixExample);
    updater.addDependency(prefixExample, prefixValue);

    // Represents container type combo box.
    final ValueSource<ISourceContainerType> selectedTypeValue =
        new ValueSource<ISourceContainerType>() {
      public ISourceContainerType getValue() {
        return elements.getContainerTypeCombo().getSelected();
      }
      {
        if (initialParams != null) {
          ISourceContainerType type = initialParams.getContainer().getType();
          elements.getContainerTypeCombo().setSelected(type);
        }
        final ValueSource<ISourceContainerType> updatableThis = this;
        SelectionListener listener = new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            updater.reportChanged(updatableThis);
            updater.update();
          }
        };
        elements.getContainerTypeCombo().addSelectionListener(listener);
      }
    };
    updater.addSource(rootScope, selectedTypeValue);

    // Represents "Configure" button that acts like a container factory.
    final ValueProcessor<ISourceContainer> containerFactoryButtonValue =
        new ValueProcessor<ISourceContainer>() {
      private ConfigureButtonAction preparedAction = null;
      {
        if (initialParams != null) {
          setCurrentValue(initialParams.getContainer());
        }
        final ValueSource<ISourceContainer> valueSourceThis = this;
        elements.getConfigureButton().addSelectionListener(new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (preparedAction != null) {
              ISourceContainer value = preparedAction.run(elements.getShell());
              if (value != null) {
                setCurrentValue(value);
              }
              updater.reportChanged(valueSourceThis);
              updater.update();
              updateAction();
            }
          }
        });
      }
      public void update(Updater updater) {
        if (getValue() != null && !getValue().getType().equals(selectedTypeValue.getValue())) {
          setCurrentValue(null);
          updater.reportChanged(this);
        }
        updateAction();
      }
      private void updateAction() {
        preparedAction = SourceNameMapperContainerDialog.prepareConfigureAction(
            selectedTypeValue.getValue(), getValue(), director);
        elements.getConfigureButton().setEnabled(preparedAction != null);
      }
    };
    updater.addSource(rootScope, containerFactoryButtonValue);
    updater.addConsumer(rootScope, containerFactoryButtonValue);
    updater.addDependency(containerFactoryButtonValue, selectedTypeValue);

    // Represents printer that shows type and name of the created container.
    ValueConsumer showContainerTypeValue = new ValueConsumer() {
      public void update(Updater updater) {
        ISourceContainer container = containerFactoryButtonValue.getValue();
        String status;
        Image image;
        String name;
        boolean enabled;
        if (container == null) {
          status = Messages.SourceNameMapperContainerDialog_NOTHING_CONFIGURED;
          name = ""; //$NON-NLS-1$
          image = null;
          enabled = false;
        } else {
          status = Messages.SourceNameMapperContainerDialog_CONFIGURED_CONTAINER;
          ISourceContainerType type = container.getType();
          name = container.getName();
          image = DebugUITools.getSourceContainerImage(type.getId());
          enabled = true;
        }
        ContainerStatusGroup group = elements.getContainerStatusGroup();
        group.getStatusLabel().setText(status);
        group.getTypeImageLabel().setImage(image);
        group.getContainerNameLabel().setText(name);
        group.setEnabled(enabled);
        group.layout();
      }
    };
    updater.addConsumer(rootScope, showContainerTypeValue);
    updater.addDependency(showContainerTypeValue, containerFactoryButtonValue);

    // Represents possible warning about unsupported container.
    ValueProcessor<String> unsupportedContainerWarning = createProcessor(new Gettable<String>() {
      @Override
      public String getValue() {
        ISourceContainer container = containerFactoryButtonValue.getValue();
        if (container == null) {
          return null;
        }
        if (ReverseSourceLookup.isGoodTargetContainer(container)) {
          return null;
        }
        return Messages.SourceNameMapperContainerDialogLogic_TARGET_CONTAINER_NOT_SUPPORTED0;
      }
    });
    updater.addSource(rootScope, unsupportedContainerWarning);
    updater.addConsumer(rootScope, unsupportedContainerWarning);
    updater.addDependency(unsupportedContainerWarning, containerFactoryButtonValue);
    warningSources.add(unsupportedContainerWarning);

    // Represents expression that constructs dialog window result.
    final ValueProcessor<? extends Optional<Result>> resultValue =
        new ExpressionProcessor<Result>(
            Arrays.<ValueSource<? extends Optional<?>>>asList(prefixValue) ) {
          @Override
          protected Optional<Result> calculateNormal() {
            final String prefix = prefixValue.getValue().getNormal();
            final ISourceContainer container = containerFactoryButtonValue.getValue();
            if (container == null) {
              return createErrorOptional(
                  new Message(Messages.SourceNameMapperContainerDialog_CONFIGURE_TARGET_CONTAINER,
                      MessagePriority.BLOCKING_INFO));
            }
            Result result = new Result() {
              public ISourceContainer getResultContainer() {
                return container;
              }
              public String getResultPrefix() {
                return prefix;
              }
            };
            return createOptional(result);
          }
    };
    updater.addSource(rootScope, resultValue);
    updater.addConsumer(rootScope, resultValue);
    updater.addDependency(resultValue, prefixValue);
    updater.addDependency(resultValue, containerFactoryButtonValue);

    // Represents controller that updates state of OK button and error messages.
    final OkButtonControl<Result> okButtonControl =
        new OkButtonControl<Result>(resultValue, warningSources, elements);
    updater.addConsumer(rootScope, okButtonControl);
    updater.addDependency(okButtonControl, okButtonControl.getDependencies());

    return new SourceNameMapperContainerDialogLogic() {
      @Override
      Result getResult() {
        return okButtonControl.getNormalValue();
      }
      @Override
      void updateAll() {
        updater.updateAll();
      }
    };
  }
View Full Code Here

TOP

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

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.