Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for #4454 - Dictionary Import , show source of entries #4465

Merged
merged 7 commits into from
Sep 24, 2024
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
7 changes: 6 additions & 1 deletion stroom-app/src/main/resources/ui/css/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ button.main-menu svg {

.SelectionPopup .listContainer {
min-width: 200px;
max-width: 300px;
max-width: 400px;
max-height: 400px;
}

Expand Down Expand Up @@ -2314,3 +2314,8 @@ button.main-menu svg {
.DuplicateManagementViewImpl {
border-top: 1px solid var(--splitter__background-color);
}

/* Add a smidge of a gap between the split and the next form group */
.DictionarySettingViewImpl .thinSplitLayoutPanel-Dragger-Outer + div > div.form-group > div.form-group-label-container {
margin-top: 0.5em;
}
23 changes: 23 additions & 0 deletions stroom-app/src/main/resources/ui/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,29 @@
padding: 0 0.4rem 0.4rem 0.4rem;
}

.selectionItemCell-content .listInputItem-container {
display: flex;
flex-direction: row;
justify-content: space-between;
gap: 2em;
width: 390px;
}

.listInputItem-container .listInputItem-word {
display: inline-block;
}

.listInputItem-container .listInputItem-source {
display: flex;
flex-direction: row;
gap: 0.25em;
}

.listInputItem-container .listInputItem-source-text {
display: inline-block;
color: var(--text-color--disabled);
}

.VisFrame-container {
position: absolute;
margin: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
/*
* Copyright 2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package stroom.item.client;

import stroom.docref.HasDisplayValue;

import com.google.gwt.safehtml.shared.SafeHtml;

import java.util.Collection;
import java.util.function.Function;

Expand All @@ -18,11 +38,22 @@ public SelectionBox() {
* <p>If the item implements {@link stroom.docref.HasDisplayValue} use the displayValue.</p>
* <p>If the item is a {@link String} use that.</p>
* <p>Else use the value of {@link Object#toString()}.</p>
* <p>The display value is the value used in the text box part when the item is selected.</p>
*/
public void setDisplayValueFunction(final Function<T, String> displayValueFunction) {
model.setDisplayValueFunction(displayValueFunction);
}

/**
* This function will be used to optionally provide a rendered form of the item in the list,
* instead of plain text (but NOT in the text box part).
* If not set then it will fall back on displayValueFunction, {@link HasDisplayValue} or
* {@link Object#toString()}.
*/
public void setRenderFunction(final Function<T, SafeHtml> renderFunction) {
model.setRenderFunction(renderFunction);
}

public void setNonSelectString(final String nonSelectString) {
model.setNonSelectString(nonSelectString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,35 @@
package stroom.item.client;

import stroom.svg.shared.SvgImage;
import stroom.util.shared.GwtNullSafe;

import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;

public interface SelectionItem {

/**
* @return The plain text label for the item
*/
String getLabel();

/**
* @return The rendered HTML form of the label, which by default is simply the label text with no markup.
* Implementations can choose to render the label how they like.
*/
default SafeHtml getRenderedLabel() {
final String label = getLabel();
if (GwtNullSafe.isBlankString(label)) {
return SafeHtmlUtils.EMPTY_SAFE_HTML;
} else {
return SafeHtmlUtils.fromString(getLabel());
}
}

default boolean hasRenderedLabel() {
return false;
}

SvgImage getIcon();

default String getIconTooltip() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import stroom.svg.shared.SvgImage;
import stroom.util.shared.GwtNullSafe;
import stroom.widget.util.client.SafeHtmlUtil;
import stroom.widget.util.client.SvgImageUtil;

import com.google.gwt.cell.client.AbstractCell;
Expand Down Expand Up @@ -56,8 +57,15 @@ public void render(final Context context, final I row, final SafeHtmlBuilder sb)
"explorerCell-icon");
content.append(iconSafeHtml);
}
content.append(template.div(getCellClassName() + "-text",
SafeHtmlUtils.fromString(row.getLabel())));
if (row.hasRenderedLabel()) {
content.append(template.div(
getCellClassName() + "-content",
row.getRenderedLabel()));
} else {
content.append(template.div(
getCellClassName() + "-text",
SafeHtmlUtil.getSafeHtml(row.getLabel())));
}

// Add parent indicator arrow.
if (row.isHasChildren()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
/*
* Copyright 2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package stroom.item.client;

import stroom.svg.shared.SvgImage;
import stroom.util.shared.GwtNullSafe;

import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;

import java.util.Objects;
import java.util.function.BiFunction;

public class SimpleSelectionItemWrapper<T> implements SelectionItem {

private final String label;
private final T item;
private final RenderFunction<T> renderFunction;

public SimpleSelectionItemWrapper(final String label,
final T item,
final RenderFunction<T> renderFunction) {
this.label = label;
this.item = item;
this.renderFunction = renderFunction;
}

public SimpleSelectionItemWrapper(final String label, final T item) {
public SimpleSelectionItemWrapper(final String label,
final T item) {
this.label = label;
this.item = item;
this.renderFunction = null;
}

public T getItem() {
Expand All @@ -23,6 +55,22 @@ public String getLabel() {
return label;
}

@Override
public SafeHtml getRenderedLabel() {
if (renderFunction != null) {
final SafeHtml safeHtml = renderFunction.apply(label, item);
return GwtNullSafe.requireNonNullElse(safeHtml, SafeHtmlUtils.EMPTY_SAFE_HTML);
} else {
// No render func so let the default method handle it as simple text with no markup
return SelectionItem.super.getRenderedLabel();
}
}

@Override
public boolean hasRenderedLabel() {
return renderFunction != null;
}

@Override
public SvgImage getIcon() {
return null;
Expand Down Expand Up @@ -57,4 +105,14 @@ public String toString() {
", item=" + item +
'}';
}


// --------------------------------------------------------------------------------


public interface RenderFunction<T> extends BiFunction<String, T, SafeHtml> {

@Override
SafeHtml apply(String label, T item);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
/*
* Copyright 2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package stroom.item.client;

import stroom.docref.HasDisplayValue;
import stroom.util.shared.GwtNullSafe;
import stroom.util.shared.PageRequest;
import stroom.util.shared.ResultPage;

import com.google.gwt.safehtml.shared.SafeHtml;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -18,6 +36,7 @@ public class SimpleSelectionListModel<T> implements SelectionListModel<T, Simple

private SimpleSelectionItemWrapper<T> nonSelectItem;
private Function<T, String> displayValueFunction = null;
private Function<T, SafeHtml> renderFunction = null;

@Override
public void onRangeChange(final SimpleSelectionItemWrapper<T> parent,
Expand All @@ -44,13 +63,22 @@ public SimpleSelectionListModel() {
}

/**
* This function will be used to provide a display value for the item. Useful if the item
* This function will be used to optionally provide a display value for the item. Useful if the item
* does not implement {@link HasDisplayValue}.
*/
public void setDisplayValueFunction(final Function<T, String> displayValueFunction) {
this.displayValueFunction = displayValueFunction;
}

/**
* This function will be used to optionally provide a rendered form of the item instead of plain text.
* If not set then it will fall back on displayValueFunction, {@link HasDisplayValue} or
* {@link Object#toString()}.
*/
public void setRenderFunction(final Function<T, SafeHtml> renderFunction) {
this.renderFunction = renderFunction;
}

public void setNonSelectString(final String nonSelectString) {
nonSelectItem = new SimpleSelectionItemWrapper<>(nonSelectString, null);
items.add(nonSelectItem);
Expand Down Expand Up @@ -111,7 +139,12 @@ public SimpleSelectionItemWrapper<T> wrap(final T item) {
} else {
displayValue = item.toString();
}
return new SimpleSelectionItemWrapper<>(displayValue, item);
if (renderFunction != null) {
return new SimpleSelectionItemWrapper<>(displayValue, item, (label, item1) ->
renderFunction.apply(item));
} else {
return new SimpleSelectionItemWrapper<>(displayValue, item);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Crown Copyright
* Copyright 2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,9 @@
import stroom.svg.shared.SvgImage;
import stroom.widget.util.client.KeyBinding.Action;

import java.util.Objects;
import java.util.Optional;

public interface TabData {

SvgImage getIcon();
Expand All @@ -30,6 +33,10 @@ default IconColour getIconColour() {

String getLabel();

default Optional<String> getTooltip() {
return Optional.empty();
}

boolean isCloseable();

String getType();
Expand All @@ -43,4 +50,9 @@ default boolean handleKeyAction(final Action action) {
// override as required
return false;
}

static String createDocumentationTooltip(final String documentType) {
Objects.requireNonNull(documentType);
return "Documentation to describe the content/purpose of this " + documentType + ".";
}
}
Loading
Loading