From 7298fdb37273c05cb0353ad658af2f975f807d80 Mon Sep 17 00:00:00 2001 From: soimugeowb Date: Tue, 14 Jan 2025 20:14:03 +0200 Subject: [PATCH 1/3] fix for https://github.com/who-icatx/icatx-project/issues/151 --- .../hierarchy/EntityHierarchyDropHandler.java | 63 ++++++++------ .../msgbox/MessageBoxWithReasonForChange.java | 84 ++++++++++++++++++ .../MessageBoxWithReasonForChangeView.java | 85 +++++++++++++++++++ .../MessageBoxWithReasonForChangeView.ui.xml | 74 ++++++++++++++++ .../msgbox/ReasonForChangeHandler.java | 5 ++ .../hierarchy/ChangeEntityParentsAction.java | 6 +- .../hierarchy/ChangeEntityParentsResult.java | 6 +- 7 files changed, 286 insertions(+), 37 deletions(-) create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChange.java create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.java create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.ui.xml create mode 100644 webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/ReasonForChangeHandler.java diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/EntityHierarchyDropHandler.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/EntityHierarchyDropHandler.java index 7181dedfb..16bb66551 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/EntityHierarchyDropHandler.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/EntityHierarchyDropHandler.java @@ -1,15 +1,16 @@ package edu.stanford.bmir.protege.web.client.hierarchy; import com.google.gwt.core.client.GWT; -import edu.stanford.bmir.protege.web.client.Messages; import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager; -import edu.stanford.bmir.protege.web.client.library.msgbox.*; +import edu.stanford.bmir.protege.web.client.library.dlg.DialogButton; +import edu.stanford.bmir.protege.web.client.library.msgbox.MessageBoxWithReasonForChange; import edu.stanford.bmir.protege.web.shared.entity.EntityNode; -import edu.stanford.bmir.protege.web.shared.hierarchy.*; import edu.stanford.bmir.protege.web.shared.hierarchy.MoveHierarchyNodeAction; +import edu.stanford.bmir.protege.web.shared.issues.CreateEntityDiscussionThreadAction; import edu.stanford.bmir.protege.web.shared.project.ProjectId; import edu.stanford.protege.gwt.graphtree.client.TreeNodeDropHandler; -import edu.stanford.protege.gwt.graphtree.shared.*; +import edu.stanford.protege.gwt.graphtree.shared.DropType; +import edu.stanford.protege.gwt.graphtree.shared.Path; import org.semanticweb.owlapi.model.OWLObject; import javax.annotation.Nonnull; @@ -29,20 +30,15 @@ public class EntityHierarchyDropHandler implements TreeNodeDropHandler nodePath, @Nonnull Path targetPath, @Nonnull DropType dropType) { - if(!hierarchyDescriptor.isPresent()) { + if (!hierarchyDescriptor.isPresent()) { return false; } if (nodePath.isEmpty()) { @@ -79,7 +75,7 @@ public void handleDrop(@Nonnull Path nodePath, @Nonnull DropType dropType, @Nonnull DropEndHandler dropEndHandler) { GWT.log("[EntityHierarchyDropHandler] handleDrop. From: " + nodePath + " To: " + nodePath); - if(!hierarchyDescriptor.isPresent()) { + if (!hierarchyDescriptor.isPresent()) { dropEndHandler.handleDropCancelled(); return; } @@ -96,19 +92,32 @@ public void handleDrop(@Nonnull Path nodePath, dropEndHandler.handleDropCancelled(); return; } - dispatchServiceManager.execute(MoveHierarchyNodeAction.create(projectId, - hierarchyDescriptor.get(), - nodePath, - targetPath, - dropType), - moveResult -> { - if(moveResult.isMoved()) { - dropEndHandler.handleDropComplete(); - } - else { - dropEndHandler.handleDropCancelled(); - } - }); + + Optional parentEntityOptional = targetPath.getLast(); + String parentEntityBrowserText = parentEntityOptional.map(EntityNode::getBrowserText).orElse(""); + messageBoxWithReasonForChange.showConfirmBoxWithReasonForChange("Move entities?", + "You are about to move selected entities to new parent " + parentEntityBrowserText + ". Are you sure?", + DialogButton.CANCEL, + dropEndHandler::handleDropCancelled, + DialogButton.YES, + (reasonForChangeText) -> dispatchServiceManager.execute(MoveHierarchyNodeAction.create(projectId, + hierarchyDescriptor.get(), + nodePath, + targetPath, + dropType), + moveResult -> { + if (moveResult.isMoved()) { + dropEndHandler.handleDropComplete(); + dispatchServiceManager.execute( + CreateEntityDiscussionThreadAction.create(projectId, nodePath.getLast().get().getEntity(), reasonForChangeText), + threadActionResult -> { + }); + } else { + dropEndHandler.handleDropCancelled(); + } + }) + ); + } @Override diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChange.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChange.java new file mode 100644 index 000000000..d9c90e2fa --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChange.java @@ -0,0 +1,84 @@ +package edu.stanford.bmir.protege.web.client.library.msgbox; + +import edu.stanford.bmir.protege.web.client.Messages; +import edu.stanford.bmir.protege.web.client.library.dlg.DialogButton; +import edu.stanford.bmir.protege.web.client.library.modal.ModalCloser; +import edu.stanford.bmir.protege.web.client.library.modal.ModalManager; +import edu.stanford.bmir.protege.web.client.library.modal.ModalPresenter; + +import javax.annotation.Nonnull; +import javax.inject.Inject; + +import static com.google.common.base.Preconditions.checkNotNull; + + +public class MessageBoxWithReasonForChange { + + private static final Void RETURN = null; + + private static final String DLG_TITLE = ""; + + private static final String DEFAULT_SUB_MESSAGE = ""; + + @Nonnull + private final ModalManager modalManager; + + private final Messages messages; + + @Inject + public MessageBoxWithReasonForChange(@Nonnull ModalManager modalManager, Messages messages) { + this.modalManager = checkNotNull(modalManager); + this.messages = messages; + } + + private MessageBoxWithReasonForChangeView createMessageBox(MessageStyle messageStyle, String mainMessage, String subMessage) { + final MessageBoxWithReasonForChangeView messageBoxView = new MessageBoxWithReasonForChangeView(messages); + messageBoxView.setMainMessage(mainMessage); + messageBoxView.setSubMessage(subMessage); + messageBoxView.setMessageStyle(messageStyle); + return messageBoxView; + } + + public void showConfirmBoxWithReasonForChange(String mainMessage, String subMessage, DialogButton acceptButton, + DialogButton cancelButton, ReasonForChangeHandler acceptHandler) { + MessageBoxWithReasonForChangeView view = createMessageBox(MessageStyle.QUESTION, mainMessage, subMessage); + + ModalPresenter presenter = modalManager.createPresenter(); + presenter.setView(view); + presenter.setPrimaryButton(acceptButton); + presenter.setEscapeButton(cancelButton); + + presenter.setButtonHandler(acceptButton, closer -> { + if (view.isReasonForChangeSet()) { + closer.closeModal(); + acceptHandler.handle(view.getReasonForChangeString()); + } + }); + + presenter.setButtonHandler(cancelButton, ModalCloser::closeModal); + + modalManager.showModal(presenter); + } + + public void showConfirmBoxWithReasonForChange(String mainMessage, String subMessage, + DialogButton escapeButton, Runnable escapeHandler, DialogButton acceptButton, + ReasonForChangeHandler acceptHandler) { + MessageBoxWithReasonForChangeView view = createMessageBox(MessageStyle.QUESTION, mainMessage, subMessage); + ModalPresenter presenter = modalManager.createPresenter(); + presenter.setView(view); + presenter.setPrimaryButton(acceptButton); + presenter.setEscapeButton(escapeButton); + presenter.setPrimaryButtonFocusedOnShow(true); + presenter.setButtonHandler(escapeButton, closer -> { + closer.closeModal(); + escapeHandler.run(); + }); + presenter.setButtonHandler(acceptButton, closer -> { + if (view.isReasonForChangeSet()) { + closer.closeModal(); + acceptHandler.handle(view.getReasonForChangeString()); + } + }); + modalManager.showModal(presenter); + } +} diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.java new file mode 100644 index 000000000..ee0215dc9 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.java @@ -0,0 +1,85 @@ +package edu.stanford.bmir.protege.web.client.library.msgbox; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.DataResource; +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.client.Messages; +import edu.stanford.bmir.protege.web.client.library.text.ExpandingTextBoxImpl; +import edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle; + +import java.util.Optional; + + +public class MessageBoxWithReasonForChangeView extends Composite implements MessageBoxView { + + interface MessageBoxViewImplUiBinder extends UiBinder { + + } + + private static MessageBoxViewImplUiBinder ourUiBinder = GWT.create(MessageBoxViewImplUiBinder.class); + + @UiField + protected HasHTML titleLabel; + + @UiField + protected HasHTML messageLabel; + + @UiField + protected Image iconImage; + + @UiField + ExpandingTextBoxImpl reasonForChangeTextBox; + + @UiField + Label reasonForChangeErrorLabel; + + private final Messages messages; + + public MessageBoxWithReasonForChangeView(Messages messages) { + this.messages = messages; + HTMLPanel rootElement = ourUiBinder.createAndBindUi(this); + initWidget(rootElement); + } + + public void setMessageStyle(MessageStyle messageStyle) { + Optional res = messageStyle.getImage(); + res.ifPresent(dataResource -> { + iconImage.getElement().getStyle().setOpacity(1); + iconImage.setUrl(dataResource.getSafeUri().asString()); + }); + if(!res.isPresent()) { + iconImage.getElement().getStyle().setOpacity(0); + } + } + + @Override + public void setMainMessage(String title) { + titleLabel.setHTML(title); + } + + @Override + public void setSubMessage(String message) { + messageLabel.setHTML(message); + } + + public boolean isReasonForChangeSet() { + if (reasonForChangeTextBox.getText().trim().isEmpty()) { + reasonForChangeErrorLabel.setText(messages.reasonForChangeError()); + reasonForChangeErrorLabel.addStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel()); + return false; + } + clearErrors(); + return true; + } + + public void clearErrors() { + reasonForChangeErrorLabel.setText(""); + reasonForChangeErrorLabel.removeStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel()); + } + + public String getReasonForChangeString(){ + return reasonForChangeTextBox.getText().trim(); + } +} \ No newline at end of file diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.ui.xml new file mode 100644 index 000000000..015aff0d5 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/MessageBoxWithReasonForChangeView.ui.xml @@ -0,0 +1,74 @@ + + + + + + .main-panel-style { + width: 100%; + max-width: 800px; + box-sizing: border-box; + overflow: hidden; + } + .message-block { + width: 100%; + padding-left: 10px; + padding-top: 20px; + box-sizing: border-box; + } + .main-message-style { + padding-bottom: 5px; + word-wrap: break-word; + word-break: break-word; + white-space: normal; + } + .sub-message-style { + font-size: 14px; + padding-top: 5px; + word-wrap: break-word; + word-break: break-word; + white-space: normal; + } + .text-box { + width: 100%; + max-width: 100%; + height: auto; + box-sizing: border-box; + } + .padding-top { + padding-top: 5px; + } + + + + + + + + + + + + + + +
+ + + + + +
+ + + +
+
+
+
+
diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/ReasonForChangeHandler.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/ReasonForChangeHandler.java new file mode 100644 index 000000000..2b8a69e67 --- /dev/null +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/library/msgbox/ReasonForChangeHandler.java @@ -0,0 +1,5 @@ +package edu.stanford.bmir.protege.web.client.library.msgbox; + +public interface ReasonForChangeHandler { + void handle(String reasonForChange); +} diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsAction.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsAction.java index fea0ab40f..b6c930198 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsAction.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsAction.java @@ -14,11 +14,7 @@ import javax.annotation.Nonnull; -/** - * Matthew Horridge - * Stanford Center for Biomedical Informatics Research - * 25 Sep 2018 - */ + @AutoValue @GwtCompatible(serializable = true) @JsonTypeName("webprotege.entities.ChangeEntityParents") diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java index f9ec343f1..94eb6f4ec 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java @@ -11,11 +11,7 @@ import javax.annotation.Nonnull; import java.util.Set; -/** - * Matthew Horridge - * Stanford Center for Biomedical Informatics Research - * 25 Sep 2018 - */ + @AutoValue @GwtCompatible(serializable = true) @JsonTypeName("webprotege.entities.ChangeEntityParents") From 983c5e9925e7a0a1be768dfe0136c9bb159e8a8f Mon Sep 17 00:00:00 2001 From: soimugeowb Date: Wed, 15 Jan 2025 13:29:46 +0200 Subject: [PATCH 2/3] interim fix for https://github.com/who-icatx/icatx-project/issues/111 refactored ChangeEntityParentsResult to include the linearizationPathParent check --- .../bmir/protege/web/client/Messages.java | 6 ++++ .../parents/EditParentsPresenter.java | 33 ++++++++----------- .../hierarchy/parents/EditParentsView.java | 8 +++-- .../parents/EditParentsViewImpl.java | 28 ++++++++++++---- .../parents/EditParentsViewImpl.ui.xml | 3 ++ .../hierarchy/ChangeEntityParentsResult.java | 29 ++++++++++++++-- 6 files changed, 77 insertions(+), 30 deletions(-) diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java index 3550bfa3a..53e095e25 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java @@ -1251,6 +1251,12 @@ public interface Messages extends com.google.gwt.i18n.client.Messages { "Please correct this in order to save changes") SafeHtml classHierarchy_parentsHaveRetiredAncestors(String classesWithRetiredParents); + @DefaultMessage("A Linearization Path Parent cannot be removed
" + + "Following parent is a linearization path parent: {0}

" + + "
" + + "Please change the linearization path parent before removing the parent") + SafeHtml classHierarchy_removeParentThatIsLinearizationPathParent(String linearizationPathParent); + @DefaultMessage("A released class cannot be moved to a retired parent!") String classHierarchy_cannotMoveReleasedClassToRetiredParent(); diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java index cefd66347..3f4653066 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java @@ -10,7 +10,6 @@ import edu.stanford.bmir.protege.web.client.library.modal.ModalPresenter; import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; import edu.stanford.bmir.protege.web.shared.hierarchy.ChangeEntityParentsAction; -import edu.stanford.bmir.protege.web.shared.hierarchy.ChangeEntityParentsResult; import edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyParentsAction; import edu.stanford.bmir.protege.web.shared.issues.CreateEntityDiscussionThreadAction; import edu.stanford.bmir.protege.web.shared.project.ProjectId; @@ -99,39 +98,33 @@ private void handleHierarchyChange(ModalCloser closer) { .collect(toImmutableSet()); dispatch.execute(ChangeEntityParentsAction.create(projectId, parentsSet, entity.asOWLClass(), view.getReasonForChange()), changeEntityParentsResult -> { - if (isResultValid(changeEntityParentsResult)) { - view.clearClassesWithCycle(); - view.clearClassesWithRetiredParents(); + if (changeEntityParentsResult.isSuccess()) { + view.clearClassesWithCycleErrors(); + view.clearClassesWithRetiredParentsErrors(); dispatch.execute( CreateEntityDiscussionThreadAction.create(projectId, entity, view.getReasonForChange()), threadActionResult -> closer.closeModal()); return; } - if(hasClassesWithRetiredParents(changeEntityParentsResult)){ - view.clearClassesWithRetiredParents(); + if(changeEntityParentsResult.hasClassesWithRetiredParents()){ + view.clearClassesWithRetiredParentsErrors(); Set classesWithRetiredParents = changeEntityParentsResult.getClassesWithRetiredParents(); view.markClassesWithRetiredParents(classesWithRetiredParents); } - if(hasClassesWithCycles(changeEntityParentsResult)){ - view.clearClassesWithCycle(); + if(changeEntityParentsResult.hasClassesWithCycle()){ + view.clearClassesWithCycleErrors(); Set classesWithCycles = changeEntityParentsResult.getClassesWithCycle(); view.markClassesWithCycles(classesWithCycles); } + + if(changeEntityParentsResult.hasLinearizationPathParent()){ + view.clearLinearizationPathParentErrors(); + OWLEntityData linearizationPathParent = changeEntityParentsResult.getLinearizationPathParent().get(); + view.markLinearizationPathParent(linearizationPathParent); + } }); } } - - private boolean isResultValid(ChangeEntityParentsResult changeEntityParentsResult) { - return !hasClassesWithCycles(changeEntityParentsResult) && !hasClassesWithRetiredParents(changeEntityParentsResult); - } - - private boolean hasClassesWithCycles(ChangeEntityParentsResult changeEntityParentsResult) { - return !changeEntityParentsResult.getClassesWithCycle().isEmpty(); - } - - private boolean hasClassesWithRetiredParents(ChangeEntityParentsResult changeEntityParentsResult) { - return !changeEntityParentsResult.getClassesWithRetiredParents().isEmpty(); - } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java index d7cc26abd..034e41845 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java @@ -24,11 +24,15 @@ public interface EditParentsView extends IsWidget, HasBusy { List getNewParentList(); - void clearClassesWithCycle(); + void clearClassesWithCycleErrors(); void markClassesWithCycles(Set classesWithCycles); - void clearClassesWithRetiredParents(); + void clearClassesWithRetiredParentsErrors(); void markClassesWithRetiredParents(Set classesWithRetiredParents); + + void clearLinearizationPathParentErrors(); + + void markLinearizationPathParent(OWLEntityData classesWithRetiredParents); } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java index 029793e4b..9a66e3a4b 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java @@ -49,6 +49,9 @@ public class EditParentsViewImpl extends Composite implements EditParentsView { @UiField HTML classesWithRetiredParentsField; + @UiField + HTML linearizationPathParentField; + private static final Logger logger = Logger.getLogger(EditParentsViewImpl.class.getName()); interface EditParentsViewImplUiBinder extends UiBinder { @@ -100,11 +103,11 @@ public boolean isReasonForChangeSet() { reasonForChangeErrorLabel.addStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel()); return false; } - clearErrors(); + clearReasonForChangeErrors(); return true; } - public void clearErrors() { + public void clearReasonForChangeErrors() { reasonForChangeErrorLabel.setText(""); reasonForChangeErrorLabel.removeStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel()); } @@ -114,8 +117,9 @@ public void clearErrors() { public void clear() { textBox.setText(""); reasonForChangeTextBox.setText(""); - clearErrors(); - clearClassesWithCycle(); + clearReasonForChangeErrors(); + clearClassesWithCycleErrors(); + clearLinearizationPathParentErrors(); } @Nonnull @@ -130,7 +134,7 @@ public List getNewParentList() { } @Override - public void clearClassesWithCycle() { + public void clearClassesWithCycleErrors() { classesWithCyclesWarningField.setVisible(false); classesWithCyclesWarningField.setHTML(""); } @@ -143,7 +147,7 @@ public void markClassesWithCycles(Set classesWithCycles) { } @Override - public void clearClassesWithRetiredParents() { + public void clearClassesWithRetiredParentsErrors() { classesWithRetiredParentsField.setVisible(false); classesWithRetiredParentsField.setHTML(""); } @@ -154,4 +158,16 @@ public void markClassesWithRetiredParents(Set classesWithRetiredP classesWithCyclesWarningField.setHTML(messages.classHierarchy_parentsHaveRetiredAncestors(classes)); classesWithCyclesWarningField.setVisible(true); } + + @Override + public void clearLinearizationPathParentErrors() { + linearizationPathParentField.setVisible(false); + linearizationPathParentField.setHTML(""); + } + + @Override + public void markLinearizationPathParent(OWLEntityData linearizationPathParent) { + linearizationPathParentField.setHTML(messages.classHierarchy_removeParentThatIsLinearizationPathParent(linearizationPathParent.getBrowserText())); + linearizationPathParentField.setVisible(true); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml index d025b4bf3..1381ed12f 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml @@ -32,6 +32,9 @@ + \ No newline at end of file diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java index 94eb6f4ec..dfbe8f0be 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java @@ -9,6 +9,7 @@ import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; import javax.annotation.Nonnull; +import java.util.Optional; import java.util.Set; @@ -20,8 +21,9 @@ public abstract class ChangeEntityParentsResult implements Result { @JsonCreator public static ChangeEntityParentsResult create(@JsonProperty("classesWithCycle") @Nonnull Set classesWithCycle, - @JsonProperty("classesWithRetiredParents") @Nonnull Set classesWithRetiredParents) { - return new AutoValue_ChangeEntityParentsResult(classesWithCycle, classesWithRetiredParents); + @JsonProperty("classesWithRetiredParents") @Nonnull Set classesWithRetiredParents, + @JsonProperty("linearizationPathParent") Optional linearizationPathParent ) { + return new AutoValue_ChangeEntityParentsResult(classesWithCycle, classesWithRetiredParents, linearizationPathParent); } @JsonProperty("classesWithCycle") @@ -32,4 +34,27 @@ public static ChangeEntityParentsResult create(@JsonProperty("classesWithCycle") @Nonnull public abstract Set getClassesWithRetiredParents(); + @JsonProperty("linearizationPathParent") + @Nonnull + public abstract Optional getLinearizationPathParent(); + + public boolean hasClassesWithCycle(){ + return !getClassesWithCycle().isEmpty(); + } + + public boolean hasClassesWithRetiredParents(){ + return !getClassesWithRetiredParents().isEmpty(); + } + + public boolean hasLinearizationPathParent(){ + return getLinearizationPathParent().isPresent(); + } + + public boolean isFailure(){ + return hasClassesWithRetiredParents()||hasClassesWithCycle()||hasLinearizationPathParent(); + } + + public boolean isSuccess(){ + return !isFailure(); + } } From e94baf9510125057a19840ab777620181dd0836d Mon Sep 17 00:00:00 2001 From: soimugeo Date: Fri, 17 Jan 2025 10:00:34 +0200 Subject: [PATCH 3/3] Revert "interim fix for https://github.com/who-icatx/icatx-project/issues/111 refactored ChangeEntityParentsResult to include the linearizationPathParent check" This reverts commit 983c5e9925e7a0a1be768dfe0136c9bb159e8a8f. --- .../bmir/protege/web/client/Messages.java | 6 ---- .../parents/EditParentsPresenter.java | 33 +++++++++++-------- .../hierarchy/parents/EditParentsView.java | 8 ++--- .../parents/EditParentsViewImpl.java | 28 ++++------------ .../parents/EditParentsViewImpl.ui.xml | 3 -- .../hierarchy/ChangeEntityParentsResult.java | 29 ++-------------- 6 files changed, 30 insertions(+), 77 deletions(-) diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java index 53e095e25..3550bfa3a 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/Messages.java @@ -1251,12 +1251,6 @@ public interface Messages extends com.google.gwt.i18n.client.Messages { "Please correct this in order to save changes") SafeHtml classHierarchy_parentsHaveRetiredAncestors(String classesWithRetiredParents); - @DefaultMessage("A Linearization Path Parent cannot be removed
" + - "Following parent is a linearization path parent: {0}

" + - "
" + - "Please change the linearization path parent before removing the parent") - SafeHtml classHierarchy_removeParentThatIsLinearizationPathParent(String linearizationPathParent); - @DefaultMessage("A released class cannot be moved to a retired parent!") String classHierarchy_cannotMoveReleasedClassToRetiredParent(); diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java index 3f4653066..cefd66347 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsPresenter.java @@ -10,6 +10,7 @@ import edu.stanford.bmir.protege.web.client.library.modal.ModalPresenter; import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; import edu.stanford.bmir.protege.web.shared.hierarchy.ChangeEntityParentsAction; +import edu.stanford.bmir.protege.web.shared.hierarchy.ChangeEntityParentsResult; import edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyParentsAction; import edu.stanford.bmir.protege.web.shared.issues.CreateEntityDiscussionThreadAction; import edu.stanford.bmir.protege.web.shared.project.ProjectId; @@ -98,33 +99,39 @@ private void handleHierarchyChange(ModalCloser closer) { .collect(toImmutableSet()); dispatch.execute(ChangeEntityParentsAction.create(projectId, parentsSet, entity.asOWLClass(), view.getReasonForChange()), changeEntityParentsResult -> { - if (changeEntityParentsResult.isSuccess()) { - view.clearClassesWithCycleErrors(); - view.clearClassesWithRetiredParentsErrors(); + if (isResultValid(changeEntityParentsResult)) { + view.clearClassesWithCycle(); + view.clearClassesWithRetiredParents(); dispatch.execute( CreateEntityDiscussionThreadAction.create(projectId, entity, view.getReasonForChange()), threadActionResult -> closer.closeModal()); return; } - if(changeEntityParentsResult.hasClassesWithRetiredParents()){ - view.clearClassesWithRetiredParentsErrors(); + if(hasClassesWithRetiredParents(changeEntityParentsResult)){ + view.clearClassesWithRetiredParents(); Set classesWithRetiredParents = changeEntityParentsResult.getClassesWithRetiredParents(); view.markClassesWithRetiredParents(classesWithRetiredParents); } - if(changeEntityParentsResult.hasClassesWithCycle()){ - view.clearClassesWithCycleErrors(); + if(hasClassesWithCycles(changeEntityParentsResult)){ + view.clearClassesWithCycle(); Set classesWithCycles = changeEntityParentsResult.getClassesWithCycle(); view.markClassesWithCycles(classesWithCycles); } - - if(changeEntityParentsResult.hasLinearizationPathParent()){ - view.clearLinearizationPathParentErrors(); - OWLEntityData linearizationPathParent = changeEntityParentsResult.getLinearizationPathParent().get(); - view.markLinearizationPathParent(linearizationPathParent); - } }); } } + + private boolean isResultValid(ChangeEntityParentsResult changeEntityParentsResult) { + return !hasClassesWithCycles(changeEntityParentsResult) && !hasClassesWithRetiredParents(changeEntityParentsResult); + } + + private boolean hasClassesWithCycles(ChangeEntityParentsResult changeEntityParentsResult) { + return !changeEntityParentsResult.getClassesWithCycle().isEmpty(); + } + + private boolean hasClassesWithRetiredParents(ChangeEntityParentsResult changeEntityParentsResult) { + return !changeEntityParentsResult.getClassesWithRetiredParents().isEmpty(); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java index 034e41845..d7cc26abd 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsView.java @@ -24,15 +24,11 @@ public interface EditParentsView extends IsWidget, HasBusy { List getNewParentList(); - void clearClassesWithCycleErrors(); + void clearClassesWithCycle(); void markClassesWithCycles(Set classesWithCycles); - void clearClassesWithRetiredParentsErrors(); + void clearClassesWithRetiredParents(); void markClassesWithRetiredParents(Set classesWithRetiredParents); - - void clearLinearizationPathParentErrors(); - - void markLinearizationPathParent(OWLEntityData classesWithRetiredParents); } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java index 9a66e3a4b..029793e4b 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.java @@ -49,9 +49,6 @@ public class EditParentsViewImpl extends Composite implements EditParentsView { @UiField HTML classesWithRetiredParentsField; - @UiField - HTML linearizationPathParentField; - private static final Logger logger = Logger.getLogger(EditParentsViewImpl.class.getName()); interface EditParentsViewImplUiBinder extends UiBinder { @@ -103,11 +100,11 @@ public boolean isReasonForChangeSet() { reasonForChangeErrorLabel.addStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel()); return false; } - clearReasonForChangeErrors(); + clearErrors(); return true; } - public void clearReasonForChangeErrors() { + public void clearErrors() { reasonForChangeErrorLabel.setText(""); reasonForChangeErrorLabel.removeStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel()); } @@ -117,9 +114,8 @@ public void clearReasonForChangeErrors() { public void clear() { textBox.setText(""); reasonForChangeTextBox.setText(""); - clearReasonForChangeErrors(); - clearClassesWithCycleErrors(); - clearLinearizationPathParentErrors(); + clearErrors(); + clearClassesWithCycle(); } @Nonnull @@ -134,7 +130,7 @@ public List getNewParentList() { } @Override - public void clearClassesWithCycleErrors() { + public void clearClassesWithCycle() { classesWithCyclesWarningField.setVisible(false); classesWithCyclesWarningField.setHTML(""); } @@ -147,7 +143,7 @@ public void markClassesWithCycles(Set classesWithCycles) { } @Override - public void clearClassesWithRetiredParentsErrors() { + public void clearClassesWithRetiredParents() { classesWithRetiredParentsField.setVisible(false); classesWithRetiredParentsField.setHTML(""); } @@ -158,16 +154,4 @@ public void markClassesWithRetiredParents(Set classesWithRetiredP classesWithCyclesWarningField.setHTML(messages.classHierarchy_parentsHaveRetiredAncestors(classes)); classesWithCyclesWarningField.setVisible(true); } - - @Override - public void clearLinearizationPathParentErrors() { - linearizationPathParentField.setVisible(false); - linearizationPathParentField.setHTML(""); - } - - @Override - public void markLinearizationPathParent(OWLEntityData linearizationPathParent) { - linearizationPathParentField.setHTML(messages.classHierarchy_removeParentThatIsLinearizationPathParent(linearizationPathParent.getBrowserText())); - linearizationPathParentField.setVisible(true); - } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml index 1381ed12f..d025b4bf3 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsViewImpl.ui.xml @@ -32,9 +32,6 @@ - \ No newline at end of file diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java index dfbe8f0be..94eb6f4ec 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/hierarchy/ChangeEntityParentsResult.java @@ -9,7 +9,6 @@ import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; import javax.annotation.Nonnull; -import java.util.Optional; import java.util.Set; @@ -21,9 +20,8 @@ public abstract class ChangeEntityParentsResult implements Result { @JsonCreator public static ChangeEntityParentsResult create(@JsonProperty("classesWithCycle") @Nonnull Set classesWithCycle, - @JsonProperty("classesWithRetiredParents") @Nonnull Set classesWithRetiredParents, - @JsonProperty("linearizationPathParent") Optional linearizationPathParent ) { - return new AutoValue_ChangeEntityParentsResult(classesWithCycle, classesWithRetiredParents, linearizationPathParent); + @JsonProperty("classesWithRetiredParents") @Nonnull Set classesWithRetiredParents) { + return new AutoValue_ChangeEntityParentsResult(classesWithCycle, classesWithRetiredParents); } @JsonProperty("classesWithCycle") @@ -34,27 +32,4 @@ public static ChangeEntityParentsResult create(@JsonProperty("classesWithCycle") @Nonnull public abstract Set getClassesWithRetiredParents(); - @JsonProperty("linearizationPathParent") - @Nonnull - public abstract Optional getLinearizationPathParent(); - - public boolean hasClassesWithCycle(){ - return !getClassesWithCycle().isEmpty(); - } - - public boolean hasClassesWithRetiredParents(){ - return !getClassesWithRetiredParents().isEmpty(); - } - - public boolean hasLinearizationPathParent(){ - return getLinearizationPathParent().isPresent(); - } - - public boolean isFailure(){ - return hasClassesWithRetiredParents()||hasClassesWithCycle()||hasLinearizationPathParent(); - } - - public boolean isSuccess(){ - return !isFailure(); - } }