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")