use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.
the class ScreenNavigationHandler method createEditor.
protected Screen createEditor(WindowInfo windowInfo, String screenRoute, NavigationState requestedState, AppUI ui) {
Map<String, Object> options = createEditorScreenOptions(windowInfo, requestedState, ui);
if (MapUtils.isEmpty(options)) {
log.info("Unable to load entity for editor: '{}'. " + "Subscribe for 'UrlParamsChangedEvent' to obtain its serialized id", windowInfo.getId());
}
Screen editor;
OpenMode openMode = getScreenOpenMode(requestedState.getNestedRoute(), screenRoute, ui);
if (isLegacyScreen(windowInfo.getControllerClass())) {
editor = ui.getScreens().create(windowInfo.getId(), openMode, new MapScreenOptions(options));
} else {
editor = ui.getScreens().create(windowInfo.getId(), openMode);
}
if (MapUtils.isNotEmpty(options)) {
Entity entity = (Entity) options.get(WindowParams.ITEM.name());
// noinspection unchecked
((EditorScreen<Entity>) editor).setEntityToEdit(entity);
}
return editor;
}
use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.
the class WebScreenTools method openDefaultScreen.
@Override
public void openDefaultScreen(Screens screens) {
String defaultScreenId = webConfig.getDefaultScreenId();
if (webConfig.getUserCanChooseDefaultScreen()) {
String userDefaultScreen = userSettingService.loadSetting(ClientType.WEB, "userDefaultScreen");
defaultScreenId = StringUtils.isEmpty(userDefaultScreen) ? defaultScreenId : userDefaultScreen;
}
if (StringUtils.isEmpty(defaultScreenId)) {
return;
}
if (!windowConfig.hasWindow(defaultScreenId)) {
log.info("Can't find default screen: {}", defaultScreenId);
return;
}
Screen screen = screens.create(defaultScreenId, OpenMode.NEW_TAB);
if (screen instanceof EditorScreen) {
((EditorScreen) screen).setEntityToEdit(getEntityToEdit(defaultScreenId));
}
screen.show();
Window window = screen.getWindow();
WebWindow webWindow;
if (window instanceof Window.Wrapper) {
webWindow = (WebWindow) ((Window.Wrapper) window).getWrappedWindow();
} else {
webWindow = (WebWindow) window;
}
webWindow.setDefaultScreenWindow(true);
if (!webConfig.getDefaultScreenCanBeClosed()) {
window.setCloseable(false);
}
}
use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.
the class ScreenHistorySupport method makeLink.
protected String makeLink(Screen frameOwner) {
Window window = frameOwner.getWindow();
Entity entity = null;
if (window.getFrameOwner() instanceof EditorScreen) {
entity = ((EditorScreen) frameOwner).getEditedEntity();
}
GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
String url = String.format("%s/open?screen=%s", globalConfig.getWebAppUrl(), frameOwner.getId());
Object entityId = referenceToEntitySupport.getReferenceIdForLink(entity);
if (entity != null) {
String item;
if (entityId instanceof String) {
item = metadata.getClassNN(entity.getClass()).getName() + "-{" + entityId + "}";
} else {
item = metadata.getClassNN(entity.getClass()).getName() + "-" + entityId;
}
url += String.format("&item=%s¶ms=item:%s", item, item);
}
Map<String, Object> params = getWindowParams(window);
StringBuilder sb = new StringBuilder();
if (params != null) {
for (Map.Entry<String, Object> param : params.entrySet()) {
Object value = param.getValue();
if (value instanceof String || /*|| value instanceof Integer || value instanceof Double*/
value instanceof Boolean) {
sb.append(",").append(param.getKey()).append(":").append(URLEncodeUtils.encodeUtf8(value.toString()));
}
}
}
if (sb.length() > 0) {
if (entity != null) {
url += sb.toString();
} else {
url += "¶ms=" + sb.deleteCharAt(0).toString();
}
}
return url;
}
use of com.haulmont.cuba.gui.screen.EditorScreen 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);
}
}
use of com.haulmont.cuba.gui.screen.EditorScreen in project cuba by cuba-platform.
the class WebUrlRouting method buildParams.
protected Map<String, String> buildParams(Screen screen, Map<String, String> urlParams) {
String route = getRoute(screen);
if (StringUtils.isEmpty(route) && (isEditor(screen) || MapUtils.isNotEmpty(urlParams))) {
log.debug("There's no route for screen \"{}\". URL params will be ignored", screen.getId());
return Collections.emptyMap();
}
if (omitParams(screen)) {
return Collections.emptyMap();
}
Map<String, String> params = new LinkedHashMap<>();
if (isEditor(screen)) {
Entity editedEntity = ((EditorScreen) screen).getEditedEntity();
if (editedEntity != null) {
if (PersistenceHelper.isNew(editedEntity)) {
params.put("id", NEW_ENTITY_ID);
} else {
Object entityId = editedEntity.getId();
if (entityId != null) {
String serializedId = UrlIdSerializer.serializeId(entityId);
if (!"".equals(serializedId)) {
params.put("id", serializedId);
}
}
}
}
}
params.putAll(urlParams != null ? urlParams : Collections.emptyMap());
return params;
}
Aggregations