Search in sources :

Example 11 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class DateFieldTest method testValueChangeListener.

@Test
public void testValueChangeListener() throws ParseException {
    DateField component = create(DateField.class);
    AtomicInteger counter = new AtomicInteger(0);
    Date value1 = new SimpleDateFormat("dd.MM.yyyy").parse("12.12.2000");
    Consumer<HasValue.ValueChangeEvent> okListener = e -> {
        assertNull(e.getPrevValue());
        assertEquals(value1, e.getValue());
        counter.addAndGet(1);
    };
    Subscription subscription = component.addValueChangeListener(okListener);
    component.setValue(value1);
    assertEquals(1, counter.get());
    subscription.remove();
    Date value2 = new SimpleDateFormat("dd.MM.yyyy").parse("10.10.2000");
    component.setValue(value2);
    assertEquals(1, counter.get());
    // noinspection unchecked
    Datasource<User> testDs = new DsBuilder().setId("testDs").setJavaClass(User.class).setView(viewRepository.getFetchPlan(User.class, FetchPlan.LOCAL)).buildDatasource();
    testDs.setItem(new User());
    ((DatasourceImpl) testDs).valid();
    Consumer<HasValue.ValueChangeEvent> dsLoadListener = e -> {
        assertEquals(value2, e.getPrevValue());
        assertNull(e.getValue());
        counter.addAndGet(1);
    };
    subscription = component.addValueChangeListener(dsLoadListener);
    component.setDatasource(testDs, "createTs");
    assertEquals(2, counter.get());
    subscription.remove();
    Date value3 = new SimpleDateFormat("dd.MM.yyyy").parse("01.01.2000");
    Consumer<HasValue.ValueChangeEvent> dsListener = e -> {
        assertNull(e.getPrevValue());
        assertEquals(value3, e.getValue());
        counter.addAndGet(1);
    };
    component.addValueChangeListener(dsListener);
    testDs.getItem().setCreateTs(value3);
    assertEquals(3, counter.get());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Subscription(io.jmix.core.common.event.Subscription) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Date(java.util.Date) FetchPlan(io.jmix.core.FetchPlan) SimpleDateFormat(java.text.SimpleDateFormat) Disabled(org.junit.jupiter.api.Disabled) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Component(io.jmix.ui.component.Component) HasValue(io.jmix.ui.component.HasValue) DateField(com.haulmont.cuba.gui.components.DateField) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Assertions(org.junit.jupiter.api.Assertions) ParseException(java.text.ParseException) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DateField(com.haulmont.cuba.gui.components.DateField) Subscription(io.jmix.core.common.event.Subscription) SimpleDateFormat(java.text.SimpleDateFormat) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 12 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class DeclarativeColumnGenerator method generateCell.

@Override
public Component generateCell(Object entity) {
    if (unableToFindMethod) {
        return null;
    }
    FrameOwner controller = getFrameOwner();
    if (method == null) {
        method = findGeneratorMethod(controller.getClass(), methodName);
        if (method == null) {
            this.unableToFindMethod = true;
            String tableId = table.getId() == null ? "" : table.getId();
            throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, tableId));
        }
    }
    try {
        return (Component) method.invoke(controller, entity);
    } catch (Exception e) {
        throw new RuntimeException("Exception in declarative Table column generator " + methodName, e);
    }
}
Also used : FrameOwner(io.jmix.ui.screen.FrameOwner) Component(io.jmix.ui.component.Component)

Example 13 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class AbstractLookup method initLookupLayout.

@Override
public void initLookupLayout() {
    Action selectAction = getAction(LOOKUP_SELECT_ACTION_ID);
    if (selectAction != null && selectAction.getOwner() == null) {
        Fragments fragments = UiControllerUtils.getScreenContext(this).getFragments();
        ScreenFragment lookupWindowActions = fragments.create(this, "lookupWindowActions");
        lookupWindowActions.getFragment().setId("lookupWindowActions");
        lookupWindowActions.getFragment().setVisible(false);
        getFrame().add(lookupWindowActions.getFragment());
    }
    Element element = ((Component.HasXmlDescriptor) getFrame()).getXmlDescriptor();
    if (element != null) {
        String lookupComponent = element.attributeValue("lookupComponent");
        if (StringUtils.isNotEmpty(lookupComponent)) {
            Component component = getFrame().getComponent(lookupComponent);
            setLookupComponent(component);
        }
    }
    Component lookupComponent = getLookupComponent();
    if (lookupComponent instanceof LookupComponent.LookupSelectionChangeNotifier) {
        LookupComponent.LookupSelectionChangeNotifier selectionNotifier = (LookupComponent.LookupSelectionChangeNotifier) lookupComponent;
        if (selectAction != null) {
            // noinspection unchecked
            selectionNotifier.addLookupValueChangeListener(valueChangeEvent -> selectAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty()));
            selectAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty());
        }
    }
}
Also used : Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) ScreenFragment(io.jmix.ui.screen.ScreenFragment) Element(org.dom4j.Element) Fragments(io.jmix.ui.Fragments) Component(io.jmix.ui.component.Component)

Example 14 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class AbstractEditor method initCommitActions.

protected void initCommitActions(@SuppressWarnings("unused") InitEvent event) {
    Component commitAndCloseButton = ComponentsHelper.findComponent(getFrame(), WINDOW_COMMIT_AND_CLOSE);
    UiScreenProperties screenProperties = getApplicationContext().getBean(UiScreenProperties.class);
    boolean commitAndCloseButtonExists = false;
    String commitShortcut = screenProperties.getCommitShortcut();
    if (commitAndCloseButton != null) {
        commitAndCloseButtonExists = true;
        getFrame().addAction(new BaseAction(WINDOW_COMMIT_AND_CLOSE).withCaption(messages.getMessage("actions.SaveClose")).withPrimary(true).withShortcut(commitShortcut).withHandler(e -> commitAndClose()));
    }
    boolean finalCommitAndCloseButtonExists = commitAndCloseButtonExists;
    Action commitAction = new BaseAction(WINDOW_COMMIT).withCaption(messages.getMessage(commitAndCloseButtonExists ? "actions.Save" : "actions.Ok")).withPrimary(!commitAndCloseButtonExists).withShortcut(commitAndCloseButtonExists ? null : commitShortcut).withHandler(e -> {
        if (!finalCommitAndCloseButtonExists) {
            commitAndClose();
        } else {
            if (commit()) {
                commitActionPerformed = true;
            }
        }
    });
    getFrame().addAction(commitAction);
    Action closeAction = new BaseAction(WINDOW_CLOSE).withCaption(messages.getMessage("actions.Cancel")).withHandler(e -> close(commitActionPerformed ? Window.COMMIT_ACTION_ID : getId()));
    getFrame().addAction(closeAction);
    Action enableEditingAction = new BaseAction(ENABLE_EDITING).withCaption(messages.getMessage("actions.EnableEditing")).withHandler(e -> setReadOnly(false));
    enableEditingAction.setVisible(false);
    getFrame().addAction(enableEditingAction);
}
Also used : Iterables(com.google.common.collect.Iterables) EntityAccessException(io.jmix.core.EntityAccessException) MetaClass(io.jmix.core.metamodel.model.MetaClass) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools) Security(com.haulmont.cuba.core.global.Security) Date(java.util.Date) ValidationErrors(io.jmix.ui.component.ValidationErrors) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) EntityValues(io.jmix.core.entity.EntityValues) Metadata(com.haulmont.cuba.core.global.Metadata) EntityOp(io.jmix.core.security.EntityOp) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) Categorized(io.jmix.dynattr.model.Categorized) Component(io.jmix.ui.component.Component) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) com.haulmont.cuba.gui.data(com.haulmont.cuba.gui.data) PersistenceHelper(com.haulmont.cuba.core.global.PersistenceHelper) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) UiCrossFieldChecks(io.jmix.core.validation.group.UiCrossFieldChecks) MetadataTools(io.jmix.core.MetadataTools) ConstraintViolation(javax.validation.ConstraintViolation) Window(io.jmix.ui.component.Window) Nullable(javax.annotation.Nullable) LockService(com.haulmont.cuba.core.app.LockService) LockNotSupported(io.jmix.core.pessimisticlocking.LockNotSupported) Collection(java.util.Collection) EntityCopyUtils(com.haulmont.cuba.gui.data.impl.EntityCopyUtils) Datatypes(com.haulmont.chile.core.datatypes.Datatypes) Validator(javax.validation.Validator) Set(java.util.Set) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) CollectionPropertyDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl) WindowParams(com.haulmont.cuba.gui.WindowParams) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) LockInfo(io.jmix.core.pessimisticlocking.LockInfo) ReadOnlyScreensSupport(io.jmix.ui.screen.ReadOnlyScreensSupport) EntityStates(io.jmix.core.EntityStates) Entity(io.jmix.core.Entity) Element(org.dom4j.Element) ReadOnlyAwareScreen(io.jmix.ui.screen.ReadOnlyAwareScreen) ElementKind(javax.validation.ElementKind) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) OperationResult(io.jmix.ui.util.OperationResult) UiScreenProperties(io.jmix.ui.UiScreenProperties) ComponentsHelper(io.jmix.ui.component.ComponentsHelper) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) UiScreenProperties(io.jmix.ui.UiScreenProperties) BaseAction(io.jmix.ui.action.BaseAction) Component(io.jmix.ui.component.Component)

Example 15 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class EntityCombinedScreen method validateEditor.

/**
 * Validates editor fields.
 *
 * @return true if all fields are valid or false otherwise
 */
protected boolean validateEditor() {
    FieldGroup fieldGroup = getFieldGroup();
    List<Validatable> components = new ArrayList<>();
    for (Component component : fieldGroup.getComponents()) {
        if (component instanceof Validatable) {
            components.add((Validatable) component);
        }
    }
    return validate(components);
}
Also used : ArrayList(java.util.ArrayList) Component(io.jmix.ui.component.Component)

Aggregations

Component (io.jmix.ui.component.Component)81 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)16 Datasource (com.haulmont.cuba.gui.data.Datasource)12 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)11 Test (org.junit.jupiter.api.Test)11 Element (org.dom4j.Element)10 Consumer (java.util.function.Consumer)9 ListComponent (com.haulmont.cuba.gui.components.ListComponent)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)7 Action (io.jmix.ui.action.Action)7 HasValue (io.jmix.ui.component.HasValue)7 FrameOwner (io.jmix.ui.screen.FrameOwner)7 ArrayList (java.util.ArrayList)7 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)6 FetchPlan (io.jmix.core.FetchPlan)6 UUID (java.util.UUID)6 Nullable (javax.annotation.Nullable)6 User (com.haulmont.cuba.core.model.common.User)5 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)5 Entity (io.jmix.core.Entity)5