Search in sources :

Example 1 with Action

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

the class DesktopWindow method close.

@Override
public boolean close(final String actionId) {
    if (!forceClose) {
        if (!delegate.preClose(actionId))
            return false;
    }
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    if (!forceClose && isModified()) {
        final Committable committable = (getWrapper() instanceof Committable) ? (Committable) getWrapper() : (this instanceof Committable) ? (Committable) this : null;
        if ((committable != null) && clientConfig.getUseSaveConfirmation()) {
            windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("saveUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.OK, Status.PRIMARY).withCaption(messages.getMainMessage("closeUnsaved.save")).withHandler(event -> {
                committable.commitAndClose();
            }), new BaseAction("discard").withIcon("icons/cancel.png").withCaption(messages.getMainMessage("closeUnsaved.discard")).withHandler(event -> {
                committable.close(actionId, true);
            }), new DialogAction(Type.CANCEL).withIcon(null).withHandler(event -> {
                doAfterClose = null;
            }) });
        } else {
            windowManager.showOptionDialog(messages.getMainMessage("closeUnsaved.caption"), messages.getMainMessage("closeUnsaved"), MessageType.WARNING, new Action[] { new DialogAction(Type.YES).withHandler(event -> {
                getWrapper().close(actionId, true);
            }), new DialogAction(Type.NO, Status.PRIMARY).withHandler(event -> {
                doAfterClose = null;
            }) });
        }
        return false;
    }
    if (!clientConfig.getManualScreenSettingsSaving()) {
        if (delegate.getWrapper() != null) {
            delegate.getWrapper().saveSettings();
        } else {
            saveSettings();
        }
    }
    delegate.disposeComponents();
    windowManager.close(this);
    boolean res = onClose(actionId);
    if (res && doAfterClose != null) {
        doAfterClose.run();
    }
    stopTimers();
    userActionsLog.trace("Window {} was closed", getId());
    return res;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter) Datasource(com.haulmont.cuba.gui.data.Datasource) LoggerFactory(org.slf4j.LoggerFactory) Settings(com.haulmont.cuba.gui.settings.Settings) AppBeans(com.haulmont.cuba.core.global.AppBeans) Icons(com.haulmont.cuba.gui.icons.Icons) BooleanUtils(org.apache.commons.lang.BooleanUtils) Pair(com.haulmont.bali.datastruct.Pair) com.haulmont.cuba.gui(com.haulmont.cuba.gui) Window(com.haulmont.cuba.gui.components.Window) Configuration(com.haulmont.cuba.core.global.Configuration) DesktopWindowManager(com.haulmont.cuba.desktop.sys.DesktopWindowManager) EventRouter(com.haulmont.bali.events.EventRouter) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) AncestorEvent(javax.swing.event.AncestorEvent) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) TopLevelFrame(com.haulmont.cuba.desktop.TopLevelFrame) Frame(com.haulmont.cuba.gui.components.Frame) Status(com.haulmont.cuba.gui.components.Action.Status) DesktopConfig(com.haulmont.cuba.desktop.DesktopConfig) Messages(com.haulmont.cuba.core.global.Messages) ApplicationListener(org.springframework.context.ApplicationListener) DialogWindow(com.haulmont.cuba.desktop.sys.DialogWindow) List(java.util.List) ClientConfig(com.haulmont.cuba.client.ClientConfig) LayoutAdapter(com.haulmont.cuba.desktop.sys.layout.LayoutAdapter) JTabbedPaneExt(com.haulmont.cuba.desktop.sys.vcl.JTabbedPaneExt) Iterables(com.google.common.collect.Iterables) java.util(java.util) LookupSelectionChangeNotifier(com.haulmont.cuba.gui.components.LookupComponent.LookupSelectionChangeNotifier) Timer(com.haulmont.cuba.gui.components.Timer) ComponentSize(com.haulmont.cuba.desktop.gui.data.ComponentSize) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AncestorListener(javax.swing.event.AncestorListener) DesktopContainerHelper(com.haulmont.cuba.desktop.gui.data.DesktopContainerHelper) CC(net.miginfocom.layout.CC) Component(com.haulmont.cuba.gui.components.Component) DsContext(com.haulmont.cuba.gui.data.DsContext) Nullable(javax.annotation.Nullable) App(com.haulmont.cuba.desktop.App) UserActionsLogger(com.haulmont.cuba.gui.logging.UserActionsLogger) Logger(org.slf4j.Logger) MigLayout(net.miginfocom.swing.MigLayout) Type(com.haulmont.cuba.gui.components.DialogAction.Type) JTextComponent(javax.swing.text.JTextComponent) Preconditions(com.haulmont.bali.util.Preconditions) java.awt(java.awt) UiEventsMulticaster(com.haulmont.cuba.gui.events.sys.UiEventsMulticaster) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction) Element(org.dom4j.Element) MigLayoutHelper(com.haulmont.cuba.desktop.sys.layout.MigLayoutHelper) Action(com.haulmont.cuba.gui.components.Action) Entity(com.haulmont.cuba.core.entity.Entity) javax.swing(javax.swing) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ClientConfig(com.haulmont.cuba.client.ClientConfig)

Example 2 with Action

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

the class WebTree method setDatasource.

@Override
public void setDatasource(HierarchicalDatasource datasource) {
    Preconditions.checkNotNullArgument(datasource, "datasource is null");
    if (this.datasource != null) {
        throw new UnsupportedOperationException("Changing datasource is not supported by the Tree component");
    }
    this.datasource = datasource;
    this.hierarchyProperty = datasource.getHierarchyPropertyName();
    collectionDsListenersWrapper = createCollectionDsListenersWrapper();
    component.setContainerDataSource(new HierarchicalDsWrapper(datasource, collectionDsListenersWrapper));
    tryToAssignCaptionProperty();
    Security security = AppBeans.get(Security.NAME);
    if (security.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION)) {
        ShowInfoAction action = (ShowInfoAction) getAction(ShowInfoAction.ACTION_ID);
        if (action == null) {
            action = new ShowInfoAction();
            addAction(action);
        }
        action.setDatasource(datasource);
    }
    collectionDsListenersWrapper.bind(datasource);
    for (Action action : getActions()) {
        action.refreshState();
    }
    assignAutoDebugId();
}
Also used : ShowInfoAction(com.haulmont.cuba.gui.components.ShowInfoAction) ShowInfoAction(com.haulmont.cuba.gui.components.ShowInfoAction) Action(com.haulmont.cuba.gui.components.Action) Security(com.haulmont.cuba.core.global.Security) HierarchicalDsWrapper(com.haulmont.cuba.web.gui.data.HierarchicalDsWrapper)

Example 3 with Action

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

the class WebWidgetsTree method setDatasource.

@Override
public void setDatasource(HierarchicalDatasource datasource) {
    Preconditions.checkNotNullArgument(datasource, "datasource is null");
    if (this.datasource != null) {
        throw new UnsupportedOperationException("Changing datasource is not supported by the WidgetsTree component");
    }
    this.datasource = datasource;
    this.hierarchyProperty = datasource.getHierarchyPropertyName();
    collectionDsListenersWrapper = createCollectionDsListenersWrapper();
    HierarchicalDsWrapper wrapper = new HierarchicalDsWrapper(datasource, collectionDsListenersWrapper);
    component.setContainerDataSource(wrapper);
    for (Action action : getActions()) {
        action.refreshState();
    }
}
Also used : Action(com.haulmont.cuba.gui.components.Action) HierarchicalDsWrapper(com.haulmont.cuba.web.gui.data.HierarchicalDsWrapper)

Example 4 with Action

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

the class DesktopAbstractTable method setDatasource.

@Override
public void setDatasource(final CollectionDatasource datasource) {
    Preconditions.checkNotNullArgument(datasource, "datasource is null");
    final Collection<Object> properties;
    if (this.columns.isEmpty()) {
        MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
        MessageTools messageTools = AppBeans.get(MessageTools.NAME);
        Collection<MetaPropertyPath> paths = datasource.getView() != null ? // if a view is specified - use view properties
        metadataTools.getViewPropertyPaths(datasource.getView(), datasource.getMetaClass()) : // otherwise use only string properties from meta-class - the temporary solution for KeyValue datasources
        metadataTools.getPropertyPaths(datasource.getMetaClass()).stream().filter(mpp -> mpp.getRangeJavaClass().equals(String.class)).collect(Collectors.toList());
        for (MetaPropertyPath metaPropertyPath : paths) {
            MetaProperty property = metaPropertyPath.getMetaProperty();
            if (!property.getRange().getCardinality().isMany() && !metadataTools.isSystem(property)) {
                Table.Column column = new Table.Column(metaPropertyPath);
                String propertyName = property.getName();
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
                column.setCaption(messageTools.getPropertyCaption(propertyMetaClass, propertyName));
                column.setType(metaPropertyPath.getRangeJavaClass());
                Element element = DocumentHelper.createElement("column");
                column.setXmlDescriptor(element);
                addColumn(column);
            }
        }
    }
    properties = this.columns.keySet();
    this.datasource = datasource;
    collectionChangeListener = e -> {
        switch(e.getOperation()) {
            case CLEAR:
            case REFRESH:
                fieldDatasources.clear();
                break;
            case UPDATE:
            case REMOVE:
                for (Object entity : e.getItems()) {
                    fieldDatasources.remove(entity);
                }
                break;
            case ADD:
                // no action
                break;
        }
    };
    // noinspection unchecked
    datasource.addCollectionChangeListener(new WeakCollectionChangeListener(datasource, collectionChangeListener));
    initTableModel(datasource);
    initChangeListener();
    setColumnIdentifiers();
    if (isSortable()) {
        impl.setRowSorter(new RowSorterImpl(tableModel));
    }
    initSelectionListener(datasource);
    List<MetaPropertyPath> editableColumns = null;
    if (isEditable()) {
        editableColumns = new LinkedList<>();
    }
    MetaClass metaClass = datasource.getMetaClass();
    for (final Object property : properties) {
        final Table.Column column = this.columns.get(property);
        if (column != null) {
            if (column.isCollapsed() && getColumnControlVisible()) {
                TableColumn tableColumn = getColumn(column);
                if (tableColumn instanceof TableColumnExt) {
                    ((TableColumnExt) tableColumn).setVisible(false);
                }
            }
            if (editableColumns != null && column.isEditable() && (property instanceof MetaPropertyPath)) {
                MetaPropertyPath propertyPath = (MetaPropertyPath) property;
                if (security.isEntityAttrUpdatePermitted(metaClass, property.toString())) {
                    editableColumns.add(propertyPath);
                }
            }
        }
    }
    if (editableColumns != null && !editableColumns.isEmpty()) {
        setEditableColumns(editableColumns);
    }
    List<Object> columnsOrder = new ArrayList<>();
    for (Table.Column column : this.columnsOrder) {
        if (column.getId() instanceof MetaPropertyPath) {
            MetaPropertyPath metaPropertyPath = (MetaPropertyPath) column.getId();
            if (security.isEntityAttrReadPermitted(metaClass, metaPropertyPath.toString())) {
                columnsOrder.add(column.getId());
            }
        } else {
            columnsOrder.add(column.getId());
        }
    }
    setVisibleColumns(columnsOrder);
    if (security.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION)) {
        ShowInfoAction action = (ShowInfoAction) getAction(ShowInfoAction.ACTION_ID);
        if (action == null) {
            action = new ShowInfoAction();
            addAction(action);
        }
        action.setDatasource(datasource);
    }
    securityCollectionChangeListener = e -> {
        onDataChange();
        packRows();
        // #PL-2035, reload selection from ds
        Set<E> selectedItems1 = getSelected();
        if (selectedItems1 == null) {
            selectedItems1 = Collections.emptySet();
        }
        Set<E> newSelection = new HashSet<>();
        for (E entity : selectedItems1) {
            if (e.getDs().containsItem(entity.getId())) {
                newSelection.add(entity);
            }
        }
        if (e.getDs().getState() == Datasource.State.VALID && e.getDs().getItem() != null) {
            if (e.getDs().containsItem(e.getDs().getItem().getId())) {
                newSelection.add((E) e.getDs().getItem());
            }
        }
        if (newSelection.isEmpty()) {
            setSelected((E) null);
        } else {
            setSelected(newSelection);
        }
    };
    // noinspection unchecked
    datasource.addCollectionChangeListener(new WeakCollectionChangeListener(datasource, securityCollectionChangeListener));
    itemPropertyChangeListener = e -> {
        List<Column> columns1 = getColumns();
        boolean find = false;
        int i = 0;
        while ((i < columns1.size()) & !find) {
            Object columnId = columns1.get(i).getId();
            if (columnId instanceof MetaPropertyPath) {
                String propertyName = ((MetaPropertyPath) columnId).getMetaProperty().getName();
                if (propertyName.equals(e.getProperty())) {
                    find = true;
                }
            }
            i++;
        }
        if (find) {
            onDataChange();
        }
        packRows();
    };
    // noinspection unchecked
    datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
    if (rowsCount != null) {
        rowsCount.setDatasource(datasource);
    }
    collectionDsActionsNotifier = new CollectionDsActionsNotifier(this);
    collectionDsActionsNotifier.bind(datasource);
    for (Action action : getActions()) {
        action.refreshState();
    }
    if (!canBeSorted(datasource))
        setSortable(false);
}
Also used : RowSorterImpl(com.haulmont.cuba.desktop.gui.data.RowSorterImpl) AbstractAction(javax.swing.AbstractAction) ShowInfoAction(com.haulmont.cuba.gui.components.sys.ShowInfoAction) BoundAction(org.jdesktop.swingx.action.BoundAction) Action(com.haulmont.cuba.gui.components.Action) Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) WeakCollectionChangeListener(com.haulmont.cuba.gui.data.impl.WeakCollectionChangeListener) TableColumn(javax.swing.table.TableColumn) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener) MetaProperty(com.haulmont.chile.core.model.MetaProperty) JXTable(org.jdesktop.swingx.JXTable) FocusableTable(com.haulmont.cuba.desktop.sys.vcl.FocusableTable) TableColumn(javax.swing.table.TableColumn) ShowInfoAction(com.haulmont.cuba.gui.components.sys.ShowInfoAction) MetaClass(com.haulmont.chile.core.model.MetaClass) TableColumnExt(org.jdesktop.swingx.table.TableColumnExt) CollectionDsActionsNotifier(com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier)

Example 5 with Action

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

the class DesktopTree method setDatasource.

@Override
public void setDatasource(HierarchicalDatasource datasource) {
    this.datasource = datasource;
    hierarchyProperty = datasource.getHierarchyPropertyName();
    model = new TreeModelAdapter(datasource, captionMode, captionProperty, true);
    impl.setModel(model);
    impl.addTreeSelectionListener(new SelectionListener());
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
    if (uss.getUserSession().isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION)) {
        ShowInfoAction action = (ShowInfoAction) getAction(ShowInfoAction.ACTION_ID);
        if (action == null) {
            action = new ShowInfoAction();
            addAction(action);
        }
        action.setDatasource(datasource);
    }
    collectionChangeListener = e -> {
        // #PL-2035, reload selection from ds
        Set<E> selectedItems = getSelected();
        if (selectedItems == null) {
            selectedItems = Collections.emptySet();
        }
        Set<E> newSelection = new HashSet<>();
        for (E entity : selectedItems) {
            if (e.getDs().containsItem(entity.getId())) {
                newSelection.add(entity);
            }
        }
        if (e.getDs().getState() == Datasource.State.VALID && e.getDs().getItem() != null) {
            // noinspection unchecked
            newSelection.add((E) e.getDs().getItem());
        }
        if (newSelection.isEmpty()) {
            setSelected((Entity) null);
        } else {
            setSelected(newSelection);
        }
    };
    // noinspection unchecked
    datasource.addCollectionChangeListener(new WeakCollectionChangeListener(datasource, collectionChangeListener));
    collectionDsActionsNotifier = new CollectionDsActionsNotifier(this);
    collectionDsActionsNotifier.bind(datasource);
    for (Action action : getActions()) {
        action.refreshState();
    }
    assignAutoDebugId();
}
Also used : ShowInfoAction(com.haulmont.cuba.gui.components.sys.ShowInfoAction) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) ShowInfoAction(com.haulmont.cuba.gui.components.sys.ShowInfoAction) Action(com.haulmont.cuba.gui.components.Action) TreeModelAdapter(com.haulmont.cuba.desktop.gui.data.TreeModelAdapter) CollectionDsActionsNotifier(com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier) WeakCollectionChangeListener(com.haulmont.cuba.gui.data.impl.WeakCollectionChangeListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener)

Aggregations

Action (com.haulmont.cuba.gui.components.Action)35 ShowInfoAction (com.haulmont.cuba.gui.components.sys.ShowInfoAction)5 AbstractAction (javax.swing.AbstractAction)5 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)4 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Component (com.haulmont.cuba.gui.components.Component)3 DialogAction (com.haulmont.cuba.gui.components.DialogAction)3 Window (com.haulmont.cuba.gui.components.Window)3 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)3 Datasource (com.haulmont.cuba.gui.data.Datasource)3 CubaButton (com.haulmont.cuba.web.widgets.CubaButton)3 Inject (javax.inject.Inject)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)2 Messages (com.haulmont.cuba.core.global.Messages)2 ValidationAwareAction (com.haulmont.cuba.desktop.sys.validation.ValidationAwareAction)2 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)2 Button (com.haulmont.cuba.gui.components.Button)2 ListActionType (com.haulmont.cuba.gui.components.actions.ListActionType)2 CollectionDsActionsNotifier (com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier)2