Skip to content

Commit

Permalink
added some fixes for edit mode of post coordination table and scale v…
Browse files Browse the repository at this point in the history
…alue cards
  • Loading branch information
soimugeo committed Sep 30, 2024
1 parent eb8e8f2 commit 1723e62
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class PostCoordinationPortletPresenter extends AbstractWebProtegePortletP

private final List<PostCoordinationCustomScales> postCoordinationCustomScalesList = new ArrayList<>();

private boolean editMode = false;

private Optional<OWLEntity> entityIri;


@Inject
public PostCoordinationPortletPresenter(@Nonnull SelectionModel selectionModel,
Expand All @@ -68,11 +72,7 @@ public void startPortlet(PortletUi portletUi, WebProtegeEventBus eventBus) {
portletUi.setWidget(view.asWidget());
setDisplaySelectedEntityNameAsSubtitle(true);

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


dispatch.execute(GetPostCoordinationTableConfigurationAction.create("ICD"), result -> {
Expand Down Expand Up @@ -126,14 +126,12 @@ remove the orElseGet() and add back the orElseThrow() when we have proper labels
});

view.setEditButtonHandler(() -> {
scaleValueCardPresenters.values().forEach(presenter -> presenter.setEditMode(true));
view.setEditMode(true);
this.setEditMode(true);
});

view.setCancelButtonHandler(() -> {
handleAfterSetEntity(getSelectedEntity());
view.setEditMode(false);
scaleValueCardPresenters.values().forEach(presenter -> presenter.setEditMode(false));
handleAfterSetEntity(this.entityIri);
this.setEditMode(false);
});

view.setSaveButtonHandler((postcoordinationSpec) -> {
Expand All @@ -143,9 +141,10 @@ remove the orElseGet() and add back the orElseThrow() when we have proper labels
}
)
);
view.setEditMode(false);
scaleValueCardPresenters.values().forEach(presenter -> presenter.setEditMode(false));
this.setEditMode(false);
});

this.setEditMode(false);
}

private ScaleValueCardPresenter createScaleValueCardPresenter(PostCoordinationTableAxisLabel axis, PostCoordinationScaleValue scaleValue) {
Expand All @@ -159,7 +158,7 @@ protected void handleReloadRequest() {

@Override
protected void handleAfterSetEntity(Optional<OWLEntity> entityData) {
clearScaleValueCards();
this.entityIri = entityData;
logger.info("Fac fetch la entity " + entityData);
entityData.ifPresent(owlEntity -> dispatch.execute(GetEntityCustomScalesAction.create(owlEntity.getIRI().toString(), getProjectId()),
(result) -> {
Expand All @@ -171,9 +170,8 @@ protected void handleAfterSetEntity(Optional<OWLEntity> entityData) {
(result) -> {
logger.info("ALEX post coord result: " + result);
view.setTableData(result.getPostCoordinationSpecification());
setEditMode(false);
}));


}

private void clearScaleValueCards() {
Expand All @@ -182,6 +180,14 @@ private void clearScaleValueCards() {
view.getScaleValueCardsView().clear();
}

private void clearAllDate() {
clearScaleValueCards();
tableLabelsForAxes.clear();
compositeAxisList.clear();
scaleLabelsForAxes.clear();
genericScale.clear();
}

public void removeScaleValueCardPresenter(String axisIri) {
ScaleValueCardPresenter presenter = scaleValueCardPresenters.get(axisIri);
if (presenter != null) {
Expand All @@ -208,7 +214,7 @@ private void addScaleValueCardPresenter(String axisIri) {
PostCoordinationScaleValue.create(axisIri, currentAxisLabels.getScaleLabel(), existingScaleValueForAxis, genericScale1)
);
scaleValueCardPresenters.put(axisIri, newPresenter);
newPresenter.start(view.getScaleValueCardsView(), false);
newPresenter.start(view.getScaleValueCardsView(), editMode);
}

private TableCellChangedHandler handleTableCellChanged() {
Expand Down Expand Up @@ -266,4 +272,10 @@ private boolean isScaleValuePresenterCreated(String axisIri) {
.orElseGet(() -> scaleValueCardPresenters.get(axisIri) != null);
}

public void setEditMode(boolean editMode) {
this.editMode = editMode;
scaleValueCardPresenters.values().forEach(presenter -> presenter.setEditMode(editMode));
view.setEditMode(editMode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ public PostCoordinationPortletViewImpl(DispatchServiceManager dispatch) {


public void setEditMode(boolean editMode) {
setTableState(!editMode);
readOnly = !editMode;
setTableState(readOnly);
saveValuesButton.setVisible(editMode);
cancelButton.setVisible(editMode);
editValuesButton.setVisible(!editMode);
}

Expand All @@ -84,7 +86,7 @@ public void setEditButtonHandler(EditButtonHandler handler) {

@Override
public void setCancelButtonHandler(CancelButtonHandler handler) {
this.cancelButtonHandler.handleCancelButton();
this.cancelButtonHandler = handler;
}

@Override
Expand All @@ -100,54 +102,6 @@ private void setTableState(boolean readOnly) {
}
}

private void cancelValues() {
dispatch.execute(GetEntityPostCoordinationAction.create(entityIri, this.projectId),
(result) -> this.setTableData(result.getPostCoordinationSpecification()));
}


private void saveValues() {
WhoficEntityPostCoordinationSpecification specification = new WhoficEntityPostCoordinationSpecification(entityIri, "ICD", new ArrayList<>());
boolean somethingChanged = false;
for (PostCoordinationTableRow tableRow : this.tableRows) {
PostCoordinationSpecification postCoordinationSpecification = new PostCoordinationSpecification(tableRow.getLinearizationDefinition().getWhoficEntityIri(),
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>());
for (PostCoordinationTableCell cell : tableRow.getCellList()) {
if (cell.isTouched()) {
if (cell.getValue().equalsIgnoreCase("NOT_ALLOWED")) {
postCoordinationSpecification.getNotAllowedAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
if (cell.getValue().equalsIgnoreCase("ALLOWED")) {
postCoordinationSpecification.getAllowedAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
if (cell.getValue().equalsIgnoreCase("REQUIRED")) {
postCoordinationSpecification.getRequiredAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
if (cell.getValue().startsWith("DEFAULT")) {
postCoordinationSpecification.getDefaultAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
}
}
specification.getPostCoordinationSpecifications().add(postCoordinationSpecification);
}
if (somethingChanged) {
dispatch.execute(SaveEntityPostCoordinationAction.create(projectId, specification), (result) -> {
setTableState(true);
editValuesButton.setVisible(true);
saveValuesButton.setVisible(false);
logger.info("ALEX a venit cu rezult");
});

}
}

private Optional<WhoficEntityPostCoordinationSpecification> createEditedSpec() {
WhoficEntityPostCoordinationSpecification specification = new WhoficEntityPostCoordinationSpecification(entityIri, "ICD", new ArrayList<>());
boolean somethingChanged = false;
Expand Down Expand Up @@ -395,6 +349,7 @@ public void setTableData(WhoficEntityPostCoordinationSpecification whoficSpecifi
setTableState(true);
editValuesButton.setVisible(true);
saveValuesButton.setVisible(false);
cancelButton.setVisible(false);
}

private static final String SVG = "<div style='width: 12px; height: 12px; margin-right:2px;' >" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ScaleValueCardPresenter {
private final DispatchServiceManager dispatchServiceManager;
private final ProjectId projectId;

private boolean isReadOnly = true;


public ScaleValueCardPresenter(PostCoordinationTableAxisLabel postCoordinationAxis,
PostCoordinationScaleValue scaleValue,
Expand Down Expand Up @@ -43,7 +45,11 @@ private void initTable() {
view.addSelectValueButton();

dispatchServiceManager.execute(GetRenderedOwlEntitiesAction.create(projectId, new HashSet<>(scaleValue.getValueIris())),
result -> result.getRenderedEntities().forEach(renderedEntity -> addRow(!renderedEntity.getBrowserText().equals("") ? renderedEntity.getBrowserText() : renderedEntity.getEntity().toStringID()))
result -> {
result.getRenderedEntities()
.forEach(renderedEntity -> addRow(!renderedEntity.getBrowserText().equals("") ? renderedEntity.getBrowserText() : renderedEntity.getEntity().toStringID()));
view.setEditMode(isReadOnly);
}
);

view.setDeleteValueButtonHandler((value) -> scaleValue.getValueIris().remove(value));
Expand All @@ -64,13 +70,14 @@ public PostCoordinationScaleValue getValues() {
}

public void setEditMode(boolean editMode) {
isReadOnly = !editMode;
view.setEditMode(editMode);
}

public void start(VerticalPanel panel, boolean isEditMode) {
bindView();
initTable();
view.setEditMode(isEditMode);
setEditMode(isEditMode);
panel.add(view.asWidget());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ public void setEditMode(boolean enabled) {

private void setReadOnly(boolean readOnly) {
isReadOnly = readOnly;
if (isReadOnly) {
rootPanel.addStyleName(postCoordinationStyle.disabled());
} else {
rootPanel.removeStyleName(postCoordinationStyle.disabled());

for (int i = 1; i < valueTable.getRowCount(); i++) {
if (readOnly) {
valueTable.getRowFormatter().addStyleName(i, postCoordinationStyle.disabled());
} else {
valueTable.getRowFormatter().removeStyleName(i, postCoordinationStyle.disabled());
}
}
}

}

0 comments on commit 1723e62

Please sign in to comment.