Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added correct ordering of the scale value cards #75

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PostCoordinationPortletPresenter extends AbstractWebProtegePortletP
private final LoggedInUserManager loggedInUserManager;
private final MessageBox messageBox;

private final Map<String, ScaleValueCardPresenter> scaleValueCardPresenters = new HashMap<>();
private final Map<String, ScaleValueCardPresenter> scaleValueCardPresenters = new LinkedHashMap<>();

private final Map<String, PostCoordinationTableAxisLabel> tableLabelsForAxes = new HashMap<>();
private final Map<String, PostCoordinationTableAxisLabel> scaleLabelsForAxes = new HashMap<>();
Expand All @@ -46,6 +46,8 @@ public class PostCoordinationPortletPresenter extends AbstractWebProtegePortletP

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

private final List<String> scaleCardsOrderByAxis = new LinkedList<>();

private boolean editMode = false;

private Optional<OWLEntity> entityIri;
Expand Down Expand Up @@ -87,6 +89,7 @@ public void startPortlet(PortletUi portletUi, WebProtegeEventBus eventBus) {
return new RuntimeException("Couldn't find label for " + availableAxis);
});
tableLabelsForAxes.put(availableAxis, existingLabel);
scaleCardsOrderByAxis.add(availableAxis);
}

scaleLabelsForAxes.putAll(tableLabelsForAxes);
Expand Down Expand Up @@ -114,10 +117,13 @@ remove the orElseGet() and add back the orElseThrow() when we have proper labels
)
);

List<String> orderedAxisListWithSubAxis = this.createOrderAxisListWithSubAxis(result.getTableConfiguration().getPostCoordinationAxes(), result.getTableConfiguration().getCompositePostCoordinationAxes());

scaleCardsOrderByAxis.addAll(orderedAxisListWithSubAxis);

view.setTableCellChangedHandler(handleTableCellChanged());

dispatch.execute(GetLinearizationDefinitionsAction.create(), definitionsResult -> {
dispatch.execute(GetLinearizationDefinitionsAction.create(), definitionsResult -> {
Map<String, LinearizationDefinition> definitionMap = new HashMap<>();
for (LinearizationDefinition definition : definitionsResult.getDefinitionList()) {
definitionMap.put(definition.getWhoficEntityIri(), definition);
Expand All @@ -127,9 +133,7 @@ remove the orElseGet() and add back the orElseThrow() when we have proper labels
});
});

view.setEditButtonHandler(() -> {
this.setEditMode(true);
});
view.setEditButtonHandler(() -> this.setEditMode(true));

view.setCancelButtonHandler(() -> {
handleAfterSetEntity(this.entityIri);
Expand All @@ -141,6 +145,21 @@ remove the orElseGet() and add back the orElseThrow() when we have proper labels
this.setEditMode(false);
}

//The corect order is determined by the order of the values that are stored in the database
private List<String> createOrderAxisListWithSubAxis(List<String> postCoordinationAxes, List<PostCoordinationCompositeAxis> compositeAxisList) {
List<String> orderedAxisList = new LinkedList<>(postCoordinationAxes);

compositeAxisList.forEach(compositeAxis ->
{
int indexForCurrAxis = orderedAxisList.indexOf(compositeAxis.getPostCoordinationAxis());
List<String> subAxisList = new LinkedList<>(compositeAxis.getSubAxis());
orderedAxisList.addAll(indexForCurrAxis+1,subAxisList);
orderedAxisList.remove(indexForCurrAxis);
}
);
return orderedAxisList;
}

private void saveEntity(Optional<WhoficEntityPostCoordinationSpecification> specification) {
this.setEditMode(false);

Expand All @@ -164,7 +183,7 @@ protected void handleReloadRequest() {

@Override
protected void handleAfterSetEntity(Optional<OWLEntity> entityData) {
if(this.editMode) {
if (this.editMode) {
this.entityIri = entityData;

messageBox.showConfirmBox(MessageStyle.ALERT,
Expand All @@ -184,11 +203,10 @@ protected void handleAfterSetEntity(Optional<OWLEntity> entityData) {


}
private void navigateToEntity(Optional<OWLEntity> entityData){

private void navigateToEntity(Optional<OWLEntity> entityData) {
entityData.ifPresent(owlEntity -> dispatch.execute(GetEntityCustomScalesAction.create(owlEntity.getIRI().toString(), getProjectId()),
(result) -> {
postCoordinationCustomScalesList.addAll(result.getWhoficCustomScaleValues().getScaleCustomizations());
}));
(result) -> postCoordinationCustomScalesList.addAll(result.getWhoficCustomScaleValues().getScaleCustomizations())));

entityData.ifPresent(owlEntity -> dispatch.execute(GetEntityPostCoordinationAction.create(owlEntity.getIRI().toString(), getProjectId()),
(result) -> {
Expand Down Expand Up @@ -237,7 +255,28 @@ private void addScaleValueCardPresenter(String axisIri) {
PostCoordinationScaleValue.create(axisIri, currentAxisLabels.getScaleLabel(), existingScaleValueForAxis, genericScale1)
);
scaleValueCardPresenters.put(axisIri, newPresenter);
newPresenter.start(view.getScaleValueCardsView(), editMode);
newPresenter.start(editMode);
updateScaleValueCards();
}

private void updateScaleValueCards() {
Map<String, ScaleValueCardPresenter> orderedScaleValueCardPresenters = getOrderedScaleValueCardPresenters();
scaleValueCardPresenters.clear();
scaleValueCardPresenters.putAll(orderedScaleValueCardPresenters);

scaleValueCardPresenters.values().forEach(scaleValueCardPresenter -> view.getScaleValueCardsView().add(scaleValueCardPresenter.getView().asWidget()));
}

private Map<String, ScaleValueCardPresenter> getOrderedScaleValueCardPresenters() {
Map<String, ScaleValueCardPresenter> orderedScaleValueCardPresenters = new LinkedHashMap<>();

for (String key : scaleCardsOrderByAxis) {
if (scaleValueCardPresenters.containsKey(key)) {
orderedScaleValueCardPresenters.put(key, scaleValueCardPresenters.get(key));
}
}

return orderedScaleValueCardPresenters;
}

private TableCellChangedHandler handleTableCellChanged() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard;

import com.google.gwt.user.client.ui.VerticalPanel;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.shared.entity.GetRenderedOwlEntitiesAction;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;
Expand Down Expand Up @@ -46,9 +45,9 @@ private void initTable() {

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

Expand All @@ -74,10 +73,9 @@ public void setEditMode(boolean editMode) {
view.setEditMode(editMode);
}

public void start(VerticalPanel panel, boolean isEditMode) {
public void start(boolean isEditMode) {
bindView();
initTable();
setEditMode(isEditMode);
panel.add(view.asWidget());
}
}
Loading