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());
}
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);
}
}
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());
}
}
}
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);
}
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);
}
Aggregations