From aa0d55a143fb160d4558ba71f5c64f25ea34e5e2 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Wed, 7 Aug 2024 16:22:13 +0300 Subject: [PATCH] added linearization parent --- .../inject/ClientApplicationModule.java | 10 +- .../LinearizationParentLabel.java | 44 +++++--- .../LinearizationParentModal.java | 31 +++++- .../linearization/LinearizationParentTree.css | 9 ++ .../LinearizationParentView.java | 16 +++ .../LinearizationParentViewImpl.java | 97 +++++++++++++++++ .../LinearizationParentViewImpl.ui.xml | 17 +++ .../LinearizationParentsResourceBundle.java | 22 ++++ .../LinearizationPortletViewImpl.java | 31 +++++- .../linearization/LinearizationTable.css | 4 + .../LinearizationTableResourceBundle.java | 2 + .../linearization/LinearizationTableRow.java | 100 +++++++++++++----- .../protege/web/shared/dispatch/Action.java | 2 + .../protege/web/shared/dispatch/Result.java | 2 + .../web/shared/dispatch/RpcWhiteList.java | 6 ++ .../shared/icd/AncestorClassHierarchy.java | 25 +++++ .../shared/icd/GetClassAncestorsAction.java | 26 +++++ .../shared/icd/GetClassAncestorsResult.java | 24 +++++ 18 files changed, 414 insertions(+), 54 deletions(-) create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentTree.css create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentView.java create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.java create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.ui.xml create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentsResourceBundle.java create mode 100644 webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/AncestorClassHierarchy.java create mode 100644 webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsAction.java create mode 100644 webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsResult.java diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/inject/ClientApplicationModule.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/inject/ClientApplicationModule.java index 6d6b40413..d9781de63 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/inject/ClientApplicationModule.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/inject/ClientApplicationModule.java @@ -65,10 +65,7 @@ import edu.stanford.bmir.protege.web.client.library.modal.ModalViewImpl; import edu.stanford.bmir.protege.web.client.library.msgbox.InputBoxView; import edu.stanford.bmir.protege.web.client.library.msgbox.InputBoxViewImpl; -import edu.stanford.bmir.protege.web.client.linearization.LinearizationCommentsView; -import edu.stanford.bmir.protege.web.client.linearization.LinearizationCommentsViewImpl; -import edu.stanford.bmir.protege.web.client.linearization.LinearizationPortletView; -import edu.stanford.bmir.protege.web.client.linearization.LinearizationPortletViewImpl; +import edu.stanford.bmir.protege.web.client.linearization.*; import edu.stanford.bmir.protege.web.client.login.LoginView; import edu.stanford.bmir.protege.web.client.login.LoginViewImpl; import edu.stanford.bmir.protege.web.client.login.SignInRequestHandler; @@ -496,6 +493,11 @@ EntityTagsSelectorView provideEntityTagsSelectorView(EntityTagsSelectorViewImpl EditorPortletView provideEditorPortletView(EditorPortletViewImpl impl) { return impl; } + @Provides + LinearizationParentView provideLinearizationParentView(LinearizationParentViewImpl impl) { + return impl; + } + @Provides LinearizationPortletView provideLinearizationPortletView(LinearizationPortletViewImpl impl) { diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentLabel.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentLabel.java index eed4c974d..0f6846091 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentLabel.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentLabel.java @@ -5,53 +5,69 @@ import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; +import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; +import edu.stanford.bmir.protege.web.shared.project.ProjectId; +import org.semanticweb.owlapi.model.IRI; import java.util.logging.Logger; public class LinearizationParentLabel implements ClickHandler { - private Label label; private LinearizationParentModal linearizationParentModal; + private IRI selectedEntityIri; + + + private ProjectId projectId; + + private ParentSelectedHandler selectedHandler; + + private boolean readOnly = true; + // Constructor - public LinearizationParentLabel(String text, LinearizationParentModal linearizationParentModal) { + public LinearizationParentLabel(String text, LinearizationParentModal linearizationParentModal, IRI entityIri, ProjectId projectId, ParentSelectedHandler parentSelectedHandler) { label = new Label(text); + label.addStyleName(LinearizationTableResourceBundle.INSTANCE.style().getLinearizationParentCell()); this.linearizationParentModal = linearizationParentModal; label.addClickHandler(this); // Register this class as the ClickHandler for the Label + this.selectedEntityIri = entityIri; + this.projectId = projectId; + this.selectedHandler = parentSelectedHandler; } - // Method to set the text of the label public void setText(String text) { label.setText(text); } - // Method to get the text of the label public String getText() { return label.getText(); } - // Method to set the style of the label - public void setStyleName(String style) { - label.setStyleName(style); - } - - // Method to get the underlying widget public Widget asWidget() { return label; } - // Implement the onClick method from ClickHandler interface + + public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + } + @Override public void onClick(ClickEvent event) { - // Handle the click event here - // For example, you can change the label's text on click - this.linearizationParentModal.showModal(); + if(!readOnly) { + this.linearizationParentModal.showModal(selectedEntityIri, projectId, selectedHandler); + } } // Method to add external ClickHandlers public HandlerRegistration addClickHandler(ClickHandler handler) { return label.addClickHandler(handler); } + + + public interface ParentSelectedHandler { + void handleParentSelected(OWLEntityData selectedParent); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentModal.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentModal.java index 5423fc6ae..d68bf87e6 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentModal.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentModal.java @@ -1,6 +1,12 @@ package edu.stanford.bmir.protege.web.client.linearization; +import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager; +import edu.stanford.bmir.protege.web.client.library.dlg.DialogButton; import edu.stanford.bmir.protege.web.client.library.modal.ModalManager; +import edu.stanford.bmir.protege.web.client.library.modal.ModalPresenter; +import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsAction; +import edu.stanford.bmir.protege.web.shared.project.ProjectId; +import org.semanticweb.owlapi.model.IRI; import javax.annotation.Nonnull; @@ -12,16 +18,35 @@ public class LinearizationParentModal { @Nonnull private final ModalManager modalManager; + + private final DispatchServiceManager dispatchServiceManager; + + Logger logger = java.util.logging.Logger.getLogger("LinearizationParentModal"); @Inject - public LinearizationParentModal(@Nonnull ModalManager modalManager) { + public LinearizationParentModal(@Nonnull ModalManager modalManager, DispatchServiceManager dispatchServiceManager) { this.modalManager = modalManager; + this.dispatchServiceManager = dispatchServiceManager; } - public void showModal() { - + public void showModal(IRI selectedEntityIri, ProjectId projectId, LinearizationParentLabel.ParentSelectedHandler parentSelectedHandler) { + dispatchServiceManager.execute(GetClassAncestorsAction.create(selectedEntityIri, projectId), getHierarchyParentsResult -> { + ModalPresenter presenter = modalManager.createPresenter(); + LinearizationParentView view = new LinearizationParentViewImpl(getHierarchyParentsResult.getAncestorsTree()); + presenter.setTitle("Set linearization parent"); + presenter.setView(view); + presenter.setEscapeButton(DialogButton.CANCEL); + presenter.setPrimaryButton(DialogButton.OK); + presenter.setButtonHandler(DialogButton.OK, closer -> { + parentSelectedHandler.handleParentSelected(view.getSelectedParent()); + presenter.closeModal(); + }); + modalManager.showModal(presenter); + }); } + + } \ No newline at end of file diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentTree.css b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentTree.css new file mode 100644 index 000000000..2ebd1e092 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentTree.css @@ -0,0 +1,9 @@ +.linearizationParentLabel tr { + width : 100%; + cursor: pointer; +} + +.parentSelected { + background-color: rgb(17, 108, 214); + color: white; +} \ No newline at end of file diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentView.java new file mode 100644 index 000000000..de59eea39 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentView.java @@ -0,0 +1,16 @@ +package edu.stanford.bmir.protege.web.client.linearization; + +import com.google.gwt.user.client.ui.IsWidget; +import edu.stanford.bmir.protege.web.shared.HasDispose; +import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; +import edu.stanford.bmir.protege.web.shared.icd.AncestorClassHierarchy; + +import java.util.List; +import java.util.Set; + +public interface LinearizationParentView extends IsWidget, HasDispose { + + void setAncestorsTree(AncestorClassHierarchy ancestorTree); + + OWLEntityData getSelectedParent(); +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.java new file mode 100644 index 000000000..7ab14a28f --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.java @@ -0,0 +1,97 @@ +package edu.stanford.bmir.protege.web.client.linearization; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.logical.shared.OpenEvent; +import com.google.gwt.event.logical.shared.OpenHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.*; +import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; +import edu.stanford.bmir.protege.web.shared.icd.AncestorClassHierarchy; +import com.google.gwt.user.client.ui.TreeItem; + +import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; + +public class LinearizationParentViewImpl extends Composite implements LinearizationParentView { + + Logger logger = java.util.logging.Logger.getLogger("LinearizationParentViewImpl"); + + @UiField + Tree tree; + + private OWLEntityData selectedEntity; + LinearizationParentsResourceBundle.LinearizationParentCss style = LinearizationParentsResourceBundle.INSTANCE.style(); + + public LinearizationParentViewImpl(AncestorClassHierarchy ancestorsTree) { + style.ensureInjected(); + initWidget(ourUiBinder.createAndBindUi(this)); + + String browserText = ancestorsTree.getCurrentNode().getBrowserText(); + browserText = browserText != null && !browserText.isEmpty() ? browserText : " "; + TreeItem root = new TreeItem(new Label(browserText)); + addTreeItems(root, ancestorsTree.getChildren()); + root.setState(true); + tree.addItem(root); + tree.setAnimationEnabled(true); + + tree.addSelectionHandler(event -> { + Iterator iter = tree.treeItemIterator(); + while(iter.hasNext()) { + TreeItem item = iter.next(); + if(event.getSelectedItem().equals(item)) { + item.getWidget().addStyleName(style.getParentSelected()); + } else { + item.getWidget().removeStyleName(style.getParentSelected()); + } + } + }); + + } + + + @Override + public void setAncestorsTree(AncestorClassHierarchy ancestorsTree) { + + + } + + @Override + public OWLEntityData getSelectedParent() { + return selectedEntity; + } + + + private void addTreeItems(TreeItem parentItem, List nodes) { + for (AncestorClassHierarchy node : nodes) { + String browserText = node.getCurrentNode().getBrowserText(); + browserText = browserText != null && !browserText.isEmpty() ? browserText : " "; + Label label = new Label(browserText); + + TreeItem treeItem = new TreeItem(label); + treeItem.setStyleName(style.getLinearizationParentLabel()); + label.addClickHandler(event -> { + selectedEntity = node.getCurrentNode(); + tree.setSelectedItem(treeItem); + }); + parentItem.addItem(treeItem); + + if (node.getChildren() != null) { + addTreeItems(treeItem, node.getChildren()); + } + treeItem.setState(true); + + } + } + @Override + public void dispose() { + tree.clear(); + } + + interface LinearizationParentViewImpllUiBinder extends UiBinder { + + } + private static LinearizationParentViewImpllUiBinder ourUiBinder = GWT.create(LinearizationParentViewImpllUiBinder.class); + +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.ui.xml new file mode 100644 index 000000000..db40da4bd --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentViewImpl.ui.xml @@ -0,0 +1,17 @@ + + + + .gwt-Tree { + } + + .gwt-TreeItem-selected { + background-color: #ebeff9; + } + + + + + + + \ No newline at end of file diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentsResourceBundle.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentsResourceBundle.java new file mode 100644 index 000000000..99306aed8 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationParentsResourceBundle.java @@ -0,0 +1,22 @@ +package edu.stanford.bmir.protege.web.client.linearization; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.CssResource; + +public interface LinearizationParentsResourceBundle extends ClientBundle { + + LinearizationParentsResourceBundle INSTANCE = GWT.create(LinearizationParentsResourceBundle.class); + + @Source("LinearizationParentTree.css") + LinearizationParentCss style(); + + + interface LinearizationParentCss extends CssResource { + + @ClassName("linearizationParentLabel") + String getLinearizationParentLabel(); + @ClassName("parentSelected") + String getParentSelected(); + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationPortletViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationPortletViewImpl.java index 5c68ece20..f8b6c9037 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationPortletViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationPortletViewImpl.java @@ -10,8 +10,10 @@ import edu.stanford.bmir.protege.web.client.form.complexcheckbox.ThreeStateCheckbox; import edu.stanford.bmir.protege.web.client.library.text.PlaceholderTextBox; import edu.stanford.bmir.protege.web.shared.entity.EntityNode; +import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; import edu.stanford.bmir.protege.web.shared.linearization.*; import edu.stanford.bmir.protege.web.shared.project.ProjectId; +import org.semanticweb.owlapi.model.IRI; import javax.inject.Inject; import java.util.*; @@ -73,8 +75,21 @@ public class LinearizationPortletViewImpl extends Composite implements Lineariza private ProjectId projectId; + private IRI entityIri; + boolean isReadOnly = true; + private final TableRefresh tableRefresh = (owlEntity) -> { + flexTable.removeAllRows(); + for(LinearizationTableRow row : tableRowList) { + row.populateDerivedLinearizationParents(this.tableRowList); + } + initializeTableHeader(); + + orderAndPopulateViewWithRows(); + }; + + @Inject public LinearizationPortletViewImpl(DispatchServiceManager dispatch, LinearizationCommentsModal commentsModal, @@ -127,10 +142,11 @@ public void setWhoFicEntity(WhoficEntityLinearizationSpecification specification try { this.specification = specification; flexTable.setStyleName(style.getLinearizationTable()); - initializeTableHeader(); if(specification != null){ + this.entityIri = specification.getEntityIRI(); + initializeTableRows(); if(specification.getLinearizationResiduals() != null) { this.suppressOthersSpecifiedResidual.setValue(specification.getLinearizationResiduals().getSuppressedOtherSpecifiedResiduals()); @@ -304,15 +320,22 @@ private void initializeTableRows() { linearizationSpecification, parentsMap, linearizationParentModal, - commentsModal); + commentsModal, + entityIri, + projectId, + tableRefresh); tableRowList.add(row); } for(LinearizationTableRow row : tableRowList) { - row.refreshParents(tableRowList); + row.populateDerivedLinearizationParents(tableRowList); } - } + } + + interface TableRefresh { + void refreshTable(OWLEntityData newParent); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTable.css b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTable.css index 1fba166fe..c985a5ba8 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTable.css +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTable.css @@ -65,6 +65,10 @@ } +.linearizationParentCell { + cursor: pointer; +} + .secondaryParent { color : #A8A8A8; } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableResourceBundle.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableResourceBundle.java index a283c75ae..e085ccb5d 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableResourceBundle.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableResourceBundle.java @@ -40,6 +40,8 @@ interface LinearizationCss extends CssResource { @ClassName("linearizationDefinition") String getLinearizationDefinition(); + @ClassName("linearizationParentCell") + String getLinearizationParentCell(); } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableRow.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableRow.java index abe520d9d..72075994c 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableRow.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/linearization/LinearizationTableRow.java @@ -5,8 +5,11 @@ import com.google.gwt.user.client.ui.Widget; import edu.stanford.bmir.protege.web.client.form.complexcheckbox.ThreeStateCheckbox; import edu.stanford.bmir.protege.web.shared.entity.EntityNode; +import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; import edu.stanford.bmir.protege.web.shared.linearization.LinearizationDefinition; import edu.stanford.bmir.protege.web.shared.linearization.LinearizationSpecification; +import edu.stanford.bmir.protege.web.shared.project.ProjectId; +import org.semanticweb.owlapi.model.IRI; import java.util.List; import java.util.Map; @@ -40,8 +43,17 @@ public class LinearizationTableRow { private LinearizationParentModal parentModal; + private LinearizationCommentsModal linearizationCommentsModal; + private ProjectId projectId; + private IRI entityIri; + + private String parentIri; + LinearizationParentLabel.ParentSelectedHandler parentSelectedHandler = this::handleParentSelected; + LinearizationPortletViewImpl.TableRefresh tableRefresh; + private LinearizationParentLabel linearizationParentLabel; + private LinearizationTableRow(){ } @@ -50,9 +62,15 @@ public LinearizationTableRow(Map definitionMap, LinearizationSpecification linearizationSpecification, Map parentsMap, LinearizationParentModal modal, - LinearizationCommentsModal commentsModal) { + LinearizationCommentsModal commentsModal, + IRI entityIri, + ProjectId projectId, + LinearizationPortletViewImpl.TableRefresh tableRefresh) { try { this.parentsMap = parentsMap; + this.projectId = projectId; + this.entityIri = entityIri; + this.tableRefresh = tableRefresh; this.linearizationCommentsModal = commentsModal; this.linearizationDefinition = definitionMap.get(linearizationSpecification.getLinearizationView()); @@ -71,41 +89,42 @@ public LinearizationTableRow(Map definitionMap, this.codingNotes = this.commentsWidget.asWidget(); this.parentModal = modal; - }catch (Exception e) { + populateEditableLinearizationParent(); + + + } catch (Exception e) { logger.info("Error while initializing table row " + e); } } - public void refreshParents(List rows) { - - boolean isDerived = linearizationDefinition.getCoreLinId() != null && !linearizationDefinition.getCoreLinId().isEmpty(); - EntityNode linearizationParentEntityNode; - if (isDerived) { - - String actualParentId = rows.stream() - .filter(linearizationRow -> linearizationRow.linearizationDefinition.getId().equalsIgnoreCase(this.linearizationDefinition.getCoreLinId())) - .findFirst() - .map(linearizationTableRow -> linearizationTableRow.linearizationSpecification.getLinearizationParent()) - .orElse(""); - - linearizationParentEntityNode = this.parentsMap.get(actualParentId); - } else { - linearizationParentEntityNode = this.parentsMap.get(linearizationSpecification.getLinearizationParent()); + private void populateEditableLinearizationParent() { + if(!isDerived()) { + EntityNode linearizationParentEntityNode = this.parentsMap.get(linearizationSpecification.getLinearizationParent()); + String browserText = linearizationParentEntityNode != null ? linearizationParentEntityNode.getBrowserText() : linearizationSpecification.getLinearizationParent(); + this.linearizationParentLabel = new LinearizationParentLabel(browserText, + parentModal, + entityIri, + projectId, + parentSelectedHandler); + this.linearizationParent = linearizationParentLabel.asWidget(); + this.parentIri = this.linearizationSpecification.getLinearizationParent(); } + } - if (linearizationParentEntityNode != null && linearizationParentEntityNode.getBrowserText() != null && !linearizationParentEntityNode.getBrowserText().isEmpty()) { - if(isDerived) { - Label label = new Label("[" + linearizationParentEntityNode.getBrowserText() + "]"); - label.addStyleName(LinearizationTableResourceBundle.INSTANCE.style().getSecondaryParent()); - this.linearizationParent = label; - } else { - this.linearizationParent = new LinearizationParentLabel(linearizationParentEntityNode.getBrowserText(), parentModal).asWidget(); - } - } else { - this.linearizationParent = new LinearizationParentLabel(linearizationSpecification.getLinearizationParent(), parentModal).asWidget(); + public void populateDerivedLinearizationParents(List rows){ + if(isDerived()) { + LinearizationTableRow mainRow = rows.stream() + .filter(linearizationRow -> linearizationRow.linearizationDefinition.getId().equalsIgnoreCase(this.linearizationDefinition.getCoreLinId())) + .findFirst() + .orElseThrow(() -> { + logger.info("Couldn't find parent with id " + linearizationDefinition.getCoreLinId()); + return new RuntimeException(); + }); + Label label = new Label("[" + mainRow.linearizationParent.getElement().getInnerText() + "]"); + label.addStyleName(LinearizationTableResourceBundle.INSTANCE.style().getSecondaryParent()); + this.linearizationParent = label; } - } public void setEnabled() { @@ -120,8 +139,13 @@ public void setEnabled() { this.isAuxAxChildCheckbox.setReadOnly(false); this.commentsWidget.enable(); + if(linearizationParentLabel != null) { + linearizationParentLabel.setReadOnly(false); + } } + + public void setReadOnly() { this.isPartOfCheckbox.setEnabled(false); this.isPartOfCheckbox.setReadOnly(true); @@ -134,6 +158,9 @@ public void setReadOnly() { this.isAuxAxChildCheckbox.setReadOnly(true); this.commentsWidget.disable(); + if(linearizationParentLabel != null) { + linearizationParentLabel.setReadOnly(true); + } } @@ -142,7 +169,7 @@ public LinearizationSpecification asLinearizationSpecification(){ return new LinearizationSpecification(this.isAuxAxChildCheckbox.getValue().getValue(), this.isGroupingCheckbox.getValue().getValue(), this.isPartOfCheckbox.getValue().getValue(), - this.linearizationSpecification.getLinearizationParent(), + this.parentIri, this.linearizationDefinition.getSortingCode(), this.linearizationDefinition.getWhoficEntityIri(), this.commentsWidget.getText() @@ -181,6 +208,7 @@ public LinearizationTableRow clone(){ LinearizationTableRow clone = new LinearizationTableRow(); clone.linearizationSpecification = linearizationSpecification; clone.linearizationParent = new Label(this.linearizationParent.getElement().getInnerText()); + clone.parentIri = this.parentIri; clone.linearizationDefinition = this.linearizationDefinition; clone.linearizationDefinitionWidget = new Label(linearizationDefinition.getDisplayLabel()); clone.isPartOfCheckbox = new ThreeStateCheckbox(new LinearizationCheckboxConfig(), linearizationSpecification.getIsIncludedInLinearization()); @@ -202,4 +230,18 @@ private void initCodingNotes(String value) { this.commentsWidget = new LinearizationComments(DEFAULT_COMMENTS_MESSAGE, linearizationCommentsModal); } } + + private void handleParentSelected(OWLEntityData owlEntityData) { + this.linearizationParent = new LinearizationParentLabel(owlEntityData.getBrowserText(), + parentModal, + entityIri, + projectId, + parentSelectedHandler).asWidget(); + this.parentIri = owlEntityData.getEntity().getIRI().toString(); + tableRefresh.refreshTable(owlEntityData); + } + + private boolean isDerived(){ + return linearizationDefinition.getCoreLinId() != null && !linearizationDefinition.getCoreLinId().isEmpty(); + } } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java index e87a76aa3..69d8ea1ac 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java @@ -23,6 +23,7 @@ import edu.stanford.bmir.protege.web.shared.form.*; import edu.stanford.bmir.protege.web.shared.frame.*; import edu.stanford.bmir.protege.web.shared.hierarchy.*; +import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsAction; import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsAction; import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsPageContainingIndividualAction; import edu.stanford.bmir.protege.web.shared.issues.*; @@ -227,6 +228,7 @@ @Type(value = TranslateEventListAction.class), @Type(value = GetLinearizationDefinitionsAction.class), @Type(value = GetEntityLinearizationAction.class), + @Type(value = GetClassAncestorsAction.class), @Type(value = SaveEntityLinearizationAction.class), @Type(value = GetRenderedOwlEntitiesAction.class) }) diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java index 2cad65ed5..c2631f78f 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java @@ -52,6 +52,7 @@ import edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyRootsResult; import edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchySiblingsResult; import edu.stanford.bmir.protege.web.shared.hierarchy.MoveHierarchyNodeResult; +import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsResult; import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsPageContainingIndividualResult; import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsResult; import edu.stanford.bmir.protege.web.shared.issues.AddEntityCommentResult; @@ -298,6 +299,7 @@ @JsonSubTypes.Type(GetEntityLinearizationResult.class), @JsonSubTypes.Type(GetUserInfoResult.class), @JsonSubTypes.Type(SaveEntityLinearizationResult.class), + @JsonSubTypes.Type(GetClassAncestorsResult.class), @JsonSubTypes.Type(GetRenderedOwlEntitiesResult.class) }) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java index 6eaae5376..d4f0aba6b 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java @@ -30,6 +30,8 @@ import edu.stanford.bmir.protege.web.shared.form.field.*; import edu.stanford.bmir.protege.web.shared.frame.*; import edu.stanford.bmir.protege.web.shared.hierarchy.*; +import edu.stanford.bmir.protege.web.shared.icd.AncestorClassHierarchy; +import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsResult; import edu.stanford.bmir.protege.web.shared.individuals.*; import edu.stanford.bmir.protege.web.shared.issues.*; import edu.stanford.bmir.protege.web.shared.itemlist.*; @@ -1014,6 +1016,10 @@ public class RpcWhiteList implements IsSerializable, Action, Result { SaveEntityLinearizationResult _SaveEntityLinearizationResult; GetRenderedOwlEntitiesResult _GetRenderedOwlEntitiesResult; + + GetClassAncestorsResult _GetClassAncestorsResult; + + AncestorClassHierarchy _AncestorClassHierarchy; public RpcWhiteList() { } } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/AncestorClassHierarchy.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/AncestorClassHierarchy.java new file mode 100644 index 000000000..c82b168be --- /dev/null +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/AncestorClassHierarchy.java @@ -0,0 +1,25 @@ +package edu.stanford.bmir.protege.web.shared.icd; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; +import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; + +import javax.annotation.Nullable; +import java.util.List; + + +@AutoValue +@GwtCompatible(serializable = true) +public abstract class AncestorClassHierarchy { + + @JsonCreator + public static AncestorClassHierarchy create(@JsonProperty("currentNode") OWLEntityData owlClass, @JsonProperty("children") @Nullable List children) { + return new AutoValue_AncestorClassHierarchy(owlClass, children); + } + + public abstract OWLEntityData getCurrentNode(); + + public abstract List getChildren(); +} diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsAction.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsAction.java new file mode 100644 index 000000000..beb27769e --- /dev/null +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsAction.java @@ -0,0 +1,26 @@ +package edu.stanford.bmir.protege.web.shared.icd; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; +import edu.stanford.bmir.protege.web.shared.dispatch.Action; +import edu.stanford.bmir.protege.web.shared.project.ProjectId; +import org.semanticweb.owlapi.model.IRI; + +@AutoValue +@GwtCompatible(serializable = true) +@JsonTypeName("webprotege.entities.GetClassAncestors") +public abstract class GetClassAncestorsAction implements Action { + + private IRI classIri; + + private ProjectId projectId; + @JsonCreator + public static GetClassAncestorsAction create(IRI classIri, ProjectId projectId) { + return new AutoValue_GetClassAncestorsAction(classIri, projectId); + } + + public abstract IRI getClassIri(); + public abstract ProjectId getProjectId(); +} diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsResult.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsResult.java new file mode 100644 index 000000000..27f72dfff --- /dev/null +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsResult.java @@ -0,0 +1,24 @@ +package edu.stanford.bmir.protege.web.shared.icd; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; +import edu.stanford.bmir.protege.web.shared.dispatch.Result; + + +import java.util.List; + + +@AutoValue +@GwtCompatible(serializable = true) +@JsonTypeName("webprotege.entities.GetClassAncestors") +public abstract class GetClassAncestorsResult implements Result { + public abstract AncestorClassHierarchy getAncestorsTree(); + + @JsonCreator + public static GetClassAncestorsResult create(@JsonProperty("ancestorTree") AncestorClassHierarchy ancestorTree ) { + return new AutoValue_GetClassAncestorsResult(ancestorTree); + } +}