Skip to content

Commit

Permalink
partially fix edit action for scale value cards. will finish it on Mo…
Browse files Browse the repository at this point in the history
…nday. Also will finish then the save action for the scale value cards.
  • Loading branch information
soimugeo committed Sep 27, 2024
1 parent 56cd47f commit eb8e8f2
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.stanford.bmir.protege.web.client.postcoordination;

public interface CancelButtonHandler {

void handleCancelButton();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.stanford.bmir.protege.web.client.postcoordination;

public interface EditButtonHandler {

void enableEditMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ remove the orElseGet() and add back the orElseThrow() when we have proper labels
view.initializeTable();
});
});

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

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

view.setSaveButtonHandler((postcoordinationSpec) -> {
postcoordinationSpec.ifPresent(whoficEntityPostCoordinationSpecification ->
dispatch.execute(SaveEntityPostCoordinationAction.create(getProjectId(), whoficEntityPostCoordinationSpecification),
(result) -> {
}
)
);
view.setEditMode(false);
scaleValueCardPresenters.values().forEach(presenter -> presenter.setEditMode(false));
});
}

private ScaleValueCardPresenter createScaleValueCardPresenter(PostCoordinationTableAxisLabel axis, PostCoordinationScaleValue scaleValue) {
Expand Down Expand Up @@ -186,7 +208,7 @@ private void addScaleValueCardPresenter(String axisIri) {
PostCoordinationScaleValue.create(axisIri, currentAxisLabels.getScaleLabel(), existingScaleValueForAxis, genericScale1)
);
scaleValueCardPresenters.put(axisIri, newPresenter);
newPresenter.start(view.getScaleValueCardsView());
newPresenter.start(view.getScaleValueCardsView(), false);
}

private TableCellChangedHandler handleTableCellChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public interface PostCoordinationPortletView extends AcceptsOneWidget, IsWidget,
void setTableCellChangedHandler(TableCellChangedHandler handler);

void setTableData(WhoficEntityPostCoordinationSpecification specification);
void setEditButtonHandler(EditButtonHandler handler);
void setCancelButtonHandler(CancelButtonHandler handler);
void setSaveButtonHandler(SaveButtonHandler handler);
void setEditMode(boolean editMode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ public class PostCoordinationPortletViewImpl extends Composite implements PostCo
protected FlexTable flexTable;
@UiField
public VerticalPanel scaleValueCardList;
@UiField Button saveValuesButton;
@UiField Button editValuesButton;
@UiField
Button saveValuesButton;
@UiField
Button editValuesButton;

@UiField Button cancelButton;
@UiField
Button cancelButton;

private boolean readOnly = true;

Expand All @@ -43,6 +46,13 @@ public class PostCoordinationPortletViewImpl extends Composite implements PostCo
private TableCellChangedHandler tableCellChanged = (isAxisEnabledOnAnyRow, checkboxValue, tableAxisLabel) -> {
};

private EditButtonHandler editButtonHandler = () -> {
};
private CancelButtonHandler cancelButtonHandler = () -> {
};
private SaveButtonHandler saveButtonHandler = (Optional<WhoficEntityPostCoordinationSpecification> specificationOptional) -> {
};

private static final PostCoordinationTableResourceBundle.PostCoordinationTableCss style = PostCoordinationTableResourceBundle.INSTANCE.style();

private static final PostCoordinationPortletViewImpl.PostCoordinationPortletViewImplUiBinder ourUiBinder = GWT.create(PostCoordinationPortletViewImpl.PostCoordinationPortletViewImplUiBinder.class);
Expand All @@ -51,25 +61,40 @@ public class PostCoordinationPortletViewImpl extends Composite implements PostCo
public PostCoordinationPortletViewImpl(DispatchServiceManager dispatch) {
initWidget(ourUiBinder.createAndBindUi(this));

saveValuesButton.addClickHandler(event -> saveValues());
cancelButton.addClickHandler(event -> cancelValues());
editValuesButton.addClickHandler(event -> enableEditValues());
saveValuesButton.addClickHandler(event -> saveButtonHandler.saveValues(createEditedSpec()));
cancelButton.addClickHandler(event -> cancelButtonHandler.handleCancelButton());
editValuesButton.addClickHandler(event -> editButtonHandler.enableEditMode());
saveValuesButton.setVisible(!readOnly);
editValuesButton.setVisible(readOnly);
this.dispatch = dispatch;
style.ensureInjected();
}

private void enableEditValues() {
setTableState(false);
saveValuesButton.setVisible(true);
editValuesButton.setVisible(false);

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

@Override
public void setEditButtonHandler(EditButtonHandler handler) {
this.editButtonHandler = handler;
}

private void setTableState(boolean readOnly){
for(PostCoordinationTableRow row : tableRows) {
for(PostCoordinationTableCell cell : row.getCellList()) {
@Override
public void setCancelButtonHandler(CancelButtonHandler handler) {
this.cancelButtonHandler.handleCancelButton();
}

@Override
public void setSaveButtonHandler(SaveButtonHandler handler) {
this.saveButtonHandler = handler;
}

private void setTableState(boolean readOnly) {
for (PostCoordinationTableRow row : tableRows) {
for (PostCoordinationTableCell cell : row.getCellList()) {
cell.setState(readOnly);
}
}
Expand All @@ -84,35 +109,35 @@ private void cancelValues() {
private void saveValues() {
WhoficEntityPostCoordinationSpecification specification = new WhoficEntityPostCoordinationSpecification(entityIri, "ICD", new ArrayList<>());
boolean somethingChanged = false;
for(PostCoordinationTableRow tableRow : this.tableRows) {
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")) {
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")) {
if (cell.getValue().equalsIgnoreCase("ALLOWED")) {
postCoordinationSpecification.getAllowedAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
if(cell.getValue().equalsIgnoreCase("REQUIRED")) {
if (cell.getValue().equalsIgnoreCase("REQUIRED")) {
postCoordinationSpecification.getRequiredAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
if(cell.getValue().startsWith("DEFAULT")) {
if (cell.getValue().startsWith("DEFAULT")) {
postCoordinationSpecification.getDefaultAxes().add(cell.getAxisLabel().getPostCoordinationAxis());
somethingChanged = true;
}
}
}
specification.getPostCoordinationSpecifications().add(postCoordinationSpecification);
}
if(somethingChanged) {
if (somethingChanged) {
dispatch.execute(SaveEntityPostCoordinationAction.create(projectId, specification), (result) -> {
setTableState(true);
editValuesButton.setVisible(true);
Expand All @@ -121,7 +146,44 @@ private void saveValues() {
});

}
}

private Optional<WhoficEntityPostCoordinationSpecification> createEditedSpec() {
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) {
return Optional.of(specification);
}

return Optional.empty();
}

@Override
Expand Down Expand Up @@ -224,7 +286,6 @@ private boolean isAxisEnabledOnAnyRow(PostCoordinationTableAxisLabel axisLabel)
}



private void updateTelescopicLinearizations(PostCoordinationTableCell cell) {
for (PostCoordinationTableRow tableRow : this.tableRows) {
tableRow.updateDerivedCell(cell);
Expand Down Expand Up @@ -310,11 +371,11 @@ public void setTableData(WhoficEntityPostCoordinationSpecification whoficSpecifi
if (specification.getNotAllowedAxes().contains(cell.getAxisLabel().getPostCoordinationAxis())) {
cell.setValue("NOT_ALLOWED");
}
if(specification.getDefaultAxes().contains(cell.getAxisLabel().getPostCoordinationAxis())) {
if (specification.getDefaultAxes().contains(cell.getAxisLabel().getPostCoordinationAxis())) {
cell.setSetValueAsDefaultParent();
}
} else {
if(row.isDerived()) {
if (row.isDerived()) {
cell.setSetValueAsDefaultParent();
} else {
cell.setValue("NOT_ALLOWED");
Expand All @@ -324,7 +385,7 @@ public void setTableData(WhoficEntityPostCoordinationSpecification whoficSpecifi
}
for (PostCoordinationTableRow row : this.tableRows) {
for (PostCoordinationTableCell cell : row.getCellList()) {
if(cell.getLinearizationDefinition().getCoreLinId() == null) {
if (cell.getLinearizationDefinition().getCoreLinId() == null) {
row.updateDerivedCell(cell);
}
}
Expand All @@ -336,12 +397,12 @@ public void setTableData(WhoficEntityPostCoordinationSpecification whoficSpecifi
saveValuesButton.setVisible(false);
}

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

interface PostCoordinationPortletViewImplUiBinder extends UiBinder<HTMLPanel, PostCoordinationPortletViewImpl> {
interface PostCoordinationPortletViewImplUiBinder extends UiBinder<HTMLPanel, PostCoordinationPortletViewImpl> {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@

}

.disabled {
pointer-events: none;
opacity: 0.5;
}


.postCoordinationTable {
border-radius: 5px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ interface PostCoordinationTableCss extends CssResource {

@ClassName("toggle-icon")
String toggleIcon();

@ClassName("disabled")
String disabled();
}

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

import edu.stanford.bmir.protege.web.shared.postcoordination.WhoficEntityPostCoordinationSpecification;

import java.util.Optional;

public interface SaveButtonHandler {

void saveValues(Optional<WhoficEntityPostCoordinationSpecification> specificationOptional);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ public PostCoordinationScaleValue getValues() {
return scaleValue;
}

public void start(VerticalPanel panel) {
public void setEditMode(boolean editMode) {
view.setEditMode(editMode);
}

public void start(VerticalPanel panel, boolean isEditMode) {
bindView();
initTable();
view.setEditMode(isEditMode);
panel.add(view.asWidget());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface ScaleValueCardView extends IsWidget {
void addSelectValueButton();

void setDeleteValueButtonHandler(DeleteScaleValueButtonHandler handler);
void setEditMode(boolean enabled);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ interface ScaleValueCardViewImplUiBinder extends UiBinder<HTMLPanel, ScaleValueC

private Button addButton;

private boolean isReadOnly = true;

public ScaleValueCardViewImpl() {
rootPanel = uiBinder.createAndBindUi(this);
createAddButton();
setReadOnly(isReadOnly);
}

private void createAddButton() {
Expand Down Expand Up @@ -138,4 +141,18 @@ public void addSelectValueButton() {
public Widget asWidget() {
return rootPanel;
}

@Override
public void setEditMode(boolean enabled) {
setReadOnly(!enabled);
}

private void setReadOnly(boolean readOnly) {
isReadOnly = readOnly;
if (isReadOnly) {
rootPanel.addStyleName(postCoordinationStyle.disabled());
} else {
rootPanel.removeStyleName(postCoordinationStyle.disabled());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@AutoValue
@GwtCompatible(serializable = true)
@JsonTypeName(CHANNEL)
public abstract class SaveEntityPostCoordinationAction extends AbstractHasProjectAction<ProcessUploadedPostCoordinationResult> {
public abstract class SaveEntityPostCoordinationAction extends AbstractHasProjectAction<SaveEntityPostCoordinationResult> {

public final static String CHANNEL = "webprotege.postcoordination.AddEntitySpecificationRevision";

Expand Down

0 comments on commit eb8e8f2

Please sign in to comment.