// really do the move private boolean moveStructureToNewParent( final String subjectStructId, final String oldParStructId, final String newParStructId, int newPos) { PortfolioStructure structToBeMvd; PortfolioStructure oldParStruct; PortfolioStructure newParStruct; try { structToBeMvd = ePFMgr.loadPortfolioStructureByKey(new Long(subjectStructId)); oldParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(oldParStructId)); newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(newParStructId)); } catch (final Exception e) { log.error( "could not load: structure to be moved, old or new structure while trying to move", e); return false; } if (oldParStructId.equals(newParStructId)) { // this is only a position move return ePFMgr.moveStructureToPosition(structToBeMvd, newPos); } return ePFMgr.moveStructureToNewParentStructure( structToBeMvd, oldParStruct, newParStruct, newPos); }
// really do the move! private boolean moveArtefactToNewParent( final String artefactId, final String oldParentId, final String newParentId) { PortfolioStructure newParStruct; PortfolioStructure oldParStruct; AbstractArtefact artefact; try { artefact = ePFMgr.loadArtefactByKey(new Long(artefactId)); oldParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(oldParentId)); newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(newParentId)); } catch (final Exception e) { log.error("could not load artefact, old and new parent", e); return false; } return ePFMgr.moveArtefactFromStructToStruct(artefact, oldParStruct, newParStruct); }
@Override public void repositoryEntryCreated(final RepositoryEntry re) { final PortfolioStructureMap mapTemp = eSTMgr.createAndPersistPortfolioMapTemplateFromEntry(getIdentity(), re); // add a page, as each map should have at least one per default! final Translator pt = PackageUtil.createPackageTranslator( EPCreateMapController.class, getLocale(), getTranslator()); final String title = pt.translate("new.page.title"); final String description = pt.translate("new.page.desc"); if (isNewTemplateAndGetsAPage) { // no additional page when this is a copy. final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean(EPFrontendManager.class); ePFMgr.createAndPersistPortfolioPage(mapTemp, title, description); } }
/** * check if a structure (page/structEl/map may be dropped here! its only allowed to move: - * StructureElement from page -> page - change the order of pages - change the order of structures * * @param subjectStructId * @param oldParStructId * @param newParStructId * @return */ private boolean checkNewStructureTarget( final String subjectStructId, final String oldParStructId, final String newParStructId) { PortfolioStructure structToBeMvd; PortfolioStructure newParStruct; if (oldParStructId.equals(newParStructId)) return true; // seems only to be a move in order if (newParStructId.equals(ROOT_NODE_IDENTIFIER)) return false; try { structToBeMvd = ePFMgr.loadPortfolioStructureByKey(new Long(subjectStructId)); newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(newParStructId)); } catch (final Exception e) { log.error("could not check for valid structure target", e); return false; } if (structToBeMvd instanceof EPPage && newParStruct instanceof EPPage) return false; if (structToBeMvd instanceof EPStructureElement && !(newParStruct instanceof EPPage)) return false; return true; }
@SuppressWarnings("unused") @Override protected void event(final UserRequest ureq, final Component source, final Event event) { if (source instanceof Link) { final Link link = (Link) source; if (link.getCommand().equals(DELETE_LINK_CMD)) { if (artefactNodeClicked != null) { final AbstractArtefact artefact = ePFMgr.loadArtefactByKey(new Long(getArtefactIdFromNodeId(artefactNodeClicked))); final PortfolioStructure parentStruct = ePFMgr.loadPortfolioStructureByKey( new Long(getArtefactParentStructIdFromNodeId(artefactNodeClicked))); ePFMgr.removeArtefactFromStructure(artefact, parentStruct); // refresh the view fireEvent(ureq, Event.CHANGED_EVENT); } else if (structureClicked != null) { if ((structureClicked instanceof EPPage) && !(structureClicked instanceof EPAbstractMap)) { PortfolioStructure ps = structureClicked; while (ePFMgr.loadStructureParent(ps) != null) { ps = ePFMgr.loadStructureParent(ps); } final int childPages = ePFMgr.countStructureChildren(ps); if (childPages > 1) { eSTMgr.removeStructureRecursively(structureClicked); // refresh the view fireEvent(ureq, Event.CHANGED_EVENT); } else { showError("last.page.not.deletable"); } } else if (structureClicked instanceof EPStructureElement && !(structureClicked instanceof EPAbstractMap)) { // structures should always be deletable eSTMgr.removeStructureRecursively(structureClicked); // refresh the view fireEvent(ureq, Event.CHANGED_EVENT); } else { showInfo("element.not.deletable"); } } } } }
/** * check if an artefact might be moved to this new parent node artefact might be moved to pages or * structureElements, but not on maps * * @param artefactId * @param structureId * @return */ private boolean checkNewArtefactTarget(final String artefactId, final String structureId) { // artefact cannot be moved directly under root if (ROOT_NODE_IDENTIFIER.equals(structureId)) { return false; } PortfolioStructure newParStruct; AbstractArtefact artefact; try { artefact = ePFMgr.loadArtefactByKey(new Long(artefactId)); newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(structureId)); } catch (final Exception e) { log.warn("could not check for valid artefact target", e); return false; } final boolean sameTarget = ePFMgr.isArtefactInStructure(artefact, newParStruct); if (sameTarget) { return false; } if (newParStruct instanceof EPAbstractMap) { return false; } return true; }
private void initFilterList(final FormItemContainer formLayout) { final List<EPFilterSettings> existingFilters = ePFMgr.getSavedFilterSettings(getIdentity()); for (final Iterator<EPFilterSettings> existingFilterIt = existingFilters.iterator(); existingFilterIt.hasNext(); ) { if (existingFilterIt.next().isFilterEmpty()) { existingFilterIt.remove(); } } final int amount = existingFilters.size() + 1; nonEmptyFilters = new ArrayList<EPFilterSettings>(amount); final String[] theKeys = new String[amount]; final String[] theValues = new String[amount]; String presetFilterIndex = theKeys[0] = "0"; theValues[0] = translate("filter.all"); int i = 1; final String presetFilterID = filterSettings.getFilterId(); for (final EPFilterSettings epFilterSettings : existingFilters) { theKeys[i] = epFilterSettings.getFilterId(); theValues[i] = epFilterSettings.getFilterName(); if (presetFilterID != null && presetFilterID.equals(epFilterSettings.getFilterId())) { presetFilterIndex = epFilterSettings.getFilterId(); } nonEmptyFilters.add(epFilterSettings); i++; } // don't show anything if no filter exists if (!nonEmptyFilters.isEmpty()) { if (formLayout.getFormComponent("filter.select") == null) { filterSel = uifactory.addDropdownSingleselect( "filter.select", formLayout, theKeys, theValues, null); filterSel.addActionListener(this, FormEvent.ONCHANGE); } else { filterSel.setKeysAndValues(theKeys, theValues, null); filterSel.setVisible(true); } if (presetFilterIndex != null) { filterSel.select(presetFilterIndex, true); } } else if (formLayout.getFormComponent("filter.select") != null) { formLayout.getFormComponent("filter.select").setVisible(false); } }
private void initTagFlc() { tagFlc.setLabel("filter.tag", null); tagAllBtn = uifactory.addToggleButton("filter.all", null, tagFlc, null, null); tagAllBtn.toggleOff(); tagNoneBtn = uifactory.addToggleButton("filter.notag", null, tagFlc, null, null); final Map<String, String> userTags = ePFMgr.getUsersMostUsedTags(getIdentity(), 8); int i = 1; tagCmpList = new ArrayList<FormToggle>(); final LinkedList<Entry<String, String>> sortEntrySet = new LinkedList<Entry<String, String>>(userTags.entrySet()); Collections.sort( sortEntrySet, new Comparator<Entry<String, String>>() { @Override public int compare(final Entry<String, String> arg0, final Entry<String, String> arg1) { return arg0.getValue().compareTo(arg1.getValue()); } }); final List<String> allActiveTagToggles = new ArrayList<String>(); for (final Entry<String, String> entry : sortEntrySet) { final String tag = entry.getValue(); final String tagCmpName = TAG_CMP_IDENTIFIER + i; if (tagFlc.getComponent(tagCmpName) != null) { tagFlc.remove(tagCmpName); } final FormToggle link = uifactory.addToggleButton(tagCmpName, tag, tagFlc, null, null); link.setLabel("tag.one", new String[] {tag}); link.setUserObject(tag); if (!selectedTagsList.isEmpty() && selectedTagsList.contains(tag)) { link.toggleOn(); allActiveTagToggles.add(tag); } tagCmpList.add(link); i++; } tagFlc.contextPut("tagCmpList", tagCmpList); tagEditBtn = uifactory.addToggleButton("filter.edit", null, tagFlc, null, null); tagEditBtn.toggleOff(); if (!allActiveTagToggles.containsAll(selectedTagsList)) { tagEditBtn.toggleOn(); } if (selectedTagsList.isEmpty()) { tagAllBtn.toggleOn(); } }
@Override protected void event(final UserRequest ureq, final Controller source, final Event event) { if (event instanceof TreeNodeClickedEvent) { resetClickedNodes(); final TreeNodeClickedEvent treeEv = (TreeNodeClickedEvent) event; final String nodeClicked = treeEv.getNodeId(); final boolean isArtefactNode = nodeClicked.startsWith(ARTEFACT_NODE_IDENTIFIER); if (!nodeClicked.equals(ROOT_NODE_IDENTIFIER) && !isArtefactNode) { structureClicked = ePFMgr.loadPortfolioStructureByKey(new Long(nodeClicked)); refreshAddElements(ureq, structureClicked); delButton.setVisible(true); // send event to load this page fireEvent( ureq, new EPStructureChangeEvent(EPStructureChangeEvent.SELECTED, structureClicked)); // needed because refreshAddElements set flc dirty, therefore selected node gets lost final String path = idToPath.get(structureClicked.getKey()); treeCtr.selectPath(path); } else if (isArtefactNode) { artefactNodeClicked = nodeClicked; refreshAddElements(ureq, null); delButton.setVisible(true); final String artIdent = getArtefactIdFromNodeId(nodeClicked); final String path = idToPath.get(new Long(artIdent)); final PortfolioStructure structure = pathToStructure.get(path); fireEvent(ureq, new EPArtefactClicked(ARTEFACT_NODE_CLICKED, structure)); // needed because refreshAddElements set flc dirty, therefore selected node gets lost treeCtr.selectPath(path); } else { // root tree node clicked, no add/delete link delButton.setVisible(false); refreshAddElements(ureq, null); fireEvent(ureq, new Event(ARTEFACT_NODE_CLICKED)); } } else if (event instanceof MoveTreeNodeEvent) { resetClickedNodes(); final MoveTreeNodeEvent moveEvent = (MoveTreeNodeEvent) event; final String movedNode = moveEvent.getNodeId(); final String oldParent = moveEvent.getOldParentNodeId(); final String newParent = moveEvent.getNewParentNodeId(); int newPos = moveEvent.getPosition(); final boolean isArtefactNode = movedNode.startsWith(ARTEFACT_NODE_IDENTIFIER); if (isArtefactNode) { final String nodeId = getArtefactIdFromNodeId(movedNode); if (checkNewArtefactTarget(nodeId, newParent)) { if (moveArtefactToNewParent(nodeId, oldParent, newParent)) { if (log.isDebugEnabled()) { log.info( "moved artefact " + nodeId + " from structure " + oldParent + " to " + newParent, null); } moveEvent.setResult(true, null, null); // refresh the view final EPMoveEvent movedEvent = new EPMoveEvent(newParent, nodeId); fireEvent(ureq, movedEvent); } else { moveEvent.setResult( false, translate("move.error.title"), translate("move.artefact.error.move")); } } else { moveEvent.setResult( false, translate("move.error.title"), translate("move.artefact.error.target")); } } else { if (checkNewStructureTarget(movedNode, oldParent, newParent)) { if (moveStructureToNewParent(movedNode, oldParent, newParent, newPos)) { if (log.isDebugEnabled()) { log.debug( "moved structure " + movedNode + " from structure " + oldParent + " to " + newParent, null); } moveEvent.setResult(true, null, null); // refresh the view final EPMoveEvent movedEvent = new EPMoveEvent(newParent, movedNode); fireEvent(ureq, movedEvent); } else { moveEvent.setResult( false, translate("move.error.title"), translate("move.struct.error.move")); } } else { moveEvent.setResult( false, translate("move.error.title"), translate("move.struct.error.target")); } } } else if (source == addElCtrl) { // refresh the view, this is a EPStructureChangeEvent fireEvent(ureq, event); } }
/** * org.olat.presentation.framework.components.form.flexible.FormItem, * org.olat.presentation.framework.components.form.flexible.impl.FormEvent) */ @SuppressWarnings("unused") @Override protected void formInnerEvent( final UserRequest ureq, final FormItem source, final FormEvent event) { if (source instanceof FormLink) { final FormLink link = (FormLink) source; if (link.getName().startsWith(TAG_CMP_IDENTIFIER)) { // a tag-Link got clicked, find out which final String selectedTag = (String) link.getUserObject(); if (!selectedTagsList.contains(selectedTag)) { selectedTagsList.add(selectedTag); tagAllBtn.toggleOff(); tagNoneBtn.toggleOff(); } else { selectedTagsList.remove(selectedTag); if (selectedTagsList.isEmpty()) { tagAllBtn.toggleOn(); } } filterSettings.setTagFilter(selectedTagsList); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } else if (link.getName().startsWith(HANDLER_PREFIX)) { // a type-link got clicked final String selectedType = (String) link.getUserObject(); if (!selectedTypeList.contains(selectedType)) { selectedTypeList.add(selectedType); typeAllBtn.toggleOff(); } else { selectedTypeList.remove(selectedType); if (selectedTypeList.isEmpty()) { typeAllBtn.toggleOn(); } } filterSettings.setTypeFilter(selectedTypeList); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } } if (source == tagAllBtn) { resetTagLinks(); tagNoneBtn.toggleOff(); filterSettings.setTagFilter(selectedTagsList); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } else if (source == tagNoneBtn) { resetTagLinks(); tagAllBtn.toggleOff(); filterSettings.setNoTagFilter(); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } else if (source == typeAllBtn) { resetTypeLinks(); filterSettings.setTypeFilter(selectedTypeList); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } else if (source == dateStart || source == dateEnd) { if (validateFormLogic(ureq)) { final List<Date> dateList = new ArrayList<Date>(); final Date selStartDate = dateStart.getDate(); final Date selEndDate = dateEnd.getDate(); dateList.add(selStartDate); dateList.add(selEndDate); filterSettings.setDateFilter(dateList); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } } else if (source == typeEditBtn) { popupTypesCallout(ureq); } else if (source == tagEditBtn) { popupTagsCallout(ureq); } else if (source == searchFld) { final String searchText = searchFld.getValue(); filterSettings.setTextFilter(searchText); fireEvent(ureq, new PortfolioFilterChangeEvent(filterSettings)); } else if (source == filterSave) { if (StringHelper.containsNonWhitespace(filterName.getValue())) { final String oldFilterName = filterSettings.getFilterName(); filterSettings.setFilterName(filterName.getValue()); filterSettings.setTextFilter(searchFld.getValue()); if (filterSave.getUserObject() != null && filterName.getValue().equals(oldFilterName)) { // fake update, delete before adding again final String filterID = (String) filterSave.getUserObject(); ePFMgr.deleteFilterFromUsersList(getIdentity(), filterID); } if (!filterName.getValue().equals(oldFilterName) && oldFilterName != null) { // set another id, to distinguish from old filterSettings.setFilterIdToUniqueId(); } final List<EPFilterSettings> filterList = ePFMgr.getSavedFilterSettings(getIdentity()); // create a new or insert existing again filterList.add(filterSettings); ePFMgr.setSavedFilterSettings(getIdentity(), filterList); toggleSaveUpdateFilterButtons(true); showInfo("filter.saved", filterSettings.getFilterName()); updateUI(ureq, filterSettings); } } else if (source == filterDel) { if (filterDel.getUserObject() != null) { ePFMgr.deleteFilterFromUsersList(getIdentity(), (String) filterDel.getUserObject()); // refresh ui filterName.setValue(""); toggleSaveUpdateFilterButtons(false); showInfo("filter.deleted"); updateUI(ureq, new EPFilterSettings()); } } else if (source == filterName) { final String oldFilterName = filterSettings.getFilterName(); if (filterSave.getUserObject() != null && !filterName.getValue().equals(oldFilterName)) { toggleSaveUpdateFilterButtons(false); } else if (filterName.getValue().equals(oldFilterName)) { toggleSaveUpdateFilterButtons(true); } } else if (source == filterSel) { if (filterSel.isOneSelected()) { final int filterIndex = filterSel.getSelected(); if (filterIndex == 0) { final EPFilterSettings newSettings = new EPFilterSettings(); updateUI(ureq, newSettings); fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings)); } else if (filterIndex > 0 && filterIndex - 1 < nonEmptyFilters.size()) { final EPFilterSettings newSettings = nonEmptyFilters.get(filterIndex - 1); if (!filterSettings.getFilterId().equals(newSettings.getFilterId())) { updateUI(ureq, newSettings); fireEvent(ureq, new PortfolioFilterChangeEvent(newSettings)); } } } } }