List of usage examples for com.vaadin.ui ComboBox addValueChangeListener
@Override
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
From source file:org.lucidj.vaadinui.BaseVaadinUI.java
License:Apache License
private void initSystemToolbar() { desktop_canvas.setSizeFull();//from w ww .j ava2 s . co m desktop_canvas.setWidth("100%"); ui_header = new HorizontalLayout(); { ui_header.setStyleName("ui-header-area"); ui_header.setWidth(100, Sizeable.Unit.PERCENTAGE); ui_header.setHeightUndefined(); ui_header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); Label logo = new Label(" ", ContentMode.HTML); { logo.addStyleName("ui-header-logo"); logo.setWidth(default_sidebar_width_pixels, Sizeable.Unit.PIXELS); } ui_header.addComponent(logo); HorizontalLayout header_components = new HorizontalLayout(); { header_components.setWidth(100, com.vaadin.server.Sizeable.Unit.PERCENTAGE); header_components.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); header_components.setSpacing(true); // Search component CssLayout search_component = new CssLayout(); { search_component.setWidth(100, com.vaadin.server.Sizeable.Unit.PERCENTAGE); search_component.setWidthUndefined(); search_component.addStyleName("v-component-group"); search_component.addStyleName("ui-header-search"); final ComboBox search_text = new ComboBox(); { search_text.setInputPrompt("Search or paste URL..."); //combo.setContainerDataSource(StringGenerator.generateContainer(200, false)); search_text.setNullSelectionAllowed(true); search_text.setTextInputAllowed(true); search_text.setNewItemsAllowed(true); //combo.select(combo.getItemIds().iterator().next()); //combo.setItemCaptionPropertyId(StringGenerator.CAPTION_PROPERTY); //combo.setItemIconPropertyId(StringGenerator.ICON_PROPERTY); // TODO: SOMEDAY DISCOVER HOW TO EXPAND THIS GROUPED COMPONENT, AND THE CURE FOR CANCER search_text.setWidth("480px"); search_text.addStyleName("invisible-focus"); search_text.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String search_args = (String) search_text.getValue(); if (search_args != null) { fireEvent("search", search_text.getValue()); value_change_button_quirk = true; } } }); // Handles the Enter key by activating on focus and deactivating on blur final ShortcutListener handle_enter = new ShortcutListener("Enter", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object o, Object o1) { value_change_button_quirk = false; fireEvent("search", search_text.getValue()); } }; search_text.addFocusListener(new FieldEvents.FocusListener() { @Override public void focus(FieldEvents.FocusEvent focusEvent) { if (nested_focus_blur_bug_count++ == 0) { search_text.addShortcutListener(handle_enter); } } }); search_text.addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(FieldEvents.BlurEvent blurEvent) { if (--nested_focus_blur_bug_count == 0) { search_text.removeShortcutListener(handle_enter); } } }); } search_component.addComponent(search_text); Button search_button = new Button(); { search_button.setIcon(FontAwesome.SEARCH); search_button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { if (!value_change_button_quirk) { fireEvent("search", search_text.getValue()); } value_change_button_quirk = false; } }); search_button.addStyleName("invisible-focus"); } search_component.addComponent(search_button); } header_components.addComponent(search_component); // User component user_component = new HorizontalLayout(); { user_component.setStyleName("ui-header-user"); user_component.setWidthUndefined(); } header_components.addComponent(user_component); // I swear someday I'll learn CSS, AFTER implementing my own distributed // operating system with augmented reality interface and a machine learning kernel, // all written in Z80 assembly, as a preparation for the task. Label spacer = new Label(); spacer.setWidthUndefined(); header_components.addComponent(spacer); // Search expands header_components.setExpandRatio(search_component, 1.0f); } ui_header.addComponent(header_components); ui_header.setExpandRatio(header_components, 1.0f); } desktop_canvas.addComponent(ui_header); desktop_canvas.addComponent(empty_desktop); desktop_canvas.setExpandRatio(empty_desktop, 1.0f); setContent(desktop_canvas); }
From source file:org.opencms.ui.apps.CmsFileExplorer.java
License:Open Source License
/** * Creates the site selector combo box.<p> * * @param cms the current cms context//from w ww .jav a2 s . c o m * * @return the combo box */ private ComboBox createSiteSelect(CmsObject cms) { final IndexedContainer availableSites = CmsVaadinUtils.getAvailableSitesContainer(cms, SITE_CAPTION); ComboBox combo = new ComboBox(null, availableSites); combo.setTextInputAllowed(true); combo.setNullSelectionAllowed(false); combo.setWidth("200px"); combo.setInputPrompt( Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_CLICK_TO_EDIT_0)); combo.setItemCaptionPropertyId(SITE_CAPTION); combo.select(cms.getRequestContext().getSiteRoot()); combo.setFilteringMode(FilteringMode.CONTAINS); combo.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; public void valueChange(ValueChangeEvent event) { String value = (String) event.getProperty().getValue(); if (availableSites.containsId(value)) { changeSite(value, null); m_appContext.updateOnChange(); availableSites.removeAllContainerFilters(); } } }); if (Page.getCurrent().getBrowserWindowHeight() > 650) { combo.setPageLength(20); } return combo; }
From source file:org.opencms.ui.dataview.CmsDataViewPanel.java
License:Open Source License
/** * Changes the displayed filters to a new set.<p> * * @param newFilters the new filters/* w w w .jav a2s . c om*/ */ public void updateFilters(List<CmsDataViewFilter> newFilters) { if (newFilters.isEmpty()) { m_filterContainer.setVisible(false); } if (m_filters.equals(newFilters)) { return; } m_filterContainer.removeAllComponents(); m_filters = newFilters; m_filterMap.clear(); for (CmsDataViewFilter filter : newFilters) { m_filterMap.put(filter.getId(), filter); final CmsDataViewFilter finalFilter = filter; ComboBox select = new ComboBox(filter.getNiceName()); select.setWidth("175px"); select.setNullSelectionAllowed(false); select.setPageLength(0); Map<String, String> options = filter.getOptions(); for (Map.Entry<String, String> entry : options.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); select.addItem(key); select.setItemCaption(key, value); } select.setValue(filter.getValue()); if (filter.getHelpText() != null) { select.setDescription(filter.getHelpText()); } select.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; public void valueChange(ValueChangeEvent event) { String newValue = (String) (event.getProperty().getValue()); updateFilter(finalFilter.getId(), newValue); } }); m_filterContainer.addComponent(select); } }
From source file:org.opencms.ui.editors.CmsSourceEditor.java
License:Open Source License
/** * @see org.opencms.ui.editors.I_CmsEditor#initUI(org.opencms.ui.apps.I_CmsAppUIContext, org.opencms.file.CmsResource, java.lang.String) *//*from w w w .ja va 2 s. com*/ public void initUI(I_CmsAppUIContext context, CmsResource resource, String backLink) { CmsMessages messages = Messages.get().getBundle(UI.getCurrent().getLocale()); context.showInfoArea(false); context.setAppTitle(messages.key(Messages.GUI_SOURCE_EDITOR_TITLE_0)); CmsAppWorkplaceUi.setWindowTitle(CmsVaadinUtils.getMessageText( org.opencms.ui.apps.Messages.GUI_CONTENT_EDITOR_TITLE_2, resource.getName(), CmsResource.getParentFolder(A_CmsUI.getCmsObject().getSitePath(resource)))); m_backLink = backLink; m_codeMirror = new CmsCodeMirror(); m_codeMirror.setSizeFull(); context.setAppContent(m_codeMirror); context.enableDefaultToolbarButtons(false); m_saveAndExit = CmsToolBar.createButton(FontOpenCms.SAVE_EXIT, messages.key(Messages.GUI_BUTTON_SAVE_AND_EXIT_0), true); m_saveAndExit.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { saveAndExit(); } }); m_saveAndExit.setEnabled(false); context.addToolbarButton(m_saveAndExit); m_save = CmsToolBar.createButton(FontOpenCms.SAVE, messages.key(Messages.GUI_BUTTON_SAVE_0), true); m_save.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { save(); } }); m_save.setEnabled(false); context.addToolbarButton(m_save); Button undo = CmsToolBar.createButton(FontOpenCms.UNDO, messages.key(Messages.GUI_BUTTON_UNDO_0), true); context.addToolbarButton(undo); Button redo = CmsToolBar.createButton(FontOpenCms.REDO, messages.key(Messages.GUI_BUTTON_REDO_0), true); context.addToolbarButton(redo); m_codeMirror.registerUndoRedo(undo, redo); Button search = CmsToolBar.createButton(FontOpenCms.SEARCH, messages.key(Messages.GUI_BUTTON_SEARCH_0), true); context.addToolbarButton(search); Button replace = CmsToolBar.createButton(FontOpenCms.SEARCH_REPLACE, messages.key(Messages.GUI_BUTTON_REPLACE_0), true); context.addToolbarButton(replace); m_codeMirror.registerSearchReplace(search, replace); EditorSettings settings; try { settings = OpenCms.getWorkplaceAppManager().getAppSettings(A_CmsUI.getCmsObject(), EditorSettings.class); } catch (Exception e) { settings = new EditorSettings(); } final Button toggleHighlight = CmsToolBar.createButton(FontOpenCms.HIGHLIGHT, messages.key(Messages.GUI_BUTTON_TOGGLE_HIGHLIGHTING_0)); toggleHighlight.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { Button b = event.getButton(); boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED); if (pressed) { b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { b.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } m_codeMirror.setHighlighting(!pressed); } }); if (settings.m_highlighting) { m_codeMirror.setHighlighting(true); toggleHighlight.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { m_codeMirror.setHighlighting(false); } context.addToolbarButtonRight(toggleHighlight); final Button toggleLineWrap = CmsToolBar.createButton(FontOpenCms.WRAP_LINES, messages.key(Messages.GUI_BUTTON_TOGGLE_LINE_WRAPPING_0)); toggleLineWrap.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { Button b = event.getButton(); boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED); if (pressed) { b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { b.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } m_codeMirror.setLineWrapping(!pressed); } }); if (settings.m_lineWrapping) { m_codeMirror.setLineWrapping(true); toggleLineWrap.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { m_codeMirror.setLineWrapping(false); } context.addToolbarButtonRight(toggleLineWrap); final Button toggleBrackets = CmsToolBar.createButton(FontOpenCms.BRACKETS, messages.key(Messages.GUI_BUTTON_TOBBLE_BRACKET_AUTOCLOSE_0)); toggleBrackets.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { Button b = event.getButton(); boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED); if (pressed) { b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { b.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } m_codeMirror.setCloseBrackets(!pressed); } }); if (settings.m_closeBrackets) { m_codeMirror.setCloseBrackets(true); toggleBrackets.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { m_codeMirror.setCloseBrackets(false); } context.addToolbarButtonRight(toggleBrackets); final Button toggleTabs = CmsToolBar.createButton(FontOpenCms.INVISIBLE_CHARS, messages.key(Messages.GUI_BUTTON_TOGGLE_TAB_VISIBILITY_0)); toggleTabs.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { Button b = event.getButton(); boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED); if (pressed) { b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { b.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } m_codeMirror.setTabsVisible(!pressed); } }); if (settings.m_tabsVisible) { m_codeMirror.setTabsVisible(true); toggleTabs.addStyleName(OpenCmsTheme.BUTTON_PRESSED); } else { m_codeMirror.setTabsVisible(false); } context.addToolbarButtonRight(toggleTabs); ComboBox modeSelect = new ComboBox(); modeSelect.setWidth("115px"); modeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD); modeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON); modeSelect.setNullSelectionAllowed(false); modeSelect.setImmediate(true); modeSelect.setNewItemsAllowed(false); for (CodeMirrorLanguage lang : CodeMirrorLanguage.values()) { modeSelect.addItem(lang); modeSelect.setItemCaption(lang, lang.name()); } CodeMirrorLanguage lang = getHighlightMode(resource); modeSelect.setValue(lang); m_codeMirror.setLanguage(lang); modeSelect.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; public void valueChange(ValueChangeEvent event) { m_codeMirror.setLanguage((CodeMirrorLanguage) event.getProperty().getValue()); } }); context.addToolbarButtonRight(modeSelect); ComboBox fontSizeSelect = new ComboBox(); fontSizeSelect.setWidth("75px"); fontSizeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD); fontSizeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON); fontSizeSelect.setNullSelectionAllowed(false); fontSizeSelect.setImmediate(true); fontSizeSelect.setNewItemsAllowed(false); for (int i = 0; i < FONT_SIZES.length; i++) { fontSizeSelect.addItem(FONT_SIZES[i]); } fontSizeSelect.setValue(settings.m_fontSize); fontSizeSelect.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; public void valueChange(ValueChangeEvent event) { m_codeMirror.setFontSize((String) event.getProperty().getValue()); } }); context.addToolbarButtonRight(fontSizeSelect); m_codeMirror.setFontSize(settings.m_fontSize); m_exit = CmsToolBar.createButton(FontOpenCms.EXIT, messages.key(Messages.GUI_BUTTON_CANCEL_0), true); m_exit.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { exit(); } }); context.addToolbarButtonRight(m_exit); try { m_file = LockedFile.lockResource(A_CmsUI.getCmsObject(), resource); String content = new String(m_file.getFile().getContents(), m_file.getEncoding()); m_codeMirror.setValue(content); } catch (Exception e) { CmsErrorDialog.showErrorDialog(e); } m_codeMirror.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; public void valueChange(ValueChangeEvent event) { onChange((String) event.getProperty().getValue()); } }); }
From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorOptions.java
License:Open Source License
/** * Initializes the language switcher UI Component {@link #m_languageSwitch}, including {@link #m_languageSelect}. * @param locales the locales that can be selected. * @param current the currently selected locale. *///from w w w.j a v a2 s . c o m private void initLanguageSwitch(Collection<Locale> locales, Locale current) { FormLayout languages = new FormLayout(); languages.setHeight("100%"); languages.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); ComboBox languageSelect = new ComboBox(); languageSelect.setCaption(m_messages.key(Messages.GUI_LANGUAGE_SWITCHER_LABEL_0)); languageSelect.setNullSelectionAllowed(false); // set Locales for (Locale locale : locales) { languageSelect.addItem(locale); String caption = locale.getDisplayName(UI.getCurrent().getLocale()); if (CmsLocaleManager.getDefaultLocale().equals(locale)) { caption += " (" + Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_DEFAULT_LOCALE_0) + ")"; } languageSelect.setItemCaption(locale, caption); } languageSelect.setValue(current); languageSelect.setNewItemsAllowed(false); languageSelect.setTextInputAllowed(false); languageSelect.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1L; public void valueChange(ValueChangeEvent event) { m_listener.handleLanguageChange((Locale) event.getProperty().getValue()); } }); if (locales.size() == 1) { languageSelect.setEnabled(false); } languages.addComponent(languageSelect); m_languageSwitch = languages; }
From source file:org.opennms.features.vaadin.config.DataCollectionGroupAdminPanel.java
License:Open Source License
/** * Instantiates a new data collection group administration panel. * * @param dataCollectionDao the OpenNMS data collection configuration DAO *///from w ww. j a v a 2 s . c o m public DataCollectionGroupAdminPanel(final DataCollectionConfigDao dataCollectionDao) { setCaption("Data Collection Groups"); final HorizontalLayout toolbar = new HorizontalLayout(); toolbar.setMargin(true); final Label comboLabel = new Label("Select Data Collection Group File"); toolbar.addComponent(comboLabel); toolbar.setComponentAlignment(comboLabel, Alignment.MIDDLE_LEFT); final File datacollectionDir = new File(ConfigFileConstants.getFilePathString(), "datacollection"); final ComboBox dcGroupSource = new ComboBox(); toolbar.addComponent(dcGroupSource); dcGroupSource.setImmediate(true); dcGroupSource.setNullSelectionAllowed(false); dcGroupSource.setContainerDataSource(new XmlFileContainer(datacollectionDir, false)); dcGroupSource.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME); dcGroupSource.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 data collection data from {}", file); DatacollectionGroup dcGroup = JaxbUtils.unmarshal(DatacollectionGroup.class, file); m_selectedGroup = dcGroup.getName(); addDataCollectionGroupPanel(dataCollectionDao, file, dcGroup); } catch (Exception e) { LOG.error("an error ocurred while parsing the data collection configuration {}: {}", file, e.getMessage(), e); Notification.show("Can't parse file " + file + " because " + e.getMessage()); } } }); final Button add = new Button("Add New Data Collection File"); toolbar.addComponent(add); add.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { PromptWindow w = new PromptWindow("New Data Collection Group", "Group Name") { @Override public void textFieldChanged(String fieldValue) { File file = new File(datacollectionDir, fieldValue.replaceAll(" ", "_") + ".xml"); LOG.info("Adding new data collection file {}", file); DatacollectionGroup dcGroup = new DatacollectionGroup(); dcGroup.setName(fieldValue); addDataCollectionGroupPanel(dataCollectionDao, file, dcGroup); } }; getUI().addWindow(w); } }); final Button remove = new Button("Remove Selected Data Collection File"); toolbar.addComponent(remove); remove.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (dcGroupSource.getValue() == null) { Notification.show("Please select a data collection group configuration file."); return; } final File file = (File) dcGroupSource.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 collect the metrics defined 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 datacollection-config.xml File configFile = ConfigFileConstants .getFile(ConfigFileConstants.DATA_COLLECTION_CONF_FILE_NAME); DatacollectionConfig config = JaxbUtils .unmarshal(DatacollectionConfig.class, configFile); boolean modified = false; for (SnmpCollection collection : config.getSnmpCollections()) { for (Iterator<IncludeCollection> it = collection .getIncludeCollections().iterator(); it.hasNext();) { IncludeCollection ic = it.next(); if (m_selectedGroup != null && m_selectedGroup .equals(ic.getDataCollectionGroup())) { it.remove(); modified = true; } } } if (modified) { LOG.info("updating data colleciton configuration on {}.", configFile); JaxbUtils.marshal(config, new FileWriter(configFile)); } // Updating UI Components dcGroupSource.select(null); removeDataCollectionGroupPanel(); } catch (Exception e) { LOG.error( "an error ocurred while saving the data collection configuration: {}", e.getMessage(), e); Notification.show( "Can't save data collection configuration. " + e.getMessage(), Notification.Type.ERROR_MESSAGE); } } else { Notification.show("Cannot delete file " + file, Notification.Type.WARNING_MESSAGE); } } } }); } }); addComponent(toolbar); addComponent(new Label("")); setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT); }
From source file:org.opennms.features.vaadin.config.EventAdminApplication.java
License:Open Source License
@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);//from w w w .ja v a 2 s . c o m 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); container.addExcludeFile("default.events.xml"); // This is a protected file, should not be updated. 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.getEventFileCollection() .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); }
From source file:org.opennms.features.vaadin.datacollection.IncludeCollectionWindow.java
License:Open Source License
/** * Instantiates a new include collection window. * //from w w w .ja v a 2 s . c o m * @param dataCollectionConfigDao the data collection configuration DAO * @param container the source list of elements * @param wrapper the current selected value */ public IncludeCollectionWindow(final DataCollectionConfigDao dataCollectionConfigDao, final OnmsBeanContainer<IncludeCollectionWrapper> container, final IncludeCollectionWrapper wrapper) { setCaption("Include SystemDef/DataCollectionGroup"); setModal(true); setWidth("400px"); setHeight("2000px"); setResizable(false); setClosable(false); addStyleName("dialog"); final ComboBox valueField = new ComboBox("Value"); valueField.setEnabled(false); valueField.setRequired(true); valueField.setImmediate(true); valueField.setNewItemsAllowed(false); valueField.setNullSelectionAllowed(false); final ComboBox typeField = new ComboBox("Type"); typeField.setRequired(true); typeField.setImmediate(true); typeField.setNewItemsAllowed(false); typeField.setNullSelectionAllowed(false); typeField.addItem(IncludeCollectionWrapper.DC_GROUP); typeField.addItem(IncludeCollectionWrapper.SYSTEM_DEF); typeField.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { String selected = (String) typeField.getValue(); if (selected == null) { return; } // Get available fields. // FIXME If a new dcGroup is added, DataCollectionConfigDao is not able to reach it. List<String> values = selected.equals(IncludeCollectionWrapper.SYSTEM_DEF) ? dataCollectionConfigDao.getAvailableSystemDefs() : dataCollectionConfigDao.getAvailableDataCollectionGroups(); // Remove already selected for (IncludeCollectionWrapper obj : container.getOnmsBeans()) { if (obj.getType().equals(selected)) { values.remove(obj.getValue()); } } // Updating combo-box valueField.removeAllItems(); for (String v : values) { valueField.addItem(v); } if (wrapper.getValue() != null) { valueField.addItem(wrapper.getValue()); } valueField.setEnabled(valueField.getItemIds().size() > 1); } }); formLayout.setImmediate(true); formLayout.setWidth("100%"); formLayout.addComponent(typeField); formLayout.addComponent(valueField); formEditor.bind(typeField, "type"); formEditor.bind(valueField, "value"); formEditor.setItemDataSource(wrapper); final HorizontalLayout toolbar = new HorizontalLayout(); toolbar.addComponent(okButton); toolbar.addComponent(cancelButton); final VerticalLayout layout = new VerticalLayout(); layout.addComponent(formLayout); layout.addComponent(toolbar); layout.setComponentAlignment(toolbar, Alignment.BOTTOM_RIGHT); layout.setMargin(true); setContent(layout); }
From source file:org.ow2.sirocco.cloudmanager.MyUI.java
License:Open Source License
@Override protected void init(final VaadinRequest request) { this.userName = request.getUserPrincipal().getName(); this.identityContext.setUserName(this.userName); this.getPage().setTitle("Sirocco Dashboard"); final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull();//from w w w. ja v a2s.c o m this.setContent(layout); // Top header ********************* HorizontalLayout header = new HorizontalLayout(); header.setMargin(true); header.setWidth("100%"); header.setHeight("70px"); header.setStyleName("topHeader"); // logo Image image = new Image(null, new ThemeResource("img/sirocco_small_logo.png")); header.addComponent(image); // spacer Label spacer = new Label(); spacer.setWidth("100%"); header.addComponent(spacer); header.setExpandRatio(spacer, 1.0f); HorizontalLayout rightButtons = new HorizontalLayout(); rightButtons.setStyleName("topHeader"); rightButtons.setSpacing(true); this.userName = request.getUserPrincipal().getName(); User user = null; try { user = this.userManager.getUserByUsername(this.userName); } catch (CloudProviderException e) { e.printStackTrace(); } Label label = new Label("Tenant:"); label.setStyleName("topHeaderLabel"); rightButtons.addComponent(label); final ComboBox tenantSelect = new ComboBox(); tenantSelect.setTextInputAllowed(false); tenantSelect.setNullSelectionAllowed(false); for (Tenant tenant : user.getTenants()) { tenantSelect.addItem(tenant.getName()); } tenantSelect.setValue(user.getTenants().iterator().next().getName()); tenantSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent event) { Notification.show("Switching to tenant " + tenantSelect.getValue()); } }); tenantSelect.setImmediate(true); rightButtons.addComponent(tenantSelect); this.tenantId = user.getTenants().iterator().next().getUuid(); this.identityContext.setTenantId(this.tenantId); // logged user name label = new Label("Logged in as: " + this.userName); label.setStyleName("topHeaderLabel"); rightButtons.addComponent(label); // sign out button Button button = new Button("Sign Out"); // button.setStyleName(BaseTheme.BUTTON_LINK); button.addClickListener(new Button.ClickListener() { public void buttonClick(final ClickEvent event) { MyUI.this.logout(); } }); rightButtons.addComponent(button); header.addComponent(rightButtons); layout.addComponent(header); // Split view HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); splitPanel.setSizeFull(); splitPanel.setFirstComponent(this.createLeftMenu()); this.inventoryContainer = new VerticalLayout(); this.inventoryContainer.setSizeFull(); this.inventoryContainer.addComponent(this.machineView); splitPanel.setSecondComponent(this.inventoryContainer); splitPanel.setSplitPosition(15); layout.addComponent(splitPanel); layout.setExpandRatio(splitPanel, 1.0f); this.listenToNotifications(); }
From source file:org.ripla.web.demo.widgets.views.SelectionWidgetsView.java
License:Open Source License
public SelectionWidgetsView(final CountryContainer inCountries) { super();/*from www. j a v a 2 s . co m*/ final IMessages lMessages = Activator.getMessages(); final VerticalLayout lLayout = initLayout(lMessages, "widgets.title.page.select"); //$NON-NLS-1$ final HorizontalLayout lColumns = new HorizontalLayout(); lColumns.setSpacing(true); lLayout.addComponent(lColumns); final VerticalLayout lCol1 = new VerticalLayout(); lCol1.setSizeUndefined(); lColumns.addComponent(lCol1); final VerticalLayout lCol2 = new VerticalLayout(); lCol2.setSizeUndefined(); lColumns.addComponent(lCol2); final VerticalLayout lCol3 = new VerticalLayout(); lCol3.setSizeUndefined(); lColumns.addComponent(lCol3); lColumns.setExpandRatio(lCol3, 1); lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.list"))); //$NON-NLS-1$ final ListSelect lList1 = new ListSelect(null, inCountries); lList1.setItemCaptionMode(ItemCaptionMode.ID); lList1.setRows(10); lList1.setMultiSelect(true); lList1.setNullSelectionAllowed(false); lList1.select(inCountries.getIdByIndex(0)); lList1.setImmediate(true); lList1.addValueChangeListener(new Listener()); lCol1.addComponent(lList1); lCol1.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.combox"))); //$NON-NLS-1$ final ComboBox lCombo = new ComboBox(null, inCountries); lCombo.setInputPrompt(lMessages.getMessage("widgets.selection.combox.prompt")); //$NON-NLS-1$ lCombo.setNullSelectionAllowed(false); lCombo.setFilteringMode(FilteringMode.STARTSWITH); lCombo.setImmediate(true); lCombo.addValueChangeListener(new Listener()); lCol1.addComponent(lCombo); lCol2.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.options.single"))); //$NON-NLS-1$ List<String> lCountries = getRandomSubset(inCountries, OPTION_SIZE, System.currentTimeMillis()); final OptionGroup lOptions1 = new OptionGroup(null, lCountries); lOptions1.setNullSelectionAllowed(false); lOptions1.select(lCountries.get(0)); lOptions1.setImmediate(true); lOptions1.addValueChangeListener(new Listener()); lCol2.addComponent(lOptions1); lCol2.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.options.multiple"))); //$NON-NLS-1$ lCountries = getRandomSubset(inCountries, OPTION_SIZE, System.currentTimeMillis() + 2000); final OptionGroup lOptions2 = new OptionGroup(null, lCountries); lOptions2.setNullSelectionAllowed(false); lOptions2.setMultiSelect(true); lOptions2.select(lCountries.get(0)); lOptions2.setImmediate(true); lOptions2.addValueChangeListener(new Listener()); lCol2.addComponent(lOptions2); lCol3.addComponent(getSubtitle(lMessages.getMessage("widgets.selection.subtitle.twin"))); //$NON-NLS-1$ final TwinColSelect lCountrySelect = new TwinColSelect(); lCountrySelect.setContainerDataSource(inCountries); lCountrySelect.setRows(OPTION_SIZE); lCountrySelect.setNullSelectionAllowed(true); lCountrySelect.setMultiSelect(true); lCountrySelect.setWidth(400, Unit.PIXELS); lCol3.addComponent(lCountrySelect); }