Search in sources :

Example 1 with Label

use of com.haulmont.cuba.gui.components.Label in project cuba by cuba-platform.

the class LabelDsTest method testValueChangeListener.

@Test
public void testValueChangeListener() {
    Label label = (Label) factory.createComponent(Label.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    // listener after datasource
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);
    // reset state
    label.removeValueChangeListener(listener);
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");
    // datasource after listener
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertEquals(true, valueWasChanged[0]);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 2 with Label

use of com.haulmont.cuba.gui.components.Label in project cuba by cuba-platform.

the class LabelDsTest method testUnsubscribeSubscribeComponentListener.

@Test
public void testUnsubscribeSubscribeComponentListener() {
    Label label = (Label) factory.createComponent(Label.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    user.setName("testName");
    label.setDatasource(userDs, "name");
    label.setDatasource(null, null);
    // datasource before listener
    label.setDatasource(userDs, "name");
    assertEquals("testName", label.getValue());
    boolean[] valueWasChanged = { false };
    Component.ValueChangeListener listener = e -> valueWasChanged[0] = true;
    label.addValueChangeListener(listener);
    user.setName("anotherName");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", label.getValue());
    // reset state
    label.removeValueChangeListener(listener);
    label.setDatasource(null, null);
    valueWasChanged[0] = false;
    label.setValue("testName");
    // listener before datasource
    label.addValueChangeListener(listener);
    label.setDatasource(userDs, "name");
    assertEquals(true, valueWasChanged[0]);
    assertEquals("anotherName", label.getValue());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Label(com.haulmont.cuba.gui.components.Label) Test(org.junit.Test) Assert(org.junit.Assert) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) User(com.haulmont.cuba.security.entity.User) Label(com.haulmont.cuba.gui.components.Label) Component(com.haulmont.cuba.gui.components.Component) Test(org.junit.Test)

Example 3 with Label

use of com.haulmont.cuba.gui.components.Label in project cuba by cuba-platform.

the class OperationResultWindow method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    if (exception != null) {
        Label traceLabel = componentsFactory.createComponent(Label.class);
        traceLabel.setValue(getExceptionMessage(exception));
        com.vaadin.ui.Label vaadinLbl = traceLabel.unwrap(com.vaadin.ui.Label.class);
        vaadinLbl.setContentMode(ContentMode.PREFORMATTED);
        resultLabel.setValue(getMessage("operationResult.exception"));
        resultContainer.add(traceLabel);
    } else if (result != null) {
        Label valueHolder = componentsFactory.createComponent(Label.class);
        valueHolder.setValue(AttributeHelper.convertToString(result));
        com.vaadin.ui.Label vaadinLbl = valueHolder.unwrap(com.vaadin.ui.Label.class);
        vaadinLbl.setContentMode(ContentMode.PREFORMATTED);
        resultLabel.setValue(getMessage("operationResult.result"));
        resultContainer.add(valueHolder);
    } else {
        resultLabel.setValue(getMessage("operationResult.void"));
    }
}
Also used : Label(com.haulmont.cuba.gui.components.Label)

Example 4 with Label

use of com.haulmont.cuba.gui.components.Label in project cuba by cuba-platform.

the class ScreenPermissionsFrameCompanion method initPermissionColoredColumns.

@Override
public void initPermissionColoredColumns(TreeTable<BasicPermissionTarget> screenPermissionsTree) {
    screenPermissionsTree.addGeneratedColumn("permissionVariant", entity -> {
        PermissionVariant permissionVariant = entity.getPermissionVariant();
        if (permissionVariant == PermissionVariant.NOTSET)
            return null;
        String labelValue = "<span class=\"role-permission-" + permissionVariant.getColor() + "\">" + messages.getMessage(permissionVariant) + "</span>";
        Label label = componentsFactory.createComponent(Label.class);
        label.setHtmlEnabled(true);
        label.setValue(labelValue);
        return label;
    });
}
Also used : Label(com.haulmont.cuba.gui.components.Label) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant)

Example 5 with Label

use of com.haulmont.cuba.gui.components.Label in project cuba by cuba-platform.

the class UiPermissionsFrameCompanion method initPermissionsColoredColumns.

@Override
public void initPermissionsColoredColumns(Table<UiPermissionTarget> uiPermissionsTable) {
    uiPermissionsTable.addGeneratedColumn("permissionVariant", entity -> {
        UiPermissionVariant permissionVariant = entity.getPermissionVariant();
        if (permissionVariant == UiPermissionVariant.NOTSET)
            return null;
        Label label = componentsFactory.createComponent(Label.class);
        label.setHtmlEnabled(true);
        String labelValue = "<span style=\"role-permission-" + permissionVariant.getColor() + "\">" + messages.getMessage(permissionVariant) + "</span>";
        label.setValue(labelValue);
        return label;
    });
}
Also used : UiPermissionVariant(com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant) Label(com.haulmont.cuba.gui.components.Label)

Aggregations

Label (com.haulmont.cuba.gui.components.Label)14 User (com.haulmont.cuba.security.entity.User)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert (org.junit.Assert)5 Ignore (org.junit.Ignore)5 PermissionVariant (com.haulmont.cuba.gui.app.security.entity.PermissionVariant)2 AttributePermissionVariant (com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant)1 AttributeTarget (com.haulmont.cuba.gui.app.security.entity.AttributeTarget)1 UiPermissionVariant (com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1