Search in sources :

Example 11 with Component

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

the class WindowCreationHelper method applyCompositeComponentPermission.

private static void applyCompositeComponentPermission(Window window, String screenId, Integer permissionValue, String componentId) {
    final Matcher matcher = INNER_COMPONENT_PATTERN.matcher(componentId);
    if (matcher.find()) {
        final String customComponentId = matcher.group(1);
        final String subComponentId = matcher.group(2);
        final Component compositeComponent = window.getComponent(customComponentId);
        if (compositeComponent != null) {
            if (compositeComponent instanceof Component.UiPermissionAware) {
                Component.UiPermissionAware uiPermissionAwareComponent = (Component.UiPermissionAware) compositeComponent;
                UiPermissionValue uiPermissionValue = UiPermissionValue.fromId(permissionValue);
                UiPermissionDescriptor permissionDescriptor;
                if (subComponentId.contains("<")) {
                    final Matcher actionMatcher = COMPONENT_ACTION_PATTERN.matcher(subComponentId);
                    if (actionMatcher.find()) {
                        final String actionHolderComponentId = actionMatcher.group(1);
                        final String actionId = actionMatcher.group(2);
                        permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, actionHolderComponentId, actionId);
                    } else {
                        log.warn(String.format("Incorrect permission definition for component %s in window %s", subComponentId, screenId));
                        return;
                    }
                } else {
                    permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, subComponentId);
                }
                uiPermissionAwareComponent.applyPermission(permissionDescriptor);
            }
        } else {
            log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
        }
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) Matcher(java.util.regex.Matcher) Component(com.haulmont.cuba.gui.components.Component) UiPermissionDescriptor(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)

Example 12 with Component

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

the class LinkColumnHelper method initColumn.

public static void initColumn(Table table, final String propertyName, final Handler handler) {
    final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
    table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {

        @Override
        public Component generateCell(final Entity entity) {
            // //process properties like building.house.room
            String[] props = propertyName.split("\\.");
            Instance nestedEntity = entity;
            for (int i = 0; i < props.length - 1; i++) {
                nestedEntity = nestedEntity.getValue(props[i]);
                if (nestedEntity == null) {
                    break;
                }
            }
            final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
            if (value != null) {
                Button button = componentsFactory.createComponent(Button.class);
                button.setStyleName("link");
                button.setAction(new AbstractAction("open") {

                    @Override
                    public void actionPerform(Component component) {
                        handler.onClick(entity);
                    }

                    @Override
                    public String getCaption() {
                        String str;
                        Datatype datatype = Datatypes.get(value.getClass());
                        if (datatype != null) {
                            UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
                            str = datatype.format(value, sessionSource.getLocale());
                        } else {
                            str = value.toString();
                        }
                        return str;
                    }
                });
                button.setStyleName("link");
                return button;
            }
            return null;
        }
    });
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Table(com.haulmont.cuba.gui.components.Table) Instance(com.haulmont.chile.core.model.Instance) Datatype(com.haulmont.chile.core.datatypes.Datatype) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Button(com.haulmont.cuba.gui.components.Button) Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 13 with Component

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

the class SessionAttributeEditor method init.

@Override
public void init(Map<String, Object> params) {
    datasource = getDsContext().get("attribute");
    FieldGroup fields = (FieldGroup) getComponent("fields");
    FieldGroup.FieldConfig field = fields.getField("datatype");
    fields.addCustomField(field, new FieldGroup.CustomFieldGenerator() {

        @Override
        public Component generateField(Datasource datasource, String propertyId) {
            LookupField lookup = AppConfig.getFactory().createComponent(LookupField.class);
            lookup.setDatasource(datasource, propertyId);
            lookup.setRequiredMessage(getMessage("datatypeMsg"));
            lookup.setRequired(true);
            lookup.setPageLength(15);
            Map<String, Object> options = new TreeMap<>();
            String mainMessagePack = AppConfig.getMessagesPack();
            for (String datatypeId : Datatypes.getIds()) {
                options.put(messages.getMessage(mainMessagePack, "Datatype." + datatypeId), datatypeId);
            }
            lookup.setOptionsMap(options);
            return lookup;
        }
    });
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) LookupField(com.haulmont.cuba.gui.components.LookupField) Component(com.haulmont.cuba.gui.components.Component) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 14 with Component

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

the class DesktopPopupButton method showPopup.

protected void showPopup() {
    popup.removeAll();
    for (final Action action : actionList) {
        if (action.isVisible()) {
            final JMenuItem menuItem = new JMenuItem(action.getCaption());
            menuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    action.actionPerform((Component) action.getOwner());
                }
            });
            menuItem.setEnabled(action.isEnabled());
            menuItem.setName(action.getId());
            initAction(action, menuItem);
            popup.add(menuItem);
        }
    }
    int popupHeight = popup.getComponentCount() * 25;
    Point pt = new Point();
    SwingUtilities.convertPointToScreen(pt, impl);
    int y;
    if (pt.getY() + impl.getHeight() + popupHeight < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) {
        y = impl.getHeight();
    } else {
        y = -popupHeight;
    }
    // do not show ugly empty popup
    if (popup.getComponentCount() > 0) {
        popup.show(impl, 0, y);
    }
}
Also used : Action(com.haulmont.cuba.gui.components.Action) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Component(com.haulmont.cuba.gui.components.Component)

Example 15 with Component

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

the class DesktopScrollBoxLayout method updateEnabled.

@Override
public void updateEnabled() {
    super.updateEnabled();
    boolean resultEnabled = isEnabledWithParent();
    for (Component component : components) {
        if (component instanceof DesktopAbstractComponent) {
            ((DesktopAbstractComponent) component).setParentEnabled(resultEnabled);
        }
    }
}
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