Search in sources :

Example 41 with Component

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

the class DesktopComponentsHelper method focusProblemComponent.

public static void focusProblemComponent(ValidationErrors errors) {
    Component component = null;
    if (!errors.getAll().isEmpty()) {
        component = errors.getAll().iterator().next().component;
    }
    if (component != null) {
        try {
            final JComponent jComponent = DesktopComponentsHelper.unwrap(component);
            java.awt.Component c = jComponent;
            java.awt.Component prevC = null;
            while (c != null) {
                if (c instanceof JTabbedPane && !((JTabbedPane) c).getSelectedComponent().equals(prevC)) {
                    final JTabbedPane tabbedPane = (JTabbedPane) c;
                    // do not focus tabbed pane on programmaticaly selection change
                    JTabbedPaneExt.setFocusOnSelectionChange(false);
                    tabbedPane.setSelectedComponent(prevC);
                    break;
                }
                if (c instanceof CollapsiblePanel && !((CollapsiblePanel) c).isExpanded()) {
                    ((CollapsiblePanel) c).setExpanded(true);
                    break;
                }
                prevC = c;
                c = c.getParent();
            }
            if (!JTabbedPaneExt.isFocusOnSelectionChange()) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        JTabbedPaneExt.setFocusOnSelectionChange(true);
                    }
                });
            }
            if (jComponent instanceof FocusableComponent) {
                ((FocusableComponent) jComponent).focus();
            } else {
                // focus first up component
                c = jComponent;
                while (c != null) {
                    if (c.isFocusable()) {
                        c.requestFocus();
                        break;
                    }
                    c = c.getParent();
                }
            }
        } catch (Exception e) {
            LoggerFactory.getLogger(DesktopComponentsHelper.class).warn("Error while problem component focusing", e);
        }
    }
}
Also used : FocusableComponent(com.haulmont.cuba.desktop.sys.vcl.FocusableComponent) FocusableComponent(com.haulmont.cuba.desktop.sys.vcl.FocusableComponent) Component(com.haulmont.cuba.gui.components.Component) CollapsiblePanel(com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel) java.awt(java.awt)

Example 42 with Component

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

the class DesktopFieldGroup method doSetParentEnabled.

protected void doSetParentEnabled(FieldConfig fc, boolean enabled) {
    if (fc.getComponent() != null) {
        Component component = fc.getComponent();
        if (component instanceof DesktopAbstractComponent) {
            ((DesktopAbstractComponent) component).setParentEnabled(enabled);
        }
        FieldConfigImpl fci = (FieldConfigImpl) fc;
        if (fci.getLabel() != null) {
            fci.getLabel().setEnabled(enabled);
        }
    }
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Example 43 with Component

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

the class DesktopFieldGroup method reattachColumnFields.

protected void reattachColumnFields(int colIndex) {
    fields.values().stream().filter(FieldConfig::isBound).map(fieldConfig -> ((FieldConfigImpl) fieldConfig)).filter(fci -> fci.getColumn() == colIndex).forEach(fci -> {
        impl.remove(fci.getCompositionNN().getComposition());
        if (fci.getLabel() != null) {
            impl.remove(fci.getLabel());
        }
        if (fci.getToolTipButton() != null) {
            impl.remove(fci.getToolTipButton());
        }
    });
    List<FieldConfig> columnFCs = columnFieldMapping.get(colIndex);
    int insertRowIndex = 0;
    for (FieldConfig fc : columnFCs) {
        if (fc.isBound()) {
            FieldConfigImpl fci = (FieldConfigImpl) fc;
            Component fieldComponent = fci.getComponentNN();
            JComponent composition = fieldComponent.unwrapComposition(JComponent.class);
            JLabel label = fci.getLabel();
            if (label != null) {
                int preferredCaptionWidth = getPreferredCaptionWidth(colIndex);
                if (preferredCaptionWidth > 0) {
                    label.setPreferredSize(new Dimension(preferredCaptionWidth, 25));
                    label.setMaximumSize(new Dimension(preferredCaptionWidth, 25));
                    label.setMinimumSize(new Dimension(preferredCaptionWidth, 25));
                } else {
                    label.setPreferredSize(new Dimension(label.getPreferredSize().width, 25));
                }
                label.setVisible(fieldComponent.isVisible());
                CC labelCc = new CC();
                MigLayoutHelper.applyAlignment(labelCc, Alignment.TOP_LEFT);
                impl.add(label, labelCc.cell(colIndex * 3, insertRowIndex, 1, 1));
            }
            ToolTipButton toolTipButton = fci.getToolTipButton();
            if (fci.getToolTipButton() != null) {
                updateTooltipButton(fci, fieldComponent);
                DesktopToolTipManager.getInstance().registerTooltip(toolTipButton);
                impl.add(toolTipButton, new CC().cell(colIndex * 3 + 2, insertRowIndex, 1, 1).alignY("top"));
            }
            CC cell = new CC().cell(colIndex * 3 + 1, insertRowIndex, 1, 1);
            MigLayoutHelper.applyWidth(cell, (int) fieldComponent.getWidth(), fieldComponent.getWidthUnits(), false);
            MigLayoutHelper.applyHeight(cell, (int) fieldComponent.getHeight(), fieldComponent.getHeightUnits(), false);
            MigLayoutHelper.applyAlignment(cell, fieldComponent.getAlignment());
            composition.putClientProperty(getSwingPropertyId(), fci.getId());
            impl.add(composition, cell);
            insertRowIndex++;
        }
    }
    impl.validate();
    impl.repaint();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) ActionListener(java.awt.event.ActionListener) UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) LoggerFactory(org.slf4j.LoggerFactory) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) AppBeans(com.haulmont.cuba.core.global.AppBeans) ToolTipButton(com.haulmont.cuba.desktop.sys.vcl.ToolTipButton) BooleanUtils(org.apache.commons.lang.BooleanUtils) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) CC(net.miginfocom.layout.CC) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) Component(com.haulmont.cuba.gui.components.Component) UiPermissionDescriptor(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Nullable(javax.annotation.Nullable) App(com.haulmont.cuba.desktop.App) DesktopToolTipManager(com.haulmont.cuba.desktop.sys.DesktopToolTipManager) Logger(org.slf4j.Logger) Formatter(com.haulmont.cuba.gui.components.Formatter) MigLayout(net.miginfocom.swing.MigLayout) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) java.awt(java.awt) Consumer(java.util.function.Consumer) CollapsiblePanel(com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel) List(java.util.List) LC(net.miginfocom.layout.LC) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) Element(org.dom4j.Element) MigLayoutHelper(com.haulmont.cuba.desktop.sys.layout.MigLayoutHelper) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) LayoutAdapter(com.haulmont.cuba.desktop.sys.layout.LayoutAdapter) javax.swing(javax.swing) CC(net.miginfocom.layout.CC) Component(com.haulmont.cuba.gui.components.Component) ToolTipButton(com.haulmont.cuba.desktop.sys.vcl.ToolTipButton)

Example 44 with Component

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

the class DesktopFieldGroup method applyFieldDefaults.

protected void applyFieldDefaults(FieldConfigImpl fci) {
    Component fieldComponent = fci.getComponentNN();
    if (fieldComponent instanceof Field) {
        Field cubaField = (Field) fieldComponent;
        if (fci.getTargetCaption() != null) {
            cubaField.setCaption(fci.getTargetCaption());
        }
        if (fci.getTargetDescription() != null) {
            cubaField.setDescription(fci.getTargetDescription());
        }
        if (cubaField instanceof HasInputPrompt && fci.getTargetInputPrompt() != null) {
            ((HasInputPrompt) cubaField).setInputPrompt(fci.getTargetInputPrompt());
        }
        if (fci.getTargetRequired() != null) {
            cubaField.setRequired(fci.getTargetRequired());
        }
        if (fci.getTargetRequiredMessage() != null) {
            cubaField.setRequiredMessage(fci.getTargetRequiredMessage());
        }
        if (fci.getTargetContextHelpText() != null) {
            cubaField.setContextHelpText(fci.getTargetContextHelpText());
        }
        if (fci.getTargetContextHelpTextHtmlEnabled() != null) {
            cubaField.setContextHelpTextHtmlEnabled(fci.getTargetContextHelpTextHtmlEnabled());
        }
        if (fci.getTargetContextHelpIconClickHandler() != null) {
            cubaField.setContextHelpIconClickHandler(fci.getTargetContextHelpIconClickHandler());
        }
        if (fci.getTargetEditable() != null) {
            cubaField.setEditable(fci.getTargetEditable());
        }
        if (fci.getTargetVisible() != null) {
            cubaField.setVisible(fci.getTargetVisible());
        }
        if (cubaField instanceof Component.Focusable && fci.getTargetTabIndex() != null) {
            ((Component.Focusable) cubaField).setTabIndex(fci.getTargetTabIndex());
        }
        for (Field.Validator validator : fci.getTargetValidators()) {
            cubaField.addValidator(validator);
        }
        if (fci.getTargetWidth() != null) {
            fieldComponent.setWidth(fci.getTargetWidth());
        } else {
            fieldComponent.setWidth(DEFAULT_FIELD_WIDTH);
        }
    } else {
        DesktopAbstractComponent composition = fci.getCompositionNN();
        if (fci.getTargetCaption() != null) {
            fci.getLabel().setText(fci.getTargetCaption());
        }
        if (fci.getTargetVisible() != null) {
            composition.setVisible(fci.getTargetVisible());
        }
        if (fci.getTargetWidth() != null) {
            composition.setWidth(fci.getTargetWidth());
        } else {
            composition.setWidth(DEFAULT_FIELD_WIDTH);
        }
    }
    if (fieldComponent instanceof Component.HasFormatter && fci.getTargetFormatter() != null) {
        ((Component.HasFormatter) fieldComponent).setFormatter(fci.getTargetFormatter());
    }
    if (StringUtils.isNotEmpty(fci.getTargetStylename())) {
        fieldComponent.setStyleName(fci.getTargetStylename());
    }
    App app = App.getInstance();
    if (app != null && app.isTestMode()) {
        fci.getCompositionNN().getComposition().setName(fci.getId());
    }
}
Also used : App(com.haulmont.cuba.desktop.App) Component(com.haulmont.cuba.gui.components.Component)

Example 45 with Component

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

the class DesktopFieldGroup method applyPermission.

@Override
public void applyPermission(UiPermissionDescriptor permissionDescriptor) {
    checkNotNullArgument(permissionDescriptor);
    final String subComponentId = permissionDescriptor.getSubComponentId();
    final UiPermissionValue permissionValue = permissionDescriptor.getPermissionValue();
    final String screenId = permissionDescriptor.getScreenId();
    if (subComponentId != null) {
        final FieldGroup.FieldConfig field = getField(subComponentId);
        if (field != null) {
            if (permissionValue == UiPermissionValue.HIDE) {
                field.setVisible(false);
            } else if (permissionValue == UiPermissionValue.READ_ONLY) {
                field.setEditable(false);
            }
        } else {
            log.info("Couldn't find suitable component {} in window {} for UI security rule", subComponentId, screenId);
        }
    } else {
        final String actionHolderComponentId = permissionDescriptor.getActionHolderComponentId();
        FieldConfig fieldConfig = getField(actionHolderComponentId);
        if (fieldConfig == null || fieldConfig.getComponent() == null || !((fieldConfig.getComponent() instanceof Component.SecuredActionsHolder))) {
            log.info("Couldn't find suitable component {} in window {} for UI security rule", actionHolderComponentId, screenId);
            return;
        }
        Component fieldComponent = fieldConfig.getComponent();
        String actionId = permissionDescriptor.getActionId();
        ActionsPermissions permissions = ((SecuredActionsHolder) fieldComponent).getActionsPermissions();
        if (permissionValue == UiPermissionValue.HIDE) {
            permissions.addHiddenActionPermission(actionId);
        } else if (permissionValue == UiPermissionValue.READ_ONLY) {
            permissions.addDisabledActionPermission(actionId);
        }
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) 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