use of com.vaadin.event.ShortcutAction in project Activiti by Activiti.
the class SubTaskComponent method initAddSubTaskPanelKeyboardActions.
protected void initAddSubTaskPanelKeyboardActions() {
addSubTaskPanel.addActionHandler(new Handler() {
public void handleAction(Action action, Object sender, Object target) {
if ("escape".equals(action.getCaption())) {
resetAddButton();
} else if ("enter".equals(action.getCaption())) {
if (newTaskTextField != null && newTaskTextField.getValue() != null && !"".equals(newTaskTextField.getValue().toString())) {
LoggedInUser loggedInUser = ExplorerApp.get().getLoggedInUser();
// save task
Task newTask = taskService.newTask();
newTask.setParentTaskId(parentTask.getId());
if (parentTask.getAssignee() != null) {
newTask.setAssignee(parentTask.getAssignee());
} else {
newTask.setAssignee(loggedInUser.getId());
}
if (parentTask.getOwner() != null) {
newTask.setOwner(parentTask.getOwner());
} else {
newTask.setOwner(loggedInUser.getId());
}
newTask.setName(newTaskTextField.getValue().toString());
taskService.saveTask(newTask);
// Reset the add button to its original state
resetAddButton();
// refresh sub tasks section
refreshSubTasks();
}
}
}
public Action[] getActions(Object target, Object sender) {
return new Action[] { new ShortcutAction("enter", ShortcutAction.KeyCode.ENTER, null), new ShortcutAction("escape", ShortcutAction.KeyCode.ESCAPE, null) };
}
});
}
use of com.vaadin.event.ShortcutAction in project cuba by cuba-platform.
the class WebPickerFieldActionHandler method addAction.
public void addAction(com.haulmont.cuba.gui.components.Action action, int index) {
actionList.add(index, action);
updateOrderedShortcuts();
KeyCombination combination = action.getShortcutCombination();
if (combination != null) {
int key = combination.getKey().getCode();
int[] modifiers = KeyCombination.Modifier.codes(combination.getModifiers());
ShortcutAction providedShortcut = new ShortcutAction(action.getCaption(), key, modifiers);
shortcuts.add(providedShortcut);
actionsMap.put(providedShortcut, action);
}
}
use of com.vaadin.event.ShortcutAction in project Activiti by Activiti.
the class TaskEventsPanel method addInputField.
protected void addInputField() {
HorizontalLayout layout = new HorizontalLayout();
layout.setSpacing(true);
layout.setWidth(100, UNITS_PERCENTAGE);
addComponent(layout);
// Hack: actionHandlers can only be attached to panels or windows
Panel textFieldPanel = new Panel();
textFieldPanel.addStyleName(Reindeer.PANEL_LIGHT);
textFieldPanel.setContent(new VerticalLayout());
textFieldPanel.setWidth(100, UNITS_PERCENTAGE);
layout.addComponent(textFieldPanel);
layout.setExpandRatio(textFieldPanel, 1.0f);
commentInputField = new TextField();
commentInputField.setWidth(100, UNITS_PERCENTAGE);
textFieldPanel.addComponent(commentInputField);
// Hack to catch keyboard 'enter'
textFieldPanel.addActionHandler(new Handler() {
public void handleAction(Action action, Object sender, Object target) {
addNewComment(commentInputField.getValue().toString());
}
public Action[] getActions(Object target, Object sender) {
return new Action[] { new ShortcutAction("enter", ShortcutAction.KeyCode.ENTER, null) };
}
});
addCommentButton = new Button(i18nManager.getMessage(Messages.TASK_ADD_COMMENT));
layout.addComponent(addCommentButton);
layout.setComponentAlignment(addCommentButton, Alignment.MIDDLE_LEFT);
addCommentButton.addListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
addNewComment(commentInputField.getValue().toString());
}
});
}
use of com.vaadin.event.ShortcutAction in project cuba by cuba-platform.
the class WebWindowManager method showWindowDialog.
protected Component showWindowDialog(Window window, OpenType openType, boolean forciblyDialog) {
final CubaWindow vWindow = createDialogWindow(window);
vWindow.setStyleName("c-app-dialog-window");
if (ui.isTestMode()) {
vWindow.setCubaId("dialog_" + window.getId());
vWindow.setId(ui.getTestIdManager().getTestId("dialog_" + window.getId()));
}
Layout layout = (Layout) WebComponentsHelper.getComposition(window);
vWindow.setContent(layout);
vWindow.addPreCloseListener(event -> {
event.setPreventClose(true);
if (!isCloseWithCloseButtonPrevented(window)) {
// user has clicked on X
window.close(Window.CLOSE_ACTION_ID);
}
});
String closeShortcut = clientConfig.getCloseShortcut();
KeyCombination closeCombination = KeyCombination.create(closeShortcut);
ShortcutAction exitAction = new ShortcutAction("closeShortcutAction", closeCombination.getKey().getCode(), KeyCombination.Modifier.codes(closeCombination.getModifiers()));
Map<com.vaadin.event.Action, Runnable> actions = singletonMap(exitAction, () -> {
if (openType.getOpenMode() != OpenMode.DIALOG || BooleanUtils.isNotFalse(window.getDialogOptions().getCloseable())) {
if (isCloseWithShortcutPrevented(window)) {
return;
}
window.close(Window.CLOSE_ACTION_ID);
}
});
WebComponentsHelper.setActions(vWindow, actions);
boolean dialogParamsSizeUndefined = openType.getHeight() == null && openType.getWidth() == null;
ThemeConstants theme = app.getThemeConstants();
if (forciblyDialog && dialogParamsSizeUndefined) {
layout.setHeight(100, Unit.PERCENTAGE);
vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.width"), Unit.PIXELS);
vWindow.setHeight(theme.getInt("cuba.web.WebWindowManager.forciblyDialog.height"), Unit.PIXELS);
// resizable by default, but may be overridden in dialog params
vWindow.setResizable(BooleanUtils.isNotFalse(openType.getResizable()));
window.setHeightFull();
} else {
if (openType.getWidth() == null) {
vWindow.setWidth(theme.getInt("cuba.web.WebWindowManager.dialog.width"), Unit.PIXELS);
} else if (openType.getWidth() == AUTO_SIZE_PX) {
vWindow.setWidthUndefined();
layout.setWidthUndefined();
window.setWidthAuto();
} else {
vWindow.setWidth(openType.getWidth(), openType.getWidthUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getWidthUnit()) : Unit.PIXELS);
}
if (openType.getHeight() != null && openType.getHeight() != AUTO_SIZE_PX) {
vWindow.setHeight(openType.getHeight(), openType.getHeightUnit() != null ? WebWrapperUtils.toVaadinUnit(openType.getHeightUnit()) : Unit.PIXELS);
layout.setHeight("100%");
window.setHeightFull();
} else {
window.setHeightAuto();
}
// non resizable by default
vWindow.setResizable(BooleanUtils.isTrue(openType.getResizable()));
}
if (openType.getCloseable() != null) {
vWindow.setClosable(openType.getCloseable());
}
boolean modal = true;
if (!hasModalWindow() && openType.getModal() != null) {
modal = openType.getModal();
}
vWindow.setModal(modal);
if (vWindow.isModal()) {
boolean informationDialog = false;
if (openType.getCloseOnClickOutside() != null) {
informationDialog = openType.getCloseOnClickOutside();
}
vWindow.setCloseOnClickOutside(informationDialog);
}
if (openType.getMaximized() != null) {
if (openType.getMaximized()) {
vWindow.setWindowMode(WindowMode.MAXIMIZED);
} else {
vWindow.setWindowMode(WindowMode.NORMAL);
}
}
if (openType.getPositionX() == null && openType.getPositionY() == null) {
vWindow.center();
} else {
if (openType.getPositionX() != null) {
vWindow.setPositionX(openType.getPositionX());
}
if (openType.getPositionY() != null) {
vWindow.setPositionY(openType.getPositionY());
}
}
getDialogParams().reset();
ui.addWindow(vWindow);
return vWindow;
}
use of com.vaadin.event.ShortcutAction in project cuba by cuba-platform.
the class WebPickerFieldActionHandler method removeAction.
public void removeAction(com.haulmont.cuba.gui.components.Action action) {
List<ShortcutAction> existActions = new LinkedList<>();
for (Map.Entry<ShortcutAction, com.haulmont.cuba.gui.components.Action> entry : actionsMap.entrySet()) {
if (entry.getValue().equals(action)) {
existActions.add(entry.getKey());
}
}
shortcuts.removeAll(existActions);
for (ShortcutAction shortcut : existActions) {
actionsMap.remove(shortcut);
}
actionList.remove(action);
updateOrderedShortcuts();
}
Aggregations