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 4a0a1aec5..a6927ba3c 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 @@ -1,6 +1,11 @@ package edu.stanford.bmir.protege.web.client.hierarchy.parents; +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.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.entity.OWLPrimitiveData; import edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyParentsAction; import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId; import edu.stanford.bmir.protege.web.shared.project.ProjectId; @@ -11,9 +16,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; +import java.util.List; import java.util.Optional; import java.util.logging.Logger; +import static com.google.common.base.Preconditions.checkNotNull; + public class EditParentsPresenter { @Nonnull @@ -33,18 +41,42 @@ public class EditParentsPresenter { private Optional hierarchyId = Optional.empty(); + @Nonnull + private final ModalManager modalManager; + + @Nonnull + private final Messages messages; + private static final Logger logger = Logger.getLogger(EditParentsPresenter.class.getName()); @Inject public EditParentsPresenter(@Nonnull ProjectId projectId, - @Nonnull EditParentsView view, @Nonnull DispatchServiceManager dispatch) { - this.projectId = projectId; - this.view = view; - this.dispatch = dispatch; + @Nonnull EditParentsView view, + @Nonnull DispatchServiceManager dispatch, + @Nonnull ModalManager modalManager, + @Nonnull Messages messages) { + this.projectId = checkNotNull(projectId); + this.view = checkNotNull(view); + this.dispatch = checkNotNull(dispatch); + this.modalManager = checkNotNull(modalManager); + this.messages = checkNotNull(messages); } public void start(@Nonnull OWLEntity entity) { + view.clear(); + ModalPresenter modalPresenter = modalManager.createPresenter(); + modalPresenter.setTitle(messages.hierarchy_editParents()); + modalPresenter.setView(view); this.entity = entity; + modalPresenter.setEscapeButton(DialogButton.CANCEL); + modalPresenter.setPrimaryButton(DialogButton.OK); + modalPresenter.setButtonHandler(DialogButton.OK, closer -> { + if (view.isReasonForChangeSet()) { + handleHierarchyChange(entity, view.getNewParentList()); + closer.closeModal(); + } + }); + modalManager.showModal(modalPresenter); dispatch.execute(GetEntityRenderingAction.create(projectId, entity), result -> view.setOwlEntityData(result.getEntityData())); @@ -62,4 +94,8 @@ public EditParentsView getView() { public void setHierarchyId(@Nonnull HierarchyId hierarchyId) { this.hierarchyId = Optional.of(hierarchyId); } + + private void handleHierarchyChange(OWLEntity entity, Optional> parentsList) { + + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsUiAction.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsUiAction.java index 4e5daf9a2..42e51d1ec 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsUiAction.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/hierarchy/parents/EditParentsUiAction.java @@ -2,9 +2,6 @@ import edu.stanford.bmir.protege.web.client.Messages; import edu.stanford.bmir.protege.web.client.action.AbstractUiAction; -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.client.selection.SelectionModel; import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId; import org.semanticweb.owlapi.model.OWLEntity; @@ -12,27 +9,21 @@ import javax.annotation.Nonnull; import javax.inject.Inject; +import static com.google.common.base.Preconditions.checkNotNull; + public class EditParentsUiAction extends AbstractUiAction { @Nonnull private final EditParentsPresenter editParentsPresenter; - @Nonnull - private final Messages messages; - @Nonnull private final SelectionModel selectionModel; - @Nonnull - private final ModalManager modalManager; - @Inject - protected EditParentsUiAction(@Nonnull EditParentsPresenter editParentsPresenter, @Nonnull Messages messages, @Nonnull SelectionModel selectionModel, @Nonnull ModalManager modalManager) { + protected EditParentsUiAction(@Nonnull EditParentsPresenter editParentsPresenter, @Nonnull Messages messages, @Nonnull SelectionModel selectionModel) { super(messages.hierarchy_editParents()); - this.editParentsPresenter = editParentsPresenter; - this.messages = messages; - this.selectionModel = selectionModel; - this.modalManager = modalManager; + this.editParentsPresenter = checkNotNull(editParentsPresenter); + this.selectionModel = checkNotNull(selectionModel); } @@ -42,16 +33,7 @@ public void execute() { } private void showDialog(OWLEntity entity) { - ModalPresenter modalPresenter = modalManager.createPresenter(); - modalPresenter.setTitle(messages.hierarchy_editParents()); - modalPresenter.setView(editParentsPresenter.getView()); editParentsPresenter.setHierarchyId(HierarchyId.CLASS_HIERARCHY); editParentsPresenter.start(entity); - modalPresenter.setEscapeButton(DialogButton.CANCEL); - modalPresenter.setPrimaryButton(DialogButton.OK); - modalPresenter.setButtonHandler(DialogButton.OK, closer -> { - closer.closeModal(); - }); - modalManager.showModal(modalPresenter); } } 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 82c1e8054..435ef0ab2 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 @@ -3,8 +3,11 @@ import com.google.gwt.user.client.ui.IsWidget; import edu.stanford.bmir.protege.web.client.progress.HasBusy; import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData; +import edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData; import javax.annotation.Nonnull; +import java.util.List; +import java.util.Optional; import java.util.Set; public interface EditParentsView extends IsWidget, HasBusy { @@ -22,4 +25,6 @@ public interface EditParentsView extends IsWidget, HasBusy { @Nonnull String getReasonForChange(); + + Optional> getNewParentList(); } 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 7c82d5d01..323673a26 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 @@ -7,8 +7,8 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Label; import edu.stanford.bmir.protege.web.client.Messages; -import edu.stanford.bmir.protege.web.client.editor.ValueListEditor; import edu.stanford.bmir.protege.web.client.library.text.ExpandingTextBoxImpl; +import edu.stanford.bmir.protege.web.client.primitive.NullFreshEntitySuggestStrategy; import edu.stanford.bmir.protege.web.client.primitive.PrimitiveDataEditor; import edu.stanford.bmir.protege.web.client.primitive.PrimitiveDataListEditor; import edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle; @@ -20,6 +20,8 @@ import javax.inject.Inject; import javax.inject.Provider; import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -55,11 +57,10 @@ interface EditParentsViewImplUiBinder extends UiBinder primitiveDataEditorProvider, @Nonnull Messages messages) { this.messages = messages; - domains = new PrimitiveDataListEditor(primitiveDataEditorProvider, PrimitiveType.CLASS); + domains = new PrimitiveDataListEditor(primitiveDataEditorProvider, new NullFreshEntitySuggestStrategy(), PrimitiveType.CLASS); initWidget(ourUiBinder.createAndBindUi(this)); domains.setPlaceholder(messages.frame_enterAClassName()); domains.setValue(new ArrayList<>()); - domains.setNewRowMode(ValueListEditor.NewRowMode.AUTOMATIC); domains.setEnabled(true); // domains.setValue(Collections.singletonList(entityData)); textBox.setEnabled(false); @@ -127,4 +128,9 @@ public String getEntityString() { public String getReasonForChange() { return reasonForChangeTextBox.getText().trim(); } + + @Override + public Optional> getNewParentList() { + return this.domains.getValue(); + } } diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/primitive/PrimitiveDataListEditor.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/primitive/PrimitiveDataListEditor.java index f84419e29..b101db730 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/primitive/PrimitiveDataListEditor.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/primitive/PrimitiveDataListEditor.java @@ -14,15 +14,25 @@ * Bio-Medical Informatics Research Group
* Date: 19/12/2012 */ -public class PrimitiveDataListEditor extends ValueListFlexEditorImpl implements HasEnabled { +public class PrimitiveDataListEditor extends ValueListFlexEditorImpl implements HasEnabled { public PrimitiveDataListEditor(Provider primitiveDataEditorProvider, - final PrimitiveType ... allowedTypes) { - super(() -> { - PrimitiveDataEditor editor = primitiveDataEditorProvider.get(); - editor.setAllowedTypes(Arrays.asList(allowedTypes)); - editor.setFreshEntitiesSuggestStrategy(new SimpleFreshEntitySuggestStrategy()); - return editor; - }); + final PrimitiveType... allowedTypes) { + super(() -> createValueEditor(primitiveDataEditorProvider, new SimpleFreshEntitySuggestStrategy(), allowedTypes)); + } + + public PrimitiveDataListEditor(Provider primitiveDataEditorProvider, + FreshEntitySuggestStrategy freshEntitySuggestStrategy, + final PrimitiveType... allowedTypes) { + super(() -> createValueEditor(primitiveDataEditorProvider, freshEntitySuggestStrategy, allowedTypes)); + } + + private static PrimitiveDataEditor createValueEditor(Provider primitiveDataEditorProvider, + FreshEntitySuggestStrategy freshEntitySuggestStrategy, + final PrimitiveType... allowedTypes) { + PrimitiveDataEditor editor = primitiveDataEditorProvider.get(); + editor.setAllowedTypes(Arrays.asList(allowedTypes)); + editor.setFreshEntitiesSuggestStrategy(freshEntitySuggestStrategy); + return editor; } }