Search in sources :

Example 16 with TableGuiConfiguration

use of org.olat.core.gui.components.table.TableGuiConfiguration in project openolat by klemens.

the class ProjectListController method createTableController.

private TableController createTableController(final UserRequest ureq, WindowControl wControl) {
    numberOfCustomFieldInTable = 0;
    numberOfEventInTable = 0;
    TableGuiConfiguration tableConfig = new TableGuiConfiguration();
    tableConfig.setTableEmptyMessage(translate("projectlist.no.projects"));
    tableConfig.setPreferencesOffered(true, "projectbrokerList");
    // Do not allow show all because many entries takes too long to render
    tableConfig.setShowAllLinkEnabled(false);
    removeAsListenerAndDispose(tableController);
    tableController = new TableController(tableConfig, ureq, wControl, this.getTranslator(), true);
    listenTo(tableController);
    int dataColumn = 0;
    tableController.addColumnDescriptor(new DefaultColumnDescriptor("projectlist.tableheader.title", dataColumn++, TABLE_ACTION_SHOW_DETAIL, getLocale()));
    CustomRenderColumnDescriptor projectManagerDescriptor = new CustomRenderColumnDescriptor("projectlist.tableheader.account.manager", dataColumn++, TABLE_ACTION_ACCOUNT_MANAGER, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new ProjectManagerColumnRenderer()) {

        /**
         * @see org.olat.core.gui.components.table.DefaultColumnDescriptor#compareTo(int, int)
         */
        @Override
        public int compareTo(int rowa, int rowb) {
            return super.compareTo(rowa, rowb);
        }

        /**
         * @see org.olat.core.gui.components.table.CustomRenderColumnDescriptor#renderValue(org.olat.core.gui.render.StringOutput, int, org.olat.core.gui.render.Renderer)
         */
        @Override
        public void renderValue(StringOutput sb, int row, Renderer renderer) {
            Object val = getModelData(row);
            // to get info about row in Renderer!
            String rowSt = Integer.toString(row);
            getCustomCellRenderer().render(sb, renderer, val, getLocale(), getAlignment(), rowSt);
        }
    };
    tableController.addColumnDescriptor(projectManagerDescriptor);
    // Custom-Fields
    List<CustomField> customFieldList = moduleConfig.getCustomFields();
    for (Iterator<CustomField> iterator = customFieldList.iterator(); iterator.hasNext(); ) {
        CustomField customField = iterator.next();
        if (customField.isTableViewEnabled()) {
            numberOfCustomFieldInTable++;
            DefaultColumnDescriptor columnDescriptor = new DefaultColumnDescriptor(customField.getName(), dataColumn++, null, getLocale());
            columnDescriptor.setTranslateHeaderKey(false);
            tableController.addColumnDescriptor(columnDescriptor);
        }
    }
    // Project Events
    for (Project.EventType eventType : Project.EventType.values()) {
        if (moduleConfig.isProjectEventEnabled(eventType) && moduleConfig.isProjectEventTableViewEnabled(eventType)) {
            numberOfEventInTable++;
            tableController.addColumnDescriptor(new CustomRenderColumnDescriptor("projectlist.tableheader.event." + eventType.getI18nKey(), dataColumn++, null, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new ProjectEventColumnRenderer()));
        }
    }
    tableController.addColumnDescriptor(new CustomRenderColumnDescriptor("projectlist.tableheader.state", dataColumn++, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new ProjectStateColumnRenderer()));
    tableController.addColumnDescriptor(new DefaultColumnDescriptor("projectlist.tableheader.numbers", dataColumn++, null, getLocale()) {

        @Override
        public int compareTo(int rowa, int rowb) {
            Object a = table.getTableDataModel().getValueAt(rowa, dataColumn);
            Object b = table.getTableDataModel().getValueAt(rowb, dataColumn);
            if (a == null || b == null) {
                boolean bb = (b == null);
                return (a == null) ? (bb ? 0 : -1) : (bb ? 1 : 0);
            }
            try {
                Long la = new Long((String) a);
                Long lb = new Long((String) b);
                return la.compareTo(lb);
            } catch (NumberFormatException e) {
                return super.compareTo(rowa, rowb);
            }
        }
    });
    String selectCmd = userCourseEnv.isCourseReadOnly() ? null : TABLE_ACTION_SELECT;
    tableController.addColumnDescriptor(new BooleanColumnDescriptor("projectlist.tableheader.select", dataColumn++, selectCmd, translate("table.action.select"), "-"));
    String cancelCmd = userCourseEnv.isCourseReadOnly() ? null : TABLE_ACTION_CANCEL_SELECT;
    tableController.addColumnDescriptor(new BooleanColumnDescriptor("projectlist.tableheader.cancel.select", dataColumn++, cancelCmd, translate("projectlist.tableheader.cancel.select"), "-"));
    return tableController;
}
Also used : CustomRenderColumnDescriptor(org.olat.core.gui.components.table.CustomRenderColumnDescriptor) TableController(org.olat.core.gui.components.table.TableController) StringOutput(org.olat.core.gui.render.StringOutput) BooleanColumnDescriptor(org.olat.core.gui.components.table.BooleanColumnDescriptor) Project(org.olat.course.nodes.projectbroker.datamodel.Project) Renderer(org.olat.core.gui.render.Renderer) CustomField(org.olat.course.nodes.projectbroker.datamodel.CustomField) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor)

Example 17 with TableGuiConfiguration

use of org.olat.core.gui.components.table.TableGuiConfiguration in project openolat by klemens.

the class WikiMainController method refreshTableDataModel.

private void refreshTableDataModel(UserRequest ureq, Wiki wiki) {
    removeAsListenerAndDispose(mediaTableCtr);
    mediaTableCtr = new TableController(new TableGuiConfiguration(), ureq, getWindowControl(), getTranslator());
    listenTo(mediaTableCtr);
    mediaTableCtr.setMultiSelect(true);
    mediaTableCtr.addMultiSelectAction(ACTION_DELETE_MEDIAS, ACTION_DELETE_MEDIAS);
    List<VFSItem> filelist = wiki.getMediaFileListWithMetadata();
    Map<String, MediaFileElement> files = new HashMap<String, MediaFileElement>();
    for (Iterator<VFSItem> iter = filelist.iterator(); iter.hasNext(); ) {
        VFSLeaf elem = (VFSLeaf) iter.next();
        if (elem.getName().endsWith(METADATA_SUFFIX)) {
            // *.metadata files
            // go here
            Properties p = new Properties();
            try {
                p.load(elem.getInputStream());
                MediaFileElement mediaFileElement = new MediaFileElement(elem.getName(), p.getProperty(MEDIA_FILE_CREATED_BY), p.getProperty(MEDIA_FILE_CREATIONDATE));
                mediaFileElement.setDeletedBy(p.getProperty(MEDIA_FILE_DELETED_BY));
                mediaFileElement.setDeletionDate(p.getProperty(MEDIA_FILE_DELETIONDATE));
                files.put(p.getProperty(MEDIA_FILE_FILENAME), mediaFileElement);
            } catch (IOException e) {
                throw new OLATRuntimeException("Could'n read properties from media file: " + elem.getName(), e);
            }
        }
    }
    for (Iterator<VFSItem> iter = filelist.iterator(); iter.hasNext(); ) {
        VFSLeaf elem = (VFSLeaf) iter.next();
        if (!elem.getName().endsWith(METADATA_SUFFIX)) {
            if (!files.containsKey(elem.getName())) {
                // legacy file without metadata
                files.put(elem.getName(), new MediaFileElement(elem.getName(), 0, elem.getLastModified()));
            } else {
                // file with metadata, update name
                MediaFileElement element = files.get(elem.getName());
                element.setFileName(elem.getName());
            }
        }
    }
    mediaFilesTableModel = new MediaFilesTableModel(new ArrayList<MediaFileElement>(files.values()), getTranslator());
    mediaFilesTableModel.addColumnDescriptors(mediaTableCtr);
    mediaTableCtr.setTableDataModel(mediaFilesTableModel);
    mediaTableCtr.setSortColumn(3, false);
    mediaTableCtr.modelChanged();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) TableController(org.olat.core.gui.components.table.TableController) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Properties(java.util.Properties) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration)

Example 18 with TableGuiConfiguration

use of org.olat.core.gui.components.table.TableGuiConfiguration 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 19 with TableGuiConfiguration

use of org.olat.core.gui.components.table.TableGuiConfiguration in project openolat by klemens.

the class ENRunController method createTableController.

private TableController createTableController(UserRequest ureq, boolean hasAnyWaitingList) {
    TableGuiConfiguration tableConfig = new TableGuiConfiguration();
    tableConfig.setTableEmptyMessage(translate("grouplist.no.groups"));
    removeAsListenerAndDispose(tableCtr);
    tableCtr = new TableController(tableConfig, ureq, getWindowControl(), getTranslator());
    listenTo(tableCtr);
    tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("grouplist.table.name", 0, CMD_VISIT_CARD, getLocale()));
    DefaultColumnDescriptor descCd = new DefaultColumnDescriptor("grouplist.table.desc", 1, null, getLocale());
    descCd.setEscapeHtml(EscapeMode.antisamy);
    tableCtr.addColumnDescriptor(descCd);
    tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("grouplist.table.partipiciant", 2, null, getLocale()) {

        @Override
        public int compareTo(int rowa, int rowb) {
            Object a = table.getTableDataModel().getValueAt(rowa, dataColumn);
            Object b = table.getTableDataModel().getValueAt(rowb, dataColumn);
            if (a == null || b == null) {
                boolean bb = (b == null);
                return (a == null) ? (bb ? 0 : -1) : (bb ? 1 : 0);
            }
            try {
                Integer la, lb;
                if (a instanceof String) {
                    String sa = (String) a;
                    la = Integer.parseInt(sa.substring(0, sa.indexOf("/")));
                } else {
                    la = (Integer) a;
                }
                if (b instanceof String) {
                    String sb = (String) b;
                    lb = Integer.parseInt(sb.substring(0, sb.indexOf("/")));
                } else {
                    lb = (Integer) b;
                }
                return la.compareTo(lb);
            } catch (NumberFormatException e) {
                return super.compareTo(rowa, rowb);
            }
        }
    });
    tableCtr.addColumnDescriptor(hasAnyWaitingList, new DefaultColumnDescriptor("grouplist.table.waitingList", 3, null, getLocale()));
    DefaultColumnDescriptor stateColdEsc = new DefaultColumnDescriptor("grouplist.table.state", 4, null, getLocale());
    stateColdEsc.setEscapeHtml(EscapeMode.none);
    tableCtr.addColumnDescriptor(stateColdEsc);
    String enrollCmd = userCourseEnv.isCourseReadOnly() ? null : CMD_ENROLL_IN_GROUP;
    BooleanColumnDescriptor columnDesc = new BooleanColumnDescriptor("grouplist.table.enroll", 5, enrollCmd, translate(CMD_ENROLL_IN_GROUP), translate("grouplist.table.no_action"));
    columnDesc.setSortingAllowed(false);
    tableCtr.addColumnDescriptor(columnDesc);
    String cancelCmd = userCourseEnv.isCourseReadOnly() ? null : CMD_ENROLLED_CANCEL;
    tableCtr.addColumnDescriptor(new BooleanColumnDescriptor("grouplist.table.cancel_enroll", 6, cancelCmd, translate(CMD_ENROLLED_CANCEL), translate("grouplist.table.no_action")));
    return tableCtr;
}
Also used : BooleanColumnDescriptor(org.olat.core.gui.components.table.BooleanColumnDescriptor) TableController(org.olat.core.gui.components.table.TableController) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor)

Example 20 with TableGuiConfiguration

use of org.olat.core.gui.components.table.TableGuiConfiguration in project openolat by klemens.

the class BusinessGroupMainRunController method doShowResources.

private void doShowResources(UserRequest ureq) {
    // always refresh data model, maybe it has changed
    RepositoryTableModel repoTableModel = new RepositoryTableModel(getLocale());
    List<RepositoryEntry> repoTableModelEntries = businessGroupService.findRepositoryEntries(Collections.singletonList(businessGroup), 0, -1);
    repoTableModel.setObjects(repoTableModelEntries);
    // init table controller only once
    if (resourcesCtr == null) {
        TableGuiConfiguration tableConfig = new TableGuiConfiguration();
        tableConfig.setTableEmptyMessage(translate("resources.noresources"));
        // removeAsListenerAndDispose(resourcesCtr);
        resourcesCtr = new TableController(tableConfig, ureq, getWindowControl(), resourceTrans);
        listenTo(resourcesCtr);
        resourcesVC = createVelocityContainer("resources");
        repoTableModel.addColumnDescriptors(resourcesCtr, true, false, false, false);
        resourcesVC.put("resources", resourcesCtr.getInitialComponent());
    }
    // add table model to table
    resourcesCtr.setTableDataModel(repoTableModel);
    mainPanel.setContent(resourcesVC);
    addToHistory(ureq, ORES_TOOLRESOURCES, null);
}
Also used : RepositoryTableModel(org.olat.repository.ui.RepositoryTableModel) TableController(org.olat.core.gui.components.table.TableController) RepositoryEntry(org.olat.repository.RepositoryEntry) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration)

Aggregations

TableController (org.olat.core.gui.components.table.TableController)60 TableGuiConfiguration (org.olat.core.gui.components.table.TableGuiConfiguration)60 DefaultColumnDescriptor (org.olat.core.gui.components.table.DefaultColumnDescriptor)38 StaticColumnDescriptor (org.olat.core.gui.components.table.StaticColumnDescriptor)14 CustomRenderColumnDescriptor (org.olat.core.gui.components.table.CustomRenderColumnDescriptor)12 BooleanColumnDescriptor (org.olat.core.gui.components.table.BooleanColumnDescriptor)10 Identity (org.olat.core.id.Identity)8 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 BaseSecurityModule (org.olat.basesecurity.BaseSecurityModule)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 Roles (org.olat.core.id.Roles)4 CourseEnvironment (org.olat.course.run.environment.CourseEnvironment)4 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)4 RepositoryTableModel (org.olat.repository.ui.RepositoryTableModel)4 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Properties (java.util.Properties)2