Пример #1
0
  /**
   * Internal method which is called when the user clicks on an editable title field.
   *
   * <p>
   */
  protected void editTitle() {

    m_title.setVisible(false);
    final TextBox box = new TextBox();
    box.setText(m_title.getText());
    box.getElement().setAttribute("size", "45");
    box.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().labelInput());
    box.addStyleName(I_CmsLayoutBundle.INSTANCE.listItemWidgetCss().titleInput());
    final String originalTitle = m_title.getText();
    // wrap the boolean flag in an array so we can change it from the event handlers
    final boolean[] checked = new boolean[] {false};

    box.addBlurHandler(
        new BlurHandler() {

          /**
           * @see
           *     com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event.dom.client.BlurEvent)
           */
          public void onBlur(BlurEvent event) {

            if (checked[0]) {
              return;
            }

            onEditTitleTextBox(box);
            checked[0] = true;
          }
        });

    box.addKeyPressHandler(
        new KeyPressHandler() {

          /**
           * @see
           *     com.google.gwt.event.dom.client.KeyPressHandler#onKeyPress(com.google.gwt.event.dom.client.KeyPressEvent)
           */
          public void onKeyPress(KeyPressEvent event) {

            if (checked[0]) {
              return;
            }

            int keycode = event.getNativeEvent().getKeyCode();

            if ((keycode == 10) || (keycode == 13)) {
              onEditTitleTextBox(box);
              checked[0] = true;
            }
            if (keycode == 27) {
              box.setText(originalTitle);
              onEditTitleTextBox(box);
              checked[0] = true;
            }
          }
        });
    m_titleRow.insert(box, 1);
    box.setFocus(true);
  }
Пример #2
0
  /**
   * Initializes the widget given a map of select options.
   *
   * <p>The keys of the map are the values of the select options, while the values of the map are
   * the labels which should be used for the checkboxes.
   *
   * @param items the map of select options
   */
  protected void init(Map<String, String> items) {

    initWidget(m_panel);
    m_items = new LinkedHashMap<String, String>(items);
    m_panel.setStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().multiCheckBox());
    m_panel.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().textMedium());
    for (Map.Entry<String, String> entry : items.entrySet()) {
      String value = entry.getValue();
      CmsCheckBox checkbox = new CmsCheckBox(value);
      // wrap the check boxes in FlowPanels to arrange them vertically
      FlowPanel checkboxWrapper = new FlowPanel();
      checkboxWrapper.add(checkbox);
      m_panel.add(checkboxWrapper);
    }
    m_panel.add(m_error);
  }