Skip to content

Commit

Permalink
Merge branch 'upload-postcoordination-file' of https://github.com/pro…
Browse files Browse the repository at this point in the history
…tegeproject/webprotege-gwt-ui into upload-postcoordination-file

� Conflicts:
�	webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java
  • Loading branch information
soimugeo committed Sep 30, 2024
2 parents 1723e62 + 564a081 commit 0ed274a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public boolean isTouched() {
return isTouched;
}

public void setTouched(Boolean touched) {
this.isTouched = touched;
}

@Override
public void fireEvent(GwtEvent<?> event) {
view.fireEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import edu.stanford.bmir.protege.web.client.HasReadOnly;

import javax.annotation.Nonnull;
import java.util.logging.Logger;

public class ConfigurableCheckbox implements IsWidget, HasValue<CheckboxValue>, HasText, HasEnabled, HasReadOnly {
@Nonnull
Expand Down Expand Up @@ -39,6 +38,10 @@ public boolean isTouched() {
return this.presenter.isTouched();
}

public void setTouched(boolean touched) {
this.presenter.setTouched(touched);
}

@Override
public Widget asWidget() {
return container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PostCoordinationCheckboxConfig extends CheckBoxConfig {
private final static String DEFAULT_NOT_ALLOWED = "<svg version=\"1.1\" id=\"Capa_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 290.658 290.658\" xml:space=\"preserve\" fill=\"#000000\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <g> <g> <rect y=\"139.474\" style=\"fill:darkgrey;\" width=\"290.658\" height=\"11.711\"></rect> </g> </g> </g></svg>";

private CheckboxValue parentValue;

private boolean isDerived = false;

public static List<CheckboxValue> AVAILABLE_VALUES_LIST = Arrays.asList(new CheckboxValue(NOT_ALLOWED, "NOT_ALLOWED"),
new CheckboxValue(CHECK_SVG, "ALLOWED"),
Expand All @@ -41,9 +41,10 @@ protected PostCoordinationCheckboxConfig() {

@Override
public CheckboxValue getNextValue(CheckboxValue checkboxValue) {
if(parentValue != null) {
if(isDerived) {
return getNextValueForDerivedClasses(checkboxValue);
} else {

return super.getNextValue(checkboxValue);
}
}
Expand Down Expand Up @@ -82,8 +83,15 @@ private CheckboxValue getNextValueForDerivedClasses(CheckboxValue checkboxValue)
}
}

public void setIsDerived(boolean isDerived){
this.isDerived = isDerived;
}

public boolean isDerived() {
return isDerived;
}

public void setParentValue(CheckboxValue parentValue) {
this.parentValue = parentValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ private void initializeTableContent() {
valueChanged.getValue(),
cell.getAxisLabel().getPostCoordinationAxis()
);
updateTelescopicLinearizations(cell);
});
flexTable.setWidget(i + 1, j + 1, cell.asWidget());
tableRow.addCell(cell);
Expand All @@ -221,9 +220,7 @@ private void initializeTableContent() {
this.tableRows.add(tableRow);
}

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

private boolean isAxisEnabledOnAnyRow(PostCoordinationTableAxisLabel axisLabel) {
Expand All @@ -240,9 +237,22 @@ private boolean isAxisEnabledOnAnyRow(PostCoordinationTableAxisLabel axisLabel)
}


private void updateTelescopicLinearizations(PostCoordinationTableCell cell) {
for (PostCoordinationTableRow tableRow : this.tableRows) {
tableRow.updateDerivedCell(cell);
private void bindCellsToParentCells(){
for(PostCoordinationTableRow row : this.tableRows) {
if(!row.isDerived()) {
for(PostCoordinationTableRow childRow : this.tableRows) {
if(childRow.isDerived() && childRow.getLinearizationDefinition().getCoreLinId().equalsIgnoreCase(row.getLinearizationDefinition().getId())) {
for(PostCoordinationTableCell parentCell: row.getCellList()) {
for(PostCoordinationTableCell childCell: childRow.getCellList()) {
if(parentCell.getAxisLabel().getPostCoordinationAxis().equalsIgnoreCase(childCell.getAxisLabel().getPostCoordinationAxis())) {
parentCell.addToChildCells(childCell);
childCell.setIsDerived();
}
}
}
}
}
}
}
}

Expand All @@ -257,7 +267,6 @@ private void addRowLabel(boolean isDerived, String label, int row, int column) {
rowLabel.getElement().setInnerHTML(rowLabelString);
rowLabel.addStyleName(style.getRowLabel());
flexTable.setWidget(row, column, rowLabel);
//flexTable.getCellFormatter().addStyleName(row, column, style.getRowLabel());
}

private void addHeaderCell(String label, int position) {
Expand Down Expand Up @@ -301,10 +310,13 @@ public void setTableData(WhoficEntityPostCoordinationSpecification whoficSpecifi
logger.info("Set table data");
this.entityIri = whoficSpecification.getWhoficEntityIri();

if (whoficSpecification.getPostCoordinationSpecifications().isEmpty()) {
tableRows = new ArrayList<>();
initializeTableContent();
} else {
for(PostCoordinationTableRow row: this.tableRows) {
for(PostCoordinationTableCell cell : row.getCellList()) {
cell.reset();
}
}

if(!whoficSpecification.getPostCoordinationSpecifications().isEmpty()) {
for (PostCoordinationTableRow row : this.tableRows) {
for (PostCoordinationTableCell cell : row.getCellList()) {
PostCoordinationSpecification specification = whoficSpecification.getPostCoordinationSpecifications().stream()
Expand All @@ -325,24 +337,20 @@ public void setTableData(WhoficEntityPostCoordinationSpecification whoficSpecifi
if (specification.getNotAllowedAxes().contains(cell.getAxisLabel().getPostCoordinationAxis())) {
cell.setValue("NOT_ALLOWED");
}
if (specification.getDefaultAxes().contains(cell.getAxisLabel().getPostCoordinationAxis())) {
cell.setSetValueAsDefaultParent();
}

} else {
if (row.isDerived()) {
cell.setSetValueAsDefaultParent();
} else {
cell.setValue("NOT_ALLOWED");
}
cell.setValue("NOT_ALLOWED");
}
}
}
for (PostCoordinationTableRow row : this.tableRows) {
for (PostCoordinationTableCell cell : row.getCellList()) {
if (cell.getLinearizationDefinition().getCoreLinId() == null) {
row.updateDerivedCell(cell);
}
}

}
bindCellsToParentCells();

for(PostCoordinationTableRow row: this.tableRows) {
for(PostCoordinationTableCell cell: row.getCellList()) {
cell.updateChildren();
cell.initializeCallback();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@
import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class PostCoordinationTableCell {
private ConfigurableCheckbox configurableCheckbox;
private LinearizationDefinition linearizationDefinition;
private PostCoordinationCheckboxConfig checkboxConfig;
private PostCoordinationTableAxisLabel axisLabel;
private PostCoordinationTableRow rowWrapper;
private PostCoordinationTableCell parentCell;

private List<PostCoordinationTableCell> childCells = new ArrayList<>();
Logger logger = java.util.logging.Logger.getLogger("PostCoordinationTableCell");

public PostCoordinationTableCell(LinearizationDefinition linearizationDefinition, PostCoordinationTableAxisLabel axisLabel, PostCoordinationTableRow parentRow) {
this.checkboxConfig = new PostCoordinationCheckboxConfig();
configurableCheckbox = new ConfigurableCheckbox(checkboxConfig, "NOT_ALLOWED");
configurableCheckbox.setReadOnly(false);
configurableCheckbox.setEnabled(true);


this.linearizationDefinition = linearizationDefinition;

this.axisLabel = axisLabel;
this.rowWrapper = parentRow;
String initialValue = "NOT_ALLOWED";
if(linearizationDefinition.getCoreLinId() != null && !linearizationDefinition.getCoreLinId().isEmpty()) {
initialValue = "DEFAULT_NOT_ALLOWED";
}
configurableCheckbox = new ConfigurableCheckbox(checkboxConfig, initialValue);
configurableCheckbox.setReadOnly(false);
configurableCheckbox.setEnabled(true);
}

public Widget asWidget(){
Expand All @@ -38,29 +43,42 @@ public Widget asWidget(){
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<CheckboxValue> handler) {
return this.configurableCheckbox.addValueChangeHandler(handler);
}

public void setSetValueAsDefaultParent(){
if(parentCell != null) {
this.setValue("DEFAULT_" + parentCell.getValue());
} else {
this.setValue("DEFAULT_NOT_ALLOWED");
}
}
public void setState(boolean readOnly) {
configurableCheckbox.setReadOnly(readOnly);
configurableCheckbox.setEnabled(!readOnly);
}

public void setValue(String value) {
this.configurableCheckbox.setValue(value);
for(PostCoordinationTableCell childCell: this.childCells) {
if(childCell.getValue().startsWith("DEFAULT")) {
childCell.setValue("DEFAULT_"+value);
}
}
}

public void addToChildCells(PostCoordinationTableCell childCell) {
this.childCells.add(childCell);
}

public boolean isTouched(){
return configurableCheckbox.isTouched();
}

public void setParentCell(PostCoordinationTableCell parentCell) {
this.parentCell = parentCell;
public void initializeCallback(){
this.configurableCheckbox.addValueChangeHandler((checkboxValue -> {
this.updateChildCells(checkboxValue.getValue().getValue());
}));
}

public void reset(){
this.childCells = new ArrayList<>();
this.configurableCheckbox.setTouched(false);
if(this.checkboxConfig.isDerived()) {
this.setValue("DEFAULT_NOT_ALLOWED");
} else {
this.setValue("NOT_ALLOWED");
}
}

public String getValue() {
Expand All @@ -79,6 +97,25 @@ public PostCoordinationTableAxisLabel getAxisLabel() {
return axisLabel;
}

public void setIsDerived(){
this.checkboxConfig.setIsDerived(true);
}

public void updateChildCells(String checkboxValue) {
if(!checkboxConfig.isDerived()) {
for(PostCoordinationTableCell childCell: this.childCells) {
if(childCell.getValue().startsWith("DEFAULT")) {
childCell.setValue("DEFAULT_"+checkboxValue);
}
childCell.setParentValue(this.getAsCheckboxValue());
}
}
}

public void updateChildren() {
updateChildCells(this.getValue());
}

public void setParentValue(CheckboxValue parentValue) {
this.checkboxConfig.setParentValue(parentValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ public void addCell(PostCoordinationTableCell cell) {
this.cellList.add(cell);
}

public void updateDerivedCell(PostCoordinationTableCell changedCell) {
if (isDerived() && linearizationDefinition.getCoreLinId().equalsIgnoreCase(changedCell.getLinearizationDefinition().getId())) {
Optional<PostCoordinationTableCell> equivalentCell = this.cellList.stream()
.filter(cell -> cell.getAxisLabel().getPostCoordinationAxis().equalsIgnoreCase(changedCell.getAxisLabel().getPostCoordinationAxis()))
.findFirst();
equivalentCell.ifPresent(cell -> {
if (!cell.isTouched() || cell.getValue().startsWith("DEFAULT")) {
cell.setParentValue(changedCell.getAsCheckboxValue());
cell.setValue("DEFAULT_" + changedCell.getValue());
}
});
}
}

public boolean isDerived() {
return linearizationDefinition.getCoreLinId() != null && !linearizationDefinition.getCoreLinId().isEmpty();
}
Expand All @@ -40,31 +26,6 @@ public LinearizationDefinition getLinearizationDefinition() {
return linearizationDefinition;
}

public void bindToParentRow(List<PostCoordinationTableRow> tableRows) {
if (isDerived()) {
PostCoordinationTableRow parentRow = findParentRow(linearizationDefinition.getCoreLinId(), tableRows);
bindCellsToParentCells(parentRow);
}
}


private void bindCellsToParentCells(PostCoordinationTableRow parentRow) {
for (PostCoordinationTableCell parentCell : parentRow.cellList) {
Optional<PostCoordinationTableCell> cellToUpload = this.cellList.stream()
.filter(myCell -> myCell.getAxisLabel().getPostCoordinationAxis().equalsIgnoreCase(parentCell.getAxisLabel().getPostCoordinationAxis()))
.findFirst();

cellToUpload.ifPresent(cell -> cell.setParentCell(parentCell));
cellToUpload.ifPresent(cell -> cell.setParentValue(parentCell.getAsCheckboxValue()));
}
}

PostCoordinationTableRow findParentRow(String parentIRI, List<PostCoordinationTableRow> rows) {
return rows.stream().filter(row -> row.linearizationDefinition.getId().equalsIgnoreCase(parentIRI))
.findFirst()
.orElseThrow(() -> new RuntimeException("Parent not found"));
}

public List<PostCoordinationTableCell> getCellList() {
return cellList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@AutoValue
@GwtCompatible(serializable = true)
@JsonTypeName(CHANNEL)
public abstract class SaveEntityPostCoordinationResult implements Result {
public class SaveEntityPostCoordinationResult implements Result {
}

0 comments on commit 0ed274a

Please sign in to comment.