Search in sources :

Example 1 with AbstractAction

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

the class DesktopExportDisplay method show.

/**
 * Show/Download resource at client side
 *
 * @param dataProvider {@link ExportDataProvider}
 * @param resourceName ResourceName for client side
 * @param format       {@link ExportFormat}
 * @see com.haulmont.cuba.gui.export.FileDataProvider
 * @see com.haulmont.cuba.gui.export.ByteArrayDataProvider
 */
@Override
public void show(final ExportDataProvider dataProvider, String resourceName, ExportFormat format) {
    backgroundWorker.checkUIAccess();
    String fileName = resourceName;
    if (format != null) {
        if (StringUtils.isEmpty(getFileExt(fileName)))
            fileName += "." + format.getFileExt();
    }
    String dialogMessage = messages.getMessage(getClass(), "export.saveFile");
    String correctName = StringUtils.replaceChars(fileName, RESERVED_SYMBOLS, "_");
    dialogMessage = String.format(dialogMessage, correctName);
    final String finalFileName = correctName;
    String fileCaption = messages.getMessage(getClass(), "export.fileCaption");
    getFrame().getWindowManager().showOptionDialog(fileCaption, dialogMessage, Frame.MessageType.CONFIRMATION, new com.haulmont.cuba.gui.components.Action[] { new AbstractAction("action.openFile", Status.PRIMARY) {

        @Override
        public void actionPerform(Component component) {
            openFileAction(finalFileName, dataProvider);
        }
    }, new AbstractAction("action.saveFile") {

        @Override
        public void actionPerform(Component component) {
            saveFileAction(finalFileName, getFrame(), dataProvider);
        }
    }, new AbstractAction("actions.Cancel") {

        @Override
        public void actionPerform(Component component) {
        // do nothing
        }
    } });
}
Also used : Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 2 with AbstractAction

use of com.haulmont.cuba.gui.components.AbstractAction 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 3 with AbstractAction

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

the class WebSideMenu method setSidePanelToggleButton.

@Override
public void setSidePanelToggleButton(Button toggleButton) {
    if (this.toggleButton != null) {
        toggleButton.setAction(null);
    }
    if (toggleButton != null) {
        AbstractAction toggleAction = new AbstractAction("toggleSideMenu") {

            @Override
            public void actionPerform(Component component) {
                toggleSidePanel();
            }
        };
        toggleAction.setCaption(toggleButton.getCaption());
        toggleAction.setIcon(toggleButton.getIcon());
        toggleAction.setDescription(toggleButton.getDescription());
        toggleAction.setEnabled(toggleButton.isEnabled());
        toggleAction.setVisible(toggleButton.isVisible());
        toggleButton.setAction(toggleAction);
    }
    this.toggleButton = toggleButton;
}
Also used : WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 4 with AbstractAction

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

the class WebButton method setAction.

@Override
public void setAction(Action action) {
    if (action != this.action) {
        if (this.action != null) {
            this.action.removeOwner(this);
            this.action.removePropertyChangeListener(actionPropertyChangeListener);
            if (Objects.equals(this.action.getCaption(), getCaption())) {
                setCaption(null);
            }
            if (Objects.equals(this.action.getDescription(), getDescription())) {
                setDescription(null);
            }
            if (Objects.equals(this.action.getIcon(), getIcon())) {
                setIcon(null);
            }
        }
        this.action = action;
        if (action != null) {
            String caption = action.getCaption();
            if (caption != null && component.getCaption() == null) {
                component.setCaption(caption);
            }
            String description = action.getDescription();
            KeyCombination shortcutCombination = action.getShortcutCombination();
            if (shortcutCombination != null) {
                setShortcutCombination(shortcutCombination);
                if (description == null) {
                    description = shortcutCombination.format();
                }
            }
            if (description != null && component.getDescription() == null) {
                component.setDescription(description);
            }
            component.setEnabled(action.isEnabled());
            component.setVisible(action.isVisible());
            if (action.getIcon() != null && getIcon() == null) {
                setIcon(action.getIcon());
            }
            action.addOwner(this);
            actionPropertyChangeListener = evt -> {
                String propertyName = evt.getPropertyName();
                if (Action.PROP_ICON.equals(propertyName)) {
                    setIcon(this.action.getIcon());
                } else if (Action.PROP_CAPTION.equals(propertyName)) {
                    setCaption(this.action.getCaption());
                } else if (Action.PROP_DESCRIPTION.equals(propertyName)) {
                    setDescription(this.action.getDescription());
                } else if (Action.PROP_ENABLED.equals(propertyName)) {
                    setEnabled(this.action.isEnabled());
                } else if (Action.PROP_VISIBLE.equals(propertyName)) {
                    setVisible(this.action.isVisible());
                } else if (Action.PROP_SHORTCUT.equals(propertyName)) {
                    setShortcutCombination(this.action.getShortcutCombination());
                }
            };
            action.addPropertyChangeListener(actionPropertyChangeListener);
            if (component.getCubaId() == null) {
                AppUI ui = AppUI.getCurrent();
                if (ui != null && ui.isTestMode()) {
                    component.setCubaId(action.getId());
                }
            }
        }
        boolean primaryAction = action instanceof AbstractAction && ((AbstractAction) action).isPrimary();
        boolean primaryButton = getStyleName().contains(PRIMARY_ACTION_STYLENAME);
        if (primaryAction || primaryButton) {
            addStyleName(PRIMARY_ACTION_STYLENAME);
        } else {
            removeStyleName(PRIMARY_ACTION_STYLENAME);
        }
    }
}
Also used : KeyCombination(com.haulmont.cuba.gui.components.KeyCombination) AppUI(com.haulmont.cuba.web.AppUI) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 5 with AbstractAction

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

the class DesktopWindowManager method createButtonsPanel.

protected JPanel createButtonsPanel(Action[] actions, final DialogWindow dialog) {
    JPanel buttonsPanel = new JPanel();
    boolean hasPrimaryAction = false;
    for (final Action action : actions) {
        JButton button = new JButton(action.getCaption());
        button.setEnabled(action.isEnabled());
        String icon = action.getIcon();
        if (icon != null) {
            button.setIcon(AppBeans.get(IconResolver.class).getIconResource(icon));
        }
        final DialogActionHandler dialogActionHandler = new DialogActionHandler(dialog, action);
        button.addActionListener(dialogActionHandler);
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JButton b = (JButton) e.getSource();
                userActionsLog.trace("Button (name = {}, text = {}) was clicked in dialog", b.getName(), b.getText());
            }
        });
        if (actions.length == 1) {
            dialog.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(WindowEvent e) {
                    dialogActionHandler.onClose();
                }
            });
        }
        button.setPreferredSize(new Dimension(button.getPreferredSize().width, DesktopComponentsHelper.BUTTON_HEIGHT));
        button.setMaximumSize(new Dimension(Integer.MAX_VALUE, DesktopComponentsHelper.BUTTON_HEIGHT));
        if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
            hasPrimaryAction = true;
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    button.requestFocus();
                }
            });
        }
        buttonsPanel.add(button);
    }
    if (!hasPrimaryAction && actions.length > 0) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                buttonsPanel.getComponent(0).requestFocus();
            }
        });
    }
    return buttonsPanel;
}
Also used : ValidationAwareAction(com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) Action(com.haulmont.cuba.gui.components.Action) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Aggregations

AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)5 Component (com.haulmont.cuba.gui.components.Component)3 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 Instance (com.haulmont.chile.core.model.Instance)1 Entity (com.haulmont.cuba.core.entity.Entity)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 ValidationAwareAction (com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)1 Action (com.haulmont.cuba.gui.components.Action)1 Button (com.haulmont.cuba.gui.components.Button)1 KeyCombination (com.haulmont.cuba.gui.components.KeyCombination)1 Table (com.haulmont.cuba.gui.components.Table)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 AppUI (com.haulmont.cuba.web.AppUI)1 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)1