Search in sources :

Example 6 with UserSessionSource

use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.

the class SearchFolder method copyFrom.

@Override
public void copyFrom(AbstractSearchFolder srcFolder) {
    super.copyFrom(srcFolder);
    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
    setUser(sessionSource.getUserSession().getUser());
}
Also used : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource)

Example 7 with UserSessionSource

use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.

the class LinkColumnHelper method initColumn.

public static void initColumn(Table table, final String propertyName, final Handler handler) {
    final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
    table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {

        @Override
        public Component generateCell(final Entity entity) {
            // //process properties like building.house.room
            String[] props = propertyName.split("\\.");
            Instance nestedEntity = entity;
            for (int i = 0; i < props.length - 1; i++) {
                nestedEntity = nestedEntity.getValue(props[i]);
                if (nestedEntity == null) {
                    break;
                }
            }
            final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
            if (value != null) {
                Button button = componentsFactory.createComponent(Button.class);
                button.setStyleName("link");
                button.setAction(new AbstractAction("open") {

                    @Override
                    public void actionPerform(Component component) {
                        handler.onClick(entity);
                    }

                    @Override
                    public String getCaption() {
                        String str;
                        Datatype datatype = Datatypes.get(value.getClass());
                        if (datatype != null) {
                            UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
                            str = datatype.format(value, sessionSource.getLocale());
                        } else {
                            str = value.toString();
                        }
                        return str;
                    }
                });
                button.setStyleName("link");
                return button;
            }
            return null;
        }
    });
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Table(com.haulmont.cuba.gui.components.Table) Instance(com.haulmont.chile.core.model.Instance) Datatype(com.haulmont.chile.core.datatypes.Datatype) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) Button(com.haulmont.cuba.gui.components.Button) Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 8 with UserSessionSource

use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.

the class EntitySnapshot method getLabel.

@MetaProperty(related = { "snapshotDate,author" })
public String getLabel() {
    String name = "";
    if (author != null && StringUtils.isNotEmpty(this.author.getCaption())) {
        name += this.author.getCaption() + " ";
    }
    Datatype datatype = Datatypes.getNN(Date.class);
    UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
    if (userSessionSource != null && userSessionSource.checkCurrentUserSession()) {
        name += datatype.format(snapshotDate, userSessionSource.getLocale());
    }
    return StringUtils.trim(name);
}
Also used : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Datatype(com.haulmont.chile.core.datatypes.Datatype) MetaProperty(com.haulmont.chile.core.annotations.MetaProperty)

Example 9 with UserSessionSource

use of com.haulmont.cuba.core.global.UserSessionSource 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 : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) 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)

Example 10 with UserSessionSource

use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.

the class ExecutionsTest method testExceptionOnUserSession.

@Test
public void testExceptionOnUserSession() {
    Executions executions = AppBeans.get(Executions.NAME);
    executions.startExecution("key", "group");
    UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
    try {
        ((TestUserSessionSource) userSessionSource).setExceptionOnGetUserSession(true);
    } finally {
        try {
            executions.endExecution();
        } catch (Exception e) {
        // Do nothing
        }
    }
    assertNull(ExecutionContextHolder.getCurrentContext());
    ((TestUserSessionSource) userSessionSource).setExceptionOnGetUserSession(false);
    executions.startExecution("key", "group");
    try {
        executions.endExecution();
    } catch (Exception e) {
    // Do nothing
    }
    assertNull(ExecutionContextHolder.getCurrentContext());
}
Also used : Executions(com.haulmont.cuba.core.app.execution.Executions) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) Test(org.junit.Test)

Aggregations

UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)16 Datatype (com.haulmont.chile.core.datatypes.Datatype)5 ParseException (java.text.ParseException)5 ValidationException (com.haulmont.cuba.gui.components.ValidationException)4 Date (java.util.Date)3 Instance (com.haulmont.chile.core.model.Instance)2 Range (com.haulmont.chile.core.model.Range)2 UserSession (com.haulmont.cuba.security.global.UserSession)2 BigDecimal (java.math.BigDecimal)2 MetaProperty (com.haulmont.chile.core.annotations.MetaProperty)1 TimeZoneAwareDatatype (com.haulmont.chile.core.datatypes.TimeZoneAwareDatatype)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 Executions (com.haulmont.cuba.core.app.execution.Executions)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Messages (com.haulmont.cuba.core.global.Messages)1 TimeSource (com.haulmont.cuba.core.global.TimeSource)1 TreeModelAdapter (com.haulmont.cuba.desktop.gui.data.TreeModelAdapter)1 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)1 Action (com.haulmont.cuba.gui.components.Action)1