use of com.vaadin.ui.Button in project vaadin-samples by xpoft.
the class ChooseLanguage method PostConstruct.
@PostConstruct
public void PostConstruct() {
setCaption(messageSource.getMessage("choose_language.select_lang"));
setWidth(-1, Unit.PIXELS);
HorizontalLayout buttons = new HorizontalLayout();
buttons.setWidth(-1, Unit.PIXELS);
buttons.setSpacing(true);
Button russian = new Button(messageSource.getMessage("choose_language.russian"), new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
UI.getCurrent().getSession().setLocale(new Locale("ru"));
// Reload page
UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
}
});
russian.setIcon(new ExternalResource("static/img/ru_flag.png"));
buttons.addComponent(russian);
Button english = new Button(messageSource.getMessage("choose_language.english"), new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
UI.getCurrent().getSession().setLocale(Locale.ENGLISH);
// Reload page
UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
}
});
english.setIcon(new ExternalResource("static/img/uk_flag.png"));
buttons.addComponent(english);
Button german = new Button(messageSource.getMessage("choose_language.german"), new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
UI.getCurrent().getSession().setLocale(Locale.GERMAN);
// Reload page
UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
}
});
german.setIcon(new ExternalResource("static/img/de_flag.png"));
buttons.addComponent(german);
Button finnish = new Button(messageSource.getMessage("choose_language.finnish"), new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
UI.getCurrent().getSession().setLocale(new Locale("fi"));
// Reload page
UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
}
});
finnish.setIcon(new ExternalResource("static/img/fi_flag.png"));
buttons.addComponent(finnish);
setContent(buttons);
}
use of com.vaadin.ui.Button in project opennms by OpenNMS.
the class NodeInfoPanelItemProvider method createComponent.
private Component createComponent(AbstractVertex ref) {
Preconditions.checkState(ref.getNodeID() != null, "no Node ID defined.");
OnmsNode node = nodeDao.get(ref.getNodeID());
FormLayout formLayout = new FormLayout();
formLayout.setSpacing(false);
formLayout.setMargin(false);
formLayout.addComponent(createLabel("Node ID", "" + node.getId()));
final HorizontalLayout nodeButtonLayout = new HorizontalLayout();
Button nodeButton = createButton(node.getLabel(), null, null, event -> new NodeInfoWindow(ref.getNodeID()).open());
nodeButton.setStyleName(BaseTheme.BUTTON_LINK);
nodeButtonLayout.addComponent(nodeButton);
nodeButtonLayout.setCaption("Node Label");
formLayout.addComponent(nodeButtonLayout);
if (!Strings.isNullOrEmpty(node.getSysObjectId())) {
formLayout.addComponent(createLabel("Enterprise OID", node.getSysObjectId()));
}
return formLayout;
}
use of com.vaadin.ui.Button 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 in project opennms by OpenNMS.
the class IncludeCollectionWindow method buttonClick.
/* (non-Javadoc)
* @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.ClickEvent)
*/
@Override
public void buttonClick(Button.ClickEvent event) {
final Button btn = event.getButton();
if (btn == okButton) {
try {
formEditor.commit();
fieldChanged();
} catch (CommitException e) {
Notification.show("Can't save include collection because " + e.getMessage(), Notification.Type.ERROR_MESSAGE);
}
}
close();
}
use of com.vaadin.ui.Button in project opennms by OpenNMS.
the class BreadcrumbComponent method createButton.
private static Button createButton(GraphContainer container, Breadcrumb breadcrumb) {
final Button button = new Button();
final String layerName = getLayerName(container, breadcrumb.getTargetNamespace());
if (breadcrumb.getSourceVertices().isEmpty()) {
button.setCaption(layerName);
} else {
String sourceLayerName = getLayerName(container, breadcrumb.getSourceVertices().get(0).getNamespace());
if (breadcrumb.getSourceVertices().size() > 2) {
button.setCaption("Multiple " + layerName);
button.setDescription(String.format("Multiple vertices from %s", sourceLayerName));
} else {
button.setCaption(breadcrumb.getSourceVertices().stream().map(b -> b.getLabel()).collect(Collectors.joining(", ")));
button.setDescription(String.format("%s from %s", button.getCaption(), sourceLayerName));
}
}
button.addStyleName(BaseTheme.BUTTON_LINK);
button.addClickListener((event) -> breadcrumb.clicked(container));
return button;
}
Aggregations