Skip to content

Commit

Permalink
some refactoring for edit parents pop-up
Browse files Browse the repository at this point in the history
  • Loading branch information
soimugeo committed May 23, 2024
1 parent 37ec264 commit cb921c8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -33,18 +41,42 @@ public class EditParentsPresenter {

private Optional<HierarchyId> 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()));

Expand All @@ -62,4 +94,8 @@ public EditParentsView getView() {
public void setHierarchyId(@Nonnull HierarchyId hierarchyId) {
this.hierarchyId = Optional.of(hierarchyId);
}

private void handleHierarchyChange(OWLEntity entity, Optional<List<OWLPrimitiveData>> parentsList) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,28 @@

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;

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);
}


Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,4 +25,6 @@ public interface EditParentsView extends IsWidget, HasBusy {

@Nonnull
String getReasonForChange();

Optional<List<OWLPrimitiveData>> getNewParentList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -55,11 +57,10 @@ interface EditParentsViewImplUiBinder extends UiBinder<HTMLPanel, EditParentsVie
public EditParentsViewImpl(Provider<PrimitiveDataEditor> 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);
Expand Down Expand Up @@ -127,4 +128,9 @@ public String getEntityString() {
public String getReasonForChange() {
return reasonForChangeTextBox.getText().trim();
}

@Override
public Optional<List<OWLPrimitiveData>> getNewParentList() {
return this.domains.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@
* Bio-Medical Informatics Research Group<br>
* Date: 19/12/2012
*/
public class PrimitiveDataListEditor extends ValueListFlexEditorImpl<OWLPrimitiveData> implements HasEnabled {
public class PrimitiveDataListEditor extends ValueListFlexEditorImpl<OWLPrimitiveData> implements HasEnabled {

public PrimitiveDataListEditor(Provider<PrimitiveDataEditor> 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<PrimitiveDataEditor> primitiveDataEditorProvider,
FreshEntitySuggestStrategy freshEntitySuggestStrategy,
final PrimitiveType... allowedTypes) {
super(() -> createValueEditor(primitiveDataEditorProvider, freshEntitySuggestStrategy, allowedTypes));
}

private static PrimitiveDataEditor createValueEditor(Provider<PrimitiveDataEditor> primitiveDataEditorProvider,
FreshEntitySuggestStrategy freshEntitySuggestStrategy,
final PrimitiveType... allowedTypes) {
PrimitiveDataEditor editor = primitiveDataEditorProvider.get();
editor.setAllowedTypes(Arrays.asList(allowedTypes));
editor.setFreshEntitiesSuggestStrategy(freshEntitySuggestStrategy);
return editor;
}
}

0 comments on commit cb921c8

Please sign in to comment.