Search in sources :

Example 1 with TabContext

use of org.olat.core.id.context.TabContext in project openolat by klemens.

the class NewControllerFactory method launch.

/**
 * Launch a controller in a tab or site in the given window from a user
 * request url
 *
 * @param ureq
 * @param wControl
 */
public boolean launch(UserRequest ureq, WindowControl wControl) {
    BusinessControl bc = wControl.getBusinessControl();
    ContextEntry mainCe = bc.popLauncherContextEntry();
    if (mainCe == null) {
        // nothing to launch
        return false;
    }
    OLATResourceable ores = mainCe.getOLATResourceable();
    // Check for RepositoryEntry resource
    RepositoryEntry re = null;
    if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(RepositoryEntry.class))) {
        if (ores instanceof RepositoryEntry) {
            re = (RepositoryEntry) ores;
            ores = re.getOlatResource();
        } else {
            // It is a repository-entry => get OLATResourceable from RepositoryEntry
            RepositoryManager repom = RepositoryManager.getInstance();
            re = repom.lookupRepositoryEntry(ores.getResourceableId());
            if (re != null) {
                ores = re.getOlatResource();
                mainCe.upgradeOLATResourceable(re);
            }
        }
    }
    // was brasato:: DTabs dts = wControl.getDTabs();
    UserSession usess = ureq.getUserSession();
    Window window = Windows.getWindows(usess).getWindow(ureq);
    if (window == null) {
        log.debug("Found no window for jumpin => take WindowBackOffice", null);
        window = wControl.getWindowBackOffice().getWindow();
    }
    DTabs dts = window.getDTabs();
    String firstType = mainCe.getOLATResourceable().getResourceableTypeName();
    // String firstTypeId = ClassToId.getInstance().lookup() BusinessGroup
    ContextEntryControllerCreator typeHandler = getContextEntryControllerCreator(firstType);
    if (typeHandler == null) {
        log.warn("Cannot found an handler for context entry: " + mainCe, null);
        // simply return and don't throw a red screen
        return false;
    }
    if (!typeHandler.validateContextEntryAndShowError(mainCe, ureq, wControl)) {
        // simply return and don't throw a red screen
        return false;
    }
    List<ContextEntry> entries = new ArrayList<ContextEntry>(5);
    while (bc.hasContextEntry()) {
        entries.add(bc.popLauncherContextEntry());
    }
    List<ContextEntry> ces = new ArrayList<ContextEntry>(entries.size() + 1);
    ces.add(mainCe);
    if (entries.size() > 0) {
        ces.addAll(entries);
    }
    TabContext context = typeHandler.getTabContext(ureq, ores, mainCe, entries);
    String siteClassName = typeHandler.getSiteClassName(ces, ureq);
    // open in existing site
    boolean launched = false;
    boolean assessmentMode = usess.isInAssessmentModeProcess();
    if (siteClassName != null) {
        if (!assessmentMode) {
            dts.activateStatic(ureq, siteClassName, context.getContext());
            launched = true;
        }
    } else if (!assessmentMode || usess.matchLockResource(ores)) {
        // get current tab or create new tab
        DTab dt = dts.getDTab(ores);
        if (dt == null) {
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, dts.getWindowControl());
            usess.addToHistory(ureq, bc);
            Controller launchC = typeHandler.createController(ces, ureq, bwControl);
            if (launchC != null) {
                dt = dts.createDTab(context.getTabResource(), re, launchC, context.getName());
                if (dt == null) {
                    launched = false;
                } else if (dts.addDTab(ureq, dt)) {
                    dts.activate(ureq, dt, context.getContext());
                    launched = true;
                }
            }
        } else {
            dts.activate(ureq, dt, context.getContext());
            launched = true;
        }
    }
    return launched;
}
Also used : Window(org.olat.core.gui.components.Window) OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntryControllerCreator(org.olat.core.id.context.ContextEntryControllerCreator) BusinessControl(org.olat.core.id.context.BusinessControl) DTabs(org.olat.core.gui.control.generic.dtabs.DTabs) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) BaseChiefController(org.olat.core.commons.chiefcontrollers.BaseChiefController) Controller(org.olat.core.gui.control.Controller) ContextEntry(org.olat.core.id.context.ContextEntry) TabContext(org.olat.core.id.context.TabContext) DTab(org.olat.core.gui.control.generic.dtabs.DTab) UserSession(org.olat.core.util.UserSession) RepositoryManager(org.olat.repository.RepositoryManager)

Example 2 with TabContext

use of org.olat.core.id.context.TabContext in project OpenOLAT by OpenOLAT.

the class NewControllerFactory method launch.

/**
 * Launch a controller in a tab or site in the given window from a user
 * request url
 *
 * @param ureq
 * @param wControl
 */
public boolean launch(UserRequest ureq, WindowControl wControl) {
    BusinessControl bc = wControl.getBusinessControl();
    ContextEntry mainCe = bc.popLauncherContextEntry();
    if (mainCe == null) {
        // nothing to launch
        return false;
    }
    OLATResourceable ores = mainCe.getOLATResourceable();
    // Check for RepositoryEntry resource
    RepositoryEntry re = null;
    if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(RepositoryEntry.class))) {
        if (ores instanceof RepositoryEntry) {
            re = (RepositoryEntry) ores;
            ores = re.getOlatResource();
        } else {
            // It is a repository-entry => get OLATResourceable from RepositoryEntry
            RepositoryManager repom = RepositoryManager.getInstance();
            re = repom.lookupRepositoryEntry(ores.getResourceableId());
            if (re != null) {
                ores = re.getOlatResource();
                mainCe.upgradeOLATResourceable(re);
            }
        }
    }
    // was brasato:: DTabs dts = wControl.getDTabs();
    UserSession usess = ureq.getUserSession();
    Window window = Windows.getWindows(usess).getWindow(ureq);
    if (window == null) {
        log.debug("Found no window for jumpin => take WindowBackOffice", null);
        window = wControl.getWindowBackOffice().getWindow();
    }
    DTabs dts = window.getDTabs();
    String firstType = mainCe.getOLATResourceable().getResourceableTypeName();
    // String firstTypeId = ClassToId.getInstance().lookup() BusinessGroup
    ContextEntryControllerCreator typeHandler = getContextEntryControllerCreator(firstType);
    if (typeHandler == null) {
        log.warn("Cannot found an handler for context entry: " + mainCe, null);
        // simply return and don't throw a red screen
        return false;
    }
    if (!typeHandler.validateContextEntryAndShowError(mainCe, ureq, wControl)) {
        // simply return and don't throw a red screen
        return false;
    }
    List<ContextEntry> entries = new ArrayList<ContextEntry>(5);
    while (bc.hasContextEntry()) {
        entries.add(bc.popLauncherContextEntry());
    }
    List<ContextEntry> ces = new ArrayList<ContextEntry>(entries.size() + 1);
    ces.add(mainCe);
    if (entries.size() > 0) {
        ces.addAll(entries);
    }
    TabContext context = typeHandler.getTabContext(ureq, ores, mainCe, entries);
    String siteClassName = typeHandler.getSiteClassName(ces, ureq);
    // open in existing site
    boolean launched = false;
    boolean assessmentMode = usess.isInAssessmentModeProcess();
    if (siteClassName != null) {
        if (!assessmentMode) {
            dts.activateStatic(ureq, siteClassName, context.getContext());
            launched = true;
        }
    } else if (!assessmentMode || usess.matchLockResource(ores)) {
        // get current tab or create new tab
        DTab dt = dts.getDTab(ores);
        if (dt == null) {
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, dts.getWindowControl());
            usess.addToHistory(ureq, bc);
            Controller launchC = typeHandler.createController(ces, ureq, bwControl);
            if (launchC != null) {
                dt = dts.createDTab(context.getTabResource(), re, launchC, context.getName());
                if (dt == null) {
                    launched = false;
                } else if (dts.addDTab(ureq, dt)) {
                    dts.activate(ureq, dt, context.getContext());
                    launched = true;
                }
            }
        } else {
            dts.activate(ureq, dt, context.getContext());
            launched = true;
        }
    }
    return launched;
}
Also used : Window(org.olat.core.gui.components.Window) OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntryControllerCreator(org.olat.core.id.context.ContextEntryControllerCreator) BusinessControl(org.olat.core.id.context.BusinessControl) DTabs(org.olat.core.gui.control.generic.dtabs.DTabs) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) BaseChiefController(org.olat.core.commons.chiefcontrollers.BaseChiefController) Controller(org.olat.core.gui.control.Controller) ContextEntry(org.olat.core.id.context.ContextEntry) TabContext(org.olat.core.id.context.TabContext) DTab(org.olat.core.gui.control.generic.dtabs.DTab) UserSession(org.olat.core.util.UserSession) RepositoryManager(org.olat.repository.RepositoryManager)

Example 3 with TabContext

use of org.olat.core.id.context.TabContext in project OpenOLAT by OpenOLAT.

the class BinderContextEntryControllerCreator method getTabContext.

@Override
public TabContext getTabContext(UserRequest ureq, OLATResourceable ores, ContextEntry mainEntry, List<ContextEntry> entries) {
    Identity identity = ureq.getIdentity();
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    Long binderKey = mainEntry.getOLATResourceable().getResourceableId();
    BinderRef binder = new BinderRefImpl(binderKey);
    List<ContextEntry> rewritedEntries = new ArrayList<ContextEntry>();
    OLATResourceable homeRes = OresHelper.createOLATResourceableInstance("HomeSite", identity.getKey());
    rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(homeRes));
    rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("PortfolioV2", 0l)));
    if (portfolioService.isMember(binder, identity, PortfolioRoles.owner.name())) {
        rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("MyBinders", 0l)));
    } else if (portfolioService.isMember(binder, identity, PortfolioRoles.coach.name(), PortfolioRoles.reviewer.name())) {
        rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("SharedWithMe", 0l)));
    }
    // Binder
    rewritedEntries.add(mainEntry);
    if (entries != null && !entries.isEmpty()) {
        // more details
        rewritedEntries.addAll(entries);
    }
    // -> HomeSite
    return new TabContext("", homeRes, rewritedEntries);
}
Also used : TabContext(org.olat.core.id.context.TabContext) OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BinderRefImpl(org.olat.modules.portfolio.model.BinderRefImpl) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 4 with TabContext

use of org.olat.core.id.context.TabContext in project openolat by klemens.

the class BinderContextEntryControllerCreator method getTabContext.

@Override
public TabContext getTabContext(UserRequest ureq, OLATResourceable ores, ContextEntry mainEntry, List<ContextEntry> entries) {
    Identity identity = ureq.getIdentity();
    PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
    Long binderKey = mainEntry.getOLATResourceable().getResourceableId();
    BinderRef binder = new BinderRefImpl(binderKey);
    List<ContextEntry> rewritedEntries = new ArrayList<ContextEntry>();
    OLATResourceable homeRes = OresHelper.createOLATResourceableInstance("HomeSite", identity.getKey());
    rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(homeRes));
    rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("PortfolioV2", 0l)));
    if (portfolioService.isMember(binder, identity, PortfolioRoles.owner.name())) {
        rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("MyBinders", 0l)));
    } else if (portfolioService.isMember(binder, identity, PortfolioRoles.coach.name(), PortfolioRoles.reviewer.name())) {
        rewritedEntries.add(BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("SharedWithMe", 0l)));
    }
    // Binder
    rewritedEntries.add(mainEntry);
    if (entries != null && !entries.isEmpty()) {
        // more details
        rewritedEntries.addAll(entries);
    }
    // -> HomeSite
    return new TabContext("", homeRes, rewritedEntries);
}
Also used : TabContext(org.olat.core.id.context.TabContext) OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BinderRefImpl(org.olat.modules.portfolio.model.BinderRefImpl) ContextEntry(org.olat.core.id.context.ContextEntry)

Aggregations

ArrayList (java.util.ArrayList)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 TabContext (org.olat.core.id.context.TabContext)4 BaseChiefController (org.olat.core.commons.chiefcontrollers.BaseChiefController)2 Window (org.olat.core.gui.components.Window)2 Controller (org.olat.core.gui.control.Controller)2 WindowControl (org.olat.core.gui.control.WindowControl)2 DTab (org.olat.core.gui.control.generic.dtabs.DTab)2 DTabs (org.olat.core.gui.control.generic.dtabs.DTabs)2 Identity (org.olat.core.id.Identity)2 BusinessControl (org.olat.core.id.context.BusinessControl)2 ContextEntryControllerCreator (org.olat.core.id.context.ContextEntryControllerCreator)2 UserSession (org.olat.core.util.UserSession)2 BinderRefImpl (org.olat.modules.portfolio.model.BinderRefImpl)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryManager (org.olat.repository.RepositoryManager)2