Search in sources :

Example 1 with Button

use of io.jmix.ui.component.Button in project jmix-sneferu by mariodavid.

the class ClickInteraction method doClick.

protected void doClick(String componentId) {
    Button button = (Button) screenTestAPI.screen().getWindow().getComponentNN(componentId);
    clickButton(button);
}
Also used : Button(io.jmix.ui.component.Button)

Example 2 with Button

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

the class BulkEditorWindow method createDataComponents.

@SuppressWarnings("unchecked")
protected void createDataComponents() {
    if (managedFields.isEmpty()) {
        infoLabel.setValue(messages.getMessage("io.jmix.ui.app.bulk/bulk.noEditableProperties"));
        applyButton.setVisible(false);
        return;
    }
    List<ManagedField> editFields = new ArrayList<>(managedFields.values());
    // sort fields
    Comparator comparator;
    if (fieldSorter != null) {
        Map<MetaProperty, Integer> sorted = fieldSorter.apply(editFields.stream().map(ManagedField::getMetaProperty).collect(Collectors.toList()));
        comparator = Comparator.<ManagedField>comparingInt(item -> sorted.get(item.getMetaProperty()));
    } else {
        comparator = Comparator.comparing(ManagedField::getLocalizedName);
    }
    editFields.sort(comparator);
    CssLayout fieldsLayout = uiComponents.create(CssLayout.NAME);
    fieldsLayout.setStyleName("jmix-bulk-editor-fields-layout");
    fieldsLayout.setWidthFull();
    fieldsLayout.setHeightFull();
    int fromField;
    int toField = 0;
    int addedColumns = 0;
    for (int col = 0; col < columnsMode.getColumnsCount(); col++) {
        fromField = toField;
        toField += getFieldsCountForColumn(editFields.size() - toField, columnsMode.getColumnsCount() - col);
        DeviceInfo deviceInfo = deviceInfoProvider.getDeviceInfo();
        VBoxLayout column = uiComponents.create(VBoxLayout.NAME);
        column.setStyleName("jmix-bulk-editor-column");
        column.setWidth(Component.AUTO_SIZE);
        for (int fieldIndex = fromField; fieldIndex < toField; fieldIndex++) {
            ManagedField field = editFields.get(fieldIndex);
            CssLayout row = uiComponents.create(CssLayout.NAME);
            row.setStyleName("jmix-bulk-editor-row");
            row.setWidth("100%");
            Label<String> label = uiComponents.create(Label.NAME);
            label.setValue(field.getLocalizedName());
            label.setStyleName("jmix-bulk-editor-label");
            row.add(label);
            Datasource<Entity> fieldDs = datasource;
            // so we can check field domain
            if (metadataTools.isJpaEmbeddable(field.getMetaProperty().getDomain())) {
                fieldDs = datasources.get(field.getParentFqn());
            }
            BulkEditorFieldFactory fieldFactory = getFieldFactory();
            Field<?> editField = fieldFactory.createField(fieldDs, field.getMetaProperty());
            if (editField != null) {
                editField.setFrame(getFrame());
                editField.setStyleName("jmix-bulk-editor-field");
                if (isPickerFieldWrapperNeeded(editField, deviceInfo)) {
                    CssLayout wrapper = uiComponents.create(CssLayout.NAME);
                    wrapper.setStyleName("jmix-bulk-editor-picker-field-wrapper");
                    wrapper.add(editField);
                    row.add(wrapper);
                } else {
                    row.add(editField);
                }
                boolean required = editField.isRequired();
                if (!required) {
                    Button clearButton = uiComponents.create(Button.class);
                    clearButton.setIconFromSet(JmixIcon.TRASH);
                    clearButton.setCaption("");
                    clearButton.setDescription(messages.getMessage("io.jmix.ui.app.bulk/bulk.clearAttribute"));
                    clearButton.addClickListener(e -> {
                        editField.setEnabled(!editField.isEnabled());
                        if (!editField.isEnabled()) {
                            if (editField instanceof ListEditor) {
                                ((Field) editField).setValue(Collections.EMPTY_LIST);
                            } else {
                                editField.setValue(null);
                            }
                            e.getSource().setIconFromSet(JmixIcon.EDIT);
                            e.getSource().setDescription(messages.getMessage("io.jmix.ui.app.bulk/bulk.editAttribute"));
                        } else {
                            e.getSource().setIconFromSet(JmixIcon.TRASH);
                            e.getSource().setDescription(messages.getMessage("io.jmix.ui.app.bulk/bulk.clearAttribute"));
                        }
                    });
                    row.add(clearButton);
                } else {
                    // hidden component for correctly showing layout
                    Button spacerButton = uiComponents.create(Button.class);
                    spacerButton.setIconFromSet(JmixIcon.TRASH);
                    spacerButton.setStyleName("jmix-bulk-editor-spacer");
                    row.add(spacerButton);
                }
                // disable bean validator
                // noinspection RedundantCast
                editField.getValidators().stream().filter(v -> v instanceof AbstractBeanValidator).findFirst().ifPresent(((Field) editField)::removeValidator);
                // disable required
                editField.setRequired(false);
                if (editField instanceof ListEditor) {
                    ((Field) editField).setValue(Collections.EMPTY_LIST);
                } else {
                    editField.setValue(null);
                }
                if (fieldValidators != null) {
                    Consumer validator = fieldValidators.get(field.getFqn());
                    if (validator != null) {
                        editField.addValidator(validator);
                    }
                }
                column.add(row);
                dataFields.put(field.getFqn(), editField);
            } else {
                column.add(uiComponents.create(Label.class));
            }
        }
        fieldsLayout.add(column);
        // if there is no fields remain
        if (editFields.size() - toField == 0) {
            addedColumns = col + 1;
            break;
        }
    }
    fieldsLayout.addStyleName(COLUMN_COUNT_STYLENAME + addedColumns);
    fieldsScrollBox.add(fieldsLayout);
    dataFields.values().stream().filter(f -> f instanceof Focusable).findFirst().ifPresent(f -> ((Focusable) f).focus());
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) LoadDescriptor(io.jmix.ui.bulk.BulkEditorDataService.LoadDescriptor) java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) BulkEditorDataService(io.jmix.ui.bulk.BulkEditorDataService) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) AbstractBeanValidator(io.jmix.ui.component.validator.AbstractBeanValidator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) EntityValues(io.jmix.core.entity.EntityValues) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) EntityOp(io.jmix.core.security.EntityOp) FieldSorter(io.jmix.ui.app.bulk.FieldSorter) Component(io.jmix.ui.component.Component) Type(io.jmix.ui.action.DialogAction.Type) DatasourceImpl(com.haulmont.cuba.gui.data.impl.DatasourceImpl) Action(io.jmix.ui.action.Action) TWO_COLUMNS(io.jmix.ui.app.bulk.ColumnsMode.TWO_COLUMNS) DialogAction(io.jmix.ui.action.DialogAction) MetadataTools(io.jmix.core.MetadataTools) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Preconditions.checkNotNullArgument(io.jmix.core.common.util.Preconditions.checkNotNullArgument) Logger(org.slf4j.Logger) EmbeddedDatasourceImpl(com.haulmont.cuba.gui.data.impl.EmbeddedDatasourceImpl) DsContextImpl(com.haulmont.cuba.gui.data.impl.DsContextImpl) FetchPlan(io.jmix.core.FetchPlan) Collectors(java.util.stream.Collectors) ColumnsMode(io.jmix.ui.app.bulk.ColumnsMode) WindowParam(io.jmix.ui.WindowParam) DeviceInfo(io.jmix.ui.deviceinfo.DeviceInfo) JmixIcon(io.jmix.ui.icon.JmixIcon) Status(io.jmix.ui.action.Action.Status) Consumer(java.util.function.Consumer) ValidationException(io.jmix.ui.component.ValidationException) EntityAttrAccess(com.haulmont.cuba.security.entity.EntityAttrAccess) Button(io.jmix.ui.component.Button) Entity(io.jmix.core.Entity) DeviceInfoProvider(io.jmix.ui.deviceinfo.DeviceInfoProvider) Pattern(java.util.regex.Pattern) UiComponents(com.haulmont.cuba.gui.UiComponents) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MessageTools(io.jmix.core.MessageTools) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) Entity(io.jmix.core.Entity) Consumer(java.util.function.Consumer) Button(io.jmix.ui.component.Button) DeviceInfo(io.jmix.ui.deviceinfo.DeviceInfo) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) AbstractBeanValidator(io.jmix.ui.component.validator.AbstractBeanValidator)

Example 3 with Button

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

the class SideMenuLoader method loadSidePanelToggleButton.

protected void loadSidePanelToggleButton(SideMenu component, Element element) {
    String toggleButtonId = element.attributeValue("sidePanelToggleButton");
    if (StringUtils.isNotEmpty(toggleButtonId)) {
        Component toggleButton = resultComponent.getFrame().getComponent(toggleButtonId);
        if (!(toggleButton instanceof Button)) {
            throw new GuiDevelopmentException("Unable to find sidePanelToggleButton for SideMenu", context, "sidePanelToggleButton", toggleButtonId);
        }
        component.setSidePanelToggleButton((Button) toggleButton);
    }
}
Also used : Button(io.jmix.ui.component.Button) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component)

Example 4 with Button

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

the class TestProgrammaticCommentaryPanel method createComponent.

protected void createComponent() {
    VBoxLayout rootPanel = uiComponents.create(VBoxLayout.class);
    rootPanel.setId("rootPanel");
    rootPanel.setMargin(true);
    rootPanel.setSpacing(true);
    rootPanel.setStyleName("commentary-panel card");
    rootPanel.setWidthFull();
    DataGrid<CommentObject> commentsDataGrid = uiComponents.create(DataGrid.of(CommentObject.class));
    commentsDataGrid.setId("commentsDataGrid");
    commentsDataGrid.setBodyRowHeight(100);
    commentsDataGrid.setColumnReorderingAllowed(false);
    commentsDataGrid.setColumnsCollapsingAllowed(false);
    commentsDataGrid.setHeaderVisible(false);
    commentsDataGrid.setSelectionMode(DataGrid.SelectionMode.NONE);
    commentsDataGrid.setWidthFull();
    CssLayout sendMessageBox = uiComponents.create(CssLayout.class);
    sendMessageBox.setId("sendMessageBox");
    sendMessageBox.setStyleName("v-component-group message-box");
    sendMessageBox.setWidthFull();
    TextField<String> messageField = uiComponents.create(TextField.TYPE_STRING);
    messageField.setId("messageField");
    messageField.setInputPrompt("Enter your message");
    messageField.setWidthFull();
    Button sendBtn = uiComponents.create(Button.class);
    sendBtn.setId("sendBtn");
    sendBtn.setCaption("Send");
    sendMessageBox.add(messageField, sendBtn);
    rootPanel.add(commentsDataGrid, sendMessageBox);
    rootPanel.expand(commentsDataGrid);
    setComposition(rootPanel);
}
Also used : VBoxLayout(io.jmix.ui.component.VBoxLayout) CssLayout(io.jmix.ui.component.CssLayout) Button(io.jmix.ui.component.Button) CommentObject(test_support.entity.model_objects.CommentObject)

Example 5 with Button

use of io.jmix.ui.component.Button in project jmix-sneferu by mariodavid.

the class ComponentTestApiTest method given_componentIsPresentOnScreen_when_retrieveRawComponentViaTestAPI_then_actualJmixComponentIsReturned.

@Test
void given_componentIsPresentOnScreen_when_retrieveRawComponentViaTestAPI_then_actualJmixComponentIsReturned(UiTestAPI uiTestAPI) {
    // given:
    final StandardLookupTestAPI<Visit, VisitBrowse> openedScreen = uiTestAPI.openStandardLookup(Visit.class, VisitBrowse.class);
    // and:
    assertThat(openedScreen.screen().getWindow().getComponent("createBtn")).isNotNull();
    // when:
    final Button createBtn = openedScreen.rawComponent(button("createBtn"));
    // then:
    assertThat(createBtn).isNotNull();
}
Also used : Button(io.jmix.ui.component.Button) Visit(io.jmix.petclinic.entity.visit.Visit) VisitBrowse(io.jmix.petclinic.screen.visit.VisitBrowse) SneferuUiTest(de.diedavids.sneferu.SneferuUiTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Button (io.jmix.ui.component.Button)7 UiComponents (com.haulmont.cuba.gui.UiComponents)2 Component (io.jmix.ui.component.Component)2 HBoxLayout (io.jmix.ui.component.HBoxLayout)2 JmixIcon (io.jmix.ui.icon.JmixIcon)2 PostConstruct (javax.annotation.PostConstruct)2 Joiner (com.google.common.base.Joiner)1 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 Field (com.haulmont.cuba.gui.components.Field)1 ListEditor (com.haulmont.cuba.gui.components.ListEditor)1 TextField (com.haulmont.cuba.gui.components.TextField)1 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 NestedDatasource (com.haulmont.cuba.gui.data.NestedDatasource)1 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)1 DsContextImpl (com.haulmont.cuba.gui.data.impl.DsContextImpl)1