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);
}
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;
}
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);
}
}
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);
}
});
}
}
});
}
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);
}
}
Aggregations