diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletPresenter.java index 9226c741e..8b4be2646 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletPresenter.java @@ -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 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 scaleValueCardPresenters = new HashMap<>(); + + private final Map labels = new HashMap<>(); + private final Map 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 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 definitionMap = new HashMap<>(); + for (LinearizationDefinition definition : definitionsResult.getDefinitionList()) { + definitionMap.put(definition.getWhoficEntityIri(), definition); } - view.setLabels(labels); - - dispatch.execute(GetLinearizationDefinitionsAction.create(), definitionsResult -> { - Map 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 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 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()); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletView.java index 738160ea2..019051b99 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletView.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletView.java @@ -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; @@ -17,4 +16,6 @@ public interface PostCoordinationPortletView extends AcceptsOneWidget, IsWidget, void setLinearizationDefinitonMap(Map linearizationDefinitonMap); void setPostCoordinationEntity(); + + VerticalPanel getScaleValueCardsView(); } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java index 495707c42..b935df616 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.java @@ -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 { @@ -23,6 +22,9 @@ public class PostCoordinationPortletViewImpl extends Composite implements PostCo @UiField protected FlexTable flexTable; + @UiField + public VerticalPanel scaleValueCardList; + private Map labels; private Map definitionMap; @@ -62,6 +64,11 @@ public void setPostCoordinationEntity() { initializeTableContent(); } + @Override + public VerticalPanel getScaleValueCardsView() { + return scaleValueCardList; + } + @Override public void setWidget(IsWidget w) { diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.ui.xml index d3b4b2cce..d6a4802aa 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.ui.xml +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationPortletViewImpl.ui.xml @@ -1,10 +1,9 @@ - - - + xmlns:g='urn:import:com.google.gwt.user.client.ui'> + + + + + - \ No newline at end of file diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTable.css b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTable.css index 8fa286340..36eaf7f76 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTable.css +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTable.css @@ -1,4 +1,3 @@ - .postCoordinationHeader { font-size: 12px; color: #fff; @@ -18,13 +17,13 @@ } .rotatedHeader div { - transform-origin: left; - transform: rotate(-75deg) translate(-50px,100%); - display: table-cell; - vertical-align: middle; - text-align: start; - text-wrap: wrap; - white-space: nowrap; + transform-origin: left; + transform: rotate(-75deg) translate(-50px, 100%); + display: table-cell; + vertical-align: middle; + text-align: start; + text-wrap: wrap; + white-space: nowrap; } .customRowStyle { @@ -67,4 +66,57 @@ margin: 15px; border-collapse: collapse; padding: 3px; +} + +.scaleValueHeader { + font-size: 14px; + color: #fff; + line-height: 1.4; + background-color: #186cd4; + padding: 10px; + font-weight: bold; + font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif; + border-top-left-radius: 5px; + border-top-right-radius: 5px +} + +.scaleValueRow { + margin-left: 15px; + margin-right: 15px; + font-size: 12px; + width: 99%; + border-bottom: 1px solid #f2f2f2; + border-top: 1px solid #f2f2f2; + min-height: 35px; + align-items: center; +} + +.scaleValueCard { + display: flex; + flex-direction: column; + -webkit-box-shadow: 0 0 40px 0 rgba(0, 0, 0, .15); + box-shadow: 0 0 40px 0 rgba(0, 0, 0, .15); + margin: 14px; + width: 97%; +} + +.scaleValue-table-button-cell { + width: 30px; + text-align: center; + vertical-align: middle; +} + +.scaleValue-table-value-cell { + padding-left: 10px; + text-align: left; +} + +.scaleValueHeaderDescription { + font-size: 11px; + font-style: italic; +} + +.toggle-icon { + cursor: pointer; + margin-right: 5px; } \ No newline at end of file diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableResourceBundle.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableResourceBundle.java index da8e9fda0..15aaf3770 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableResourceBundle.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/PostCoordinationTableResourceBundle.java @@ -1,8 +1,7 @@ package edu.stanford.bmir.protege.web.client.postcoordination; import com.google.gwt.core.client.GWT; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.CssResource; +import com.google.gwt.resources.client.*; public interface PostCoordinationTableResourceBundle extends ClientBundle { @@ -13,7 +12,6 @@ public interface PostCoordinationTableResourceBundle extends ClientBundle { PostCoordinationTableCss style(); - interface PostCoordinationTableCss extends CssResource { @ClassName("postCoordinationHeader") @@ -33,12 +31,34 @@ interface PostCoordinationTableCss extends CssResource { @ClassName("rotatedHeader") String getRotatedHeader(); + @ClassName("headerLabelRow") String getHeaderLabelRow(); @ClassName("evenRowStyle") String getEvenRowStyle(); + @ClassName("scaleValueHeader") + String scaleValueHeader(); + + @ClassName("scaleValueRow") + String scaleValueRow(); + + @ClassName("scaleValueCard") + String scaleValueCard(); + + @ClassName("scaleValue-table-button-cell") + String scaleValueTableButtonCell(); + + + @ClassName("scaleValue-table-value-cell") + String scaleValueTableValueCell(); + + @ClassName("scaleValueHeaderDescription") + String scaleValueHeaderDescription(); + + @ClassName("toggle-icon") + String toggleIcon(); } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/DeleteScaleValueButtonHandler.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/DeleteScaleValueButtonHandler.java new file mode 100644 index 000000000..da1db6b52 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/DeleteScaleValueButtonHandler.java @@ -0,0 +1,6 @@ +package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard; + +public interface DeleteScaleValueButtonHandler { + + void handleDeleteButton(String value); +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/PostCoordinationAxisToGenericScale.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/PostCoordinationAxisToGenericScale.java new file mode 100644 index 000000000..da0902250 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/PostCoordinationAxisToGenericScale.java @@ -0,0 +1,33 @@ +package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard; + +public class PostCoordinationAxisToGenericScale { + private final String postcoordinationAxis; + private final String genericPostcoordinationScaleTopClass; + private final ScaleAllowMultiValue allowMultiValue; + + public PostCoordinationAxisToGenericScale(String postcoordinationAxis, + String genericPostcoordinationScaleTopClass, + ScaleAllowMultiValue allowMultiValue) { + this.postcoordinationAxis = postcoordinationAxis; + this.genericPostcoordinationScaleTopClass = genericPostcoordinationScaleTopClass; + this.allowMultiValue = allowMultiValue; + } + + public PostCoordinationAxisToGenericScale create(String postcoordinationAxis, + String genericPostcoordinationScaleTopClass, + ScaleAllowMultiValue allowMultiValue) { + return new PostCoordinationAxisToGenericScale(postcoordinationAxis, genericPostcoordinationScaleTopClass, allowMultiValue); + } + + public String getPostcoordinationAxis() { + return postcoordinationAxis; + } + + public String getGenericPostcoordinationScaleTopClass() { + return genericPostcoordinationScaleTopClass; + } + + public ScaleAllowMultiValue getAllowMultiValue() { + return allowMultiValue; + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/PostCoordinationScaleValue.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/PostCoordinationScaleValue.java new file mode 100644 index 000000000..e108b2b72 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/PostCoordinationScaleValue.java @@ -0,0 +1,42 @@ +package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard; + +import java.util.*; + +public class PostCoordinationScaleValue { + + private final String axisIri; + private final String axisLabel; + private final List valueIris; + private final PostCoordinationAxisToGenericScale genericScale; + + public PostCoordinationScaleValue(String axisIri, + String axisLabel, + List valueIris, PostCoordinationAxisToGenericScale genericScale) { + this.axisIri = axisIri; + this.axisLabel = axisLabel; + this.valueIris = valueIris; + this.genericScale = genericScale; + } + + public static PostCoordinationScaleValue createEmpty(String axisIri, + String axisLabel, + PostCoordinationAxisToGenericScale genericScale) { + return new PostCoordinationScaleValue(axisIri, axisLabel, new ArrayList<>(), genericScale); + } + + public String getAxisIri() { + return axisIri; + } + + public String getAxisLabel() { + return axisLabel; + } + + public List getValueIris() { + return valueIris; + } + + public PostCoordinationAxisToGenericScale getGenericScale(){ + return genericScale; + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleAllowMultiValue.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleAllowMultiValue.java new file mode 100644 index 000000000..19fc103e1 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleAllowMultiValue.java @@ -0,0 +1,26 @@ +package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard; + +public enum ScaleAllowMultiValue { + NotAllowed("This does not allow multiple values"), + AllowAlways("This always allows multiple values"), + AllowedExceptFromSameBlock("This allows multiple values except from the same block"); + + private final String description; + + ScaleAllowMultiValue(String description) { + this.description = description; + } + + public String getBrowserText() { + return description; + } + + public static ScaleAllowMultiValue fromString(String value) { + for (ScaleAllowMultiValue scaleAllowMultiValue : ScaleAllowMultiValue.values()) { + if (scaleAllowMultiValue.name().equalsIgnoreCase(value)) { + return scaleAllowMultiValue; + } + } + throw new IllegalArgumentException("Unknown value: " + value); + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardPresenter.java new file mode 100644 index 000000000..246dbd2a2 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardPresenter.java @@ -0,0 +1,68 @@ +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; +import edu.stanford.bmir.protege.web.shared.project.ProjectId; + +import java.util.HashSet; + +public class ScaleValueCardPresenter { + + private final ScaleValueCardView view; + private final PostCoordinationTableAxisLabel postCoordinationAxis; + private final PostCoordinationScaleValue scaleValue; + private final DispatchServiceManager dispatchServiceManager; + private final ProjectId projectId; + + + public ScaleValueCardPresenter(PostCoordinationTableAxisLabel postCoordinationAxis, + PostCoordinationScaleValue scaleValue, + ScaleValueCardView view, + DispatchServiceManager dispatchServiceManager, + ProjectId projectId) { + this.view = view; + this.postCoordinationAxis = postCoordinationAxis; + this.scaleValue = scaleValue; + this.dispatchServiceManager = dispatchServiceManager; + this.projectId = projectId; + } + + //implement here the pop-up modal for selecting a scale value + private void bindView() { + view.setAddButtonClickHandler(event -> addRow("New Value")); + } + + private void initTable() { + view.clearTable(); + view.addHeader(postCoordinationAxis.getScaleLabel(), scaleValue.getGenericScale().getAllowMultiValue().getBrowserText()); + view.addSelectValueButton(); + + dispatchServiceManager.execute(GetRenderedOwlEntitiesAction.create(projectId, new HashSet<>(scaleValue.getValueIris())), + result -> result.getRenderedEntities().forEach(renderedEntity -> addRow(!renderedEntity.getBrowserText().equals("") ? renderedEntity.getBrowserText() : renderedEntity.getEntity().toStringID())) + ); + + view.setDeleteValueButtonHandler((value) -> scaleValue.getValueIris().remove(value)); + + } + + private void addRow(String value) { + scaleValue.getValueIris().add(value); + view.addRow(value); + } + + public ScaleValueCardView getView() { + return view; + } + + public PostCoordinationScaleValue getValues() { + return scaleValue; + } + + public void start(VerticalPanel panel) { + bindView(); + initTable(); + panel.add(view.asWidget()); + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardView.java new file mode 100644 index 000000000..da0040802 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardView.java @@ -0,0 +1,19 @@ +package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard; + +import com.google.gwt.user.client.ui.IsWidget; +import com.google.gwt.event.dom.client.ClickHandler; + +public interface ScaleValueCardView extends IsWidget { + + void setAddButtonClickHandler(ClickHandler clickHandler); + + void clearTable(); + + void addHeader(String headerText, String description); + + void addRow(String value) ; + + void addSelectValueButton(); + + void setDeleteValueButtonHandler(DeleteScaleValueButtonHandler handler); +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardViewImpl.java new file mode 100644 index 000000000..e356baff6 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardViewImpl.java @@ -0,0 +1,141 @@ +package edu.stanford.bmir.protege.web.client.postcoordination.scaleValuesCard; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.*; +import com.google.gwt.user.client.ui.*; +import edu.stanford.bmir.protege.web.client.library.button.DeleteButton; +import edu.stanford.bmir.protege.web.client.postcoordination.PostCoordinationTableResourceBundle; +import edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle; + +public class ScaleValueCardViewImpl implements ScaleValueCardView { + + interface ScaleValueCardViewImplUiBinder extends UiBinder { + } + + private static final ScaleValueCardViewImplUiBinder uiBinder = GWT.create(ScaleValueCardViewImplUiBinder.class); + private final HTMLPanel rootPanel; + private HTML headerHtml; + private boolean isCollapsed = false; + private final String collapseIcon = "▼"; + private final String expandIcon = "▶"; + private static final PostCoordinationTableResourceBundle.PostCoordinationTableCss postCoordinationStyle = PostCoordinationTableResourceBundle.INSTANCE.style(); + + private static final WebProtegeClientBundle.ButtonsCss buttonCss = WebProtegeClientBundle.BUNDLE.buttons(); + + private DeleteScaleValueButtonHandler deleteScaleValueButtonHandler = (value) -> { + }; + + @UiField + FlexTable valueTable; + + private Button addButton; + + public ScaleValueCardViewImpl() { + rootPanel = uiBinder.createAndBindUi(this); + createAddButton(); + } + + private void createAddButton() { + addButton = new Button(); + addButton.setStyleName(buttonCss.addButton()); + addButton.setTitle("Select value"); + } + + @Override + public void setAddButtonClickHandler(ClickHandler clickHandler) { + addButton.addClickHandler(clickHandler); + } + + @Override + public void clearTable() { + valueTable.removeAllRows(); + } + + @Override + public void addHeader(String headerText, String description) { + GWT.log("Adding header. Current row count: " + valueTable.getRowCount()); + + headerHtml = new HTML("" + collapseIcon + " " + headerText + "
" + description + ""); + headerHtml.setStyleName(postCoordinationStyle.scaleValueHeader()); + + valueTable.setWidget(0, 0, headerHtml); + valueTable.getFlexCellFormatter().setColSpan(0, 0, 2); + valueTable.getCellFormatter().setStyleName(0, 0, postCoordinationStyle.scaleValueHeader()); + + headerHtml.addClickHandler(event -> toggleTable()); + + GWT.log("Header added. Current row count: " + valueTable.getRowCount()); + } + + @Override + public void addRow(String value) { + int addButtonRowIndex = valueTable.getRowCount(); + + valueTable.insertRow(addButtonRowIndex - 1); + setRowContents(addButtonRowIndex - 1, value); + } + + + private void setRowContents(int rowIndex, String value) { + valueTable.setWidget(rowIndex, 0, new Label(value)); + + Button deleteButton = new DeleteButton(); + + valueTable.setWidget(rowIndex, 1, deleteButton); + + valueTable.getCellFormatter().setStyleName(rowIndex, 0, postCoordinationStyle.scaleValueTableValueCell()); + valueTable.getCellFormatter().setStyleName(rowIndex, 1, postCoordinationStyle.scaleValueTableButtonCell()); + + valueTable.getRowFormatter().addStyleName(rowIndex, postCoordinationStyle.scaleValueRow()); + + deleteButton.addClickHandler(event -> { + deleteScaleValueButtonHandler.handleDeleteButton(value); + int row = valueTable.getCellForEvent(event).getRowIndex(); + GWT.log("Deleting row at index: " + row); + valueTable.removeRow(row); + GWT.log("Row deleted. Current row count: " + valueTable.getRowCount()); + }); + + GWT.log("New row added. Current row count: " + valueTable.getRowCount()); + } + + @Override + public void setDeleteValueButtonHandler(DeleteScaleValueButtonHandler handler) { + this.deleteScaleValueButtonHandler = handler; + } + + private void toggleTable() { + isCollapsed = !isCollapsed; + + for (int i = 1; i < valueTable.getRowCount(); i++) { + valueTable.getRowFormatter().setVisible(i, !isCollapsed); + } + + String currentHtml = headerHtml.getHTML(); + String icon = isCollapsed ? expandIcon : collapseIcon; + + if (currentHtml.contains("")) { + int spanEnd = currentHtml.indexOf("") + 7; // 7 to move past "" + + currentHtml = currentHtml.substring(spanEnd).trim(); // Extract text after the span + } + + headerHtml.setHTML("" + icon + " " + currentHtml); + } + + @Override + public void addSelectValueButton() { + int lastRow = valueTable.getRowCount(); + valueTable.setWidget(lastRow, 0, addButton); + valueTable.getFlexCellFormatter().setColSpan(lastRow, 0, 2); + valueTable.getFlexCellFormatter().addStyleName(lastRow, 0, postCoordinationStyle.scaleValueTableValueCell()); + valueTable.getRowFormatter().addStyleName(lastRow, postCoordinationStyle.scaleValueRow()); + GWT.log("Select value button added. Row count: " + valueTable.getRowCount()); + } + + @Override + public Widget asWidget() { + return rootPanel; + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardViewImpl.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardViewImpl.ui.xml new file mode 100644 index 000000000..a95dc787f --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/postcoordination/scaleValuesCard/ScaleValueCardViewImpl.ui.xml @@ -0,0 +1,13 @@ + + + + + + + + + +