Skip to content

Commit

Permalink
Create configuration cards #3 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeoWB authored Aug 30, 2024
1 parent f79c2a4 commit 788c20d
Show file tree
Hide file tree
Showing 14 changed files with 584 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,153 @@
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.lang.DisplayNameRenderer;
import edu.stanford.bmir.protege.web.client.library.msgbox.MessageBox;
import edu.stanford.bmir.protege.web.client.portlet.AbstractWebProtegePortletPresenter;
import edu.stanford.bmir.protege.web.client.portlet.PortletUi;
import edu.stanford.bmir.protege.web.client.portlet.*;
import edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard.*;
import edu.stanford.bmir.protege.web.client.selection.SelectionModel;
import edu.stanford.bmir.protege.web.client.user.LoggedInUserManager;
import edu.stanford.bmir.protege.web.shared.event.WebProtegeEventBus;
import edu.stanford.bmir.protege.web.shared.linearization.GetLinearizationDefinitionsAction;
import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition;
import edu.stanford.bmir.protege.web.shared.postcoordination.GetPostCoordinationTableConfigurationAction;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;
import edu.stanford.bmir.protege.web.shared.linearization.*;
import edu.stanford.bmir.protege.web.shared.postcoordination.*;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import edu.stanford.webprotege.shared.annotations.Portlet;
import org.semanticweb.owlapi.model.OWLEntity;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.logging.Logger;

import java.util.stream.Collectors;

@Portlet(id = "portlets.PostCoordination",
title = "iCat-X Post-Coordinations",
tooltip = "Displays the Post-Coordination configuration on the current entity.")
public class PostCoordinationPortletPresenter extends AbstractWebProtegePortletPresenter {

private final PostCoordinationPortletView view;
Logger logger = java.util.logging.Logger.getLogger("PostCoordinationPortletPresenter");

private DispatchServiceManager dispatch;
private final EventBus eventBus;

private final LoggedInUserManager loggedInUserManager;


private MessageBox messageBox;

@Inject
public PostCoordinationPortletPresenter(@Nonnull SelectionModel selectionModel,
@Nonnull ProjectId projectId,
@Nonnull DisplayNameRenderer displayNameRenderer,
@Nonnull DispatchServiceManager dispatch,
@Nonnull PostCoordinationPortletView view,
@Nonnull EventBus eventBus,
@Nonnull MessageBox messageBox,
@Nonnull LoggedInUserManager loggedInUserManager) {
super(selectionModel, projectId, displayNameRenderer, dispatch);
this.view = view;
this.messageBox = messageBox;
this.dispatch = dispatch;
this.eventBus = eventBus;
this.loggedInUserManager = loggedInUserManager;
this.view.setProjectId(projectId);

}

@Override
public void startPortlet(PortletUi portletUi, WebProtegeEventBus eventBus) {

portletUi.setWidget(view.asWidget());
setDisplaySelectedEntityNameAsSubtitle(true);

dispatch.execute(GetPostCoordinationTableConfigurationAction.create("ICD"), result -> {
Map<String, PostCoordinationTableAxisLabel> labels = new HashMap<>();
for(String availableAxis : result.getTableConfiguration().getPostCoordinationAxes()) {
PostCoordinationTableAxisLabel existingLabel = result.getLabels().stream()
.filter(label -> label.getPostCoordinationAxis().equalsIgnoreCase(availableAxis))
.findFirst().orElseThrow( () -> new RuntimeException("Couldn't find label for " + availableAxis));
labels.put(availableAxis, existingLabel);
public class PostCoordinationPortletPresenter extends AbstractWebProtegePortletPresenter {

private final PostCoordinationPortletView view;
private final Logger logger = Logger.getLogger("PostCoordinationPortletPresenter");

private final DispatchServiceManager dispatch;
private final EventBus eventBus;

private final LoggedInUserManager loggedInUserManager;
private final MessageBox messageBox;

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

private final Map<String, PostCoordinationTableAxisLabel> labels = new HashMap<>();
private final Map<String, PostCoordinationAxisToGenericScale> genericScale = new HashMap<>();


@Inject
public PostCoordinationPortletPresenter(@Nonnull SelectionModel selectionModel,
@Nonnull ProjectId projectId,
@Nonnull DisplayNameRenderer displayNameRenderer,
@Nonnull DispatchServiceManager dispatch,
@Nonnull PostCoordinationPortletView view,
@Nonnull EventBus eventBus,
@Nonnull MessageBox messageBox,
@Nonnull LoggedInUserManager loggedInUserManager) {
super(selectionModel, projectId, displayNameRenderer, dispatch);
this.view = view;
this.messageBox = messageBox;
this.dispatch = dispatch;
this.eventBus = eventBus;
this.loggedInUserManager = loggedInUserManager;
this.view.setProjectId(projectId);
}

@Override
public void startPortlet(PortletUi portletUi, WebProtegeEventBus eventBus) {
portletUi.setWidget(view.asWidget());
setDisplaySelectedEntityNameAsSubtitle(true);

scaleValueCardPresenters.clear();
labels.clear();
genericScale.clear();


dispatch.execute(GetPostCoordinationTableConfigurationAction.create("ICD"), result -> {
for (String availableAxis : result.getTableConfiguration().getPostCoordinationAxes()) {
PostCoordinationTableAxisLabel existingLabel = result.getLabels().stream()
.filter(label -> label.getPostCoordinationAxis().equalsIgnoreCase(availableAxis))
.findFirst()
.orElseThrow(() -> new RuntimeException("Couldn't find label for " + availableAxis));
labels.put(availableAxis, existingLabel);
}
view.setLabels(labels);

/*
ToDo:
populate genericScale using a dispatch request.
*/
Map<String, ScaleValueCardPresenter> axisMapWithValues = labels.values()
.stream()
.collect(Collectors.toMap(
PostCoordinationTableAxisLabel::getPostCoordinationAxis,
tabelAxisLabel -> {
PostCoordinationAxisToGenericScale genericScale1 = genericScale.getOrDefault(
tabelAxisLabel.getPostCoordinationAxis(),
new PostCoordinationAxisToGenericScale(tabelAxisLabel.getPostCoordinationAxis(), "", ScaleAllowMultiValue.NotAllowed)
);
return createScaleValueCardPresenter(
tabelAxisLabel,
new PostCoordinationScaleValue(
tabelAxisLabel.getPostCoordinationAxis(),
tabelAxisLabel.getScaleLabel(),
new ArrayList<>(Arrays.asList("iri1.1", "iri1.2", "iri1.3")),
genericScale1)
);
}
));

scaleValueCardPresenters.putAll(axisMapWithValues);
//Do batch action for all scaleValues
dispatch.beginBatch();
scaleValueCardPresenters.values().forEach(presenter -> presenter.start(view.getScaleValueCardsView()));
dispatch.executeCurrentBatch();


dispatch.execute(GetLinearizationDefinitionsAction.create(), definitionsResult -> {
Map<String, LinearizationDefinition> definitionMap = new HashMap<>();
for (LinearizationDefinition definition : definitionsResult.getDefinitionList()) {
definitionMap.put(definition.getWhoficEntityIri(), definition);
}
view.setLabels(labels);

dispatch.execute(GetLinearizationDefinitionsAction.create(), definitionsResult -> {
Map<String, LinearizationDefinition> definitionMap = new HashMap<>();

for (LinearizationDefinition definition : definitionsResult.getDefinitionList()) {
definitionMap.put(definition.getWhoficEntityIri(), definition);
}
view.setLinearizationDefinitonMap(definitionMap);
view.setPostCoordinationEntity();
});

view.setLinearizationDefinitonMap(definitionMap);
view.setPostCoordinationEntity();
});


}



@Override
protected void handleReloadRequest() {

}

@Override
protected void handleAfterSetEntity(Optional<OWLEntity> entityData) {


}

});
}

private ScaleValueCardPresenter createScaleValueCardPresenter(PostCoordinationTableAxisLabel axis, PostCoordinationScaleValue scaleValue) {
ScaleValueCardView view = new ScaleValueCardViewImpl();
return new ScaleValueCardPresenter(axis, scaleValue, view, dispatch, getProjectId());
}

@Override
protected void handleReloadRequest() {
}

@Override
protected void handleAfterSetEntity(Optional<OWLEntity> entityData) {
}

public void removeScaleValueCardPresenter(String axisIri) {
ScaleValueCardPresenter presenter = scaleValueCardPresenters.get(axisIri);
view.getScaleValueCardsView().remove(presenter.getView().asWidget());
scaleValueCardPresenters.remove(axisIri);
}

private void addScaleValueCardPresenter(String axisIri) {
PostCoordinationTableAxisLabel currentAxisLabels = labels.get(axisIri);
PostCoordinationAxisToGenericScale genericScale1 = genericScale.getOrDefault(
axisIri,
new PostCoordinationAxisToGenericScale(axisIri, "", ScaleAllowMultiValue.NotAllowed)
);
ScaleValueCardPresenter newPresenter = createScaleValueCardPresenter(
currentAxisLabels,
PostCoordinationScaleValue.createEmpty(axisIri, currentAxisLabels.getScaleLabel(), genericScale1)
);
scaleValueCardPresenters.put(axisIri, newPresenter);
newPresenter.start(view.getScaleValueCardsView());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.stanford.bmir.protege.web.client.postcoordination;

import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.shared.HasDispose;
import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;
Expand All @@ -17,4 +16,6 @@ public interface PostCoordinationPortletView extends AcceptsOneWidget, IsWidget,
void setLinearizationDefinitonMap(Map<String, LinearizationDefinition> linearizationDefinitonMap);

void setPostCoordinationEntity();

VerticalPanel getScaleValueCardsView();
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package edu.stanford.bmir.protege.web.client.postcoordination;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.*;
import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition;
import edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard.ScaleValueCardView;
import edu.stanford.bmir.protege.web.shared.postcoordination.PostCoordinationTableAxisLabel;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.*;

public class PostCoordinationPortletViewImpl extends Composite implements PostCoordinationPortletView {

Expand All @@ -23,6 +22,9 @@ public class PostCoordinationPortletViewImpl extends Composite implements PostCo

@UiField
protected FlexTable flexTable;
@UiField
public VerticalPanel scaleValueCardList;

private Map<String, PostCoordinationTableAxisLabel> labels;
private Map<String, LinearizationDefinition> definitionMap;

Expand Down Expand Up @@ -62,6 +64,11 @@ public void setPostCoordinationEntity() {
initializeTableContent();
}

@Override
public VerticalPanel getScaleValueCardsView() {
return scaleValueCardList;
}

@Override
public void setWidget(IsWidget w) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:custom="urn:import:edu.stanford.bmir.protege.web.client.form.complexcheckbox"
xmlns:text="urn:import:edu.stanford.bmir.protege.web.client.library.text">
<g:HTMLPanel ui:field="paneContainer">
<g:HTMLPanel width="100%">
<g:FlexTable width="97%" height="100%" ui:field="flexTable"/>
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:HTMLPanel ui:field="paneContainer">
<g:HTMLPanel width="100%">
<g:FlexTable width="97%" height="100%" ui:field="flexTable"/>
</g:HTMLPanel>
<g:VerticalPanel width="100%" ui:field="scaleValueCardList"/>
</g:HTMLPanel>
</g:HTMLPanel>
</ui:UiBinder>
Loading

0 comments on commit 788c20d

Please sign in to comment.