Search in sources :

Example 26 with Component

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

the class DesktopFieldGroup method bindDeclarativeFieldConfigs.

protected void bindDeclarativeFieldConfigs() {
    List<Integer> reattachColumns = new ArrayList<>();
    for (FieldConfig fc : getColumnOrderedFields()) {
        if (!fc.isCustom() && !fc.isBound()) {
            FieldConfigImpl fci = (FieldConfigImpl) fc;
            Datasource targetDs = fc.getTargetDatasource();
            if (targetDs == null) {
                throw new IllegalStateException(String.format("Unable to get datasource for field '%s'", id));
            }
            FieldGroupFieldFactory.GeneratedField generatedField = fieldFactory.createField(fc);
            Component fieldComponent = generatedField.getComponent();
            fci.assignComponent(fieldComponent);
            fci.setAttachMode(generatedField.getAttachMode());
            setupFieldComponent(fci);
            DesktopAbstractComponent fieldImpl = (DesktopAbstractComponent) fieldComponent;
            fci.setComposition(fieldImpl);
            assignTypicalAttributes(fieldComponent);
            if (generatedField.getAttachMode() == FieldAttachMode.APPLY_DEFAULTS) {
                applyFieldDefaults(fci);
            }
            int columnIndex = fci.getColumn();
            if (!reattachColumns.contains(columnIndex)) {
                reattachColumns.add(columnIndex);
            }
        }
    }
    if (!reattachColumns.isEmpty()) {
        this.rows = detectRowsCount();
        for (Integer reattachColumnIndex : reattachColumns) {
            reattachColumnFields(reattachColumnIndex);
        }
    }
    impl.revalidate();
    impl.repaint();
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Component(com.haulmont.cuba.gui.components.Component)

Example 27 with Component

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

the class DesktopGridLayout method updateEnabled.

@Override
public void updateEnabled() {
    super.updateEnabled();
    boolean resultEnabled = isEnabledWithParent();
    for (Component component : ownComponents) {
        if (component instanceof DesktopAbstractComponent) {
            ((DesktopAbstractComponent) component).setParentEnabled(resultEnabled);
        }
    }
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Example 28 with Component

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

the class DesktopAbstractBox method add.

@Override
public void add(Component component, int index) {
    if (component.getParent() != null && component.getParent() != this) {
        throw new IllegalStateException("Component already has parent");
    }
    if (ownComponents.contains(component)) {
        int existingIndex = new ArrayList<>(ownComponents).indexOf(component);
        if (index > existingIndex) {
            index--;
        }
        remove(component);
    }
    JComponent composition = DesktopComponentsHelper.getComposition(component);
    boolean hasExternalCaption = DesktopContainerHelper.hasExternalCaption(component);
    if (hasExternalCaption || DesktopContainerHelper.hasExternalContextHelp(component)) {
        ComponentCaption caption = new ComponentCaption(component);
        captions.put(component, caption);
        JPanel wrapper = new LayoutSlot();
        BoxLayoutAdapter adapter = BoxLayoutAdapter.create(wrapper);
        adapter.setExpandLayout(true);
        adapter.setSpacing(false);
        adapter.setMargin(false);
        wrapper.add(composition);
        if (hasExternalCaption) {
            adapter.setFlowDirection(BoxLayoutAdapter.FlowDirection.Y);
            wrapper.add(caption, 0);
        } else {
            wrapper.add(caption, new CC().alignY("top"));
        }
        impl.add(wrapper, layoutAdapter.getConstraints(component), index);
        wrappers.put(component, new Pair<>(wrapper, adapter));
    } else {
        impl.add(composition, layoutAdapter.getConstraints(component), index);
    }
    if (component.getId() != null) {
        componentByIds.put(component.getId(), component);
    }
    if (frame != null) {
        if (component instanceof BelongToFrame && ((BelongToFrame) component).getFrame() == null) {
            ((BelongToFrame) component).setFrame(frame);
        } else {
            attachToFrame(component);
        }
    }
    if (index == ownComponents.size()) {
        ownComponents.add(component);
    } else {
        List<Component> componentsTempList = new ArrayList<>(ownComponents);
        componentsTempList.add(index, component);
        ownComponents.clear();
        ownComponents.addAll(componentsTempList);
    }
    DesktopContainerHelper.assignContainer(component, this);
    if (component instanceof DesktopAbstractComponent && !isEnabledWithParent()) {
        ((DesktopAbstractComponent) component).setParentEnabled(false);
    }
    component.setParent(this);
    requestContainerUpdate();
    requestRepaint();
}
Also used : CC(net.miginfocom.layout.CC) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter) Component(com.haulmont.cuba.gui.components.Component)

Example 29 with Component

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

the class WebWindow method validateAll.

@Override
public boolean validateAll() {
    ValidationErrors errors = new ValidationErrors();
    Collection<Component> components = ComponentsHelper.getComponents(this);
    for (Component component : components) {
        if (component instanceof Validatable) {
            Validatable validatable = (Validatable) component;
            if (validatable.isValidateOnCommit()) {
                try {
                    validatable.validate();
                } catch (ValidationException e) {
                    if (log.isTraceEnabled())
                        log.trace("Validation failed", e);
                    else if (log.isDebugEnabled())
                        log.debug("Validation failed: " + e);
                    ComponentsHelper.fillErrorMessages(validatable, e, errors);
                }
            }
        }
    }
    validateAdditionalRules(errors);
    return handleValidationErrors(errors);
}
Also used : WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.haulmont.cuba.gui.components.Component)

Example 30 with Component

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

the class WebAbstractBox method removeAll.

@Override
public void removeAll() {
    component.removeAllComponents();
    Component[] components = ownComponents.toArray(new Component[ownComponents.size()]);
    ownComponents.clear();
    for (Component childComponent : components) {
        childComponent.setParent(null);
    }
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Aggregations

Component (com.haulmont.cuba.gui.components.Component)78 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Datasource (com.haulmont.cuba.gui.data.Datasource)10 User (com.haulmont.cuba.security.entity.User)9 List (java.util.List)9 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)8 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Group (com.haulmont.cuba.security.entity.Group)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 Element (org.dom4j.Element)6 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)5 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)5 Frame (com.haulmont.cuba.gui.components.Frame)4 AbstractComponent (com.vaadin.ui.AbstractComponent)4