Search in sources :

Example 1 with ScreenHistoryEntity

use of com.haulmont.cuba.security.entity.ScreenHistoryEntity in project cuba by cuba-platform.

the class ScreenHistorySupport method saveScreenHistory.

public void saveScreenHistory(Window window, WindowManager.OpenMode openMode) {
    Security security = AppBeans.get(Security.NAME);
    if (security.isEntityOpPermitted(ScreenHistoryEntity.class, EntityOp.CREATE) && window.getFrame() != null && (window.getFrame() instanceof Window.Editor) && openMode != WindowManager.OpenMode.DIALOG && (screenIds == null || screenIds.contains(window.getId()))) {
        String caption = window.getCaption();
        UUID entityId = null;
        Frame frame = window.getFrame();
        Entity entity = null;
        if (frame instanceof Window.Editor) {
            entity = ((Window.Editor) frame).getItem();
            if (entity != null) {
                if (PersistenceHelper.isNew(entity)) {
                    return;
                }
                if (StringUtils.isBlank(caption))
                    caption = messages.getTools().getEntityCaption(entity.getMetaClass()) + " " + entity.getInstanceName();
                entityId = (UUID) entity.getId();
            }
        }
        ScreenHistoryEntity screenHistoryEntity = metadata.create(ScreenHistoryEntity.class);
        screenHistoryEntity.setCaption(StringUtils.abbreviate(caption, 255));
        screenHistoryEntity.setUrl(makeLink(window));
        screenHistoryEntity.setEntityId(entityId);
        addAdditionalFields(screenHistoryEntity, entity);
        CommitContext cc = new CommitContext(Collections.singleton(screenHistoryEntity));
        DataService dataService = AppBeans.get(DataService.NAME);
        dataService.commit(cc);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Entity(com.haulmont.cuba.core.entity.Entity) Frame(com.haulmont.cuba.gui.components.Frame) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) DataService(com.haulmont.cuba.core.app.DataService)

Example 2 with ScreenHistoryEntity

use of com.haulmont.cuba.security.entity.ScreenHistoryEntity 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)

Example 3 with ScreenHistoryEntity

use of com.haulmont.cuba.security.entity.ScreenHistoryEntity in project cuba by cuba-platform.

the class ScreenHistoryBrowse method openUrl.

protected void openUrl(Entity entity) {
    ScreenHistoryEntity screenHistoryEntity = (ScreenHistoryEntity) entity;
    Map<String, String> paramsScreen = new HashMap<>();
    String url = screenHistoryEntity.getUrl();
    url = url.substring(url.indexOf("\u003f") + 1);
    paramsScreen.put("local", "true");
    String[] params = url.split("&");
    for (String param : params) {
        String name = param.split("=")[0];
        String value = param.split("=")[1];
        paramsScreen.put(name, value);
    }
    List<String> actions = configuration.getConfig(WebConfig.class).getLinkHandlerActions();
    LinkHandler linkHandler = AppBeans.getPrototype(LinkHandler.NAME, App.getInstance(), actions.isEmpty() ? "open" : actions.get(0), paramsScreen);
    if (linkHandler.canHandleLink()) {
        linkHandler.handle();
    }
}
Also used : ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) HashMap(java.util.HashMap) WebConfig(com.haulmont.cuba.web.WebConfig) LinkHandler(com.haulmont.cuba.web.sys.LinkHandler)

Example 4 with ScreenHistoryEntity

use of com.haulmont.cuba.security.entity.ScreenHistoryEntity in project cuba by cuba-platform.

the class ScreenHistoryBrowse method init.

@Override
public void init(Map<String, Object> params) {
    LinkColumnHelper.initColumn(historyTable, "caption", entity -> {
        close("windowClose");
        openUrl(entity);
    });
    historyTable.addAction(new ShowLinkAction(historyTable.getDatasource(), entity -> entity != null ? ((ScreenHistoryEntity) entity).getUrl() : ""));
}
Also used : LinkColumnHelper(com.haulmont.cuba.gui.app.LinkColumnHelper) ScreenHistoryEntity(com.haulmont.cuba.security.entity.ScreenHistoryEntity) Table(com.haulmont.cuba.gui.components.Table) App(com.haulmont.cuba.web.App) HashMap(java.util.HashMap) AppBeans(com.haulmont.cuba.core.global.AppBeans) Inject(javax.inject.Inject) List(java.util.List) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) Configuration(com.haulmont.cuba.core.global.Configuration) LinkHandler(com.haulmont.cuba.web.sys.LinkHandler) WebConfig(com.haulmont.cuba.web.WebConfig) Map(java.util.Map) ShowLinkAction(com.haulmont.cuba.web.gui.components.ShowLinkAction) Entity(com.haulmont.cuba.core.entity.Entity) ShowLinkAction(com.haulmont.cuba.web.gui.components.ShowLinkAction)

Aggregations

ScreenHistoryEntity (com.haulmont.cuba.security.entity.ScreenHistoryEntity)4 Entity (com.haulmont.cuba.core.entity.Entity)3 WebConfig (com.haulmont.cuba.web.WebConfig)2 LinkHandler (com.haulmont.cuba.web.sys.LinkHandler)2 HashMap (java.util.HashMap)2 DataService (com.haulmont.cuba.core.app.DataService)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 WindowContext (com.haulmont.cuba.gui.WindowContext)1 LinkColumnHelper (com.haulmont.cuba.gui.app.LinkColumnHelper)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Frame (com.haulmont.cuba.gui.components.Frame)1 Table (com.haulmont.cuba.gui.components.Table)1 Window (com.haulmont.cuba.gui.components.Window)1 EditorScreen (com.haulmont.cuba.gui.screen.EditorScreen)1 App (com.haulmont.cuba.web.App)1 ShowLinkAction (com.haulmont.cuba.web.gui.components.ShowLinkAction)1 List (java.util.List)1 Map (java.util.Map)1 Inject (javax.inject.Inject)1