use of org.vaadin.dialogs.ConfirmDialog 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 org.vaadin.dialogs.ConfirmDialog in project opennms by OpenNMS.
the class DataCollectionGroupPanel method processDataCollection.
/**
* Process data collection.
*
* @param dataCollectionConfigDao the OpenNMS data collection configuration DAO
* @param logger the logger
*/
private void processDataCollection(final DataCollectionConfigDao dataCollectionConfigDao, final Logger logger) {
final DatacollectionGroup dcGroup = getOnmsDataCollection();
if (isExistingGroup()) {
ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to override the existig file?\nAll current information will be lost.", "Yes", "No", new ConfirmDialog.Listener() {
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
saveFile(existingFile, dcGroup, logger);
}
}
});
} else {
if (dataCollectionConfigDao.getAvailableDataCollectionGroups().contains(dcGroup.getName())) {
Notification.show("There is a group with the same name, please pick another one.");
} else {
final File configDir = new File(ConfigFileConstants.getHome(), "etc" + File.separatorChar + "datacollection");
final File file = new File(configDir, dcGroup.getName().replaceAll(" ", "_") + ".xml");
saveFile(file, dcGroup, logger);
}
}
}
use of org.vaadin.dialogs.ConfirmDialog 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);
}
}
});
}
Aggregations