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