Search in sources :

Example 1 with Action

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) };
        }
    });
}
Also used : ShortcutAction(com.vaadin.event.ShortcutAction) Action(com.vaadin.event.Action) Task(org.activiti.engine.task.Task) Handler(com.vaadin.event.Action.Handler) LoggedInUser(org.activiti.explorer.identity.LoggedInUser) ShortcutAction(com.vaadin.event.ShortcutAction)

Example 2 with Action

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);
            }
        }
    });
}
Also used : Window(com.vaadin.ui.Window) EventWindow(org.opennms.features.vaadin.events.EventWindow) DataCollectionWindow(org.opennms.features.vaadin.datacollection.DataCollectionWindow) Action(com.vaadin.event.Action) File(java.io.File) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Example 3 with Action

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());
        }
    });
}
Also used : Panel(com.vaadin.ui.Panel) ShortcutAction(com.vaadin.event.ShortcutAction) Action(com.vaadin.event.Action) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) Handler(com.vaadin.event.Action.Handler) ShortcutAction(com.vaadin.event.ShortcutAction) ClickListener(com.vaadin.ui.Button.ClickListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

Action (com.vaadin.event.Action)3 Handler (com.vaadin.event.Action.Handler)2 ShortcutAction (com.vaadin.event.ShortcutAction)2 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Panel (com.vaadin.ui.Panel)1 TextField (com.vaadin.ui.TextField)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Window (com.vaadin.ui.Window)1 File (java.io.File)1 Task (org.activiti.engine.task.Task)1 LoggedInUser (org.activiti.explorer.identity.LoggedInUser)1 DataCollectionWindow (org.opennms.features.vaadin.datacollection.DataCollectionWindow)1 EventWindow (org.opennms.features.vaadin.events.EventWindow)1 ConfirmDialog (org.vaadin.dialogs.ConfirmDialog)1