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