Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for https://github.com/who-icatx/icatx-project/issues/151 #98

Open
wants to merge 3 commits into
base: master-who
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,20 +30,15 @@ public class EntityHierarchyDropHandler implements TreeNodeDropHandler<EntityNod
@Nonnull
private final DispatchServiceManager dispatchServiceManager;

@Nonnull
private final MessageBox messageBox;

private final Messages messages;
private final MessageBoxWithReasonForChange messageBoxWithReasonForChange;

@Inject
public EntityHierarchyDropHandler(@Nonnull ProjectId projectId,
@Nonnull DispatchServiceManager dispatchServiceManager,
@Nonnull MessageBox messageBox,
@Nonnull Messages messages) {
@Nonnull MessageBoxWithReasonForChange messageBoxWithReasonForChange) {
this.projectId = checkNotNull(projectId);
this.dispatchServiceManager = checkNotNull(dispatchServiceManager);
this.messageBox = checkNotNull(messageBox);
this.messages = checkNotNull(messages);
this.messageBoxWithReasonForChange = messageBoxWithReasonForChange;
}

@Nonnull
Expand All @@ -57,7 +53,7 @@ public void start(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
public boolean isDropPossible(@Nonnull Path<EntityNode> nodePath,
@Nonnull Path<EntityNode> targetPath,
@Nonnull DropType dropType) {
if(!hierarchyDescriptor.isPresent()) {
if (!hierarchyDescriptor.isPresent()) {
return false;
}
if (nodePath.isEmpty()) {
Expand All @@ -79,7 +75,7 @@ public void handleDrop(@Nonnull Path<EntityNode> nodePath,
@Nonnull DropType dropType,
@Nonnull DropEndHandler dropEndHandler) {
GWT.log("[EntityHierarchyDropHandler] handleDrop. From: " + nodePath + " To: " + nodePath);
if(!hierarchyDescriptor.isPresent()) {
if (!hierarchyDescriptor.isPresent()) {
dropEndHandler.handleDropCancelled();
return;
}
Expand All @@ -96,19 +92,32 @@ public void handleDrop(@Nonnull Path<EntityNode> nodePath,
dropEndHandler.handleDropCancelled();
return;
}
dispatchServiceManager.execute(MoveHierarchyNodeAction.create(projectId,
hierarchyDescriptor.get(),
nodePath,
targetPath,
dropType),
moveResult -> {
if(moveResult.isMoved()) {
dropEndHandler.handleDropComplete();
}
else {
dropEndHandler.handleDropCancelled();
}
});

Optional<EntityNode> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<HTMLPanel, MessageBoxWithReasonForChangeView> {

}

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<DataResource> 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:text='urn:import:edu.stanford.bmir.protege.web.client.library.text'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>

<ui:with field="wp" type="edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle"/>

<ui:style>
.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;
}
</ui:style>


<g:HTMLPanel addStyleNames="{style.main-panel-style}">
<!-- I originally implemented this with divs but had lots of problems with the settings box sizing correctly. I
know tables aren't meant to be used for layout, but this works really nicely in this case. -->
<table>
<colgroup>
<col width="70px" valign="top"/>
<col width="*" valign="top"/>
</colgroup>
<tr>
<td valign="top">
<g:Image url="{wp.messageIcon.getSafeUri.asString}" ui:field="iconImage" width="120px"/>
</td>
<td valign="top">
<g:HTMLPanel addStyleNames="{style.message-block}">
<g:HTML ui:field="titleLabel" addStyleNames="{style.main-message-style} {wp.settings.title}"/>
<g:HTML ui:field="messageLabel" addStyleNames="{style.sub-message-style}"/>
<div class="{wp.style.formGroup}" addStyleNames="{style.padding-top}">
<g:Label text="Reason for change" addStyleNames="{wp.style.formLabel}"/>
<text:ExpandingTextBoxImpl ui:field="reasonForChangeTextBox"
mode="MULTI_LINE"
anchorVisible="false"
addStyleNames="{style.text-box}"/>
<g:Label ui:field='reasonForChangeErrorLabel' addStyleNames="{wp.style.formHelpText}"/>
</div>
</g:HTMLPanel>
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package edu.stanford.bmir.protege.web.client.library.msgbox;

public interface ReasonForChangeHandler {
void handle(String reasonForChange);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading