Search in sources :

Example 1 with ShortName

use of org.olat.core.gui.ShortName in project OpenOLAT by OpenOLAT.

the class MailListController method reloadModel.

private void reloadModel() {
    List<DBMailLight> mails;
    if (outbox) {
        if (StringHelper.containsNonWhitespace(metaId)) {
            mails = mailManager.getEmailsByMetaId(metaId);
        } else {
            mails = mailManager.getOutbox(getIdentity(), 0, -1, true);
        }
        // strip meta emails
        Set<String> metaIds = new HashSet<>();
        for (Iterator<DBMailLight> it = mails.iterator(); it.hasNext(); ) {
            DBMailLight mail = it.next();
            if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                if (metaIds.contains(mail.getMetaId())) {
                    it.remove();
                } else {
                    metaIds.add(mail.getMetaId());
                }
            }
        }
    } else {
        mails = mailManager.getInbox(getIdentity(), null, Boolean.TRUE, null, 0, -1);
    }
    // extract contexts
    Map<String, String> bpToContexts = new HashMap<>();
    for (DBMailLight mail : mails) {
        String businessPath = mail.getContext().getBusinessPath();
        if (StringHelper.containsNonWhitespace(businessPath) && !bpToContexts.containsKey(businessPath)) {
            String contextName = contextResolver.getName(businessPath, getLocale());
            if (StringHelper.containsNonWhitespace(contextName)) {
                bpToContexts.put(businessPath, contextName);
            }
        }
    }
    if (!bpToContexts.isEmpty()) {
        List<ShortName> filters = new ArrayList<>();
        Map<String, MailContextShortName> uniqueNames = new HashMap<>();
        ShortName allContextFilter = new MailContextShortName("-");
        filters.add(allContextFilter);
        for (Map.Entry<String, String> entry : bpToContexts.entrySet()) {
            String businessPath = entry.getKey();
            String contextName = entry.getValue();
            if (!uniqueNames.containsKey(contextName)) {
                MailContextShortName cxt = new MailContextShortName(contextName, new HashSet<String>());
                filters.add(cxt);
                uniqueNames.put(contextName, cxt);
            }
            uniqueNames.get(contextName).getBusinessPaths().add(businessPath);
        }
        tableCtr.setFilters(filters, allContextFilter);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    MailDataModel dataModel = new MailDataModel(mails, bpToContexts, getIdentity(), getTranslator(), formatter, outbox);
    tableCtr.setTableDataModel(dataModel);
}
Also used : HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) ShortName(org.olat.core.gui.ShortName) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with ShortName

use of org.olat.core.gui.ShortName in project OpenOLAT by OpenOLAT.

the class OrderDetailController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    backLink = uifactory.addFormLink("back", formLayout, Link.LINK_BACK);
    FormLayoutContainer mainLayout = FormLayoutContainer.createDefaultFormLayout("mainCmp", getTranslator());
    mainLayout.setRootForm(mainForm);
    formLayout.add("mainCmp", mainLayout);
    String orderNr = order.getOrderNr();
    uifactory.addStaticTextElement("order-nr", "order.nr", orderNr, mainLayout);
    Date creationDate = order.getCreationDate();
    String creationDateStr = Formatter.getInstance(getLocale()).formatDateAndTime(creationDate);
    uifactory.addStaticTextElement("creation-date", "order.creationDate", creationDateStr, mainLayout);
    String orderTotal = PriceFormat.fullFormat(order.getTotal());
    String orderTotalStr;
    if (acModule.isVatEnabled()) {
        BigDecimal vat = acModule.getVat();
        String vatStr = vat == null ? "" : vat.setScale(3, BigDecimal.ROUND_HALF_EVEN).toPlainString();
        orderTotalStr = translate("access.info.price.vat", new String[] { orderTotal, vatStr });
    } else {
        orderTotalStr = translate("access.info.price.noVat", new String[] { orderTotal });
    }
    uifactory.addStaticTextElement("order-total", "order.total", orderTotalStr, mainLayout);
    OrderItemsDataModel tableModel = getOrderItemsDataModel();
    if (tableModel.getRowCount() == 1) {
        OrderItemWrapper wrapper = tableModel.getObject(0);
        if (wrapper.getItem().getOffer().getResource() != null) {
            // resource is null if the resource has been deleted
            String linkName = StringHelper.escapeHtml(wrapper.getDisplayName());
            selectResourceLink = uifactory.addFormLink("resource", linkName, translate("order.item"), mainLayout, Link.NONTRANSLATED);
            selectResourceLink.setUserObject(wrapper);
            selectResourceLink.setCustomEnabledLinkCSS("form-control-static");
        }
    }
    User user = order.getDelivery().getUser();
    String delivery = StringHelper.escapeHtml(userManager.getUserDisplayName(user));
    uifactory.addStaticTextElement("delivery", "order.delivery", delivery, mainLayout);
    if (formLayout instanceof FormLayoutContainer) {
        TableGuiConfiguration tableConfig = new TableGuiConfiguration();
        tableConfig.setDownloadOffered(false);
        tableConfig.setTableEmptyMessage(translate("orders.empty"));
        tableCtr = new TableController(tableConfig, ureq, getWindowControl(), Collections.<ShortName>emptyList(), null, null, null, false, getTranslator());
        tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("order.item.name", 0, null, getLocale()));
        tableCtr.addColumnDescriptor(new CustomRenderColumnDescriptor("order.part.payment", 1, null, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new AccessMethodRenderer(acModule)));
        tableCtr.addColumnDescriptor(new StaticColumnDescriptor(CMD_SELECT, "table.order.details", getTranslator().translate("order.details")));
        tableCtr.setTableDataModel(tableModel);
        listenTo(tableCtr);
        FormLayoutContainer layoutContainer = (FormLayoutContainer) formLayout;
        layoutContainer.put("orderItemList", tableCtr.getInitialComponent());
    }
}
Also used : CustomRenderColumnDescriptor(org.olat.core.gui.components.table.CustomRenderColumnDescriptor) User(org.olat.core.id.User) TableController(org.olat.core.gui.components.table.TableController) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ShortName(org.olat.core.gui.ShortName) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) Date(java.util.Date) BigDecimal(java.math.BigDecimal) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor)

Example 3 with ShortName

use of org.olat.core.gui.ShortName in project OpenOLAT by OpenOLAT.

the class RepositorySearchController method updateFilters.

protected void updateFilters(List<RepositoryEntry> entries, Identity owner) {
    List<ShortName> restrictedTypes = new ArrayList<ShortName>();
    Set<String> uniqueTypes = new HashSet<String>();
    for (RepositoryEntry entry : entries) {
        // no red screen for that
        if (entry.getOlatResource() == null)
            continue;
        String type = entry.getOlatResource().getResourceableTypeName();
        if (type != null && !uniqueTypes.contains(type)) {
            String label = translate(type);
            restrictedTypes.add(new TypeFilter(type, label, owner));
            uniqueTypes.add(type);
        }
    }
    if (restrictedTypes.size() > 1) {
        tableCtr.setFilters(restrictedTypes, null);
    } else {
        tableCtr.setFilters(null, null);
    }
}
Also used : ArrayList(java.util.ArrayList) ShortName(org.olat.core.gui.ShortName) RepositoryEntry(org.olat.repository.RepositoryEntry) HashSet(java.util.HashSet)

Example 4 with ShortName

use of org.olat.core.gui.ShortName in project openolat by klemens.

the class OrderDetailController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    backLink = uifactory.addFormLink("back", formLayout, Link.LINK_BACK);
    FormLayoutContainer mainLayout = FormLayoutContainer.createDefaultFormLayout("mainCmp", getTranslator());
    mainLayout.setRootForm(mainForm);
    formLayout.add("mainCmp", mainLayout);
    String orderNr = order.getOrderNr();
    uifactory.addStaticTextElement("order-nr", "order.nr", orderNr, mainLayout);
    Date creationDate = order.getCreationDate();
    String creationDateStr = Formatter.getInstance(getLocale()).formatDateAndTime(creationDate);
    uifactory.addStaticTextElement("creation-date", "order.creationDate", creationDateStr, mainLayout);
    String orderTotal = PriceFormat.fullFormat(order.getTotal());
    String orderTotalStr;
    if (acModule.isVatEnabled()) {
        BigDecimal vat = acModule.getVat();
        String vatStr = vat == null ? "" : vat.setScale(3, BigDecimal.ROUND_HALF_EVEN).toPlainString();
        orderTotalStr = translate("access.info.price.vat", new String[] { orderTotal, vatStr });
    } else {
        orderTotalStr = translate("access.info.price.noVat", new String[] { orderTotal });
    }
    uifactory.addStaticTextElement("order-total", "order.total", orderTotalStr, mainLayout);
    OrderItemsDataModel tableModel = getOrderItemsDataModel();
    if (tableModel.getRowCount() == 1) {
        OrderItemWrapper wrapper = tableModel.getObject(0);
        if (wrapper.getItem().getOffer().getResource() != null) {
            // resource is null if the resource has been deleted
            String linkName = StringHelper.escapeHtml(wrapper.getDisplayName());
            selectResourceLink = uifactory.addFormLink("resource", linkName, translate("order.item"), mainLayout, Link.NONTRANSLATED);
            selectResourceLink.setUserObject(wrapper);
            selectResourceLink.setCustomEnabledLinkCSS("form-control-static");
        }
    }
    User user = order.getDelivery().getUser();
    String delivery = StringHelper.escapeHtml(userManager.getUserDisplayName(user));
    uifactory.addStaticTextElement("delivery", "order.delivery", delivery, mainLayout);
    if (formLayout instanceof FormLayoutContainer) {
        TableGuiConfiguration tableConfig = new TableGuiConfiguration();
        tableConfig.setDownloadOffered(false);
        tableConfig.setTableEmptyMessage(translate("orders.empty"));
        tableCtr = new TableController(tableConfig, ureq, getWindowControl(), Collections.<ShortName>emptyList(), null, null, null, false, getTranslator());
        tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("order.item.name", 0, null, getLocale()));
        tableCtr.addColumnDescriptor(new CustomRenderColumnDescriptor("order.part.payment", 1, null, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new AccessMethodRenderer(acModule)));
        tableCtr.addColumnDescriptor(new StaticColumnDescriptor(CMD_SELECT, "table.order.details", getTranslator().translate("order.details")));
        tableCtr.setTableDataModel(tableModel);
        listenTo(tableCtr);
        FormLayoutContainer layoutContainer = (FormLayoutContainer) formLayout;
        layoutContainer.put("orderItemList", tableCtr.getInitialComponent());
    }
}
Also used : CustomRenderColumnDescriptor(org.olat.core.gui.components.table.CustomRenderColumnDescriptor) User(org.olat.core.id.User) TableController(org.olat.core.gui.components.table.TableController) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ShortName(org.olat.core.gui.ShortName) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) Date(java.util.Date) BigDecimal(java.math.BigDecimal) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor)

Example 5 with ShortName

use of org.olat.core.gui.ShortName in project openolat by klemens.

the class MailListController method reloadModel.

private void reloadModel() {
    List<DBMailLight> mails;
    if (outbox) {
        if (StringHelper.containsNonWhitespace(metaId)) {
            mails = mailManager.getEmailsByMetaId(metaId);
        } else {
            mails = mailManager.getOutbox(getIdentity(), 0, -1, true);
        }
        // strip meta emails
        Set<String> metaIds = new HashSet<>();
        for (Iterator<DBMailLight> it = mails.iterator(); it.hasNext(); ) {
            DBMailLight mail = it.next();
            if (StringHelper.containsNonWhitespace(mail.getMetaId())) {
                if (metaIds.contains(mail.getMetaId())) {
                    it.remove();
                } else {
                    metaIds.add(mail.getMetaId());
                }
            }
        }
    } else {
        mails = mailManager.getInbox(getIdentity(), null, Boolean.TRUE, null, 0, -1);
    }
    // extract contexts
    Map<String, String> bpToContexts = new HashMap<>();
    for (DBMailLight mail : mails) {
        String businessPath = mail.getContext().getBusinessPath();
        if (StringHelper.containsNonWhitespace(businessPath) && !bpToContexts.containsKey(businessPath)) {
            String contextName = contextResolver.getName(businessPath, getLocale());
            if (StringHelper.containsNonWhitespace(contextName)) {
                bpToContexts.put(businessPath, contextName);
            }
        }
    }
    if (!bpToContexts.isEmpty()) {
        List<ShortName> filters = new ArrayList<>();
        Map<String, MailContextShortName> uniqueNames = new HashMap<>();
        ShortName allContextFilter = new MailContextShortName("-");
        filters.add(allContextFilter);
        for (Map.Entry<String, String> entry : bpToContexts.entrySet()) {
            String businessPath = entry.getKey();
            String contextName = entry.getValue();
            if (!uniqueNames.containsKey(contextName)) {
                MailContextShortName cxt = new MailContextShortName(contextName, new HashSet<String>());
                filters.add(cxt);
                uniqueNames.put(contextName, cxt);
            }
            uniqueNames.get(contextName).getBusinessPaths().add(businessPath);
        }
        tableCtr.setFilters(filters, allContextFilter);
    }
    Formatter formatter = Formatter.getInstance(getLocale());
    MailDataModel dataModel = new MailDataModel(mails, bpToContexts, getIdentity(), getTranslator(), formatter, outbox);
    tableCtr.setTableDataModel(dataModel);
}
Also used : HashMap(java.util.HashMap) Formatter(org.olat.core.util.Formatter) ArrayList(java.util.ArrayList) ShortName(org.olat.core.gui.ShortName) DBMailLight(org.olat.core.util.mail.model.DBMailLight) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

ShortName (org.olat.core.gui.ShortName)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 CustomRenderColumnDescriptor (org.olat.core.gui.components.table.CustomRenderColumnDescriptor)2 DefaultColumnDescriptor (org.olat.core.gui.components.table.DefaultColumnDescriptor)2 StaticColumnDescriptor (org.olat.core.gui.components.table.StaticColumnDescriptor)2 TableController (org.olat.core.gui.components.table.TableController)2 TableGuiConfiguration (org.olat.core.gui.components.table.TableGuiConfiguration)2 User (org.olat.core.id.User)2 Formatter (org.olat.core.util.Formatter)2 DBMailLight (org.olat.core.util.mail.model.DBMailLight)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2