Skip to content

Commit

Permalink
Postcoordination table (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilaghi authored Aug 30, 2024
1 parent 6534894 commit 7baf800
Show file tree
Hide file tree
Showing 22 changed files with 871 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected CheckBoxConfig(CheckboxValue defaultValue, List<CheckboxValue> scrolla
this.readOnly = true;
}

CheckboxValue getNextValue(CheckboxValue checkboxValue) {
public CheckboxValue getNextValue(CheckboxValue checkboxValue) {
int pos = scrollableValues.indexOf(checkboxValue);
if(pos >= 0) {
if(pos == scrollableValues.size() - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import static com.google.common.base.Preconditions.checkNotNull;

public class ConfigurableCheckBoxPresenter implements HasValue<CheckboxValue>, HasText, HasEnabled, HasReadOnly {
Logger logger = java.util.logging.Logger.getLogger("ConfigurableCheckBoxPresenter");

@Nonnull
private final ConfigurableCheckBoxView view;

private boolean isTouched = false;

private CheckBoxConfig config;

@Inject
Expand Down Expand Up @@ -58,6 +58,7 @@ private void toggleSelected() {
}
CheckboxValue nextSel = config.getNextValue(view.getValue());
view.setValue(nextSel);
isTouched = true;
}

@Override
Expand Down Expand Up @@ -89,6 +90,10 @@ public HandlerRegistration addValueChangeHandler(ValueChangeHandler<CheckboxValu
return view.addValueChangeHandler(handler);
}

public boolean isTouched() {
return isTouched;
}

@Override
public void fireEvent(GwtEvent<?> event) {
view.fireEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ConfigurableCheckbox implements IsWidget, HasValue<CheckboxValue>,
@Nonnull
private final ConfigurableCheckBoxPresenter presenter;


private final CheckBoxConfig checkBoxConfig;

public ConfigurableCheckbox(CheckBoxConfig checkBoxConfig, String initialValue) {
Expand All @@ -35,6 +36,10 @@ public ConfigurableCheckbox(CheckBoxConfig checkBoxConfig, String initialValue)
this.setValue(checkboxValue);
}

public boolean isTouched() {
return this.presenter.isTouched();
}

@Override
public Widget asWidget() {
return container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
import edu.stanford.bmir.protege.web.client.portlet.PortletChooserViewImpl;
import edu.stanford.bmir.protege.web.client.portlet.PortletUi;
import edu.stanford.bmir.protege.web.client.portlet.PortletUiImpl;
import edu.stanford.bmir.protege.web.client.postcoordination.PostCoordinationPortletView;
import edu.stanford.bmir.protege.web.client.postcoordination.PostCoordinationPortletViewImpl;
import edu.stanford.bmir.protege.web.client.primitive.PrimitiveDataEditorImageView;
import edu.stanford.bmir.protege.web.client.primitive.PrimitiveDataEditorImageViewImpl;
import edu.stanford.bmir.protege.web.client.progress.BusyView;
Expand Down Expand Up @@ -504,6 +506,11 @@ LinearizationPortletView provideLinearizationPortletView(LinearizationPortletVie
return impl;
}

@Provides
PostCoordinationPortletView providePostCoordinationPortletView(PostCoordinationPortletViewImpl impl){
return impl;
}

@Provides
LinearizationCommentsView provideLienarizationCommentsView(LinearizationCommentsViewImpl impl){
return impl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ private void addCommentsHeader(String headerText, int column) {

private void initializeTableHeader() {
addHeaderCell("Linearization", 0);
addCheckboxHeaderCell("Is part of?", 1);
addCheckboxHeaderCell("Is grouping?",2);
addCheckboxHeaderCell("Aux.ax.child?", 3);
addWideHeaderCell("Linearization parent", 4);
addCommentsHeader("Coding notes", 5);
addCheckboxHeaderCell("Is Part Of?", 1);
addCheckboxHeaderCell("Is Grouping?",2);
addCheckboxHeaderCell("Aux.Ax.Child?", 3);
addWideHeaderCell("Linearization Path Parent", 4);
addCommentsHeader("Coding Notes", 5);
flexTable.getRowFormatter().addStyleName(0, style.getLinearizationHeader());
}

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

import edu.stanford.bmir.protege.web.client.form.complexcheckbox.CheckBoxConfig;
import edu.stanford.bmir.protege.web.client.form.complexcheckbox.CheckboxValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

public class PostCoordinationCheckboxConfig extends CheckBoxConfig {
private final Logger logger = Logger.getLogger("CheckBoxConfig");

private final static String CHECK_SVG = "<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" stroke=\"#2cd900\"><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=\"M4 12.6111L8.92308 17.5L20 6.5\" stroke=\"#2cd900\" stroke-width=\"2.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path> </g></svg>";
private final static String REQUIRED_SVG = "<svg viewBox=\"0 0 512 512\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" fill=\"#000000\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <title>mandatory-done</title> <g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"> <g id=\"icon\" fill=\"#c23f42\" transform=\"translate(114.773333, 42.666667)\"> <path d=\"M322.588167,146.773333 L367.843001,192.028167 L130.588167,429.283001 L-2.61257984e-15,298.694834 L45.254834,253.44 L130.588167,338.780167 L322.588167,146.773333 Z M169.347879,7.10542736e-15 L159.927965,83.3939394 L236.94961,49.3160173 L253.850043,103.619048 L172.672554,119.411255 L226.975584,180.08658 L180.707186,213.333333 L141.088139,141.298701 L101.746147,213.333333 L55.2006926,180.08658 L109.503723,119.411255 L28.60329,103.619048 L45.2266667,49.3160173 L122.248312,83.3939394 L112.828398,7.10542736e-15 L169.347879,7.10542736e-15 Z\" id=\"Combined-Shape\"> </path> </g> </g> </g></svg>";

private final static String UNKNOWN_SVG = "<svg version=\"1.1\" id=\"Capa_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 290.658 290.658\" xml:space=\"preserve\" fill=\"#000000\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <g> <g> <rect y=\"139.474\" style=\"fill:darkgrey;\" width=\"290.658\" height=\"11.711\"></rect> </g> </g> </g></svg>";

private final static String DEFAULT_CHECK_SVG = "<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=\"M4 12.6111L8.92308 17.5L20 6.5\" stroke=\"#919191\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path> </g></svg>";
private final static String DEFAULT_REQUIRED_SVG = "<svg viewBox=\"0 0 512 512\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" fill=\"#000000\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <title>mandatory-done</title> <g id=\"Page-1\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"> <g id=\"icon\" fill=\"#919191\" transform=\"translate(114.773333, 42.666667)\"> <path d=\"M322.588167,146.773333 L367.843001,192.028167 L130.588167,429.283001 L-2.61257984e-15,298.694834 L45.254834,253.44 L130.588167,338.780167 L322.588167,146.773333 Z M169.347879,7.10542736e-15 L159.927965,83.3939394 L236.94961,49.3160173 L253.850043,103.619048 L172.672554,119.411255 L226.975584,180.08658 L180.707186,213.333333 L141.088139,141.298701 L101.746147,213.333333 L55.2006926,180.08658 L109.503723,119.411255 L28.60329,103.619048 L45.2266667,49.3160173 L122.248312,83.3939394 L112.828398,7.10542736e-15 L169.347879,7.10542736e-15 Z\" id=\"Combined-Shape\"> </path> </g> </g> </g></svg>";

private final static String DEFAULT_UNKNOWN_SVG = "<svg version=\"1.1\" id=\"Capa_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 290.658 290.658\" xml:space=\"preserve\" fill=\"#000000\"><g id=\"SVGRepo_bgCarrier\" stroke-width=\"0\"></g><g id=\"SVGRepo_tracerCarrier\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></g><g id=\"SVGRepo_iconCarrier\"> <g> <g> <rect y=\"139.474\" style=\"fill:darkgrey;\" width=\"290.658\" height=\"11.711\"></rect> </g> </g> </g></svg>";


private CheckboxValue parentValue;


public static List<CheckboxValue> AVAILABLE_VALUES_LIST = Arrays.asList(new CheckboxValue(UNKNOWN_SVG, "UNKNOWN"),
new CheckboxValue(CHECK_SVG, "ALLOWED"),
new CheckboxValue(REQUIRED_SVG, "REQUIRED")
);

public static List<CheckboxValue> AVAILABLE_DEFAULT_VALUE_LIST = Arrays.asList(
new CheckboxValue(DEFAULT_UNKNOWN_SVG, "DEFAULT_UNKNOWN"),
new CheckboxValue(DEFAULT_CHECK_SVG, "DEFAULT_ALLOWED"),
new CheckboxValue(DEFAULT_REQUIRED_SVG, "DEFAULT_REQUIRED"));

protected PostCoordinationCheckboxConfig() {
super(new CheckboxValue(UNKNOWN_SVG, "UNKNOWN"), AVAILABLE_VALUES_LIST);
}

@Override
public CheckboxValue getNextValue(CheckboxValue checkboxValue) {
if(parentValue != null) {
return getNextValueForDerivedClasses(checkboxValue);
} else {
return super.getNextValue(checkboxValue);
}
}

@Override
public CheckboxValue findValue(String inputValue) {
if(inputValue == null || inputValue.isEmpty()) {
return new CheckboxValue(UNKNOWN_SVG, "UNKNOWN");
}
List<CheckboxValue> allValues = new ArrayList<>();
allValues.addAll(AVAILABLE_VALUES_LIST);
allValues.addAll(AVAILABLE_DEFAULT_VALUE_LIST);

return allValues.stream().filter(value -> value.getValue().equalsIgnoreCase(inputValue))
.findFirst()
.orElse(new CheckboxValue(UNKNOWN_SVG, "UNKNOWN"));
}

private CheckboxValue getNextValueForDerivedClasses(CheckboxValue checkboxValue) {
if(checkboxValue.getValue().startsWith("DEFAULT")) {
return AVAILABLE_VALUES_LIST.get(0);
}

int pos = AVAILABLE_VALUES_LIST.indexOf(checkboxValue);
if(pos >= 0) {
if (pos == AVAILABLE_VALUES_LIST.size()-1) {
return AVAILABLE_DEFAULT_VALUE_LIST.stream().filter(value -> ("DEFAULT_"+parentValue.getValue()).equalsIgnoreCase(value.getValue()))
.findFirst()
.orElseThrow(() -> new RuntimeException("Missing parent"));
} else {
return AVAILABLE_VALUES_LIST.get(pos + 1);

}
}else {
throw new RuntimeException("Given value " + checkboxValue + " is not in scrollable values ");
}
}

public void setParentValue(CheckboxValue parentValue) {
this.parentValue = parentValue;
}

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

import com.google.web.bindery.event.shared.EventBus;
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.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.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.logging.Logger;


@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);
}
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();
});

});


}



@Override
protected void handleReloadRequest() {

}

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


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 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;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;

import java.util.Map;

public interface PostCoordinationPortletView extends AcceptsOneWidget, IsWidget, HasDispose {
void setProjectId(ProjectId projectId);

void setLabels(Map<String, PostCoordinationTableAxisLabel> labels);

void setLinearizationDefinitonMap(Map<String, LinearizationDefinition> linearizationDefinitonMap);

void setPostCoordinationEntity();
}
Loading

0 comments on commit 7baf800

Please sign in to comment.