/**
*
* BPS Bildungsportal Sachsen GmbH<br>
* Bahnhofstrasse 6<br>
* 09111 Chemnitz<br>
* Germany<br>
*
* Copyright (c) 2005-2008 by BPS Bildungsportal Sachsen GmbH<br>
* http://www.bps-system.de<br>
*
* All rights reserved.
*/
package de.bps.olat.repository.controllers;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.olat.basesecurity.Constants;
import org.olat.basesecurity.Manager;
import org.olat.basesecurity.ManagerFactory;
import org.olat.basesecurity.SecurityGroup;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.table.TableController;
import org.olat.core.gui.components.table.TableGuiConfiguration;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.translator.PackageTranslator;
import org.olat.core.id.Roles;
import org.olat.core.util.Util;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryTableModel;
import org.olat.repository.SearchForm;
import org.olat.repository.controllers.RepositorySearchController;
/**
* Description:<br>
* RepositorySearchController with multiselection element.
*
* <P>
* Initial Date: 04.11.2008 <br>
* @author bja
*/
public class RepositorySearchMultiSelectController extends RepositorySearchController {
private static final String PACKAGE = RepositoryManager.class.getPackage().getName();
private static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(RepositoryManager.class);
public static final String ACTION_MULTI_SELECT = "action.multi.select";
/**
* @param selectButtonLabel
* @param ureq
* @param myWControl
* @param withCancel
* @param enableDirectLaunch
* @param limitType
*/
public RepositorySearchMultiSelectController(String selectButtonLabel, UserRequest ureq, WindowControl myWControl, boolean withCancel,
boolean enableDirectLaunch, String limitType) {
this(selectButtonLabel, ureq, myWControl, withCancel, enableDirectLaunch, limitType, null);
}
public RepositorySearchMultiSelectController(String selectButtonLabel, UserRequest ureq, WindowControl myWControl, boolean withCancel,
boolean enableDirectLaunch, String limitType, String limitUser) {
super(myWControl);
init(selectButtonLabel, ureq, withCancel, enableDirectLaunch, limitType, limitUser);
}
private void init(String selectButtonLabel, UserRequest ureq, boolean withCancel, boolean enableDirectLaunch, String limitType, String limitUser) {
translator = new PackageTranslator(PACKAGE, ureq.getLocale());
Roles roles = ureq.getUserSession().getRoles();
vc = new VelocityContainer("reposearch", VELOCITY_ROOT + "/search.html", translator, this);
Manager secMgr = ManagerFactory.getManager();
SecurityGroup usermanagerGroup = secMgr.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
boolean isUserManager = secMgr.isIdentityInSecurityGroup(ureq.getIdentity(), usermanagerGroup);
searchForm = new SearchForm("searchform", translator, withCancel, isUserManager||roles.isOLATAdmin(), limitType, limitUser);
searchForm.addListener(this);
searchForm.setVisible(false);
vc.put("searchform",searchForm);
TableGuiConfiguration tableConfig = new TableGuiConfiguration();
if (selectButtonLabel != null) tableConfig.setPreferencesOffered(true, "repositorySearchResult");
tableCtr = new TableController(tableConfig, ureq, getWindowControl(), translator, this);
repoTableModel = new RepositoryTableModel(translator);
repoTableModel.addColumnDescriptors(tableCtr, selectButtonLabel, enableDirectLaunch);
tableCtr.addMultiSelectAction("resource.table.select", ACTION_MULTI_SELECT);
tableCtr.setMultiSelect(true);
tableCtr.setTableDataModel(repoTableModel);
tableCtr.setSortColumn(2, true);
vc.put("repotable", tableCtr.getInitialComponent());
vc.contextPut("isAuthor", Boolean.valueOf(roles.isAuthor()));
vc.contextPut("withCancel", Boolean.valueOf(withCancel));
enableBackToSearchFormLink(false); // default, must be enabled explicitly
enableSearchforAllReferencalbeInSearchForm(false); // default
setInitialComponent(vc);
}
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
public void event(UserRequest urequest, Controller source, Event event) {
if (source == tableCtr) {
fireEvent(urequest, event);
}
}
/**
*
* @param row
* @return
*/
public RepositoryEntry getValueAt(int row) {
RepositoryEntry repoEntry = (RepositoryEntry)repoTableModel.getObject(row);
return repoEntry;
}
/**
* Implementation normal search: find all repo entries
* @param ureq
*/
public void doSearchAll(UserRequest ureq) {
RepositoryManager rm = RepositoryManager.getInstance();
Set s = searchForm.getRestrictedTypes();
List restrictedTypes = (s == null) ? null : new ArrayList(s);
List entries = rm.genericANDQueryWithRolesRestriction(null, null, null, null, ureq.getUserSession().getRoles(), ureq.getIdentity().getUser().getProperty("institutionalName", null));
repoTableModel.setEntries(entries);
tableCtr.modelChanged();
displaySearchResults(ureq);
}
}