use of com.vaadin.event.Action 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.Action in project opennms by OpenNMS.
the class MibCompilerPanel method initMibTree.
/**
* Initialize the MIB tree.
*
* @param logger the logger
*/
private void initMibTree(final Logger logger) {
File[] folders = new File[] { MIBS_COMPILED_DIR, MIBS_PENDING_DIR };
for (File folder : folders) {
addTreeItem(folder.getName(), null);
}
for (File folder : folders) {
String[] files = folder.list();
if (files == null)
continue;
for (String file : files) {
addTreeItem(file, folder.getName());
}
}
mibsTree.expandItemsRecursively(COMPILED);
mibsTree.expandItemsRecursively(PENDING);
mibsTree.addActionHandler(new Action.Handler() {
@Override
public Action[] getActions(Object target, Object sender) {
if (target == null) {
return new Action[] {};
}
Object parent = mibsTree.getParent(target);
if (parent == null) {
return new Action[] {};
}
if (parent.equals(COMPILED)) {
return new Action[] { ACTION_EVENTS, ACTION_COLLECT, ACTION_VIEW, ACTION_DELETE };
} else {
return new Action[] { ACTION_EDIT, ACTION_DELETE, ACTION_COMPILE };
}
}
@Override
public void handleAction(Action action, Object sender, Object target) {
final String fileName = (String) target;
if (action == ACTION_DELETE) {
ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to delete " + fileName + "?\nThis cannot be undone.", "Yes", "No", new ConfirmDialog.Listener() {
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
String source = mibsTree.getParent(fileName).toString();
File file = new File(PENDING.equals(source) ? MIBS_PENDING_DIR : MIBS_COMPILED_DIR, fileName);
if (file.delete()) {
mibsTree.removeItem(fileName);
logger.info("MIB " + file + " has been successfully removed.");
} else {
Notification.show("Can't delete " + file);
}
}
}
});
}
if (action == ACTION_EDIT) {
Window w = new FileEditorWindow(new File(MIBS_PENDING_DIR, fileName), logger, false);
getUI().addWindow(w);
}
if (action == ACTION_VIEW) {
Window w = new FileEditorWindow(new File(MIBS_COMPILED_DIR, fileName), logger, true);
getUI().addWindow(w);
}
if (action == ACTION_COMPILE) {
if (parseMib(logger, new File(MIBS_PENDING_DIR, fileName))) {
// Renaming the file to be sure that the target name is correct and always has a file extension.
final String mibFileName = mibParser.getMibName() + MIB_FILE_EXTENTION;
final File currentFile = new File(MIBS_PENDING_DIR, fileName);
final File suggestedFile = new File(MIBS_COMPILED_DIR, mibFileName);
if (suggestedFile.exists()) {
ConfirmDialog.show(getUI(), "Are you sure?", "The MIB " + mibFileName + " already exist on the compiled directory?<br/>Override the existing file could break other compiled mibs, so proceed with caution.<br/>This cannot be undone.", "Yes", "No", new ConfirmDialog.Listener() {
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
renameFile(logger, currentFile, suggestedFile);
}
}
});
} else {
renameFile(logger, currentFile, suggestedFile);
}
}
}
if (action == ACTION_EVENTS) {
generateEvents(logger, fileName);
}
if (action == ACTION_COLLECT) {
generateDataCollection(logger, fileName);
}
}
});
}
use of com.vaadin.event.Action 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());
}
});
}
Aggregations