Search in sources :

Example 1 with AbstractEditor

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

the class LinkCellClickListener method onClick.

@Override
public void onClick(Entity rowItem, String columnId) {
    Table.Column column = table.getColumn(columnId);
    if (column.getXmlDescriptor() != null) {
        String invokeMethodName = column.getXmlDescriptor().attributeValue("linkInvoke");
        if (StringUtils.isNotEmpty(invokeMethodName)) {
            callControllerInvoke(rowItem, columnId, invokeMethodName);
            return;
        }
    }
    Entity entity;
    Object value = rowItem.getValueEx(columnId);
    if (value instanceof Entity) {
        entity = (Entity) value;
    } else {
        entity = rowItem;
    }
    WindowManager wm;
    Window window = ComponentsHelper.getWindow(table);
    if (window == null) {
        throw new IllegalStateException("Please specify Frame for Table");
    } else {
        wm = window.getWindowManager();
    }
    Messages messages = beanLocator.get(Messages.NAME, Messages.class);
    if (entity instanceof SoftDelete && ((SoftDelete) entity).isDeleted()) {
        wm.showNotification(messages.getMainMessage("OpenAction.objectIsDeleted"), Frame.NotificationType.HUMANIZED);
        return;
    }
    if (window.getFrameOwner() instanceof LegacyFrame) {
        LegacyFrame frameOwner = (LegacyFrame) window.getFrameOwner();
        DataSupplier dataSupplier = frameOwner.getDsContext().getDataSupplier();
        entity = dataSupplier.reload(entity, View.MINIMAL);
    } else {
        DataManager dataManager = beanLocator.get(DataManager.NAME, DataManager.class);
        entity = dataManager.reload(entity, View.MINIMAL);
    }
    WindowConfig windowConfig = beanLocator.get(WindowConfig.NAME, WindowConfig.class);
    String windowAlias = null;
    if (column.getXmlDescriptor() != null) {
        windowAlias = column.getXmlDescriptor().attributeValue("linkScreen");
    }
    if (StringUtils.isEmpty(windowAlias)) {
        windowAlias = windowConfig.getEditorScreenId(entity.getMetaClass());
    }
    OpenType screenOpenType = OpenType.THIS_TAB;
    if (column.getXmlDescriptor() != null) {
        String openTypeAttribute = column.getXmlDescriptor().attributeValue("linkScreenOpenType");
        if (StringUtils.isNotEmpty(openTypeAttribute)) {
            screenOpenType = OpenType.valueOf(openTypeAttribute);
        }
    }
    AbstractEditor editor = (AbstractEditor) wm.openEditor(windowConfig.getWindowInfo(windowAlias), entity, screenOpenType);
    editor.addCloseListener(actionId -> {
        // move focus to component
        table.focus();
        if (Window.COMMIT_ACTION_ID.equals(actionId)) {
            Entity editorItem = editor.getItem();
            handleEditorCommit(editorItem, rowItem, columnId);
        }
    });
}
Also used : Window(com.haulmont.cuba.gui.components.Window) Entity(com.haulmont.cuba.core.entity.Entity) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Table(com.haulmont.cuba.gui.components.Table) Messages(com.haulmont.cuba.core.global.Messages) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) DataManager(com.haulmont.cuba.core.global.DataManager) AbstractEditor(com.haulmont.cuba.gui.components.AbstractEditor) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Aggregations

Entity (com.haulmont.cuba.core.entity.Entity)1 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)1 DataManager (com.haulmont.cuba.core.global.DataManager)1 Messages (com.haulmont.cuba.core.global.Messages)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 AbstractEditor (com.haulmont.cuba.gui.components.AbstractEditor)1 Table (com.haulmont.cuba.gui.components.Table)1 Window (com.haulmont.cuba.gui.components.Window)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1