Example usage for com.google.gwt.user.client.ui Label getText

List of usage examples for com.google.gwt.user.client.ui Label getText

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label getText.

Prototype

public String getText() 

Source Link

Usage

From source file:org.nsesa.editor.gwt.core.client.ui.visualstructure.VisualStructureAttributesViewImpl.java

License:EUPL

/**
 * Create a list of labels and text boxes based on the given map
 * and fire {@link org.nsesa.editor.gwt.core.client.event.visualstructure.VisualStructureModificationEvent} whenever the user change the value from textbox
 *
 * @param attributes A map of attributes where the key is the attribute name and the value is the attribute value
 *///from  ww  w.  java  2s . c  om
@Override
public void setAttributes(Map<String, String> attributes) {
    attributesHolder.clear();
    attributesPanel.resize(attributes.size(), 2);
    int i = 0;
    for (Map.Entry<String, String> attr : attributes.entrySet()) {
        final Label lbl = new Label(attr.getKey());
        final TextBox txtBox = new TextBox();
        txtBox.setText(attr.getValue());
        // add change handler
        txtBox.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent event) {
                final Map<String, String> attrs = new HashMap<String, String>();
                attrs.put(lbl.getText(), txtBox.getText());
                eventBus.fireEvent(new VisualStructureModificationEvent(attrs));
            };
        });

        attributesPanel.setWidget(i, 0, lbl);
        attributesPanel.setWidget(i, 1, txtBox);
        i++;
        attributesHolder.put(lbl, txtBox);
    }
}

From source file:org.pentaho.gwt.widgets.samples.SampleApp.java

License:Open Source License

@SuppressWarnings("deprecation")
public void onModuleLoad() {

    DragController dragController = new PickupDragController(RootPanel.get(), false) {

        {/*w  w w  .j ava  2  s. c o m*/
            setBehaviorDragProxy(true);
            setBehaviorDragStartSensitivity(5);

        }
        private Widget proxy;

        @Override
        protected void restoreSelectedWidgetsStyle() {
        }

        @Override
        protected void saveSelectedWidgetsLocationAndStyle() {
        }

        @Override
        protected void restoreSelectedWidgetsLocation() {
        }

        @Override
        public void dragStart() {
            super.dragStart();
        }

        @Override
        public void dragEnd() {
            proxy.removeFromParent();
            proxy = null;
        }

        @Override
        protected Widget newDragProxy(DragContext context) {
            proxy = ((Draggable) context.draggable).makeProxy(context.draggable);
            return proxy;
        }

        @Override
        public void previewDragEnd() throws VetoDragException {

        }
    };

    final CustomListBox list = new CustomListBox();

    list.setDragController(dragController);

    list.addItem("Alberta");
    list.addItem("Atlanta");
    list.addItem("San Francisco");
    list.addItem("Alberta");
    list.addItem("Atlanta");
    list.addItem("San Francisco");
    list.addItem("Alberta");
    list.addItem("Atlanta");
    list.addItem("San Francisco");
    list.addItem("Alberta");
    list.addItem(new DefaultListItem("Testing", new Image("16x16sample.png")));
    list.addItem(new DefaultListItem("Testing 2", new CheckBox()));

    // list.setVisibleRowCount(6);

    list.addChangeListener(new ChangeListener() {
        public void onChange(Widget widget) {
            System.out.println("" + list.getSelectedIndex());
        }
    });

    list.setWidth("100%");
    list.setHeight("100%");

    // RootPanel.get().add(new Label("Combo: "));
    // RootPanel.get().add(list);

    final CustomListBox list2 = new CustomListBox();

    list2.setDragController(dragController);

    list2.addItem("Alberta");
    list2.addItem("Atlanta");
    list2.addItem("San Francisco");
    list2.addItem("Alberta");
    list2.addItem("Atlanta");
    list2.addItem("San Francisco");
    list2.addItem("Alberta");
    list2.addItem("Atlanta");
    list2.addItem("San Francisco");
    list2.addItem("Alberta");
    list2.addItem("Atlanta");
    list2.addItem("San Francisco");
    list2.add("Alberta");
    list2.add("Atlanta");
    list2.add("San Francisco");
    list2.add("Alberta");
    list2.add("Atlanta");
    list2.add("San Francisco");
    list2.add(new DefaultListItem("Testing", new Image("16x16sample.png")));
    list2.addItem(new DefaultListItem("Testing 2", new CheckBox()));
    list2.setVisibleRowCount(6);
    // list2.setEditable(true);
    list2.setValue("Bogus");

    list2.setMultiSelect(true);

    final Label selected = new Label();
    list2.addChangeListener(new ChangeListener() {
        @Override
        public void onChange(Widget widget) {
            int[] sels = list2.getSelectedIndices();
            selected.setText("");
            for (int i = 0; i < sels.length; i++) {
                selected.setText(selected.getText() + ", " + sels[i]);
            }
        }
    });

    RootPanel.get().add(new Label(""));
    RootPanel.get().add(new Label("Combo2: "));
    RootPanel.get().add(list2);
    RootPanel.get().add(selected);

    CustomListBox list3 = new CustomListBox();

    DefaultListItem dli = null;
    dli = new DefaultListItem("Testing 1", new Image("16x16sample.png"));
    dli.setValue("Value of Testing 1");
    list3.add(dli);

    dli = new DefaultListItem("Testing 2", new CheckBox());
    dli.setValue("Value of Testing 2");
    list3.add(dli);

    // RootPanel.get().add(new Label(""));
    // RootPanel.get().add(new Label("Combo3: "));
    // RootPanel.get().add(list3);

    Label showSelectedLabel = new Label("Selected item's value:");

    final TextBox showSelectedTextBox = new TextBox();
    showSelectedTextBox.setReadOnly(true);

    list3.addChangeListener(new ChangeListener() {

        public void onChange(Widget widget) {
            String val = (String) ((CustomListBox) widget).getSelectedItem().getValue();
            if (val != null) {
                showSelectedTextBox.setText(val);
            }
        }
    });
    final CustomListBox list4 = new CustomListBox();

    list4.addItem("Albert");
    list4.addItem("Greg");
    list4.setWidth("170px");

    RootPanel.get().add(new Label(""));
    RootPanel.get().add(new Label("Combo4: "));
    RootPanel.get().add(list4);

    RootPanel.get().add(showSelectedLabel);
    RootPanel.get().add(showSelectedTextBox);

    final ColorPicker picker = new ColorPicker();
    picker.addColorPickerListener(new ColorPickerListener() {

        public void colorPicked(ColorPicker picker) {
            System.out.println("color: " + picker.getColor());

        }

    });

    RootPanel.get().add(picker);
    Button btn = new Button("colorPicker");
    RootPanel.get().add(btn);

    btn.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            picker.showPicker();

        }

    });
}

From source file:org.pentaho.pat.client.ui.panels.windows.DimensionMenu.java

License:Open Source License

/**
 * Loads all Members of a given dimension and query
 * /*from  www .j a v  a2s.  com*/
 * @param queryId
 *            - Query to use to discover dimension members
 * @param dimensionId
 *            - Dimension of interest
 * @param empty
 *            - empty before populating
 */
public final void loadMembers(final String queryId, final String dimensionId, final Boolean empty) {
    if (empty) {
        dimensionTree.clear();
        memberListBoxModel.clear();
        filterModel = new FilterProxyListModel<MemberSelectionLabel, String>(memberListBoxModel);
        memberListBox.setModel(filterModel);
    }
    ServiceFactory.getDiscoveryInstance().getMembers(Pat.getSessionID(), queryId, dimensionId,
            new AsyncCallback<StringTree>() {

                public void onFailure(final Throwable arg0) {
                    dimensionTree.clear();
                    MessageBox.error(Pat.CONSTANTS.error(),
                            MessageFactory.getInstance().failedMemberFetch(arg0.getLocalizedMessage()));
                }

                public void onSuccess(final StringTree labels) {
                    final Label dimensionLabel = new Label(labels.getValue());

                    final TreeItem parent = dimensionTree.addItem(dimensionLabel);

                    ServiceFactory.getQueryInstance().getSelection(Pat.getSessionID(), Pat.getCurrQuery(),
                            dimensionLabel.getText(), new AsyncCallback<String[][]>() {

                                public void onFailure(final Throwable arg0) {
                                    MessageBox.error(Pat.CONSTANTS.error(), MessageFactory.getInstance()
                                            .failedMemberFetch(arg0.getLocalizedMessage()));

                                }

                                public void onSuccess(final String[][] selectionlist) {

                                    ServiceFactory.getQueryInstance().getSortOrder(Pat.getSessionID(),
                                            Pat.getCurrQuery(), dimensionId, new AsyncCallback<String>() {

                                                public void onFailure(final Throwable arg0) {
                                                    MessageBox.error(Pat.CONSTANTS.error(),
                                                            MessageFactory.getInstance().failedGetSort());

                                                }

                                                public void onSuccess(final String arg0) {
                                                    for (int i = 0; i < sortComboBox.getItemCount(); i++)
                                                        if (arg0 == null) {
                                                            DimensionMenu.this.sortModeModel
                                                                    .setSelectedItem(null);

                                                        } else {
                                                            if ("ASC".equals(arg0)) { //$NON-NLS-1$
                                                                DimensionMenu.this.sortModeModel
                                                                        .setSelectedItem(
                                                                                Pat.CONSTANTS.sortAscending());
                                                                break;
                                                            } else if ("DESC".equals(arg0)) { //$NON-NLS-1$
                                                                DimensionMenu.this.sortModeModel
                                                                        .setSelectedItem(
                                                                                Pat.CONSTANTS.sortDescending());
                                                                break;
                                                            } else if ("BASC".equals(arg0)) { //$NON-NLS-1$
                                                                DimensionMenu.this.sortModeModel
                                                                        .setSelectedItem(Pat.CONSTANTS
                                                                                .sortBreakAscending());
                                                                break;
                                                            } else if ("BDESC".equals(arg0)) { //$NON-NLS-1$
                                                                DimensionMenu.this.sortModeModel
                                                                        .setSelectedItem(Pat.CONSTANTS
                                                                                .sortBreakDescending());
                                                                break;
                                                            }
                                                        }

                                                    DimensionMenu.this.sortModeModel.getSelectedItem();

                                                    ServiceFactory.getQueryInstance().getHierarchizeMode(
                                                            Pat.getSessionID(), Pat.getCurrQuery(), dimensionId,
                                                            new AsyncCallback<String>() {

                                                                public void onFailure(final Throwable arg0) {
                                                                    // TODO Auto-generated method stub

                                                                }

                                                                public void onSuccess(final String arg0) {
                                                                    /*
                                                                     * for (int i = 0; i < hierarchyComboBox
                                                                     * .getItemCount(); i++) if
                                                                     * (hierarchyComboBox
                                                                     * .getModel().getElementAt(i)
                                                                     * .equals(arg0)){
                                                                     * DimensionMenu.this.hierarchyModeModel
                                                                     * .setSelectedItem(arg0);
                                                                     * DimensionMenu.this.hierarchyModeModel
                                                                     * .getSelectedItem(); break; } else
                                                                     * DimensionMenu
                                                                     * .this.hierarchyModeModel.setSelectedItem
                                                                     * (null);
                                                                     */
                                                                    addDimensionTreeItem(labels, parent,
                                                                            selectionlist,
                                                                            dimensionLabel.getText());
                                                                    // TODO why do i have to do it here and not
                                                                    // in
                                                                    // the constructor?
                                                                    filterModel = new FilterProxyListModel<MemberSelectionLabel, String>(
                                                                            memberListBoxModel);
                                                                    filterModel.setModelFilter(
                                                                            new Filter<MemberSelectionLabel, String>() {
                                                                                public boolean select(
                                                                                        final MemberSelectionLabel element,
                                                                                        final String filter) {
                                                                                    if (filter == null || filter
                                                                                            .length() == 0) {
                                                                                        return true;
                                                                                    }
                                                                                    return element.getText()
                                                                                            .toUpperCase()
                                                                                            .contains(filter
                                                                                                    .toUpperCase());
                                                                                }
                                                                            });
                                                                    memberListBox.setModel(filterModel);

                                                                }

                                                            });

                                                }

                                            });

                                }

                            });
                }

            });
}

From source file:org.pentaho.pat.client.ui.popups.CellModeMenu.java

License:Open Source License

protected final String getDimensionName(final CellLabelPanel targetLabel) {
    final Tree tree = (Tree) targetLabel.getParent();
    final TreeItem rootItem = tree.getItem(0);
    final Label widget = (Label) rootItem.getWidget();

    return widget.getText();
}

From source file:org.pentaho.pat.client.ui.popups.MeasureLabelSelectionModeMenu.java

License:Open Source License

protected final String getDimensionName(final MeasureLabel targetLabel) {
    final Tree tree = (Tree) targetLabel.getParent();
    final TreeItem rootItem = tree.getItem(0);
    final Label widget = (Label) rootItem.getWidget();

    return widget.getText();
}

From source file:org.pentaho.pat.client.ui.popups.SelectionModeMenu.java

License:Open Source License

protected final String getDimensionName(final MemberSelectionLabel targetLabel) {
    final Tree tree = (Tree) targetLabel.getParent();
    final TreeItem rootItem = tree.getItem(0);
    final Label widget = (Label) rootItem.getWidget();

    return widget.getText();
}

From source file:org.roda.wui.client.common.utils.FormUtilities.java

private static void addTextField(FlowPanel panel, final FlowPanel layout, final MetadataValue mv,
        final boolean mandatory) {
    // Top label/*w  w w  .j a v  a 2 s . c o m*/
    Label mvLabel = new Label(getFieldLabel(mv));
    mvLabel.addStyleName("form-label");
    if (mandatory) {
        mvLabel.addStyleName("form-label-mandatory");
    }
    // Field
    final TextBox mvText = new TextBox();
    mvText.setTitle(mvLabel.getText());
    mvText.addStyleName("form-textbox");
    if (mv.get("value") != null) {
        mvText.setText(mv.get("value"));
    }

    mvText.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            mv.set("value", mvText.getValue());
            if (mandatory && (mvText.getValue() != null && !"".equalsIgnoreCase(mvText.getValue().trim()))) {
                mvText.removeStyleName("isWrong");
            } else if (mandatory && (mvText.getValue() == null || "".equals(mvText.getValue().trim()))) {
                mvText.addStyleName("isWrong");
            }
        }
    });

    layout.add(mvLabel);
    layout.add(mvText);

    // Description
    String description = mv.get("description");
    if (description != null && description.length() > 0) {
        Label mvDescription = new Label(description);
        mvDescription.addStyleName("form-help");
        layout.add(mvDescription);
    }

    if (mv.get("error") != null && !"".equals(mv.get("error").trim())) {
        Label errorLabel = new Label(mv.get("error"));
        errorLabel.addStyleName("form-label-error");
        layout.add(errorLabel);
        mvText.addStyleName("isWrong");
    }
    panel.add(layout);
}

From source file:org.roda.wui.client.common.utils.FormUtilities.java

private static void addTextArea(FlowPanel panel, final FlowPanel layout, final MetadataValue mv,
        final boolean mandatory) {
    // Top label/*from www  .  jav a 2 s .  com*/
    Label mvLabel = new Label(getFieldLabel(mv));
    mvLabel.addStyleName("form-label");
    if (mandatory) {
        mvLabel.addStyleName("form-label-mandatory");
    }
    // Field
    final TextArea mvText = new TextArea();
    mvText.setTitle(mvLabel.getText());
    mvText.addStyleName("form-textbox metadata-form-text-area");
    if (mv.get("value") != null) {
        mvText.setText(mv.get("value"));
    }

    mvText.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            mv.set("value", mvText.getValue());
            if (mandatory && (mvText.getValue() != null && !"".equals(mvText.getValue().trim()))) {
                mvText.removeStyleName("isWrong");
            } else if (mandatory
                    && (mvText.getValue() == null || "".equalsIgnoreCase(mvText.getValue().trim()))) {
                mvText.addStyleName("isWrong");
            }
        }
    });

    layout.add(mvLabel);
    layout.add(mvText);

    // Description
    String description = mv.get("description");
    if (description != null && description.length() > 0) {
        Label mvDescription = new Label(description);
        mvDescription.addStyleName("form-help");
        layout.add(mvDescription);
    }

    if (mv.get("error") != null && !"".equalsIgnoreCase(mv.get("error").trim())) {
        Label errorLabel = new Label(mv.get("error"));
        errorLabel.addStyleName("form-label-error");
        layout.add(errorLabel);
        mvText.addStyleName("isWrong");
    }
    panel.add(layout);
}

From source file:org.roda.wui.client.common.utils.FormUtilities.java

private static void addList(FlowPanel panel, final FlowPanel layout, final MetadataValue mv,
        final boolean mandatory) {
    // Top Label//from  ww  w.  j  a v a  2 s . c  om
    Label mvLabel = new Label(getFieldLabel(mv));
    mvLabel.addStyleName("form-label");
    if (mandatory) {
        mvLabel.addStyleName("form-label-mandatory");
    }
    // Field
    final ListBox mvList = new ListBox();
    mvList.setTitle(mvLabel.getText());
    mvList.addStyleName("form-textbox");

    String options = mv.get("options");
    JSONArray optionsArray = null;
    if (options != null) {
        optionsArray = JSONParser.parseLenient(options).isArray();
    }

    String list = mv.get("optionsLabels");
    mvList.addItem("");

    if (list != null) {
        JSONArray jsonArray = JSONParser.parseLenient(list).isArray();
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.size(); i++) {
                String value = jsonArray.get(i).isString().stringValue();
                mvList.addItem(value);

                if (value.equals(mv.get("value"))) {
                    mvList.setSelectedIndex(i + 1);
                }
            }
        } else {
            JSONObject jsonObject = JSONParser.parseLenient(list).isObject();
            if (jsonObject != null) {
                String loc = LocaleInfo.getCurrentLocale().getLocaleName();
                int i = 0;

                if (optionsArray != null) {
                    for (int pos = 0; pos < optionsArray.size(); pos++) {
                        String key = optionsArray.get(pos).isString().stringValue();
                        JSONValue entry = jsonObject.get(key);
                        if (entry.isObject() != null) {
                            JSONValue jsonValue = entry.isObject().get(loc);
                            String value;
                            if (jsonValue != null) {
                                value = jsonValue.isString().stringValue();
                            } else {
                                value = entry.isObject().get(entry.isObject().keySet().iterator().next())
                                        .isString().stringValue();
                            }
                            if (value != null) {
                                mvList.addItem(value, key);
                                if (key.equals(mv.get("value"))) {
                                    mvList.setSelectedIndex(i + 1);
                                }
                            }
                        }
                        i++;
                    }
                } else {
                    for (String key : jsonObject.keySet()) {
                        JSONValue entry = jsonObject.get(key);
                        if (entry.isObject() != null) {
                            JSONValue jsonValue = entry.isObject().get(loc);
                            String value;
                            if (jsonValue != null) {
                                value = jsonValue.isString().stringValue();
                            } else {
                                value = entry.isObject().get(entry.isObject().keySet().iterator().next())
                                        .isString().stringValue();
                            }
                            if (value != null) {
                                mvList.addItem(value, key);
                                if (key.equals(mv.get("value"))) {
                                    mvList.setSelectedIndex(i + 1);
                                }
                            }
                        }
                        i++;
                    }
                }
            }
        }
    } else {
        if (optionsArray != null) {
            int i = 0;
            for (int pos = 0; pos < optionsArray.size(); pos++) {
                String key = optionsArray.get(pos).isString().stringValue();
                if (key != null) {
                    mvList.addItem(key, key);
                    if (key.equals(mv.get("value"))) {
                        mvList.setSelectedIndex(i + 1);
                    }
                }
                i++;
            }
        }
    }

    mvList.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            mv.set("value", mvList.getSelectedValue());
            if (mandatory
                    && (mvList.getSelectedValue() != null && !"".equals(mvList.getSelectedValue().trim()))) {
                mvList.removeStyleName("isWrong");
            }

            if (mandatory && (mvList.getSelectedValue() == null
                    || "".equalsIgnoreCase(mvList.getSelectedValue().trim()))) {
                mvList.removeStyleName("isWrong");
            }
        }
    });

    if (mv.get("value") == null || mv.get("value").isEmpty()) {
        mvList.setSelectedIndex(0);
        mv.set("value", mvList.getSelectedValue());
    }

    layout.add(mvLabel);
    layout.add(mvList);

    // Description
    String description = mv.get("description");
    if (description != null && description.length() > 0) {
        Label mvDescription = new Label(description);
        mvDescription.addStyleName("form-help");
        layout.add(mvDescription);
    }

    if (mv.get("error") != null && !"".equals(mv.get("error").trim())) {
        Label errorLabel = new Label(mv.get("error"));
        errorLabel.addStyleName("form-label-error");
        layout.add(errorLabel);
        mvList.addStyleName("isWrong");
    }
    panel.add(layout);
}

From source file:org.roda.wui.client.common.utils.FormUtilities.java

private static void addDatePicker(FlowPanel panel, final FlowPanel layout, final MetadataValue mv,
        final boolean mandatory) {
    // Top label/*from ww w.j ava2 s.c  o m*/
    final DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
    Label mvLabel = new Label(getFieldLabel(mv));
    mvLabel.addStyleName("form-label");
    if (mandatory) {
        mvLabel.addStyleName("form-label-mandatory");
    }
    // Field
    final DateBox mvDate = new DateBox();
    mvDate.setTitle(mvLabel.getText());
    mvDate.getDatePicker().setYearAndMonthDropdownVisible(true);
    mvDate.getDatePicker().setYearArrowsVisible(true);
    mvDate.addStyleName("form-textbox");
    mvDate.setFormat(new DateBox.DefaultFormat() {
        @Override
        public String format(DateBox dateBox, Date date) {
            if (date == null)
                return null;
            return dateTimeFormat.format(date);
        }
    });

    String value = mv.get("value");
    if (value != null && value.length() > 0) {
        try {
            Date date = dateTimeFormat.parse(value.trim());
            mvDate.setValue(date);
        } catch (IllegalArgumentException iae) {
            mvDate.getTextBox().setValue(value);
        }
    }

    mvDate.addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
        public void onValueChange(ValueChangeEvent<Date> valueChangeEvent) {
            String newValue = dateTimeFormat.format(mvDate.getValue());
            mv.set("value", newValue);
            if (mandatory && (newValue != null && !"".equals(newValue.trim()))) {
                mvDate.removeStyleName("isWrong");
            } else if (mandatory && (newValue == null || "".equals(newValue.trim()))) {
                mvDate.addStyleName("isWrong");
            }
        }
    });

    mvDate.getTextBox().addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            String value = event.getValue();
            try {
                Date date = dateTimeFormat.parse(value.trim());
                mvDate.setValue(date);
                mv.set("value", value);
            } catch (IllegalArgumentException iae) {
                if (event.getValue() == null || "".equals(event.getValue().trim())) {
                    mv.set("value", null);
                }
                mvDate.getTextBox().setValue(value);
            }
        }
    });

    layout.add(mvLabel);
    layout.add(mvDate);

    // Description
    String description = mv.get("description");
    if (description != null && description.length() > 0) {
        Label mvDescription = new Label(description);
        mvDescription.addStyleName("form-help");
        layout.add(mvDescription);
    }

    if (mv.get("error") != null && !"".equals(mv.get("error").trim())) {
        Label errorLabel = new Label(mv.get("error"));
        errorLabel.addStyleName("form-label-error");
        layout.add(errorLabel);
        mvDate.addStyleName("isWrong");
    }
    panel.add(layout);
}