Skip to content

Commit

Permalink
linked postcoordination table value to the scaleValue cards. Still ha…
Browse files Browse the repository at this point in the history
…ve a bug to fix before we can merge
  • Loading branch information
soimugeo committed Aug 29, 2024
1 parent e3257e5 commit 8405a5c
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class PostCoordinationPortletPresenter extends AbstractWebProtegePortletP

private final Map<String, ScaleValueCardPresenter> scaleValueCardPresenters = new HashMap<>();

private final Map<String, PostCoordinationTableAxisLabel> labels = new HashMap<>();
private final Map<String, PostCoordinationTableAxisLabel> tableLabelsForAxes = new HashMap<>();
private final Map<String, PostCoordinationTableAxisLabel> scaleLabelsForAxes = new HashMap<>();
private final List<PostCoordinationCompositeAxis> compositeAxisList = new ArrayList<>();
private final Map<String, PostCoordinationAxisToGenericScale> genericScale = new HashMap<>();


Expand Down Expand Up @@ -65,7 +67,9 @@ public void startPortlet(PortletUi portletUi, WebProtegeEventBus eventBus) {
setDisplaySelectedEntityNameAsSubtitle(true);

scaleValueCardPresenters.clear();
labels.clear();
tableLabelsForAxes.clear();
compositeAxisList.clear();
scaleLabelsForAxes.clear();
genericScale.clear();


Expand All @@ -75,41 +79,67 @@ public void startPortlet(PortletUi portletUi, WebProtegeEventBus eventBus) {
.filter(label -> label.getPostCoordinationAxis().equalsIgnoreCase(availableAxis))
.findFirst()
.orElseThrow(() -> new RuntimeException("Couldn't find label for " + availableAxis));
labels.put(availableAxis, existingLabel);
tableLabelsForAxes.put(availableAxis, existingLabel);
}
view.setLabels(labels);

scaleLabelsForAxes.putAll(tableLabelsForAxes);

view.setLabels(tableLabelsForAxes);


compositeAxisList.addAll(result.getTableConfiguration().getCompositePostCoordinationAxes());

compositeAxisList.forEach(compositeAxis ->
compositeAxis.getSubAxis()
.forEach(subAxis -> {
PostCoordinationTableAxisLabel existingLabel = result.getLabels().stream()
.filter(label -> label.getPostCoordinationAxis().equalsIgnoreCase(subAxis))
.findFirst()
/*
ToDo:
remove the orElseGet() and add back the orElseThrow() when we have proper labels
*/
.orElseGet(() -> new PostCoordinationTableAxisLabel(subAxis, "hardCodedTableName", "hardCodedTableName"));
// .orElseThrow(() -> new RuntimeException("Couldn't find label for " + subAxis));
scaleLabelsForAxes.put(subAxis, existingLabel);
}
)
);

/*
ToDo:
populate genericScale using a dispatch request.
1. populate genericScale using a dispatch request.
2. populate a list of scaleCustomizations from BE with the real scale values for each axis/subaxis
*/
Map<String, ScaleValueCardPresenter> axisMapWithValues = labels.values()
.stream()
.collect(Collectors.toMap(
PostCoordinationTableAxisLabel::getPostCoordinationAxis,
tabelAxisLabel -> {
PostCoordinationAxisToGenericScale genericScale1 = genericScale.getOrDefault(
tabelAxisLabel.getPostCoordinationAxis(),
new PostCoordinationAxisToGenericScale(tabelAxisLabel.getPostCoordinationAxis(), "", ScaleAllowMultiValue.NotAllowed)
);
return createScaleValueCardPresenter(
tabelAxisLabel,
new PostCoordinationScaleValue(
tabelAxisLabel.getPostCoordinationAxis(),
tabelAxisLabel.getScaleLabel(),
new ArrayList<>(Arrays.asList("iri1.1", "iri1.2", "iri1.3")),
genericScale1)
);
}
));

scaleValueCardPresenters.putAll(axisMapWithValues);
// Map<String, ScaleValueCardPresenter> axisMapWithValues = tableLabelsForAxes.values()
// .stream()
// .collect(Collectors.toMap(
// PostCoordinationTableAxisLabel::getPostCoordinationAxis,
// tabelAxisLabel -> {
// PostCoordinationAxisToGenericScale genericScale1 = genericScale.getOrDefault(
// tabelAxisLabel.getPostCoordinationAxis(),
// new PostCoordinationAxisToGenericScale(tabelAxisLabel.getPostCoordinationAxis(), "", ScaleAllowMultiValue.NotAllowed)
// );
// return createScaleValueCardPresenter(
// tabelAxisLabel,
// new PostCoordinationScaleValue(
// tabelAxisLabel.getPostCoordinationAxis(),
// tabelAxisLabel.getScaleLabel(),
// new ArrayList<>(Arrays.asList("iri1.1", "iri1.2", "iri1.3")),
// genericScale1)
// );
// }
// ));
//
// scaleValueCardPresenters.putAll(axisMapWithValues);
//Do batch action for all scaleValues
dispatch.beginBatch();
scaleValueCardPresenters.values().forEach(presenter -> presenter.start(view.getScaleValueCardsView()));
dispatch.executeCurrentBatch();


view.setTableCellChangedHandler(handleTableCellChanged());

dispatch.execute(GetLinearizationDefinitionsAction.create(), definitionsResult -> {
Map<String, LinearizationDefinition> definitionMap = new HashMap<>();
for (LinearizationDefinition definition : definitionsResult.getDefinitionList()) {
Expand Down Expand Up @@ -141,16 +171,71 @@ public void removeScaleValueCardPresenter(String axisIri) {
}

private void addScaleValueCardPresenter(String axisIri) {
PostCoordinationTableAxisLabel currentAxisLabels = labels.get(axisIri);
PostCoordinationTableAxisLabel currentAxisLabels = scaleLabelsForAxes.get(axisIri);
PostCoordinationAxisToGenericScale genericScale1 = genericScale.getOrDefault(
axisIri,
/*
ToDo:
return an error here if we don't have a value in genericScale
*/
new PostCoordinationAxisToGenericScale(axisIri, "", ScaleAllowMultiValue.NotAllowed)
);
ScaleValueCardPresenter newPresenter = createScaleValueCardPresenter(
currentAxisLabels,
/*
ToDo:
create a post PostCoordinationScaleValue also using the scale value from BE if it exists. if not then use createEmpty()
*/
PostCoordinationScaleValue.createEmpty(axisIri, currentAxisLabels.getScaleLabel(), genericScale1)
);
scaleValueCardPresenters.put(axisIri, newPresenter);
newPresenter.start(view.getScaleValueCardsView());
}

private TableCellChangedHandler handleTableCellChanged() {
return (isOnMultipleRows, checkboxValue, tableAxisIri) -> {
boolean presenterExists = isScaleValuePresenterCreated(tableAxisIri);
if ((checkboxValue.getValue().equals("ALLOWED") ||
checkboxValue.getValue().equals("REQUIRED")) &&
!presenterExists
) {
if (isCompositeAxis(tableAxisIri)) {
List<PostCoordinationCompositeAxis> compositeAxes = compositeAxisList.stream()
.filter(compositeAxis -> compositeAxis.getPostCoordinationAxis().equals(tableAxisIri))
.collect(Collectors.toList());

compositeAxes.forEach(compositeAxis ->
compositeAxis.getSubAxis()
.forEach(this::addScaleValueCardPresenter)
);
} else {
addScaleValueCardPresenter(tableAxisIri);
}
} else if (!isOnMultipleRows &&
(!checkboxValue.getValue().equals("ALLOWED") ||
!checkboxValue.getValue().equals("REQUIRED"))) {
if (isCompositeAxis(tableAxisIri)) {
List<PostCoordinationCompositeAxis> compositeAxes = compositeAxisList.stream()
.filter(compositeAxis -> compositeAxis.getPostCoordinationAxis().equals(tableAxisIri))
.collect(Collectors.toList());

compositeAxes.forEach(compositeAxis ->
compositeAxis.getSubAxis()
.forEach(this::removeScaleValueCardPresenter));
} else {
removeScaleValueCardPresenter(tableAxisIri);
}
}
};
}

private boolean isCompositeAxis(String tableAxisIri) {
return compositeAxisList.stream()
.anyMatch(compositeAxis -> compositeAxis.getPostCoordinationAxis().equals(tableAxisIri));
}

private boolean isScaleValuePresenterCreated(String axisIri) {
return scaleValueCardPresenters.get(axisIri) != null;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.stanford.bmir.protege.web.client.postcoordination;

import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard.ScaleValueCardView;
import edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard.*;
import edu.stanford.bmir.protege.web.shared.HasDispose;
import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;
Expand All @@ -19,4 +19,6 @@ public interface PostCoordinationPortletView extends AcceptsOneWidget, IsWidget,
void setPostCoordinationEntity();

VerticalPanel getScaleValueCardsView();

void setTableCellChangedHandler(TableCellChangedHandler handler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import com.google.gwt.uibinder.client.*;
import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.form.complexcheckbox.CheckboxValue;
import edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard.TableCellChangedHandler;
import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition;
import edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard.ScaleValueCardView;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

public class PostCoordinationPortletViewImpl extends Composite implements PostCoordinationPortletView {

Expand All @@ -28,12 +28,15 @@ public class PostCoordinationPortletViewImpl extends Composite implements PostCo
private Map<String, PostCoordinationTableAxisLabel> labels;
private Map<String, LinearizationDefinition> definitionMap;

private List<PostCoordinationTableRow> tableRows = new ArrayList<>();
private final List<PostCoordinationTableRow> tableRows = new ArrayList<>();
private final DispatchServiceManager dispatch;

private static PostCoordinationTableResourceBundle.PostCoordinationTableCss style = PostCoordinationTableResourceBundle.INSTANCE.style();
private TableCellChangedHandler tableCellChanged = (tableRows, checkboxValue, tableAxisLabel) -> {
};

private static PostCoordinationPortletViewImpl.PostCoordinationPortletViewImplUiBinder ourUiBinder = GWT.create(PostCoordinationPortletViewImpl.PostCoordinationPortletViewImplUiBinder.class);
private static final PostCoordinationTableResourceBundle.PostCoordinationTableCss style = PostCoordinationTableResourceBundle.INSTANCE.style();

private static final PostCoordinationPortletViewImpl.PostCoordinationPortletViewImplUiBinder ourUiBinder = GWT.create(PostCoordinationPortletViewImpl.PostCoordinationPortletViewImplUiBinder.class);

@Inject
public PostCoordinationPortletViewImpl(DispatchServiceManager dispatch) {
Expand Down Expand Up @@ -101,37 +104,52 @@ private void initializeTableContent() {
addRowLabel(tableRow.isDerived(), definitions.get(i).getDisplayLabel(), i + 1, 0);
List<PostCoordinationTableAxisLabel> labelList = new ArrayList<>(this.labels.values());
for (int j = 0; j < labelList.size(); j++) {

PostCoordinationTableCell cell = new PostCoordinationTableCell(definitions.get(i), labelList.get(j), tableRow);
LinearizationDefinition linDef = definitions.get(i);
PostCoordinationTableAxisLabel axisLabel = labelList.get(j);
PostCoordinationTableCell cell = new PostCoordinationTableCell(linDef, axisLabel, tableRow);
cell.addValueChangeHandler(valueChanged -> {
tableCellChanged.handleTableCellChanged(
isValueSetOnMultipleRowsForAxis(axisLabel, valueChanged.getValue()),
valueChanged.getValue(),
cell.getAxisLabel().getPostCoordinationAxis()
);
updateTelescopicLinearizations(cell);
});
flexTable.setWidget(i + 1, j + 1, cell.asWidget());
tableRow.addCell(cell);
}
addRowLabel(false, definitions.get(i).getDisplayLabel(), i + 1, labelList.size()+1);
addRowLabel(false, definitions.get(i).getDisplayLabel(), i + 1, labelList.size() + 1);

flexTable.getRowFormatter().addStyleName(i+1, style.getCustomRowStyle());
if( (i + 1) % 2 == 1) {
flexTable.getRowFormatter().addStyleName(i+1, style.getEvenRowStyle());
flexTable.getRowFormatter().addStyleName(i + 1, style.getCustomRowStyle());
if ((i + 1) % 2 == 1) {
flexTable.getRowFormatter().addStyleName(i + 1, style.getEvenRowStyle());
}
this.tableRows.add(tableRow);
}

for(PostCoordinationTableRow tableRow : tableRows) {
for (PostCoordinationTableRow tableRow : tableRows) {
tableRow.bindToParentRow(tableRows);
}
}

private boolean isValueSetOnMultipleRowsForAxis(PostCoordinationTableAxisLabel axisLabel, CheckboxValue valueChanged) {
List<PostCoordinationTableRow> tableRowsWithAxisChecked = this.tableRows.stream()
.filter(tableRow -> tableRow.getCellList()
.stream()
.anyMatch(cell -> cell.getAxisLabel().equals(axisLabel) && cell.getValue().equals(valueChanged.getValue())))
.collect(Collectors.toList());
return tableRowsWithAxisChecked.size() > 1;
}

private void updateTelescopicLinearizations(PostCoordinationTableCell cell) {
for(PostCoordinationTableRow tableRow: this.tableRows) {
for (PostCoordinationTableRow tableRow : this.tableRows) {
tableRow.updateDerivedCell(cell);
}
}

private void addRowLabel(boolean isDerived, String label, int row, int column) {
String rowLabelString;
if(isDerived) {
if (isDerived) {
rowLabelString = SVG + label;
} else {
rowLabelString = label;
Expand All @@ -154,7 +172,7 @@ private void addHeaderCell(String label, int position) {

private String getHeaderLabelPadded(int padding, String label) {

StringBuilder result = new StringBuilder();
StringBuilder result = new StringBuilder();
int lastBreak = 0;

for (int i = padding; i < label.length(); i += padding) {
Expand All @@ -173,7 +191,13 @@ private String getHeaderLabelPadded(int padding, String label) {

return result.toString();
}
private static String SVG = "<div style='width: 12px; height: 12px; margin-right:2px;' >" +

@Override
public void setTableCellChangedHandler(TableCellChangedHandler handler) {
this.tableCellChanged = handler;
}

private static final String SVG = "<div style='width: 12px; height: 12px; margin-right:2px;' >" +

"<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <path d=\"M3 7V8.2C3 9.88016 3 10.7202 3.32698 11.362C3.6146 11.9265 4.07354 12.3854 4.63803 12.673C5.27976 13 6.11984 13 7.8 13H21M21 13L17 9M21 13L17 17\" stroke=\"#000000\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path> </g></svg>" +
"</div>";
Expand Down
Loading

0 comments on commit 8405a5c

Please sign in to comment.