Search in sources :

Example 1 with ClickEvent

use of com.vaadin.ui.Button.ClickEvent in project opennms by OpenNMS.

the class EventAdminApplication method init.

/* (non-Javadoc)
     * @see com.vaadin.Application#init()
     */
@Override
public void init(VaadinRequest request) {
    if (eventProxy == null)
        throw new RuntimeException("eventProxy cannot be null.");
    if (eventConfDao == null)
        throw new RuntimeException("eventConfDao cannot be null.");
    final VerticalLayout layout = new VerticalLayout();
    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setMargin(true);
    final Label comboLabel = new Label("Select Events Configuration File");
    toolbar.addComponent(comboLabel);
    toolbar.setComponentAlignment(comboLabel, Alignment.MIDDLE_LEFT);
    final File eventsDir = new File(ConfigFileConstants.getFilePathString(), "events");
    final XmlFileContainer container = new XmlFileContainer(eventsDir, true);
    // This is a protected file, should not be updated.
    container.addExcludeFile("default.events.xml");
    final ComboBox eventSource = new ComboBox();
    toolbar.addComponent(eventSource);
    eventSource.setImmediate(true);
    eventSource.setNullSelectionAllowed(false);
    eventSource.setContainerDataSource(container);
    eventSource.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    eventSource.addValueChangeListener(new ComboBox.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            final File file = (File) event.getProperty().getValue();
            if (file == null)
                return;
            try {
                LOG.info("Loading events from {}", file);
                final Events events = JaxbUtils.unmarshal(Events.class, file);
                addEventPanel(layout, file, events);
            } catch (Exception e) {
                LOG.error("an error ocurred while saving the event configuration {}: {}", file, e.getMessage(), e);
                Notification.show("Can't parse file " + file + " because " + e.getMessage());
            }
        }
    });
    final Button add = new Button("Add New Events File");
    toolbar.addComponent(add);
    add.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            PromptWindow w = new PromptWindow("New Events Configuration", "Events File Name") {

                @Override
                public void textFieldChanged(String fieldValue) {
                    final File file = new File(eventsDir, normalizeFilename(fieldValue));
                    LOG.info("Adding new events file {}", file);
                    final Events events = new Events();
                    addEventPanel(layout, file, events);
                }
            };
            addWindow(w);
        }
    });
    final Button remove = new Button("Remove Selected Events File");
    toolbar.addComponent(remove);
    remove.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            if (eventSource.getValue() == null) {
                Notification.show("Please select an event configuration file.");
                return;
            }
            final File file = (File) eventSource.getValue();
            ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to remove the file " + file.getName() + "?\nThis cannot be undone and OpenNMS won't be able to handle the events configured on this file.", "Yes", "No", new ConfirmDialog.Listener() {

                public void onClose(ConfirmDialog dialog) {
                    if (dialog.isConfirmed()) {
                        LOG.info("deleting file {}", file);
                        if (file.delete()) {
                            try {
                                // Updating eventconf.xml
                                boolean modified = false;
                                File configFile = ConfigFileConstants.getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME);
                                Events config = JaxbUtils.unmarshal(Events.class, configFile);
                                for (Iterator<String> it = config.getEventFiles().iterator(); it.hasNext(); ) {
                                    String fileName = it.next();
                                    if (file.getAbsolutePath().contains(fileName)) {
                                        it.remove();
                                        modified = true;
                                    }
                                }
                                if (modified) {
                                    JaxbUtils.marshal(config, new FileWriter(configFile));
                                    EventBuilder eb = new EventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "WebUI");
                                    eventProxy.send(eb.getEvent());
                                }
                                // Updating UI Components
                                eventSource.select(null);
                                if (layout.getComponentCount() > 1)
                                    layout.removeComponent(layout.getComponent(1));
                            } catch (Exception e) {
                                LOG.error("an error ocurred while saving the event configuration: {}", e.getMessage(), e);
                                Notification.show("Can't save event configuration. " + e.getMessage(), Notification.Type.ERROR_MESSAGE);
                            }
                        } else {
                            Notification.show("Cannot delete file " + file, Notification.Type.WARNING_MESSAGE);
                        }
                    }
                }
            });
        }
    });
    layout.addComponent(toolbar);
    layout.addComponent(new Label(""));
    layout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT);
    setContent(layout);
}
Also used : ComboBox(com.vaadin.ui.ComboBox) ClickEvent(com.vaadin.ui.Button.ClickEvent) FileWriter(java.io.FileWriter) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Events(org.opennms.netmgt.xml.eventconf.Events) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) File(java.io.File) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Example 2 with ClickEvent

use of com.vaadin.ui.Button.ClickEvent in project opennms by OpenNMS.

the class AlarmIdColumnLinkGenerator method generateCell.

@Override
public Object generateCell(final Table source, Object itemId, Object columnId) {
    // no source
    if (source == null)
        return null;
    Property<Integer> alarmIdProperty = source.getContainerProperty(itemId, alarmIdPropertyName);
    final Integer alarmId = alarmIdProperty.getValue();
    // no value
    if (alarmId == null)
        return null;
    // create Link
    Button button = new Button("" + alarmId);
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 3698209256202413810L;

        @Override
        public void buttonClick(ClickEvent event) {
            // try if alarm is there, otherwise show information dialog
            OnmsAlarm alarm = alarmDao.get(alarmId);
            if (alarm == null) {
                new DialogWindow(source.getUI(), "Alarm does not exist!", "The alarm information cannot be shown. \nThe alarm does not exist anymore. \n\nPlease refresh the Alarm Table.");
                return;
            }
            // alarm still exists, show alarm details
            final URI currentLocation = Page.getCurrent().getLocation();
            final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath();
            final String redirectFragment = contextRoot + "/alarm/detail.htm?quiet=true&id=" + alarmId;
            LOG.debug("alarm {} clicked, current location = {}, uri = {}", alarmId, currentLocation, redirectFragment);
            try {
                source.getUI().addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new LabelCreator() {

                    @Override
                    public String getLabel() {
                        return "Alarm Info " + alarmId;
                    }
                }));
            } catch (MalformedURLException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    });
    return button;
}
Also used : MalformedURLException(java.net.MalformedURLException) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ClickEvent(com.vaadin.ui.Button.ClickEvent) InfoWindow(org.opennms.features.topology.api.support.InfoWindow) URI(java.net.URI) URL(java.net.URL) Button(com.vaadin.ui.Button) DialogWindow(org.opennms.features.topology.api.support.DialogWindow) ClickListener(com.vaadin.ui.Button.ClickListener) LabelCreator(org.opennms.features.topology.api.support.InfoWindow.LabelCreator)

Example 3 with ClickEvent

use of com.vaadin.ui.Button.ClickEvent in project Activiti by Activiti.

the class TaskDetailPanel method initProcessLink.

protected void initProcessLink() {
    if (task.getProcessInstanceId() != null) {
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
        Button showProcessInstanceButton = new Button(i18nManager.getMessage(Messages.TASK_PART_OF_PROCESS, getProcessDisplayName(processDefinition)));
        showProcessInstanceButton.addStyleName(Reindeer.BUTTON_LINK);
        showProcessInstanceButton.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                viewManager.showMyProcessInstancesPage(task.getProcessInstanceId());
            }
        });
        centralLayout.addComponent(showProcessInstanceButton);
        addEmptySpace(centralLayout);
    }
}
Also used : Button(com.vaadin.ui.Button) LayoutClickEvent(com.vaadin.event.LayoutEvents.LayoutClickEvent) ClickEvent(com.vaadin.ui.Button.ClickEvent) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ClickListener(com.vaadin.ui.Button.ClickListener) LayoutClickListener(com.vaadin.event.LayoutEvents.LayoutClickListener) ClaimTaskClickListener(org.activiti.explorer.ui.task.listener.ClaimTaskClickListener)

Example 4 with ClickEvent

use of com.vaadin.ui.Button.ClickEvent in project Activiti by Activiti.

the class TaskDetailPanel method initDescription.

protected void initDescription(HorizontalLayout layout) {
    final CssLayout descriptionLayout = new CssLayout();
    descriptionLayout.setWidth(100, UNITS_PERCENTAGE);
    layout.addComponent(descriptionLayout);
    layout.setExpandRatio(descriptionLayout, 1.0f);
    layout.setComponentAlignment(descriptionLayout, Alignment.MIDDLE_LEFT);
    String descriptionText = null;
    if (task.getDescription() != null && !"".equals(task.getDescription())) {
        descriptionText = task.getDescription();
    } else {
        descriptionText = i18nManager.getMessage(Messages.TASK_NO_DESCRIPTION);
    }
    final Label descriptionLabel = new Label(descriptionText);
    descriptionLabel.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
    descriptionLayout.addComponent(descriptionLabel);
    descriptionLayout.addListener(new LayoutClickListener() {

        public void layoutClick(LayoutClickEvent event) {
            if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) {
                // layout for textarea + ok button
                final VerticalLayout editLayout = new VerticalLayout();
                editLayout.setSpacing(true);
                // textarea
                final TextArea descriptionTextArea = new TextArea();
                descriptionTextArea.setNullRepresentation("");
                descriptionTextArea.setWidth(100, UNITS_PERCENTAGE);
                descriptionTextArea.setValue(task.getDescription());
                editLayout.addComponent(descriptionTextArea);
                // ok button
                Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK));
                editLayout.addComponent(okButton);
                editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);
                // replace
                descriptionLayout.replaceComponent(descriptionLabel, editLayout);
                // When OK is clicked -> update task data + ui
                okButton.addListener(new ClickListener() {

                    public void buttonClick(ClickEvent event) {
                        // Update data
                        task.setDescription(descriptionTextArea.getValue().toString());
                        taskService.saveTask(task);
                        // Update UI
                        descriptionLabel.setValue(task.getDescription());
                        descriptionLayout.replaceComponent(editLayout, descriptionLabel);
                    }
                });
            }
        }
    });
}
Also used : LayoutClickEvent(com.vaadin.event.LayoutEvents.LayoutClickEvent) CssLayout(com.vaadin.ui.CssLayout) TextArea(com.vaadin.ui.TextArea) Button(com.vaadin.ui.Button) LayoutClickEvent(com.vaadin.event.LayoutEvents.LayoutClickEvent) ClickEvent(com.vaadin.ui.Button.ClickEvent) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) VerticalLayout(com.vaadin.ui.VerticalLayout) ClickListener(com.vaadin.ui.Button.ClickListener) LayoutClickListener(com.vaadin.event.LayoutEvents.LayoutClickListener) ClaimTaskClickListener(org.activiti.explorer.ui.task.listener.ClaimTaskClickListener) LayoutClickListener(com.vaadin.event.LayoutEvents.LayoutClickListener)

Example 5 with ClickEvent

use of com.vaadin.ui.Button.ClickEvent in project Activiti by Activiti.

the class TaskDetailPanel method initParentTaskLink.

protected void initParentTaskLink() {
    if (task.getParentTaskId() != null) {
        final Task parentTask = taskService.createTaskQuery().taskId(task.getParentTaskId()).singleResult();
        Button showParentTaskButton = new Button(i18nManager.getMessage(Messages.TASK_SUBTASK_OF_PARENT_TASK, parentTask.getName()));
        showParentTaskButton.addStyleName(Reindeer.BUTTON_LINK);
        showParentTaskButton.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                viewManager.showTaskPage(parentTask.getId());
            }
        });
        centralLayout.addComponent(showParentTaskButton);
        addEmptySpace(centralLayout);
    }
}
Also used : Task(org.activiti.engine.task.Task) Button(com.vaadin.ui.Button) LayoutClickEvent(com.vaadin.event.LayoutEvents.LayoutClickEvent) ClickEvent(com.vaadin.ui.Button.ClickEvent) ClickListener(com.vaadin.ui.Button.ClickListener) LayoutClickListener(com.vaadin.event.LayoutEvents.LayoutClickListener) ClaimTaskClickListener(org.activiti.explorer.ui.task.listener.ClaimTaskClickListener)

Aggregations

ClickEvent (com.vaadin.ui.Button.ClickEvent)68 ClickListener (com.vaadin.ui.Button.ClickListener)66 Button (com.vaadin.ui.Button)63 HorizontalLayout (com.vaadin.ui.HorizontalLayout)17 Label (com.vaadin.ui.Label)13 VerticalLayout (com.vaadin.ui.VerticalLayout)8 SubmitEvent (org.activiti.explorer.ui.event.SubmitEvent)8 LayoutClickEvent (com.vaadin.event.LayoutEvents.LayoutClickEvent)7 LayoutClickListener (com.vaadin.event.LayoutEvents.LayoutClickListener)7 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)5 ValueChangeListener (com.vaadin.data.Property.ValueChangeListener)4 TextField (com.vaadin.ui.TextField)4 Map (java.util.Map)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 ClaimTaskClickListener (org.activiti.explorer.ui.task.listener.ClaimTaskClickListener)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ExternalResource (com.vaadin.terminal.ExternalResource)3 Form (com.vaadin.ui.Form)3 URL (java.net.URL)3