Search in sources :

Example 1 with ComboBox

use of com.vaadin.ui.ComboBox 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 ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class PropertyTable method addPropertyRow.

protected void addPropertyRow(Object itemId, String propertyName, String propertyType, Boolean required) {
    Object newItemId = null;
    if (itemId == null) {
        // add at the end of list
        newItemId = addItem();
    } else {
        newItemId = addItemAfter(itemId);
    }
    Item newItem = getItem(newItemId);
    // name
    newItem.getItemProperty(ID_PROPERTY_NAME).setValue(propertyName == null ? DEFAULT_PROPERTY_NAME : propertyName);
    // type
    ComboBox typeComboBox = new ComboBox("", Arrays.asList("text", "number", "date"));
    typeComboBox.setNullSelectionAllowed(false);
    if (propertyType == null) {
        typeComboBox.setValue(typeComboBox.getItemIds().iterator().next());
    } else {
        typeComboBox.setValue(propertyType);
    }
    newItem.getItemProperty(ID_PROPERTY_TYPE).setValue(typeComboBox);
    // required
    CheckBox requiredCheckBox = new CheckBox();
    requiredCheckBox.setValue(required == null ? false : required);
    newItem.getItemProperty(ID_PROPERTY_REQUIRED).setValue(requiredCheckBox);
    // actions
    HorizontalLayout actionButtons = new HorizontalLayout();
    Button deleteRowButton = new Button("-");
    deleteRowButton.setData(newItemId);
    deleteRowButton.addListener(new DeletePropertyClickListener(this));
    actionButtons.addComponent(deleteRowButton);
    Button addRowButton = new Button("+");
    addRowButton.setData(newItemId);
    addRowButton.addListener(new AddPropertyClickListener(this));
    actionButtons.addComponent(addRowButton);
    newItem.getItemProperty(ID_PROPERTY_ACTIONS).setValue(actionButtons);
}
Also used : Item(com.vaadin.data.Item) DeletePropertyClickListener(org.activiti.explorer.ui.process.simple.editor.listener.DeletePropertyClickListener) Button(com.vaadin.ui.Button) ComboBox(com.vaadin.ui.ComboBox) CheckBox(com.vaadin.ui.CheckBox) AddPropertyClickListener(org.activiti.explorer.ui.process.simple.editor.listener.AddPropertyClickListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class TaskTable method addTaskRow.

protected Object addTaskRow(Object previousTaskItemId, String taskName, String taskAssignee, String taskGroups, String taskDescription, Boolean startWithPrevious) {
    Object newItemId = null;
    if (previousTaskItemId == null) {
        // add at the end of list
        newItemId = addItem();
    } else {
        newItemId = addItemAfter(previousTaskItemId);
    }
    Item newItem = getItem(newItemId);
    // name
    newItem.getItemProperty(ID_NAME).setValue(taskName == null ? "my task" : taskName);
    // assignee
    ComboBox assigneeComboBox = new ComboBox();
    assigneeComboBox.setNullSelectionAllowed(true);
    try {
        for (User user : ProcessEngines.getDefaultProcessEngine().getIdentityService().createUserQuery().orderByUserFirstName().asc().list()) {
            assigneeComboBox.addItem(user.getId());
            assigneeComboBox.setItemCaption(user.getId(), user.getFirstName() + " " + user.getLastName());
        }
    } catch (Exception e) {
    // Don't do anything. Will be an empty dropdown.
    }
    if (taskAssignee != null) {
        assigneeComboBox.select(taskAssignee);
    }
    newItem.getItemProperty(ID_ASSIGNEE).setValue(assigneeComboBox);
    // groups
    ComboBox groupComboBox = new ComboBox();
    groupComboBox.setNullSelectionAllowed(true);
    try {
        for (Group group : ProcessEngines.getDefaultProcessEngine().getIdentityService().createGroupQuery().orderByGroupName().asc().list()) {
            groupComboBox.addItem(group.getId());
            groupComboBox.setItemCaption(group.getId(), group.getName());
        }
    } catch (Exception e) {
    // Don't do anything. Will be an empty dropdown.
    }
    if (taskGroups != null) {
        groupComboBox.select(taskGroups);
    }
    newItem.getItemProperty(ID_GROUPS).setValue(groupComboBox);
    // description
    TextField descriptionTextField = new TextField();
    descriptionTextField.setColumns(16);
    descriptionTextField.setRows(1);
    if (taskDescription != null) {
        descriptionTextField.setValue(taskDescription);
    }
    newItem.getItemProperty(ID_DESCRIPTION).setValue(descriptionTextField);
    // concurrency
    CheckBox startWithPreviousCheckBox = new CheckBox(i18nManager.getMessage(Messages.PROCESS_EDITOR_TASK_START_WITH_PREVIOUS));
    startWithPreviousCheckBox.setValue(startWithPrevious == null ? false : startWithPrevious);
    newItem.getItemProperty(ID_START_WITH_PREVIOUS).setValue(startWithPreviousCheckBox);
    // actions
    newItem.getItemProperty(ID_ACTIONS).setValue(generateActionButtons(newItemId));
    return newItemId;
}
Also used : Item(com.vaadin.data.Item) Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) ComboBox(com.vaadin.ui.ComboBox) CheckBox(com.vaadin.ui.CheckBox) TextField(com.vaadin.ui.TextField)

Example 4 with ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class GroupDetailPanel method initGroupProperties.

protected void initGroupProperties() {
    detailsGrid = new GridLayout(2, 3);
    detailsGrid.setSpacing(true);
    detailLayout.setMargin(true, true, true, false);
    detailLayout.addComponent(detailsGrid);
    // id
    Label idLabel = new Label(i18nManager.getMessage(Messages.GROUP_ID) + ": ");
    idLabel.addStyleName(ExplorerLayout.STYLE_LABEL_BOLD);
    detailsGrid.addComponent(idLabel);
    Label idValueLabel = new Label(group.getId());
    detailsGrid.addComponent(idValueLabel);
    // name
    Label nameLabel = new Label(i18nManager.getMessage(Messages.GROUP_NAME) + ": ");
    nameLabel.addStyleName(ExplorerLayout.STYLE_LABEL_BOLD);
    detailsGrid.addComponent(nameLabel);
    if (!editingDetails) {
        Label nameValueLabel = new Label(group.getName());
        detailsGrid.addComponent(nameValueLabel);
    } else {
        nameTextField = new TextField(null, group.getName());
        detailsGrid.addComponent(nameTextField);
    }
    // Type
    Label typeLabel = new Label(i18nManager.getMessage(Messages.GROUP_TYPE) + ": ");
    typeLabel.addStyleName(ExplorerLayout.STYLE_LABEL_BOLD);
    detailsGrid.addComponent(typeLabel);
    if (!editingDetails) {
        Label typeValueLabel = new Label(group.getType());
        detailsGrid.addComponent(typeValueLabel);
    } else {
        typeCombobox = new ComboBox(null, Arrays.asList("assignment", "security-role"));
        typeCombobox.setNullSelectionAllowed(false);
        typeCombobox.setInvalidAllowed(false);
        typeCombobox.select(group.getType());
        detailsGrid.addComponent(typeCombobox);
    }
}
Also used : GridLayout(com.vaadin.ui.GridLayout) ComboBox(com.vaadin.ui.ComboBox) Label(com.vaadin.ui.Label) TextField(com.vaadin.ui.TextField)

Example 5 with ComboBox

use of com.vaadin.ui.ComboBox in project Activiti by Activiti.

the class ProcessDefinitionFormPropertyRenderer method getPropertyField.

public Field getPropertyField(FormProperty formProperty) {
    ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
    comboBox.setRequired(formProperty.isRequired());
    comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
    comboBox.setEnabled(formProperty.isWritable());
    List<ProcessDefinition> processDefinitions = ProcessEngines.getDefaultProcessEngine().getRepositoryService().createProcessDefinitionQuery().orderByProcessDefinitionName().asc().orderByProcessDefinitionVersion().asc().list();
    for (ProcessDefinition processDefinition : processDefinitions) {
        comboBox.addItem(processDefinition.getId());
        String name = processDefinition.getName() + " (v" + processDefinition.getVersion() + ")";
        comboBox.setItemCaption(processDefinition.getId(), name);
    }
    // Select first
    if (!processDefinitions.isEmpty()) {
        comboBox.setNullSelectionAllowed(false);
        comboBox.select(processDefinitions.get(0).getId());
    }
    return comboBox;
}
Also used : ComboBox(com.vaadin.ui.ComboBox) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Aggregations

ComboBox (com.vaadin.ui.ComboBox)41 HorizontalLayout (com.vaadin.ui.HorizontalLayout)7 TextField (com.vaadin.ui.TextField)7 Button (com.vaadin.ui.Button)6 SplitComboBox (au.com.vaadinutils.crud.splitFields.SplitComboBox)5 LegacySplitComboBox (au.com.vaadinutils.crud.splitFields.legacy.LegacySplitComboBox)5 Item (com.vaadin.data.Item)5 Label (com.vaadin.ui.Label)5 VerticalLayout (com.vaadin.ui.VerticalLayout)5 Test (org.junit.Test)4 LegacyComboBox (org.vaadin.ui.LegacyComboBox)4 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 Panel (com.vaadin.ui.Panel)3 UI (com.vaadin.ui.UI)3 LinkkiComboBox (org.linkki.core.ui.components.LinkkiComboBox)3 TimePicker (au.com.vaadinutils.layout.TimePicker)2 ViewRiksdagenCommittee (com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee)2 ApplicationEventGroup (com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup)2 DataContainer (com.hack23.cia.service.api.DataContainer)2