Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions api/src/org/labkey/api/data/AbstractExcelDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.labkey.api.view.ActionURL;
import org.labkey.api.writer.HtmlWriter;

import java.io.IOException;
import java.io.Writer;

public abstract class AbstractExcelDisplayColumn extends DisplayColumn
Expand Down Expand Up @@ -44,24 +43,12 @@ public void renderDetailsCellContents(RenderContext ctx, HtmlWriter out)
throw new UnsupportedOperationException("This is for excel only.");
}

@Override
public void renderDetailsCellContents(RenderContext ctx, Writer oldWriter, HtmlWriter out)
{
throw new UnsupportedOperationException("This is for excel only.");
}

@Override
public void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value)
{
throw new UnsupportedOperationException("This is for excel only.");
}

@Override
protected void renderInputHtml(RenderContext ctx, Writer oldWriter, HtmlWriter out, Object value) throws IOException
{
throw new UnsupportedOperationException("This is for excel only.");
}

@Override
public HtmlString getTitle(RenderContext ctx)
{
Expand Down
176 changes: 83 additions & 93 deletions api/src/org/labkey/api/data/DataColumn.java

Large diffs are not rendered by default.

46 changes: 6 additions & 40 deletions api/src/org/labkey/api/data/DisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ public boolean shouldRenderInCurrentRow(RenderContext ctx)
/*
Note: DataRegion plus its subclasses and the vast majority of DisplayColumn (and subclasses) have been rewritten
to use HtmlWriter, DOM, and builders instead of String-based HTML generation. They also no longer throw
IOException. The three deprecated methods below that take both Writer and HtmlWriter are temporary, present only
until their overrides are migrated to use HtmlWriter, DOM, and builders, and adjusted to override the
corresponding non-Writer variant. Once migrated, the deprecated methods will be removed and the non-deprecated
variants will be made abstract.
IOException. The deprecated renderGridCellContents() variant below that take both Writer and HtmlWriter is
temporary, present only until its overrides are migrated to use HtmlWriter, DOM, and builders, and adjusted to
override the corresponding non-Writer variant. Once migrated, the deprecated method will be removed and the
non-deprecated variant will be made abstract.
*/

public void renderGridCellContents(RenderContext ctx, HtmlWriter out)
Expand All @@ -169,43 +169,9 @@ protected void renderGridCellContents(RenderContext ctx, Writer oldWriter, HtmlW
throw new IllegalStateException("Must override renderGridCellContents()");
}

public void renderDetailsCellContents(RenderContext ctx, HtmlWriter out)
{
try
{
renderDetailsCellContents(ctx, out.unwrap(), out);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}

// No callers (other than just above)
@Deprecated
protected void renderDetailsCellContents(RenderContext ctx, Writer oldWriter, HtmlWriter out) throws IOException
{
throw new IllegalStateException("Must override renderDetailsCellContents()");
}
public abstract void renderDetailsCellContents(RenderContext ctx, HtmlWriter out);

public void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value)
{
try
{
renderInputHtml(ctx, out.unwrap(), out, value);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}

// No callers (other than just above)
@Deprecated
protected void renderInputHtml(RenderContext ctx, Writer oldWriter, HtmlWriter out, Object value) throws IOException
{
throw new IllegalStateException("Must override renderInputHtml()");
}
public abstract void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value);

public @Nullable HtmlString getTitle(RenderContext ctx)
{
Expand Down
65 changes: 22 additions & 43 deletions api/src/org/labkey/api/data/MVDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.HtmlStringBuilder;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.element.Select.SelectBuilder;
import org.labkey.api.writer.HtmlWriter;

import java.io.IOException;
import java.io.Writer;
import java.util.Set;

import static org.labkey.api.util.DOM.Attribute.style;
Expand Down Expand Up @@ -180,57 +179,37 @@ public void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value)
{
DIV(at(style,"margin-top:5px")).appendTo(out);
super.renderInputHtml(ctx, out, value);
try
{
renderMVPicker(ctx, out);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
renderMVPicker(ctx, out);
}

private void renderMVPicker(RenderContext ctx, HtmlWriter out) throws IOException
private void renderMVPicker(RenderContext ctx, HtmlWriter out)
{
Writer oldWriter = out.unwrap();
String formFieldName = ctx.getForm().getFormFieldName(mvIndicatorColumn);
String selectedMvIndicator = getMvIndicator(ctx);
Set<String> mvIndicators = MvUtil.getMvIndicators(ctx.getContainer());
oldWriter.write("Missing Value Indicator:&nbsp;");
oldWriter.write("<select style=\"margin-bottom:5px; margin-top:2px\"");
outputName(ctx, oldWriter, formFieldName);
if (isDisabledInput())
oldWriter.write(" DISABLED");
oldWriter.write(">\n");
oldWriter.write("<option value=\"\"></option>");
for (String mvIndicator : mvIndicators)
{
oldWriter.write(" <option value=\"");
oldWriter.write(mvIndicator);
oldWriter.write("\"");
if (null != selectedMvIndicator && mvIndicator.equals(selectedMvIndicator))
oldWriter.write(" selected ");
oldWriter.write(" >");
oldWriter.write(mvIndicator);
oldWriter.write("</option>\n");
}
oldWriter.write("</select>");
// disabled inputs are not posted with the form, so we output a hidden form element:
//if (isDisabledInput())
// renderHiddenFormInput(ctx, out, formFieldName, value);
}

private void outputName(RenderContext ctx, Writer out, String formFieldName) throws IOException
{
out.write(" name=\"");
out.write(PageFlowUtil.filter(formFieldName));
out.write("\"");

String setFocusId = (String)ctx.get("setFocusId");
if (null != setFocusId)
{
out.write(" id=\"" + PageFlowUtil.filter(setFocusId) + "\"");
ctx.remove("setFocusId");
}

out.write("Missing Value Indicator:");
out.write(HtmlString.NBSP);

new SelectBuilder()
.addStyle("margin-bottom:5px")
.addStyle("margin-top:2px")
.className(null)
.name(formFieldName)
.id(setFocusId)
.disabled(isDisabledInput())
.addOption("")
.addOptions(mvIndicators)
.selected(selectedMvIndicator)
.appendTo(out);

// disabled inputs are not posted with the form, so we output a hidden form element:
//if (isDisabledInput())
// renderHiddenFormInput(ctx, out, formFieldName, value);
}
}
10 changes: 2 additions & 8 deletions api/src/org/labkey/api/data/SimpleDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public Object getValue(RenderContext ctx)
}

@Override
public void renderDetailsCellContents(RenderContext ctx, Writer oldWriter, HtmlWriter out) throws IOException
public void renderDetailsCellContents(RenderContext ctx, HtmlWriter out)
{
Object value = getValue(ctx);
if (value != null)
oldWriter.write(value.toString());
out.write(value.toString());
}

@Override
Expand Down Expand Up @@ -167,12 +167,6 @@ public void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value)
throw new UnsupportedOperationException("Non Bound columns not editable for " + this);
}

@Override
public void renderInputHtml(RenderContext ctx, Writer oldWriter, HtmlWriter out, Object value) throws IOException
{
throw new UnsupportedOperationException("Non Bound columns not editable for " + this);
}

@Override
public @NotNull HtmlString getTitle(RenderContext ctx)
{
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/query/PropertiesDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public boolean isEditable()
}

@Override
public void renderInputHtml(RenderContext ctx, Writer oldWriter, HtmlWriter out, Object value)
public void renderInputHtml(RenderContext ctx, HtmlWriter out, Object value)
{
// no-op
}
Expand Down
42 changes: 20 additions & 22 deletions api/src/org/labkey/api/study/actions/StudyPickerColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.study.Study;
import org.labkey.api.study.publish.StudyPublishService;
import org.labkey.api.util.DOM.Renderable;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.util.element.Input;
import org.labkey.api.util.element.Option.OptionBuilder;
import org.labkey.api.util.element.Select.SelectBuilder;
import org.labkey.api.writer.HtmlWriter;

import java.io.IOException;
import java.io.Writer;
import java.util.Set;

import static org.labkey.api.util.DOM.TD;
import static org.labkey.api.util.DOM.cl;

public class StudyPickerColumn extends UploadWizardAction.InputDisplayColumn
{
ColumnInfo _colInfo;
Expand Down Expand Up @@ -69,29 +71,25 @@ public void renderDetailsCaptionCell(RenderContext ctx, HtmlWriter out, @Nullabl
if (null == _caption)
return;

Writer oldWriter = out.unwrap();
try
{
oldWriter.write("<td class=\"" + (cls != null ? cls : "lk-form-label") + "\">");
oldWriter.write(getTitle(ctx).toString());
int mode = ctx.getMode();
if (mode == DataRegion.MODE_INSERT || mode == DataRegion.MODE_UPDATE)
{
if (_colInfo != null)
TD(
cl(cls != null ? cls : "lk-form-label"),
getTitle(ctx),
(Renderable) ret -> {
int mode = ctx.getMode();
if (mode == DataRegion.MODE_INSERT || mode == DataRegion.MODE_UPDATE)
{
String helpPopupText = ((_colInfo.getFriendlyTypeName() != null) ? "Type: " + _colInfo.getFriendlyTypeName() + "\n" : "") +
((_colInfo.getDescription() != null) ? "Description: " + _colInfo.getDescription() + "\n" : "");
PageFlowUtil.popupHelp(HtmlString.of(helpPopupText), _colInfo.getName());
if (!_colInfo.isNullable())
oldWriter.write(" *");
if (_colInfo != null)
{
String helpPopupText = ((_colInfo.getFriendlyTypeName() != null) ? "Type: " + _colInfo.getFriendlyTypeName() + "\n" : "") +
((_colInfo.getDescription() != null) ? "Description: " + _colInfo.getDescription() + "\n" : "");
out.write(PageFlowUtil.popupHelp(HtmlString.of(helpPopupText), _colInfo.getName()));
if (!_colInfo.isNullable())
out.write(" *");
}
}
return ret;
}
oldWriter.write("</td>");
}
catch (IOException e)
{
throw new RuntimeException(e);
}
).appendTo(out);
}

protected boolean isDisabledInput()
Expand Down
33 changes: 33 additions & 0 deletions api/src/org/labkey/api/util/element/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.labkey.api.util.element;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.RenderContext;
import org.labkey.api.util.HasHtmlString;
Expand Down Expand Up @@ -122,6 +123,7 @@ public static State get(String stateName)
private final @Nullable HtmlString _value;
private final Integer _tabIndex;
private final List<String> _styles;
private final List<InputBuilder.DataAttribute> _dataAttributes;

protected Input(InputBuilder<?> builder)
{
Expand Down Expand Up @@ -169,6 +171,7 @@ protected Input(InputBuilder<?> builder)
_needsWrapping = builder._needsWrapping == null || builder._needsWrapping;
_tabIndex = builder._tabIndex;
_styles = builder._styles;
_dataAttributes = builder._dataAttributes;
}

public String getAutoComplete()
Expand Down Expand Up @@ -406,6 +409,11 @@ public List<String> getStyles()
return _styles;
}

private List<InputBuilder.DataAttribute> getDataAttributes()
{
return _dataAttributes;
}

@Override
public void render(RenderContext ctx, Writer out) throws IOException
{
Expand Down Expand Up @@ -566,6 +574,7 @@ protected void doInput(Appendable sb) throws IOException
sb.append(" tabIndex=\"").append(h(_tabIndex)).append("\"");

doStyles(sb);
doDataAttributes(sb);
if (!HtmlString.isBlank(getValue()))
sb.append(" value=\"").append(h(getValue())).append("\"");
doInputEvents(id);
Expand Down Expand Up @@ -610,6 +619,20 @@ protected void doStyles(Appendable sb) throws IOException
}
}

protected void doDataAttributes(Appendable sb)
{
getDataAttributes().forEach(attr -> {
try
{
sb.append(" data-").append(attr.name()).append("=\"").append(h(attr.value())).append("\"");
}
catch (IOException io)
{
UnexpectedException.rethrow(io);
}
});
}

protected void doInputEvents(String id)
{
var pageConfig = HttpView.currentPageConfig();
Expand Down Expand Up @@ -760,6 +783,9 @@ public static class InputBuilder<T extends InputBuilder<T>> implements HasHtmlSt
private Integer _tabIndex;

private final List<String> _styles = new LinkedList<>();
private final List<DataAttribute> _dataAttributes = new LinkedList<>();

private record DataAttribute(String name, String value) {}

public InputBuilder()
{
Expand Down Expand Up @@ -1061,6 +1087,13 @@ public T addStyles(List<String> styles)
return (T)this;
}

// Add an arbitrary "data-" attribute. Name should not include "data-"... the builder will add prefix.
public T addDataAttribute(@NotNull String name, @NotNull String value)
{
_dataAttributes.add(new DataAttribute(name, value));
return (T)this;
}

public Input build()
{
return new Input(this);
Expand Down
2 changes: 2 additions & 0 deletions api/src/org/labkey/api/util/element/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected void doInput(Appendable sb) throws IOException

doStyles(sb);

doDataAttributes(sb);

doInputEvents(id);

if (isDisabled())
Expand Down
Loading