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());
}
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;
}
});
}
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);
}
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();
}
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());
}
Aggregations