Search in sources :

Example 1 with WindowManager

use of com.haulmont.cuba.gui.WindowManager in project cuba by cuba-platform.

the class Param method createNumberField.

protected Component createNumberField(final Datatype datatype, final ValueProperty valueProperty) {
    if (inExpr) {
        ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
        listEditor.setItemType(ListEditorHelper.itemTypeFromDatatype(datatype));
        initListEditor(listEditor, valueProperty);
        return listEditor;
    }
    TextField field = componentsFactory.createComponent(TextField.class);
    field.addValueChangeListener(e -> {
        if (e.getValue() == null || e.getValue() instanceof Number) {
            _setValue(e.getValue(), valueProperty);
        } else if (e.getValue() instanceof String && !StringUtils.isBlank((String) e.getValue())) {
            UserSessionSource userSessionSource1 = AppBeans.get(UserSessionSource.NAME);
            Object v;
            try {
                v = datatype.parse((String) e.getValue(), userSessionSource1.getLocale());
            } catch (ParseException ex) {
                WindowManager wm = AppBeans.get(WindowManagerProvider.class).get();
                wm.showNotification(messages.getMainMessage("filter.param.numberInvalid"), Frame.NotificationType.TRAY);
                return;
            }
            _setValue(v, valueProperty);
        } else if (e.getValue() instanceof String && StringUtils.isBlank((String) e.getValue())) {
            _setValue(null, valueProperty);
        } else {
            throw new IllegalStateException("Invalid value: " + e.getValue());
        }
    });
    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
    // noinspection unchecked
    field.setValue(datatype.format(_getValue(valueProperty), sessionSource.getLocale()));
    return field;
}
Also used : WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) ParseException(java.text.ParseException) WindowManager(com.haulmont.cuba.gui.WindowManager)

Example 2 with WindowManager

use of com.haulmont.cuba.gui.WindowManager in project cuba by cuba-platform.

the class ChangePasswordLauncher method run.

@Override
public void run() {
    WindowManager wm = App.getInstance().getMainFrame().getWindowManager();
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    WindowInfo windowInfo = windowConfig.getWindowInfo("sec$User.changePassword");
    wm.openWindow(windowInfo, OpenType.DIALOG, ParamsMap.of("currentPasswordRequired", true));
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo)

Example 3 with WindowManager

use of com.haulmont.cuba.gui.WindowManager in project cuba by cuba-platform.

the class ListEditorDelegateImpl method init.

@PostConstruct
public void init() {
    WindowManager windowManager = windowManagerProvider.get();
    layout = componentsFactory.createComponent(HBoxLayout.class);
    layout.setStyleName("c-listeditor-layout");
    layout.setWidth("100%");
    displayValuesField = componentsFactory.createComponent(TextField.class);
    displayValuesField.setStyleName("c-listeditor-text");
    displayValuesField.setEditable(false);
    Button openEditorBtn = componentsFactory.createComponent(Button.class);
    openEditorBtn.setIconFromSet(CubaIcon.PICKERFIELD_LOOKUP);
    openEditorBtn.setStyleName("c-listeditor-button");
    openEditorBtn.setCaption("");
    openEditorBtn.setAction(new AbstractAction("openEditor") {

        @Override
        public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
            Map<String, Object> params = new HashMap<>();
            params.put("itemType", itemType);
            params.put("entityName", entityName);
            params.put("useLookupField", useLookupField);
            params.put("optionsList", optionsList);
            params.put("optionsMap", optionsMap);
            params.put("enumClass", enumClass);
            params.put("lookupScreen", lookupScreen);
            params.put("entityJoinClause", entityJoinClause);
            params.put("entityWhereClause", entityWhereClause);
            params.put("values", getValue());
            params.put("editable", editable);
            params.put("timeZone", timeZone);
            if (editorParamsSupplier != null) {
                Map<String, Object> additionalParams = getEditorParamsSupplier().get();
                if (additionalParams != null) {
                    params.putAll(additionalParams);
                }
            }
            ListEditorWindowController listEditorPopup = (ListEditorWindowController) windowManager.openWindow(windowConfig.getWindowInfo(editorWindowId), WindowManager.OpenType.DIALOG, params);
            listEditorPopup.addCloseListener(actionId -> {
                if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                    actualField.setValue(listEditorPopup.getValue());
                }
                ListEditor.EditorCloseEvent editorCloseEvent = new ListEditor.EditorCloseEvent(actionId, listEditorPopup);
                getEventRouter().fireEvent(ListEditor.EditorCloseListener.class, ListEditor.EditorCloseListener::editorClosed, editorCloseEvent);
            });
        }
    });
    layout.add(displayValuesField);
    layout.add(openEditorBtn);
    layout.expand(displayValuesField);
}
Also used : java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) PostConstruct(javax.annotation.PostConstruct) EventRouter(com.haulmont.bali.events.EventRouter) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) WindowManagerProvider(com.haulmont.cuba.gui.WindowManagerProvider) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Joiner(com.google.common.base.Joiner) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) WindowManager(com.haulmont.cuba.gui.WindowManager) PostConstruct(javax.annotation.PostConstruct)

Example 4 with WindowManager

use of com.haulmont.cuba.gui.WindowManager in project cuba by cuba-platform.

the class WebEntityLinkField method openEntityEditor.

protected void openEntityEditor() {
    Object value = getValue();
    Entity entity;
    if (value instanceof Entity) {
        entity = (Entity) value;
    } else {
        entity = datasource.getItem();
    }
    if (entity == null) {
        return;
    }
    WindowManager wm;
    Window window = ComponentsHelper.getWindow(this);
    if (window == null) {
        throw new IllegalStateException("Please specify Frame for EntityLinkField");
    } else {
        wm = window.getWindowManager();
    }
    if (screenOpenType.getOpenMode() == OpenMode.DIALOG && screenDialogParams != null) {
        wm.getDialogParams().copyFrom(screenDialogParams);
    }
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        Messages messages = AppBeans.get(Messages.NAME);
        wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
        return;
    }
    DataSupplier dataSupplier = window.getDsContext().getDataSupplier();
    entity = dataSupplier.reload(entity, View.MINIMAL);
    String windowAlias = screen;
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    if (windowAlias == null) {
        windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
    }
    final Window.Editor editor = wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType, screenParams != null ? screenParams : Collections.<String, Object>emptyMap());
    editor.addCloseListener(actionId -> {
        // move focus to component
        component.focus();
        if (Window.COMMIT_ACTION_ID.equals(actionId)) {
            Entity item = editor.getItem();
            afterCommitOpenedEntity(item);
        }
        if (screenCloseListener != null) {
            screenCloseListener.windowClosed(editor, actionId);
        }
    });
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Entity(com.haulmont.cuba.core.entity.Entity) Messages(com.haulmont.cuba.core.global.Messages) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) WindowManager(com.haulmont.cuba.gui.WindowManager)

Aggregations

WindowManager (com.haulmont.cuba.gui.WindowManager)4 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)3 WindowManagerProvider (com.haulmont.cuba.gui.WindowManagerProvider)2 Joiner (com.google.common.base.Joiner)1 EventRouter (com.haulmont.bali.events.EventRouter)1 Entity (com.haulmont.cuba.core.entity.Entity)1 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)1 Messages (com.haulmont.cuba.core.global.Messages)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 Window (com.haulmont.cuba.gui.components.Window)1 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)1 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)1 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)1 CubaIcon (com.haulmont.cuba.gui.icons.CubaIcon)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 ParseException (java.text.ParseException)1 java.util (java.util)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1