private PushButton createButton(final Pair<T, V> item, boolean plusButton) {
    final T value = item.getFirst();
    final V widget = item.getSecond();

    final PushButton button =
        new PushButton(new Image(plusButton ? resources.increaseIcon() : resources.decreaseIcon()));
    button.addStyleName(style.buttonStyle());
    button.addStyleName("buttonStyle_pfly_fix"); // $NON-NLS-1$

    button.addClickHandler(
        plusButton
            ? new ClickHandler() {

              @Override
              public void onClick(ClickEvent event) {
                getEntry(widget).removeLastButton();
                Pair<T, V> item = addGhostEntry();
                onAdd(item.getFirst(), item.getSecond());
              }
            }
            : new ClickHandler() {

              @Override
              public void onClick(ClickEvent event) {
                if (vetoRemoveWidget(item, value, widget)) {
                  return;
                }

                doRemoveItem(item, value, widget);
              }
            });

    return button;
  }
Exemplo n.º 2
0
  /**
   * Create a slider bar.
   *
   * @param minValue the minimum value in the range
   * @param maxValue the maximum value in the range
   * @param labelFormatter the label formatter
   * @param images the images to use for the slider
   */
  public SliderBar(double minValue, double maxValue, LabelFormatter labelFormatter) {
    super();
    resources.sliderBarCss().ensureInjected();
    this.minValue = minValue;
    this.maxValue = maxValue;
    setLabelFormatter(labelFormatter);

    // Create the outer shell
    DOM.setStyleAttribute(getElement(), "position", "relative"); // $NON-NLS-1$ //$NON-NLS-2$
    setStyleName("gwt-SliderBar-shell"); // $NON-NLS-1$

    // Create the line
    lineElement = DOM.createDiv();
    DOM.appendChild(getElement(), lineElement);
    DOM.setStyleAttribute(lineElement, "position", "absolute"); // $NON-NLS-1$ //$NON-NLS-2$
    DOM.setElementProperty(
        lineElement, "className", "gwt-SliderBar-line"); // $NON-NLS-1$ //$NON-NLS-2$

    // Create the knob
    knobImage.setResource(resources.slider());
    Element knobElement = knobImage.getElement();
    DOM.appendChild(getElement(), knobElement);
    DOM.setStyleAttribute(knobElement, "position", "absolute"); // $NON-NLS-1$ //$NON-NLS-2$
    DOM.setElementProperty(
        knobElement, "className", "gwt-SliderBar-knob"); // $NON-NLS-1$ //$NON-NLS-2$

    sinkEvents(Event.MOUSEEVENTS | Event.KEYEVENTS | Event.FOCUSEVENTS);
  }
Exemplo n.º 3
0
 /**
  * Sets whether this widget is enabled.
  *
  * @param enabled true to enable the widget, false to disable it
  */
 public void setEnabled(boolean enabled) {
   this.enabled = enabled;
   if (enabled) {
     knobImage.setResource(resources.slider());
     DOM.setElementProperty(
         lineElement,
         "className", //$NON-NLS-1$
         "gwt-SliderBar-line"); //$NON-NLS-1$
   } else {
     knobImage.setResource(resources.sliderDisabled());
     DOM.setElementProperty(
         lineElement,
         "className", //$NON-NLS-1$
         "gwt-SliderBar-line gwt-SliderBar-line-disabled"); //$NON-NLS-1$
   }
   redraw();
 }
Exemplo n.º 4
0
 /**
  * Start sliding the knob.
  *
  * @param highlight true to change the style
  * @param fireEvent true to fire the event
  */
 private void startSliding(boolean highlight, boolean fireEvent) {
   if (highlight) {
     DOM.setElementProperty(
         lineElement,
         "className", //$NON-NLS-1$
         "gwt-SliderBar-line gwt-SliderBar-line-sliding"); //$NON-NLS-1$
     DOM.setElementProperty(
         knobImage.getElement(),
         "className", //$NON-NLS-1$
         "gwt-SliderBar-knob gwt-SliderBar-knob-sliding"); //$NON-NLS-1$
     knobImage.setResource(resources.sliderSliding());
   }
 }
  @Override
  public void initTable() {
    super.initTable();

    getTable()
        .addActionButton(
            new UiCommandButtonDefinition<DiskImage>(getEventBus(), "New") {
              @Override
              protected UICommand resolveCommand() {
                return getModel().getNewCommand();
              }
            });

    getTable()
        .addActionButton(
            new UiCommandButtonDefinition<DiskImage>(getEventBus(), "Edit") {
              @Override
              protected UICommand resolveCommand() {
                return getModel().getEditCommand();
              }
            });

    getTable()
        .addActionButton(
            new UiCommandButtonDefinition<DiskImage>(getEventBus(), "Remove") {
              @Override
              protected UICommand resolveCommand() {
                return getModel().getRemoveCommand();
              }
            });

    getTable()
        .addActionButton(
            new UiCommandButtonDefinition<DiskImage>(getEventBus(), "Move") {
              @Override
              protected UICommand resolveCommand() {
                return getModel().getMoveCommand();
              }
            });

    plugButtonDefinition =
        new ImageUiCommandButtonDefinition<DiskImage>(
            getEventBus(),
            "Activate",
            resources.upImage(),
            resources.upDisabledImage(),
            true,
            false) {
          @Override
          protected UICommand resolveCommand() {
            return getModel().getPlugCommand();
          }

          @Override
          public String getCustomToolTip() {
            if (!getModel().isVmDown()
                && getModel().isHotPlugAvailable()
                && !getModel().getIsDiskHotPlugSupported()) {
              return constants.diskHotPlugNotSupported();
            } else {
              return this.getTitle();
            }
          }
        };
    getTable().addActionButton(plugButtonDefinition);

    unPlugButtonDefinition =
        new ImageUiCommandButtonDefinition<DiskImage>(
            getEventBus(),
            "Deactivate",
            resources.downImage(),
            resources.downDisabledImage(),
            true,
            false) {
          @Override
          protected UICommand resolveCommand() {
            return getModel().getUnPlugCommand();
          }

          @Override
          public String getCustomToolTip() {
            if (!getModel().isVmDown()
                && getModel().isHotPlugAvailable()
                && !getModel().getIsDiskHotPlugSupported()) {
              return constants.diskHotPlugNotSupported();
            } else {
              return this.getTitle();
            }
          }
        };
    getTable().addActionButton(unPlugButtonDefinition);

    attachListenersForModel();
  }