Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upload-postcoordination-file' in…
Browse files Browse the repository at this point in the history
…to upload-postcoordination-file

# Conflicts:
#	webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java
  • Loading branch information
alexsilaghi committed Sep 30, 2024
2 parents 170ae0b + eb8e8f2 commit 564a081
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 31 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 @@ -86,43 +111,80 @@ 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);
saveValuesButton.setVisible(false);
});

}
}

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 @@ -344,12 +406,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 All @@ -73,7 +78,7 @@
color: #fff;
line-height: 1.4;
background-color: #186cd4;
padding: 10px;
padding: 4px;
font-weight: bold;
font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif;
border-top-left-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 @@ -19,6 +19,7 @@ interface ScaleValueCardViewImplUiBinder extends UiBinder<HTMLPanel, ScaleValueC
private boolean isCollapsed = false;
private final String collapseIcon = "&#9660;";
private final String expandIcon = "&#9654;";
private final String spaceSymbol = "&nbsp;";
private static final PostCoordinationTableResourceBundle.PostCoordinationTableCss postCoordinationStyle = PostCoordinationTableResourceBundle.INSTANCE.style();

private static final WebProtegeClientBundle.ButtonsCss buttonCss = WebProtegeClientBundle.BUNDLE.buttons();
Expand All @@ -31,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 All @@ -56,8 +60,7 @@ public void clearTable() {
public void addHeader(String headerText, String description) {
GWT.log("Adding header. Current row count: " + valueTable.getRowCount());

headerHtml = new HTML("<span class=\"" + postCoordinationStyle.toggleIcon() + "\">" + collapseIcon + "</span> " + headerText + "<br><span class=\"" + postCoordinationStyle.scaleValueHeaderDescription() + "\">" + description + "</span>");
headerHtml.setStyleName(postCoordinationStyle.scaleValueHeader());
headerHtml = new HTML("<span class=\"" + postCoordinationStyle.toggleIcon() + "\">" + collapseIcon + "</span> " + headerText + spaceSymbol + "<span class=\"" + postCoordinationStyle.scaleValueHeaderDescription() + "\">(" + description + ")</span>");

valueTable.setWidget(0, 0, headerHtml);
valueTable.getFlexCellFormatter().setColSpan(0, 0, 2);
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());
}
}
}

0 comments on commit 564a081

Please sign in to comment.