Search in sources :

Example 1 with WindowContext

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

the class ScreenHistorySupport method saveScreenHistory.

public void saveScreenHistory(Screen frameOwner) {
    WindowContext windowContext = frameOwner.getWindow().getContext();
    if (security.isEntityOpPermitted(ScreenHistoryEntity.class, EntityOp.CREATE) && (frameOwner instanceof EditorScreen) && windowContext.getLaunchMode() != OpenMode.DIALOG && (screenIds.contains(frameOwner.getId()))) {
        String caption = frameOwner.getWindow().getCaption();
        Object entityId = null;
        Entity entity = ((EditorScreen) frameOwner).getEditedEntity();
        if (entity != null) {
            if (PersistenceHelper.isNew(entity)) {
                return;
            }
            if (StringUtils.isBlank(caption)) {
                caption = messages.getTools().getEntityCaption(entity.getMetaClass()) + " " + metadata.getTools().getInstanceName(entity);
            }
            entityId = referenceToEntitySupport.getReferenceIdForLink(entity);
        }
        ScreenHistoryEntity screenHistoryEntity = metadata.create(ScreenHistoryEntity.class);
        screenHistoryEntity.setCaption(StringUtils.abbreviate(caption, 255));
        screenHistoryEntity.setUrl(makeLink(frameOwner));
        screenHistoryEntity.setObjectEntityId(entityId);
        addAdditionalFields(screenHistoryEntity, entity);
        CommitContext cc = new CommitContext(Collections.singleton(screenHistoryEntity));
        dataManager.commit(cc);
    }
}
Also used : ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Entity(com.haulmont.cuba.core.entity.Entity) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) WindowContext(com.haulmont.cuba.gui.WindowContext)

Aggregations

Entity (com.haulmont.cuba.core.entity.Entity)1 WindowContext (com.haulmont.cuba.gui.WindowContext)1 EditorScreen (com.haulmont.cuba.gui.screen.EditorScreen)1 ScreenHistoryEntity (com.haulmont.cuba.security.entity.ScreenHistoryEntity)1