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