From b6522fd6ae493ab6e91b687c217701eec232ee23 Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Wed, 20 Jun 2018 17:14:40 +0200 Subject: [PATCH] OO-3542: add a style to align text vertical=top --- .../elements/table/XlsFlexiTableExporter.java | 5 +- .../core/util/openxml/OpenXMLWorkbook.java | 18 ++++++- .../util/openxml/OpenXMLWorkbookStyles.java | 27 +++++++---- .../util/openxml/workbookstyle/Alignment.java | 47 +++++++++++++++++++ .../util/openxml/workbookstyle/CellStyle.java | 23 ++++++++- .../curriculum/model/CurriculumMember.java | 19 ++++++++ .../ui/EditCurriculumOverviewController.java | 19 ++++++++ 7 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/olat/core/util/openxml/workbookstyle/Alignment.java diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/XlsFlexiTableExporter.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/XlsFlexiTableExporter.java index f9b9506dc01..396b94662a5 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/XlsFlexiTableExporter.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/table/XlsFlexiTableExporter.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.List; import org.apache.commons.lang.StringEscapeUtils; +import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.media.MediaResource; import org.olat.core.gui.render.EmptyURLBuilder; import org.olat.core.gui.render.StringOutput; @@ -113,6 +114,8 @@ public class XlsFlexiTableExporter implements FlexiTableExporter { dataRow.addCell(col, (Date)value, workbook.getStyles().getDateStyle()); } else if(value instanceof Number) { dataRow.addCell(col, (Number)value, null); + } else if(value instanceof FormItem) { + // do nothing } else { StringOutput so = StringOutputPool.allocStringBuilder(1000); cd.getCellRenderer().render(null, so, value, row, ftC, ubu, translator); @@ -123,7 +126,7 @@ public class XlsFlexiTableExporter implements FlexiTableExporter { if(StringHelper.containsNonWhitespace(cellValue)) { cellValue = StringEscapeUtils.unescapeHtml(cellValue); } - dataRow.addCell(col, cellValue, null); + dataRow.addCell(col, cellValue, workbook.getStyles().getTopAlignStyle()); } } } catch (Exception e) { diff --git a/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbook.java b/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbook.java index 90d3e71851a..88eab3cfd9c 100644 --- a/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbook.java +++ b/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbook.java @@ -702,10 +702,24 @@ public class OpenXMLWorkbook implements Closeable { if(style.getFill().getIndex() > 0) { writer.writeAttribute("applyFill", "1"); } - if(StringHelper.containsNonWhitespace(style.getApplyNumberFormat())) { writer.writeAttribute("applyNumberFormat", style.getApplyNumberFormat()); - } + } + if(StringHelper.containsNonWhitespace(style.getApplyAlignment())) { + writer.writeAttribute("applyalignment", style.getApplyAlignment()); + } + + if(style.getAlignment() != null) { + writer.writeStartElement("alignment"); + if(StringHelper.containsNonWhitespace(style.getAlignment().getVertical())) { + writer.writeAttribute("vertical", style.getAlignment().getVertical()); + } + if(StringHelper.containsNonWhitespace(style.getAlignment().getWraptext())) { + writer.writeAttribute("wraptext", style.getAlignment().getWraptext()); + } + writer.writeEndElement(); + } + writer.writeEndElement(); } diff --git a/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbookStyles.java b/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbookStyles.java index 6e9b226dcc7..911f501e2e6 100644 --- a/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbookStyles.java +++ b/src/main/java/org/olat/core/util/openxml/OpenXMLWorkbookStyles.java @@ -22,6 +22,7 @@ package org.olat.core.util.openxml; import java.util.ArrayList; import java.util.List; +import org.olat.core.util.openxml.workbookstyle.Alignment; import org.olat.core.util.openxml.workbookstyle.Border; import org.olat.core.util.openxml.workbookstyle.CellStyle; import org.olat.core.util.openxml.workbookstyle.Fill; @@ -63,6 +64,7 @@ public class OpenXMLWorkbookStyles { private final CellStyle correctStyle; private final CellStyle percentStyle; private final CellStyle lightGrayStyle; + private final CellStyle topAlignStyle; public OpenXMLWorkbookStyles() { standardFont = new Font(fonts.size(), "12", "1", "Calibri", "2", "minor", FontStyle.none); @@ -84,24 +86,27 @@ public class OpenXMLWorkbookStyles { borderRight = new Border(borders.size(), "thin", null, null, null); borders.add(borderRight); - standardStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, noBorder, null, null); + standardStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, noBorder, null, null, null, null); cellXfs.add(standardStyle); - borderRightStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, borderRight, null, null); + borderRightStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, borderRight, null, null, null, null); cellXfs.add(borderRightStyle); - dateStyle = new CellStyle(cellXfs.size(), DATE_FORMAT, standardFont, noneFile, noBorder, null, "1"); + dateStyle = new CellStyle(cellXfs.size(), DATE_FORMAT, standardFont, noneFile, noBorder, null, "1", null, null); cellXfs.add(dateStyle); - dateTimeStyle = new CellStyle(cellXfs.size(), DATE_TIME_FORMAT, standardFont, noneFile, noBorder, null, "1"); + dateTimeStyle = new CellStyle(cellXfs.size(), DATE_TIME_FORMAT, standardFont, noneFile, noBorder, null, "1", null, null); cellXfs.add(dateTimeStyle); - durationStyle = new CellStyle(cellXfs.size(), TIME_FORMAT, standardFont, noneFile, borderRight, null, "1"); + durationStyle = new CellStyle(cellXfs.size(), TIME_FORMAT, standardFont, noneFile, borderRight, null, "1", null, null); cellXfs.add(durationStyle); - headerStyle = new CellStyle(cellXfs.size(), "0", boldFont, noneFile, noBorder, null, null); + headerStyle = new CellStyle(cellXfs.size(), "0", boldFont, noneFile, noBorder, null, null, null, null); cellXfs.add(headerStyle); - correctStyle = new CellStyle(cellXfs.size(), "0", boldFont, correctFill, noBorder, null, null); + correctStyle = new CellStyle(cellXfs.size(), "0", boldFont, correctFill, noBorder, null, null, null, null); cellXfs.add(correctStyle); - percentStyle = new CellStyle(cellXfs.size(), PERCENT_FORMAT, standardFont, noneFile, borderRight, null, "1"); + percentStyle = new CellStyle(cellXfs.size(), PERCENT_FORMAT, standardFont, noneFile, borderRight, null, "1", null, null); cellXfs.add(percentStyle); - lightGrayStyle = new CellStyle(cellXfs.size(), "0", standardFont, lightGrayFill, borderRight, null, null); + lightGrayStyle = new CellStyle(cellXfs.size(), "0", standardFont, lightGrayFill, borderRight, null, null, null, null); cellXfs.add(lightGrayStyle); + Alignment topAlign = new Alignment(Alignment.TOP, "1"); + topAlignStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, noBorder, null, null, topAlign, "1"); + cellXfs.add(topAlignStyle); } public CellStyle getBorderRightStyle() { @@ -144,6 +149,10 @@ public class OpenXMLWorkbookStyles { return lightGrayStyle; } + public CellStyle getTopAlignStyle() { + return topAlignStyle; + } + public List<Font> getFonts() { return fonts; } diff --git a/src/main/java/org/olat/core/util/openxml/workbookstyle/Alignment.java b/src/main/java/org/olat/core/util/openxml/workbookstyle/Alignment.java new file mode 100644 index 00000000000..febf5b2dda9 --- /dev/null +++ b/src/main/java/org/olat/core/util/openxml/workbookstyle/Alignment.java @@ -0,0 +1,47 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.core.util.openxml.workbookstyle; + +/** + * + * Initial date: 20 juin 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class Alignment { + + public static final String TOP = "top"; + + private final String vertical; + private final String wraptext; + + public Alignment(String vertical, String wraptext) { + this.vertical = vertical; + this.wraptext = wraptext; + } + + public String getVertical() { + return vertical; + } + + public String getWraptext() { + return wraptext; + } +} diff --git a/src/main/java/org/olat/core/util/openxml/workbookstyle/CellStyle.java b/src/main/java/org/olat/core/util/openxml/workbookstyle/CellStyle.java index b54afe11029..ad2bb91c1ad 100644 --- a/src/main/java/org/olat/core/util/openxml/workbookstyle/CellStyle.java +++ b/src/main/java/org/olat/core/util/openxml/workbookstyle/CellStyle.java @@ -35,13 +35,14 @@ public class CellStyle extends IndexedObject { private Border border; private String applyBorder; private String applyNumberFormat; + private Alignment alignment; + private String applyAlignment; - public CellStyle(int index) { super(index); } - public CellStyle(int index, String numFmtId, Font font, Fill fill, Border border, String applyBorder, String applyNumberFormat) { + public CellStyle(int index, String numFmtId, Font font, Fill fill, Border border, String applyBorder, String applyNumberFormat, Alignment alignment, String applyAlignment) { super(index); this.numFmtId = numFmtId; this.font = font; @@ -49,6 +50,8 @@ public class CellStyle extends IndexedObject { this.border = border; this.applyBorder = applyBorder; this.applyNumberFormat = applyNumberFormat; + this.applyAlignment = applyAlignment; + this.alignment = alignment; } public Font getFont() { @@ -106,4 +109,20 @@ public class CellStyle extends IndexedObject { public void setApplyNumberFormat(String applyNumberFormat) { this.applyNumberFormat = applyNumberFormat; } + + public String getApplyAlignment() { + return applyAlignment; + } + + public void setApplyAlignment(String applyAlignment) { + this.applyAlignment = applyAlignment; + } + + public Alignment getAlignment() { + return alignment; + } + + public void setAlignment(Alignment alignment) { + this.alignment = alignment; + } } diff --git a/src/main/java/org/olat/modules/curriculum/model/CurriculumMember.java b/src/main/java/org/olat/modules/curriculum/model/CurriculumMember.java index 48e0ff21266..4cd8bb7e28a 100644 --- a/src/main/java/org/olat/modules/curriculum/model/CurriculumMember.java +++ b/src/main/java/org/olat/modules/curriculum/model/CurriculumMember.java @@ -1,3 +1,22 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ package org.olat.modules.curriculum.model; import org.olat.basesecurity.GroupMembershipInheritance; diff --git a/src/main/java/org/olat/modules/curriculum/ui/EditCurriculumOverviewController.java b/src/main/java/org/olat/modules/curriculum/ui/EditCurriculumOverviewController.java index 4b670504c33..d5ba608a2c2 100644 --- a/src/main/java/org/olat/modules/curriculum/ui/EditCurriculumOverviewController.java +++ b/src/main/java/org/olat/modules/curriculum/ui/EditCurriculumOverviewController.java @@ -1,3 +1,22 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ package org.olat.modules.curriculum.ui; import org.olat.core.gui.UserRequest; -- GitLab