Search in sources :

Example 26 with ComboBox

use of com.vaadin.ui.ComboBox in project cuba by cuba-platform.

the class SettingsWindow method init.

@Override
public void init(Map<String, Object> params) {
    Boolean changeThemeEnabledParam = (Boolean) params.get("changeThemeEnabled");
    if (changeThemeEnabledParam != null) {
        changeThemeEnabled = changeThemeEnabledParam;
    }
    AppWorkArea.Mode mode = userSettingsTools.loadAppWindowMode();
    msgTabbed = getMessage("modeTabbed");
    msgSingle = getMessage("modeSingle");
    modeOptions.setOptionsList(Arrays.asList(msgTabbed, msgSingle));
    if (mode == AppWorkArea.Mode.TABBED)
        modeOptions.setValue(msgTabbed);
    else
        modeOptions.setValue(msgSingle);
    ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME);
    Set<String> supportedThemes = themeRepository.getAvailableThemes();
    appThemeField.setOptionsList(new ArrayList<>(supportedThemes));
    String userAppTheme = userSettingsTools.loadAppWindowTheme();
    appThemeField.setValue(userAppTheme);
    ComboBox vAppThemeField = (ComboBox) WebComponentsHelper.unwrap(appThemeField);
    vAppThemeField.setTextInputAllowed(false);
    appThemeField.setEditable(changeThemeEnabled);
    initTimeZoneFields();
    User user = userSession.getUser();
    changePasswordBtn.setAction(new BaseAction("changePassw").withCaption(getMessage("changePassw")).withHandler(event -> {
        Window passwordDialog = openWindow("sec$User.changePassword", OpenType.DIALOG, ParamsMap.of("currentPasswordRequired", true));
        passwordDialog.addCloseListener(actionId -> {
            // move focus back to window
            changePasswordBtn.requestFocus();
        });
    }));
    if (!user.equals(userSession.getCurrentOrSubstitutedUser()) || ExternalUserCredentials.isLoggedInWithExternalAuth(userSession)) {
        changePasswordBtn.setEnabled(false);
    }
    Map<String, Locale> locales = globalConfig.getAvailableLocales();
    TreeMap<String, Object> options = new TreeMap<>();
    for (Map.Entry<String, Locale> entry : locales.entrySet()) {
        options.put(entry.getKey(), messages.getTools().localeToString(entry.getValue()));
    }
    appLangField.setOptionsMap(options);
    appLangField.setValue(userManagementService.loadOwnLocale());
    Action commitAction = new BaseAction("commit").withCaption(messages.getMainMessage("actions.Ok")).withShortcut(clientConfig.getCommitShortcut()).withHandler(event -> commit());
    addAction(commitAction);
    okBtn.setAction(commitAction);
    cancelBtn.setAction(new BaseAction("cancel").withCaption(messages.getMainMessage("actions.Cancel")).withHandler(event -> cancel()));
    initDefaultScreenField();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) MenuConfig(com.haulmont.cuba.gui.config.MenuConfig) UserSettingsTools(com.haulmont.cuba.web.app.UserSettingsTools) ComboBox(com.vaadin.ui.ComboBox) ParamsMap(com.haulmont.bali.util.ParamsMap) AppBeans(com.haulmont.cuba.core.global.AppBeans) CollectionUtils(org.apache.commons.collections4.CollectionUtils) UserSession(com.haulmont.cuba.security.global.UserSession) Inject(javax.inject.Inject) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) GlobalConfig(com.haulmont.cuba.core.global.GlobalConfig) ClientType(com.haulmont.cuba.core.global.ClientType) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) UserSettingService(com.haulmont.cuba.security.app.UserSettingService) TimeZones(com.haulmont.cuba.core.global.TimeZones) App(com.haulmont.cuba.web.App) UserManagementService(com.haulmont.cuba.security.app.UserManagementService) User(com.haulmont.cuba.security.entity.User) WebComponentsHelper(com.haulmont.cuba.web.gui.components.WebComponentsHelper) WebConfig(com.haulmont.cuba.web.WebConfig) MenuItem(com.haulmont.cuba.gui.config.MenuItem) ExternalUserCredentials(com.haulmont.cuba.web.security.ExternalUserCredentials) ClientConfig(com.haulmont.cuba.client.ClientConfig) UserTimeZone(com.haulmont.cuba.security.app.UserTimeZone) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) User(com.haulmont.cuba.security.entity.User) ComboBox(com.vaadin.ui.ComboBox) ThemeConstantsRepository(com.haulmont.cuba.gui.theme.ThemeConstantsRepository) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 27 with ComboBox

use of com.vaadin.ui.ComboBox in project cuba by cuba-platform.

the class ServerLogWindow method init.

@Override
public void init(Map<String, Object> params) {
    localJmxField.setValue(jmxControlAPI.getLocalNodeName());
    localJmxField.setEditable(false);
    localJmxInstance = jmxControlAPI.getLocalInstance();
    jmxInstancesDs.refresh();
    jmxConnectionField.setValue(localJmxInstance);
    jmxConnectionField.setRequired(true);
    jmxConnectionField.addValueChangeListener(e -> {
        JmxInstance jmxInstance = (JmxInstance) e.getValue();
        try {
            refreshHostInfo();
        } catch (JmxControlException ex) {
            showNotification(getMessage("exception.unableToConnectToInterface"), NotificationType.WARNING);
            if (jmxInstance != localJmxInstance) {
                jmxConnectionField.setValue(localJmxInstance);
            }
        }
    });
    autoRefreshCheck.addValueChangeListener(e -> {
        if (Boolean.TRUE.equals(e.getValue())) {
            updateLogTailTimer.start();
        } else {
            updateLogTailTimer.stop();
        }
    });
    jmxConnectionField.removeAllActions();
    LookupAction action = LookupAction.create(jmxConnectionField);
    action.setAfterLookupCloseHandler((window, actionId) -> {
        jmxInstancesDs.refresh();
    });
    jmxConnectionField.addAction(action);
    jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
        JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
        instanceEditor.addCloseListener(actionId -> {
            if (COMMIT_ACTION_ID.equals(actionId)) {
                jmxInstancesDs.refresh();
                jmxConnectionField.setValue(instanceEditor.getItem());
            }
        });
    }));
    logTailLabel.setSizeAuto();
    logTailLabel.setHtmlEnabled(true);
    logTailLabel.setStyleName("c-log-content");
    loggerLevelField.setOptionsList(LoggingHelper.getLevels());
    appenderLevelField.setOptionsList(LoggingHelper.getLevels());
    refreshHostInfo();
    loggerNameField.addValueChangeListener(e -> {
        List<String> currentLoggers = new ArrayList<>(jmxRemoteLoggingAPI.getLoggerNames(getSelectedConnection()));
        Collections.sort(currentLoggers);
        currentLoggers.add(0, getMessage("logger.new"));
        if (e.getValue() != null && e.getValue().equals(currentLoggers.get(0))) {
            openAddLoggerDialog();
        }
    });
    downloadButton.setEnabled(security.isSpecificPermitted("cuba.gui.administration.downloadlogs"));
    ComboBox comboBox = logFileNameField.unwrap(ComboBox.class);
    comboBox.addShortcutListener(new ShortcutListener("", KeyCode.D, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {

        @Override
        public void handleAction(Object sender, Object target) {
            downloadLog();
        }
    });
    comboBox.addShortcutListener(new ShortcutListener("", KeyCode.S, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {

        @Override
        public void handleAction(Object sender, Object target) {
            showLogTail();
        }
    });
    downloadButton.setDescription("CTRL-SHIFT-D");
    showTailButton.setDescription("CTRL-SHIFT-S");
}
Also used : LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) Security(com.haulmont.cuba.core.global.Security) ComboBox(com.vaadin.ui.ComboBox) LoggerFactory(org.slf4j.LoggerFactory) ParamsMap(com.haulmont.bali.util.ParamsMap) Settings(com.haulmont.cuba.gui.settings.Settings) Timer(com.haulmont.cuba.gui.components.Timer) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) JmxControlAPI(com.haulmont.cuba.web.jmx.JmxControlAPI) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) LogArchiver(com.haulmont.cuba.core.sys.logging.LogArchiver) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) Logger(org.slf4j.Logger) LoggingHelper(com.haulmont.cuba.core.sys.logging.LoggingHelper) LogDataProvider(com.haulmont.cuba.web.export.LogDataProvider) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) IOException(java.io.IOException) JmxRemoteLoggingAPI(com.haulmont.cuba.web.jmx.JmxRemoteLoggingAPI) CubaScrollBoxLayout(com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Level(ch.qos.logback.classic.Level) ModifierKey(com.vaadin.event.ShortcutAction.ModifierKey) StringReader(java.io.StringReader) AppConfig(com.haulmont.cuba.gui.AppConfig) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) ShortcutListener(com.vaadin.event.ShortcutListener) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) BufferedReader(java.io.BufferedReader) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ComboBox(com.vaadin.ui.ComboBox) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) ShortcutListener(com.vaadin.event.ShortcutListener) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 28 with ComboBox

use of com.vaadin.ui.ComboBox in project cuba by cuba-platform.

the class WebComponentsUtils method allowNullSelection.

@Deprecated
public static void allowNullSelection(LookupField lookupField) {
    ComboBox vCombobox = (ComboBox) WebComponentsHelper.unwrap(lookupField);
    vCombobox.setNullSelectionAllowed(true);
}
Also used : ComboBox(com.vaadin.ui.ComboBox)

Example 29 with ComboBox

use of com.vaadin.ui.ComboBox in project opennms by OpenNMS.

the class ShowNCSPathOperation method execute.

@Override
public void execute(List<VertexRef> targets, final OperationContext operationContext) {
    // Get the current NCS criteria from here you can get the foreignIds foreignSource and deviceA and Z
    for (Criteria criterium : operationContext.getGraphContainer().getCriteria()) {
        try {
            NCSServiceCriteria ncsCriterium = (NCSServiceCriteria) criterium;
            if (ncsCriterium.getServiceCount() > 0) {
                m_storedCriteria = ncsCriterium;
                break;
            }
        } catch (ClassCastException e) {
        }
    }
    final VertexRef defaultVertRef = targets.get(0);
    final SelectionManager selectionManager = operationContext.getGraphContainer().getSelectionManager();
    // selectionManager.getSelectedVertexRefs();
    final Collection<VertexRef> vertexRefs = getVertexRefsForNCSService(m_storedCriteria);
    final UI mainWindow = operationContext.getMainWindow();
    final Window ncsPathPrompt = new Window("Show NCS Path");
    ncsPathPrompt.setModal(true);
    ncsPathPrompt.setResizable(false);
    ncsPathPrompt.setWidth("300px");
    ncsPathPrompt.setHeight("220px");
    // Items used in form field
    final PropertysetItem item = new PropertysetItem();
    item.addItemProperty("Device A", new ObjectProperty<String>("", String.class));
    item.addItemProperty("Device Z", new ObjectProperty<String>("", String.class));
    FormFieldFactory fieldFactory = new FormFieldFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public Field<?> createField(Item item, Object propertyId, Component uiContext) {
            String pid = (String) propertyId;
            ComboBox select = new ComboBox();
            for (VertexRef vertRef : vertexRefs) {
                select.addItem(vertRef.getId());
                select.setItemCaption(vertRef.getId(), vertRef.getLabel());
            }
            select.setNewItemsAllowed(false);
            select.setNullSelectionAllowed(false);
            select.setImmediate(true);
            select.setScrollToSelectedItem(true);
            if ("Device A".equals(pid)) {
                select.setCaption("Device A");
            } else {
                select.setCaption("Device Z");
            }
            return select;
        }
    };
    final Form promptForm = new Form() {

        @Override
        public void commit() {
            String deviceA = (String) getField("Device A").getValue();
            String deviceZ = (String) getField("Device Z").getValue();
            if (deviceA.equals(deviceZ)) {
                Notification.show("Device A and Device Z cannot be the same", Notification.Type.WARNING_MESSAGE);
                throw new Validator.InvalidValueException("Device A and Device Z cannot be the same");
            }
            OnmsNode nodeA = m_nodeDao.get(Integer.valueOf(deviceA));
            String deviceANodeForeignId = nodeA.getForeignId();
            // Use nodeA's foreignSource, deviceZ should have the same foreignSource. It's an assumption
            // which might need to changed in the future. Didn't want to hard code it it "space" if they
            // change it in the future
            String nodeForeignSource = nodeA.getForeignSource();
            String deviceZNodeForeignId = m_nodeDao.get(Integer.valueOf(deviceZ)).getForeignId();
            NCSComponent ncsComponent = m_dao.get(m_storedCriteria.getServiceIds().get(0));
            String foreignSource = ncsComponent.getForeignSource();
            String foreignId = ncsComponent.getForeignId();
            String serviceName = ncsComponent.getName();
            try {
                NCSServicePath path = getNcsPathProvider().getPath(foreignId, foreignSource, deviceANodeForeignId, deviceZNodeForeignId, nodeForeignSource, serviceName);
                if (path.getStatusCode() == 200) {
                    NCSServicePathCriteria criteria = new NCSServicePathCriteria(path.getEdges());
                    m_serviceManager.registerCriteria(criteria, operationContext.getGraphContainer().getSessionId());
                    // Select only the vertices in the path
                    selectionManager.setSelectedVertexRefs(path.getVertices());
                } else {
                    LoggerFactory.getLogger(this.getClass()).warn("An error occured while retrieving the NCS Path, Juniper NetworkAppsApi send error code: " + path.getStatusCode());
                    mainWindow.showNotification("An error occurred while retrieving the NCS Path\nStatus Code: " + path.getStatusCode(), Notification.TYPE_ERROR_MESSAGE);
                }
            } catch (Exception e) {
                if (e.getCause() instanceof ConnectException) {
                    LoggerFactory.getLogger(this.getClass()).warn("Connection Exception Occurred while retreiving path {}", e);
                    Notification.show("Connection Refused when attempting to reach the NetworkAppsApi", Notification.Type.TRAY_NOTIFICATION);
                } else if (e.getCause() instanceof HttpOperationFailedException) {
                    HttpOperationFailedException httpException = (HttpOperationFailedException) e.getCause();
                    if (httpException.getStatusCode() == 401) {
                        LoggerFactory.getLogger(this.getClass()).warn("Authentication error when connecting to NetworkAppsApi {}", httpException);
                        Notification.show("Authentication error when connecting to NetworkAppsApi, please check the username and password", Notification.Type.TRAY_NOTIFICATION);
                    } else {
                        LoggerFactory.getLogger(this.getClass()).warn("An error occured while retrieving the NCS Path {}", httpException);
                        Notification.show("An error occurred while retrieving the NCS Path\n" + httpException.getMessage(), Notification.Type.TRAY_NOTIFICATION);
                    }
                } else if (e.getCause() instanceof Validator.InvalidValueException) {
                    Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE);
                } else {
                    LoggerFactory.getLogger(this.getClass()).warn("Exception Occurred while retreiving path {}", e);
                    Notification.show("An error occurred while calculating the path please check the karaf.log file for the exception: \n" + e.getMessage(), Notification.Type.TRAY_NOTIFICATION);
                }
            }
        }
    };
    promptForm.setBuffered(true);
    promptForm.setFormFieldFactory(fieldFactory);
    promptForm.setItemDataSource(item);
    Button ok = new Button("OK");
    ok.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -2742886456007926688L;

        @Override
        public void buttonClick(ClickEvent event) {
            promptForm.commit();
            mainWindow.removeWindow(ncsPathPrompt);
        }
    });
    promptForm.getFooter().addComponent(ok);
    Button cancel = new Button("Cancel");
    cancel.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -9026067481179449095L;

        @Override
        public void buttonClick(ClickEvent event) {
            mainWindow.removeWindow(ncsPathPrompt);
        }
    });
    promptForm.getFooter().addComponent(cancel);
    ncsPathPrompt.setContent(promptForm);
    mainWindow.addWindow(ncsPathPrompt);
    promptForm.getField("Device A").setValue(defaultVertRef.getId());
}
Also used : Form(com.vaadin.ui.Form) ClickEvent(com.vaadin.ui.Button.ClickEvent) PropertysetItem(com.vaadin.data.util.PropertysetItem) NCSServiceCriteria(org.opennms.features.topology.plugins.ncs.NCSEdgeProvider.NCSServiceCriteria) NCSServicePathCriteria(org.opennms.features.topology.plugins.ncs.NCSPathEdgeProvider.NCSServicePathCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) NCSServicePathCriteria(org.opennms.features.topology.plugins.ncs.NCSPathEdgeProvider.NCSServicePathCriteria) FormFieldFactory(com.vaadin.ui.FormFieldFactory) PropertysetItem(com.vaadin.data.util.PropertysetItem) Item(com.vaadin.data.Item) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) UI(com.vaadin.ui.UI) Button(com.vaadin.ui.Button) NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) Component(com.vaadin.ui.Component) ClickListener(com.vaadin.ui.Button.ClickListener) ConnectException(java.net.ConnectException) Window(com.vaadin.ui.Window) SelectionManager(org.opennms.features.topology.api.SelectionManager) OnmsNode(org.opennms.netmgt.model.OnmsNode) ComboBox(com.vaadin.ui.ComboBox) NCSServiceCriteria(org.opennms.features.topology.plugins.ncs.NCSEdgeProvider.NCSServiceCriteria) HttpOperationFailedException(org.apache.camel.component.http.HttpOperationFailedException) ConnectException(java.net.ConnectException) HttpOperationFailedException(org.apache.camel.component.http.HttpOperationFailedException) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Validator(com.vaadin.data.Validator)

Example 30 with ComboBox

use of com.vaadin.ui.ComboBox in project linkki by linkki-framework.

the class DynamicFieldBindingTest method testDynamicField_shouldBindToComboBox.

@Test
public void testDynamicField_shouldBindToComboBox() {
    String value = "semi-annual";
    Pmo pmo = new Pmo(new Model(value, true));
    Component component = TestUiUtil.createFirstComponentOf(pmo);
    assertNotNull(component);
    assertTrue(component instanceof ComboBox);
    ComboBox cb = (ComboBox) component;
    assertThat(cb.getContainerDataSource().getItemIds(), contains(pmo.getPaymentMethodAvailableValues().toArray()));
    assertThat(cb.getValue(), is(value));
    String newValue = "annual";
    cb.setValue(newValue);
    assertThat(pmo.model.paymentMethod, is(newValue));
    pmo.model.paymentMethod = null;
    assertThat(cb.getValue(), is(nullValue()));
}
Also used : UIComboBox(org.linkki.core.ui.section.annotations.UIComboBox) ComboBox(com.vaadin.ui.ComboBox) Component(com.vaadin.ui.Component) Test(org.junit.Test)

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