Search in sources :

Example 1 with ToolTipButton

use of com.haulmont.cuba.desktop.sys.vcl.ToolTipButton in project cuba by cuba-platform.

the class ComponentCaption method takeOwnerProperties.

private void takeOwnerProperties() {
    if (!(owner instanceof DesktopCheckBox)) {
        if (label == null) {
            label = new JLabel();
            add(label);
        }
        label.setText(((Component.HasCaption) owner).getCaption());
    }
    String contextHelpText = getContextHelpText();
    boolean hasContextHelpIconClickListeners = hasContextHelpIconClickListeners();
    if (StringUtils.isNotEmpty(contextHelpText) || hasContextHelpIconClickListeners) {
        if (toolTipButton == null) {
            toolTipButton = new ToolTipButton();
            toolTipButton.setFocusable(false);
            add(toolTipButton);
        }
        if (hasContextHelpIconClickListeners) {
            if (toolTipButtonActionListener == null) {
                toolTipButtonActionListener = e -> fireContextHelpIconClickEvent();
                toolTipButton.addActionListener(toolTipButtonActionListener);
            }
            toolTipButton.setToolTipText(null);
        } else {
            removeToolTipButtonActionListener();
            toolTipButton.setToolTipText(contextHelpText);
        }
        DesktopToolTipManager.getInstance().registerTooltip(toolTipButton);
    } else if (toolTipButton != null) {
        removeToolTipButtonActionListener();
        remove(toolTipButton);
        toolTipButton = null;
    }
    setVisible(owner.isVisible());
    setEnabled(owner.isEnabled());
}
Also used : Component(com.haulmont.cuba.gui.components.Component) ToolTipButton(com.haulmont.cuba.desktop.sys.vcl.ToolTipButton)

Example 2 with ToolTipButton

use of com.haulmont.cuba.desktop.sys.vcl.ToolTipButton 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 3 with ToolTipButton

use of com.haulmont.cuba.desktop.sys.vcl.ToolTipButton in project cuba by cuba-platform.

the class DesktopFieldGroup method updateTooltipButton.

protected void updateTooltipButton(FieldConfigImpl fci, Component component) {
    ToolTipButton toolTipButton = fci.getToolTipButton();
    boolean hasContextHelpIconClickListeners = hasContextHelpIconClickListeners(component);
    String contextHelpText = DesktopComponentsHelper.getContextHelpText(fci.getContextHelpText(), BooleanUtils.isTrue(fci.isContextHelpTextHtmlEnabled()));
    ActionListener toolTipButtonActionListener = fci.getToolTipButtonActionListener();
    if (hasContextHelpIconClickListeners) {
        if (toolTipButtonActionListener == null) {
            toolTipButtonActionListener = e -> fireContextHelpIconClickEvent(component);
            toolTipButton.addActionListener(toolTipButtonActionListener);
        }
        toolTipButton.setToolTipText(null);
    } else {
        if (toolTipButtonActionListener != null) {
            toolTipButton.removeActionListener(toolTipButtonActionListener);
            fci.setToolTipButtonActionListener(null);
        }
        toolTipButton.setToolTipText(contextHelpText);
    }
    toolTipButton.setVisible(component.isVisible() && (StringUtils.isNotEmpty(contextHelpText) || hasContextHelpIconClickListeners));
}
Also used : ActionListener(java.awt.event.ActionListener) ToolTipButton(com.haulmont.cuba.desktop.sys.vcl.ToolTipButton)

Aggregations

ToolTipButton (com.haulmont.cuba.desktop.sys.vcl.ToolTipButton)3 Component (com.haulmont.cuba.gui.components.Component)2 ActionListener (java.awt.event.ActionListener)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 App (com.haulmont.cuba.desktop.App)1 DesktopToolTipManager (com.haulmont.cuba.desktop.sys.DesktopToolTipManager)1 LayoutAdapter (com.haulmont.cuba.desktop.sys.layout.LayoutAdapter)1 MigLayoutHelper (com.haulmont.cuba.desktop.sys.layout.MigLayoutHelper)1 CollapsiblePanel (com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel)1 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)1 UiPermissionDescriptor (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)1 UiPermissionValue (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 Formatter (com.haulmont.cuba.gui.components.Formatter)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1