Search in sources :

Example 1 with ValueChangeEvent

use of com.vaadin.data.Property.ValueChangeEvent 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 ValueChangeEvent

use of com.vaadin.data.Property.ValueChangeEvent in project opennms by OpenNMS.

the class CheckboxGenerator method generateCell.

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    final Property<Integer> property = source.getContainerProperty(itemId, m_valueProperty);
    if (property.getValue() == null) {
        return null;
    } else {
        if (SecurityContextHolder.getContext().toString().contains(Authentication.ROLE_READONLY)) {
            // Do not render the checkboxes for read-only users
            return null;
        } else {
            final CheckBox button = new CheckBox();
            button.setData(property.getValue());
            button.setValue(isSelected((Integer) property.getValue()));
            button.addValueChangeListener(new ValueChangeListener() {

                private static final long serialVersionUID = 2991986878904005830L;

                @Override
                public void valueChange(ValueChangeEvent event) {
                    if (Boolean.TRUE.equals(event.getProperty().getValue())) {
                        m_selectedCheckboxes.add(property.getValue());
                        m_notSelectedCheckboxes.remove(property.getValue());
                    } else {
                        m_selectedCheckboxes.remove(property.getValue());
                        m_notSelectedCheckboxes.add(property.getValue());
                    }
                }
            });
            m_checkboxes.add(button);
            return button;
        }
    }
}
Also used : ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) CheckBox(com.vaadin.ui.CheckBox)

Example 3 with ValueChangeEvent

use of com.vaadin.data.Property.ValueChangeEvent in project Activiti by Activiti.

the class ActiveProcessDefinitionPage method createList.

protected Table createList() {
    processDefinitionTable = new Table();
    processDefinitionListQuery = new ActiveProcessDefinitionListQuery();
    processDefinitionListContainer = new LazyLoadingContainer(processDefinitionListQuery);
    processDefinitionTable.setContainerDataSource(processDefinitionListContainer);
    // Column headers
    processDefinitionTable.addContainerProperty("name", String.class, null);
    processDefinitionTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
    // Listener to change right panel when clicked on a user
    processDefinitionTable.addListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            // the value of the property is the itemId of the table entry
            Item item = processDefinitionTable.getItem(event.getProperty().getValue());
            if (item != null) {
                String processDefinitionId = (String) item.getItemProperty("id").getValue();
                setDetailComponent(new ActiveProcessDefinitionDetailPanel(processDefinitionId, ActiveProcessDefinitionPage.this));
                // Update URL
                ExplorerApp.get().setCurrentUriFragment(new UriFragment(ActiveProcessDefinitionNavigator.ACTIVE_PROC_DEF_URI_PART, processDefinitionId));
            } else {
                // Nothing selected
                setDetailComponent(null);
                ExplorerApp.get().setCurrentUriFragment(new UriFragment(ActiveProcessDefinitionNavigator.ACTIVE_PROC_DEF_URI_PART));
            }
        }
    });
    return processDefinitionTable;
}
Also used : Item(com.vaadin.data.Item) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) Table(com.vaadin.ui.Table) LazyLoadingContainer(org.activiti.explorer.data.LazyLoadingContainer) Property(com.vaadin.data.Property) UriFragment(org.activiti.explorer.navigation.UriFragment)

Example 4 with ValueChangeEvent

use of com.vaadin.data.Property.ValueChangeEvent in project Activiti by Activiti.

the class ChangeProcessSuspensionStatePopupWindow method addTimeSection.

protected void addTimeSection(boolean suspend) {
    Label timeLabel = new Label(suspend ? i18nManager.getMessage(Messages.PROCESS_SUSPEND_POPUP_TIME_DESCRIPTION) : i18nManager.getMessage(Messages.PROCESS_ACTIVATE_POPUP_TIME_DESCRIPTION));
    verticalLayout.addComponent(timeLabel);
    verticalLayout.addComponent(new Label("&nbsp", Label.CONTENT_XHTML));
    nowCheckBox = new CheckBox(i18nManager.getMessage(Messages.PROCESS_SUSPEND_POPUP_TIME_NOW), true);
    nowCheckBox.addStyleName(ExplorerLayout.STYLE_PROCESS_DEFINITION_SUSPEND_CHOICE);
    nowCheckBox.setImmediate(true);
    nowCheckBox.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            if (nowCheckBox.booleanValue() == true) {
                dateField.setValue(null);
                dateCheckBox.setValue(false);
            } else {
                dateCheckBox.setValue(true);
                dateField.setValue(new Date());
            }
        }
    });
    verticalLayout.addComponent(nowCheckBox);
    HorizontalLayout dateLayout = new HorizontalLayout();
    verticalLayout.addComponent(dateLayout);
    dateCheckBox = new CheckBox(i18nManager.getMessage(Messages.PROCESS_SUSPEND_POPUP_TIME_DATE));
    dateCheckBox.addStyleName(ExplorerLayout.STYLE_PROCESS_DEFINITION_SUSPEND_CHOICE);
    dateCheckBox.setImmediate(true);
    dateCheckBox.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            if (dateCheckBox.booleanValue() == true) {
                dateField.setValue(new Date());
                nowCheckBox.setValue(false);
            } else {
                dateField.setValue(null);
                nowCheckBox.setValue(true);
            }
        }
    });
    dateLayout.addComponent(dateCheckBox);
    dateField = new DateField();
    dateField.setImmediate(true);
    dateField.addListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent event) {
            if (dateField.getValue() != null) {
                nowCheckBox.setValue(false);
                dateCheckBox.setValue(true);
            }
        }
    });
    dateLayout.addComponent(dateField);
}
Also used : ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) CheckBox(com.vaadin.ui.CheckBox) ClickEvent(com.vaadin.ui.Button.ClickEvent) Label(com.vaadin.ui.Label) DateField(com.vaadin.ui.DateField) ClickListener(com.vaadin.ui.Button.ClickListener) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 5 with ValueChangeEvent

use of com.vaadin.data.Property.ValueChangeEvent in project Activiti by Activiti.

the class ProcessDefinitionPage method createList.

@Override
protected Table createList() {
    final Table processDefinitionTable = new Table();
    processDefinitionTable.addStyleName(ExplorerLayout.STYLE_PROCESS_DEFINITION_LIST);
    // Set non-editable, selectable and full-size
    processDefinitionTable.setEditable(false);
    processDefinitionTable.setImmediate(true);
    processDefinitionTable.setSelectable(true);
    processDefinitionTable.setNullSelectionAllowed(false);
    processDefinitionTable.setSortDisabled(true);
    processDefinitionTable.setSizeFull();
    LazyLoadingQuery lazyLoadingQuery = new ProcessDefinitionListQuery(repositoryService, definitionFilter);
    this.processDefinitionContainer = new LazyLoadingContainer(lazyLoadingQuery, 30);
    processDefinitionTable.setContainerDataSource(processDefinitionContainer);
    // Listener to change right panel when clicked on a task
    processDefinitionTable.addListener(new Property.ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            Item item = processDefinitionTable.getItem(event.getProperty().getValue());
            String processDefinitionId = (String) item.getItemProperty("id").getValue();
            showProcessDefinitionDetail(processDefinitionId);
        }
    });
    // Create columns
    processDefinitionTable.addGeneratedColumn("icon", new ThemeImageColumnGenerator(Images.PROCESS_22));
    processDefinitionTable.setColumnWidth("icon", 22);
    processDefinitionTable.addContainerProperty("name", String.class, null);
    processDefinitionTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
    return processDefinitionTable;
}
Also used : Item(com.vaadin.data.Item) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) Table(com.vaadin.ui.Table) ThemeImageColumnGenerator(org.activiti.explorer.ui.util.ThemeImageColumnGenerator) LazyLoadingContainer(org.activiti.explorer.data.LazyLoadingContainer) Property(com.vaadin.data.Property) LazyLoadingQuery(org.activiti.explorer.data.LazyLoadingQuery)

Aggregations

ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)30 Table (com.vaadin.ui.Table)21 Item (com.vaadin.data.Item)20 Property (com.vaadin.data.Property)19 UriFragment (org.activiti.explorer.navigation.UriFragment)13 ValueChangeListener (com.vaadin.data.Property.ValueChangeListener)11 LazyLoadingContainer (org.activiti.explorer.data.LazyLoadingContainer)11 ThemeImageColumnGenerator (org.activiti.explorer.ui.util.ThemeImageColumnGenerator)10 Label (com.vaadin.ui.Label)6 ClickEvent (com.vaadin.ui.Button.ClickEvent)5 Button (com.vaadin.ui.Button)4 ClickListener (com.vaadin.ui.Button.ClickListener)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 LazyLoadingQuery (org.activiti.explorer.data.LazyLoadingQuery)4 CheckBox (com.vaadin.ui.CheckBox)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 CellStyleGenerator (com.vaadin.ui.Table.CellStyleGenerator)2 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)2 PrettyTimeLabel (org.activiti.explorer.ui.custom.PrettyTimeLabel)2