diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckBoxPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckBoxPresenter.java index 598837a20..e12e7c01f 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckBoxPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckBoxPresenter.java @@ -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); diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckbox.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckbox.java index 4bdaa9679..1dbaeedb6 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckbox.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/form/complexcheckbox/ConfigurableCheckbox.java @@ -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, HasText, HasEnabled, HasReadOnly { @Nonnull @@ -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; diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationCheckboxConfig.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationCheckboxConfig.java index 686d1a8e5..2ccaeb480 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationCheckboxConfig.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationCheckboxConfig.java @@ -22,7 +22,7 @@ public class PostCoordinationCheckboxConfig extends CheckBoxConfig { private final static String DEFAULT_NOT_ALLOWED = " "; private CheckboxValue parentValue; - + private boolean isDerived = false; public static List AVAILABLE_VALUES_LIST = Arrays.asList(new CheckboxValue(NOT_ALLOWED, "NOT_ALLOWED"), new CheckboxValue(CHECK_SVG, "ALLOWED"), @@ -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); } } @@ -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; } - } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java index eac2fa72e..a4238cd06 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java @@ -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); @@ -221,9 +220,7 @@ private void initializeTableContent() { this.tableRows.add(tableRow); } - for (PostCoordinationTableRow tableRow : tableRows) { - tableRow.bindToParentRow(tableRows); - } + bindCellsToParentCells(); } private boolean isAxisEnabledOnAnyRow(PostCoordinationTableAxisLabel axisLabel) { @@ -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(); + } + } + } + } + } + } } } @@ -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) { @@ -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() @@ -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(); } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableCell.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableCell.java index 31a00ade4..6dff67ece 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableCell.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableCell.java @@ -8,6 +8,8 @@ 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 { @@ -15,20 +17,23 @@ public class PostCoordinationTableCell { private LinearizationDefinition linearizationDefinition; private PostCoordinationCheckboxConfig checkboxConfig; private PostCoordinationTableAxisLabel axisLabel; - private PostCoordinationTableRow rowWrapper; - private PostCoordinationTableCell parentCell; - + private List 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(){ @@ -38,14 +43,6 @@ public Widget asWidget(){ public HandlerRegistration addValueChangeHandler(ValueChangeHandler 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); @@ -53,14 +50,35 @@ public void setState(boolean 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() { @@ -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); } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableRow.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableRow.java index 8f19a7093..5becb434e 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableRow.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableRow.java @@ -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 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(); } @@ -40,31 +26,6 @@ public LinearizationDefinition getLinearizationDefinition() { return linearizationDefinition; } - public void bindToParentRow(List tableRows) { - if (isDerived()) { - PostCoordinationTableRow parentRow = findParentRow(linearizationDefinition.getCoreLinId(), tableRows); - bindCellsToParentCells(parentRow); - } - } - - - private void bindCellsToParentCells(PostCoordinationTableRow parentRow) { - for (PostCoordinationTableCell parentCell : parentRow.cellList) { - Optional 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 rows) { - return rows.stream().filter(row -> row.linearizationDefinition.getId().equalsIgnoreCase(parentIRI)) - .findFirst() - .orElseThrow(() -> new RuntimeException("Parent not found")); - } - public List getCellList() { return cellList; } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/postcoordination/SaveEntityPostCoordinationResult.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/postcoordination/SaveEntityPostCoordinationResult.java index eab6ffb56..a01e3fc0b 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/postcoordination/SaveEntityPostCoordinationResult.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/postcoordination/SaveEntityPostCoordinationResult.java @@ -10,5 +10,5 @@ @AutoValue @GwtCompatible(serializable = true) @JsonTypeName(CHANNEL) -public abstract class SaveEntityPostCoordinationResult implements Result { +public class SaveEntityPostCoordinationResult implements Result { }