protected void renderEditors(final Component parent) { final DefaultLiveEditBrowserModel model = (DefaultLiveEditBrowserModel) getModel(); final PreviewDataModel previewData = model.getPreviewData(); if (previewData != null) { final TypedObject previewDataTO = getTypeService().wrapItem(previewData); final Collection<EditorRowConfiguration> rowConfigs = getRowConfigs(previewDataTO.getType()); final Collection<PropertyDescriptor> props = new ArrayList<PropertyDescriptor>(); for (final EditorRowConfiguration row : rowConfigs) { props.add(row.getPropertyDescriptor()); } final ObjectValueContainer valueContainer = TypeTools.createValueContainer( previewDataTO, new HashSet<PropertyDescriptor>(props), UISessionUtils.getCurrentSession().getSystemService().getAvailableLanguageIsos()); int index = 0; Hbox singleRow = null; for (final EditorRowConfiguration row : rowConfigs) { if (index % EDITORS_PER_ROW == 0) { singleRow = new Hbox(); parent.appendChild(singleRow); } singleRow.appendChild(createEditor(previewDataTO, row, valueContainer)); index++; } } }
protected SearchType getRootSearchType(final PropertyDescriptor propDescr) { SearchType searchType = null; final String valueTypeCode = UISessionUtils.getCurrentSession().getTypeService().getValueTypeCode(propDescr); if (valueTypeCode != null) { try { // get search type searchType = UISessionUtils.getCurrentSession().getSearchService().getSearchType(valueTypeCode); } catch (final Exception e) { // log.warn("Could not get search type for property descriptor (Reason: '" + // e.getMessage() + "')."); } } return searchType; }
@Override public PreviewDataModel getPreviewData() { PreviewDataModel previewData = this.getViewModel().getCurrentPreviewData(); // create a new one if null or invalid if (previewData == null || UISessionUtils.getCurrentSession().getModelService().isRemoved(previewData)) { previewData = UISessionUtils.getCurrentSession().getModelService().create(PreviewDataModel.class); previewData.setLanguage( getI18NService() .getLanguage(UISessionUtils.getCurrentSession().getGlobalDataLanguageIso())); previewData.setTime(null); previewData.setUser(frontendUser); this.getViewModel().setCurrentPreviewData(previewData); } return previewData; }
private void fillCombo(final Combobox combo, final Locale curLocale) { if (combo.getItemCount() == 0) { final Locale currentLocale = UISessionUtils.getCurrentSession().getLocale(); for (final Locale locale : getPlayerFacade().getAllCountries()) { final Comboitem item = new Comboitem(locale.getDisplayCountry(currentLocale)); item.setValue(locale); combo.appendChild(item); if (curLocale.getCountry().equals(locale.getCountry())) { combo.setSelectedItem(item); } } } }
public static CatalogVersionSyncJobModel createDefaultSyncJob( final String code, final CatalogVersionModel catVerStaged, final CatalogVersionModel catVerOnline) { final ModelService modelService = UISessionUtils.getCurrentSession().getModelService(); final CatalogVersionSyncJobModel catalogVersionSyncJob = modelService.create("CatalogVersionSyncJob"); catalogVersionSyncJob.setCode(code); catalogVersionSyncJob.setSourceVersion(catVerStaged); catalogVersionSyncJob.setTargetVersion(catVerOnline); catalogVersionSyncJob.setRemoveMissingItems(Boolean.TRUE); catalogVersionSyncJob.setCreateNewItems(Boolean.TRUE); return catalogVersionSyncJob; }
protected Collection<EditorRowConfiguration> getRowConfigs(final BaseType type) { final List<EditorRowConfiguration> ret = new ArrayList<EditorRowConfiguration>(); final EditorConfiguration componentConfiguration = UISessionUtils.getCurrentSession() .getUiConfigurationService() .getComponentConfiguration( getTypeService().getObjectTemplate(type.getCode()), "liveEditPreviewArea", EditorConfiguration.class); if (componentConfiguration != null) { for (final EditorSectionConfiguration section : componentConfiguration.getSections()) { ret.addAll(section.getSectionRows()); } } return ret; }
public static synchronized List<PageTemplateModel> copyPageTemplatesDeep( final List<PageTemplateModel> sourceTemplates, final CatalogVersionModel catVersion, final ContentCatalogModel contentCatalog) { final ModelService modelService = UISessionUtils.getCurrentSession().getModelService(); return copyPageTemplatesDeepImpl( sourceTemplates, catVersion, contentCatalog, modelService, new RandomProducer() { @Override public String getSequenceUidValue(final String typeCode, final String prefix) { return getGenericRandomNameProducer().generateSequence(typeCode, prefix); } }); }
@Override public void handleEvent( final UICockpitPerspective perspective, final Map<String, String[]> params) { final String itemParam = this.getParameter(params, COMPETITION_KEY); CompetitionModel competition = null; try { final TypedObject item = UISessionUtils.getCurrentSession().getTypeService().wrapItem(PK.parse(itemParam)); if (item != null) { competition = (CompetitionModel) item.getObject(); } } catch (final Exception e) { LOG.warn("competition specified in jumpin URL not forund: " + itemParam, e); } if (competition != null) { getFrontendController().changeCompetition(competition.getCode()); } }
public static void createHomepage( final String uid, final String label, final CatalogVersionModel catVersion, final ContentCatalogModel contentCatalog, final CMSSiteModel cmsSiteModel, final List<PageTemplateModel> clonedTemplates) { final PageTemplateModel firstTemplate = clonedTemplates.iterator().next(); final ModelService modelService = UISessionUtils.getCurrentSession().getModelService(); final ContentPageModel contentPage = modelService.create(CONTENT_PAGE); contentPage.setUid(uid); contentPage.setName(uid); contentPage.setLabel(label); contentPage.setHomepage(true); contentPage.setCatalogVersion(catVersion); contentPage.setMasterTemplate(firstTemplate); contentPage.setDefaultPage(Boolean.TRUE); cmsSiteModel.setStartingPage(contentPage); adjustHomePageTemplate(contentPage, clonedTemplates); modelService.save(contentPage); }
@Override public void initialize(final Map<String, Object> params) { UISessionUtils.getCurrentSession().sendGlobalEvent(new CmsPerspectiveInitEvent(this)); super.initialize(params); }
private Component createEditor( final TypedObject object, final EditorRowConfiguration rowConfig, final ObjectValueContainer valueContainer) { final Div editorContainer = new Div(); editorContainer.setStyle( "float: left; position: relative; padding-left: 25px; padding-top: 8px; padding-bottom: 5px; padding-right: 3px;"); final Div labelDiv = new Div(); // labelDiv.setStyle("width: 145px; overflow: hidden; text-align: right; position: relative; // top: 3px;"); labelDiv.setStyle("overflow: hidden; text-align: left; padding: 3px;"); final PropertyDescriptor propDesc = rowConfig.getPropertyDescriptor(); String label = propDesc.getName(); if (StringUtils.isBlank(label)) { label = propDesc.getQualifier(); } final Label labelComp = new Label(label); labelComp.setStyle("font-weight: bold; color: #666;"); labelDiv.appendChild(labelComp); editorContainer.appendChild(labelDiv); final Div editorDiv = new Div(); editorDiv.setStyle("width: 150px; position: relative;"); editorContainer.appendChild(editorDiv); final Collection<PropertyEditorDescriptor> matchingEditorDescriptors = getEditorFactory().getMatchingEditorDescriptors(propDesc.getEditorType()); if (!matchingEditorDescriptors.isEmpty()) { final ObjectValueContainer.ObjectValueHolder valueHolder = valueContainer.getValue(propDesc, null); final PropertyEditorDescriptor ped = matchingEditorDescriptors.iterator().next(); final UIEditor editor = org.apache.commons.lang.StringUtils.isNotBlank(rowConfig.getEditor()) ? ped.createUIEditor(rowConfig.getEditor()) : ped.createUIEditor(TypeTools.getMultiplicityString(propDesc)); editor.setEditable(true); CreateContext createContext = null; if (editor instanceof ReferenceUIEditor) { SearchType rootType = getRootSearchType(propDesc); if (rootType != null && rootType.isAssignableFrom( UISessionUtils.getCurrentSession() .getTypeService() .getObjectType(UserModel._TYPECODE))) { rootType = UISessionUtils.getCurrentSession() .getSearchService() .getSearchType(CustomerModel._TYPECODE); } if (rootType != null) { ((ReferenceUIEditor) editor).setRootType(rootType); } // final SearchType rootType = getRootSearchType(propDesc); createContext = new CreateContext( rootType, UISessionUtils.getCurrentSession() .getTypeService() .wrapItem(valueContainer.getObject()), propDesc, UISessionUtils.getCurrentSession().getLanguageIso()); } final Map<String, Object> customParameters = new HashMap<String, Object>(rowConfig.getParameters()); customParameters.put(AbstractUIEditor.ATTRIBUTE_QUALIFIER_PARAM, propDesc.getQualifier()); customParameters.put("languageIso", UISessionUtils.getCurrentSession().getLanguageIso()); final CMSSiteModel cmsSiteModel = getCmsAdminSiteService().getActiveSite(); final CatalogVersionModel catalogVersionModel = getCmsAdminSiteService().getActiveCatalogVersion(); if (cmsSiteModel != null) { customParameters.put( "availableItems", getCmsPreviewService().getEditableCatalogs(cmsSiteModel, catalogVersionModel)); } if (createContext != null) { try { customParameters.put("createContext", createContext.clone()); } catch (final CloneNotSupportedException e) { LOG.error("Clone not support for preview data!", e); } } final HtmlBasedComponent viewComponent = editor.createViewComponent( valueHolder.getCurrentValue(), customParameters, new EditorListener() { @Override public void valueChanged(final Object value) { valueHolder.setLocalValue(value); for (final ObjectValueHandler valueHandler : UISessionUtils.getCurrentSession() .getValueHandlerRegistry() .getValueHandlerChain(object.getType())) { try { valueHandler.storeValues(valueContainer); } catch (final ValueHandlerException e) { if (LOG.isDebugEnabled()) { LOG.error(e.getMessage(), e); } } } } @Override public void actionPerformed(final String actionCode) { // nop } }); editorDiv.appendChild(viewComponent); } return editorContainer; }
protected TypeService getTypeService() { return UISessionUtils.getCurrentSession().getTypeService(); }
@Override public void onCockpitEvent(final CockpitEvent event) { // make sure newly created item is selected if (event instanceof ItemChangedEvent) { final ItemChangedEvent changedEvent = (ItemChangedEvent) event; switch (changedEvent.getChangeType()) { case CREATED: final TypedObject createdItem = changedEvent.getItem(); if (changedEvent.getSource() instanceof BrowserSectionModel) { final BrowserSectionModel sectionModel = (BrowserSectionModel) changedEvent.getSource(); final List<TypedObject> sectionItems = sectionModel.getItems(); if (sectionItems != null && !sectionItems.isEmpty()) { final int itemIndex = sectionItems.indexOf(createdItem); if (itemIndex != -1) { sectionModel.update(); sectionModel.setSelectedIndex(itemIndex); getContentEditorSection().setRootItem(createdItem); getContentEditorSection().setVisible(true); getContentEditorSection().update(); } } } else if (changedEvent.getSource() == null) { // createProperViewModel(); for (final BrowserSectionModel sectionModel : getBrowserSectionModels()) { if (sectionModel.getItems().contains(createdItem)) { final int selectedIndex = sectionModel.getItems().indexOf(createdItem); sectionModel.setSelectedIndex(selectedIndex); } } getContentEditorSection().setRootItem(createdItem); getContentEditorSection().setVisible(true); getContentEditorSection().update(); updateItems(); } break; case REMOVED: // if a page is deleted make sure any related struct tabs are closed if (changedEvent.getItem().equals(getCurrentPageObject())) { getArea().close(this); } if (changedEvent.getSource() instanceof SectionTableModel) { final BrowserSectionModel sectionModel = ((SectionTableModel) changedEvent.getSource()).getModel(); final List<TypedObject> sectionItems = sectionModel.getItems(); if (sectionItems != null && !sectionItems.isEmpty() && sectionItems.contains(changedEvent.getItem())) { final int removedIndex = sectionItems.indexOf(changedEvent.getItem()); if (sectionModel.getSelectedIndex() != null) { if (removedIndex < sectionModel.getSelectedIndex().intValue()) { sectionModel.setSelectedIndex(sectionModel.getSelectedIndex().intValue() - 1); } else if (removedIndex == sectionModel.getSelectedIndex().intValue()) { sectionModel.setSelectedIndexes(Collections.EMPTY_LIST); } } removeComponentFromSlot( (TypedObject) sectionModel.getRootItem(), changedEvent.getItem()); sectionModel.update(); } if (getContentEditorSection().getRootItem() != null && getContentEditorSection().getRootItem().equals(changedEvent.getItem())) { getContentEditorSection().setRootItem(null); getContentEditorSection().setVisible(false); } final AbstractBrowserArea area = (AbstractBrowserArea) UISessionUtils.getCurrentSession().getCurrentPerspective().getBrowserArea(); final AbstractContentBrowser content = area.getCorrespondingContentBrowser(this); if (content != null && content.getToolbarComponent() != null) { content.getToolbarComponent().update(); } } break; case CHANGED: for (final BrowserSectionModel sectionModel : getBrowserSectionModels()) { if (sectionModel.equals(event.getSource())) { continue; } final List<TypedObject> sectionItems = sectionModel.getItems(); final TypedObject changedItem = changedEvent.getItem(); if (sectionItems.contains(changedItem)) { final TypedObject typedObject = sectionItems.get(sectionItems.indexOf(changedItem)); modelService.refresh(typedObject.getObject()); sectionModel.update(); } if ((sectionModel.getRootItem() != null && sectionModel.getRootItem().equals(changedItem))) { final TypedObject rootItem = (TypedObject) sectionModel.getRootItem(); final ItemModel itemModel = (ItemModel) rootItem.getObject(); modelService.refresh(itemModel); if (sectionModel instanceof Lockable) { getContentEditorSection().setReadOnly(((Lockable) sectionModel).isLocked()); } sectionModel.update(); } } break; } } }