Skip to content

Commit

Permalink
Changes to implement hierarchy filtering
Browse files Browse the repository at this point in the history
- Changed all hierarchy related actions to use hierarchy descriptors
  • Loading branch information
matthewhorridge committed Oct 15, 2024
1 parent 0915cd3 commit aa0e0d0
Show file tree
Hide file tree
Showing 42 changed files with 531 additions and 573 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ public interface Messages extends com.google.gwt.i18n.client.Messages {
@Key("hierarchy.objectproperties")
String hierarchy_objectproperties();


@DefaultMessage("Configure hierarchy...")
@Key("hierarchy.configure")
String hierarchy_configure();


@DefaultMessage("History")
@Key("history")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.google.common.collect.ImmutableSet;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyDescriptor;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyFieldPresenter;
import edu.stanford.bmir.protege.web.shared.HasBrowserText;
import edu.stanford.bmir.protege.web.shared.bulkop.MoveEntitiesToParentAction;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.event.WebProtegeEventBus;
import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import org.semanticweb.owlapi.model.EntityType;
import org.semanticweb.owlapi.model.OWLClass;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void displayErrorMessage() {

}

public void setHierarchyId(@Nonnull HierarchyId hierarchyId) {
hierarchyFieldPresenter.setHierarchyId(hierarchyId);
public void setHierarchyDescriptor(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
hierarchyFieldPresenter.setHierarchyDescriptor(hierarchyDescriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableSet;
import edu.stanford.bmir.protege.web.client.action.AbstractUiAction;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyDescriptor;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId;
import org.semanticweb.owlapi.model.EntityType;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void execute() {
workflow.start();
}

public void setHierarchyId(@Nonnull HierarchyId hierarchyId) {
parentPresenter.setHierarchyId(hierarchyId);
public void setHierarchyDescriptor(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
parentPresenter.setHierarchyDescriptor(hierarchyDescriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.stanford.bmir.protege.web.client.Messages;
import edu.stanford.bmir.protege.web.client.bulkop.BulkEditOperationPresenter;
import edu.stanford.bmir.protege.web.client.bulkop.BulkOpMessageFormatter;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyDescriptor;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyFieldPresenter;
import edu.stanford.bmir.protege.web.shared.HasBrowserText;
import edu.stanford.bmir.protege.web.shared.dispatch.Action;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void displayErrorMessage() {

}

public void setHierarchyId(@Nonnull HierarchyId hierarchyId) {
hierarchyFieldPresenter.setHierarchyId(hierarchyId);
public void setHierarchyDescriptor(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
hierarchyFieldPresenter.setHierarchyDescriptor(hierarchyDescriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import edu.stanford.bmir.protege.web.client.action.AbstractUiAction;
import edu.stanford.bmir.protege.web.client.bulkop.BulkEditOperationWorkflow;
import edu.stanford.bmir.protege.web.client.bulkop.BulkEditOperationWorkflowFactory;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyDescriptor;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -44,8 +44,8 @@ public void setSelectionSupplier(@Nonnull Supplier<ImmutableSet<OWLEntityData>>
this.selectionSupplier = checkNotNull(selectionSupplier);
}

public void setHierarchyId(@Nonnull HierarchyId hierarchyId) {
presenter.setHierarchyId(hierarchyId);
public void setHierarchyDescriptor(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
presenter.setHierarchyDescriptor(hierarchyDescriptor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ public void startPortlet(@Nonnull PortletUi portletUi,

actionStatePresenter.start(eventBus);

hierarchyModel.start(eventBus, CLASS_HIERARCHY);
hierarchyModel.start(eventBus, ClassHierarchyDescriptor.get());
renderer.setDisplayLanguage(displayNameSettingsManager.getLocalDisplayNameSettings());
treeWidget.setRenderer(renderer);
treeWidget.setModel(GraphTreeNodeModel.create(hierarchyModel,
node -> node.getEntity()));
treeWidget.setDropHandler(this.dropHandler);
dropHandler.start(CLASS_HIERARCHY);
dropHandler.start(ClassHierarchyDescriptor.get());
contextMenuPresenterFactory.create(hierarchyModel,
treeWidget,
createClassAction,
deleteClassAction)
deleteClassAction,
getProjectId())
.install();

tagVisibilityPresenter.start(filterView, treeWidget);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package edu.stanford.bmir.protege.web.client.hierarchy;

import com.google.auto.factory.AutoFactory;
import com.google.auto.factory.Provided;
import com.google.gwt.user.client.Window;
import edu.stanford.bmir.protege.web.client.Messages;
import edu.stanford.bmir.protege.web.client.action.AbstractUiAction;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.shared.dispatch.DispatchService;
import edu.stanford.bmir.protege.web.shared.entity.EntityNode;
import edu.stanford.bmir.protege.web.shared.hierarchy.AddNamedHierarchyAction;
import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId;
import edu.stanford.bmir.protege.web.shared.inject.ProjectSingleton;
import edu.stanford.bmir.protege.web.shared.lang.LanguageMap;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import edu.stanford.protege.gwt.graphtree.client.TreeWidget;
import edu.stanford.protege.gwt.graphtree.shared.tree.impl.GraphTreeNodeModel;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLEntity;

import javax.inject.Inject;
import java.util.Set;
import java.util.stream.Collectors;

@AutoFactory
public class ConfigureHierarchyAction extends AbstractUiAction {

private final TreeWidget<EntityNode, OWLEntity> treeWidget;

private final EntityHierarchyModel model;

private final DispatchServiceManager dispatch;

private final ProjectId projectId;

public ConfigureHierarchyAction(@Provided Messages messages,
TreeWidget<EntityNode, OWLEntity> treeWidget,
EntityHierarchyModel model,
@Provided DispatchServiceManager dispatch,
@Provided ProjectId projectId) {
super(messages.hierarchy_configure());
this.treeWidget = treeWidget;
this.model = model;
this.dispatch = dispatch;
this.projectId = projectId;
}

@Override
public void execute() {
Set<OWLClass> sel = treeWidget.getSelectedKeys()
.stream()
.filter(e -> e.isOWLClass())
.map(e -> e.asOWLClass())
.collect(Collectors.toSet());
HierarchyDescriptor hierarchyDescriptor;
if(sel.isEmpty()) {
hierarchyDescriptor = ClassHierarchyDescriptor.get();
}
else {
hierarchyDescriptor = ClassHierarchyDescriptor.get(sel);
}
dispatch.execute(AddNamedHierarchyAction.get(projectId, LanguageMap.of("en", "Class hierarchy fragment"),
LanguageMap.empty(),
hierarchyDescriptor),
result -> {
model.setHierarchyDescriptor(hierarchyDescriptor);
treeWidget.setModel(GraphTreeNodeModel.create(model, EntityNode::getEntity));
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import edu.stanford.bmir.protege.web.client.bulkop.EditAnnotationsUiAction;
import edu.stanford.bmir.protege.web.client.bulkop.MoveToParentUiAction;
import edu.stanford.bmir.protege.web.client.bulkop.SetAnnotationValueUiAction;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.entity.MergeEntitiesUiAction;
import edu.stanford.bmir.protege.web.client.library.msgbox.InputBox;
import edu.stanford.bmir.protege.web.client.library.popupmenu.PopupMenu;
Expand All @@ -18,6 +19,7 @@
import edu.stanford.bmir.protege.web.client.watches.WatchUiAction;
import edu.stanford.bmir.protege.web.shared.entity.EntityNode;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import edu.stanford.protege.gwt.graphtree.client.TreeWidget;
import edu.stanford.protege.gwt.graphtree.shared.tree.TreeNode;
import edu.stanford.protege.gwt.graphtree.shared.tree.impl.GraphTreeNodeModel;
Expand Down Expand Up @@ -90,18 +92,26 @@ public class EntityHierarchyContextMenuPresenter {

private final InputBox inputBox;

private DispatchServiceManager dispatch;
private ProjectId projectId;

public EntityHierarchyContextMenuPresenter(@Nonnull EntityHierarchyModel model,
@Nonnull TreeWidget<EntityNode, OWLEntity> treeWidget,
@Nonnull UIAction createEntityAction,
@Nonnull UIAction deleteEntityAction,
@Nonnull ProjectId projectId,
@Provided @Nonnull DispatchServiceManager dispatch,
@Provided @Nonnull SetAnnotationValueUiAction setAnnotationValueUiAction,
@Provided @Nonnull MoveToParentUiAction moveToParentUiAction, @Provided @Nonnull MergeEntitiesUiAction mergeEntitiesAction,
@Provided @Nonnull EditAnnotationsUiAction editAnnotationsUiAction,
@Provided @Nonnull EditEntityTagsUiAction editEntityTagsAction,
@Provided @Nonnull ConfigureHierarchyActionFactory configureHierarchyAction,
@Provided Messages messages,
@Provided @Nonnull WatchUiAction watchUiAction,
@Provided @Nonnull LoggedInUserProjectPermissionChecker permissionChecker,
@Provided @Nonnull InputBox inputBox) {
this.projectId = projectId;
this.dispatch = dispatch;
this.setAnnotationValueUiAction = checkNotNull(setAnnotationValueUiAction);
this.moveToParentUiAction = checkNotNull(moveToParentUiAction);
this.editAnnotationsUiAction = checkNotNull(editAnnotationsUiAction);
Expand Down Expand Up @@ -158,8 +168,8 @@ private void createContextMenu() {
contextMenu.addItem(messages.refreshTree(), this::handleRefresh);

// This needs tidying somehow. We don't do this for other actions.
moveToParentUiAction.setHierarchyId(model.getHierarchyId());
mergeEntitiesAction.setHierarchyId(model.getHierarchyId());
moveToParentUiAction.setHierarchyDescriptor(model.getHierarchyDescriptor());
mergeEntitiesAction.setHierarchyDescriptor(model.getHierarchyDescriptor());
Supplier<ImmutableSet<OWLEntityData>> selectionSupplier = () ->
treeWidget.getSelectedNodes().stream()
.map(TreeNode::getUserObject)
Expand All @@ -169,6 +179,7 @@ private void createContextMenu() {
moveToParentUiAction.setSelectionSupplier(selectionSupplier);
mergeEntitiesAction.setSelectionSupplier(selectionSupplier);
editAnnotationsUiAction.setSelectionSupplier(selectionSupplier);

updateActionStates();
}

Expand Down Expand Up @@ -200,6 +211,9 @@ private void updateActionStates() {
}
}

private void configureHierarchy() {

}

private void pruneSelectedNodesToRoot() {
treeWidget.pruneToSelectedNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gwt.core.client.GWT;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.shared.entity.EntityNode;
import edu.stanford.bmir.protege.web.shared.hierarchy.HierarchyId;
import edu.stanford.bmir.protege.web.shared.hierarchy.MoveHierarchyNodeAction;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import edu.stanford.protege.gwt.graphtree.client.TreeNodeDropHandler;
Expand Down Expand Up @@ -36,18 +35,18 @@ public EntityHierarchyDropHandler(@Nonnull ProjectId projectId,
}

@Nonnull
private Optional<HierarchyId> hierarchyId = Optional.empty();
private Optional<HierarchyDescriptor> hierarchyDescriptor = Optional.empty();


public void start(@Nonnull HierarchyId hierarchyId) {
this.hierarchyId = Optional.of(hierarchyId);
public void start(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
this.hierarchyDescriptor = Optional.of(hierarchyDescriptor);
}

@Override
public boolean isDropPossible(@Nonnull Path<EntityNode> nodePath,
@Nonnull Path<EntityNode> targetPath,
@Nonnull DropType dropType) {
if(!hierarchyId.isPresent()) {
if(!hierarchyDescriptor.isPresent()) {
return false;
}
if(nodePath.isEmpty()) {
Expand All @@ -69,7 +68,7 @@ public void handleDrop(@Nonnull Path<EntityNode> nodePath,
@Nonnull DropType dropType,
@Nonnull DropEndHandler dropEndHandler) {
GWT.log("[EntityHierarchyDropHandler] handleDrop. From: " + nodePath + " To: " + nodePath);
if(!hierarchyId.isPresent()) {
if(!hierarchyDescriptor.isPresent()) {
dropEndHandler.handleDropCancelled();
return;
}
Expand All @@ -87,7 +86,7 @@ public void handleDrop(@Nonnull Path<EntityNode> nodePath,
return;
}
dispatchServiceManager.execute(MoveHierarchyNodeAction.create(projectId,
hierarchyId.get(),
hierarchyDescriptor.get(),
nodePath,
targetPath,
dropType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import com.google.gwt.user.client.Window;
import com.google.web.bindery.event.shared.HandlerRegistration;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.entity.EntityNodeUpdater;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class EntityHierarchyModel implements GraphModel<EntityNode, OWLEntity>,
private final Set<OWLEntity> rootNodes = new HashSet<>();

@Nonnull
private HierarchyId hierarchyId = CLASS_HIERARCHY;
private HierarchyDescriptor hierarchyDescriptor = ClassHierarchyDescriptor.get();

@Inject
public EntityHierarchyModel(@Nonnull DispatchServiceManager dispatchServiceManager,
Expand All @@ -57,18 +58,28 @@ public EntityHierarchyModel(@Nonnull DispatchServiceManager dispatchServiceManag
}

@Nonnull
public HierarchyId getHierarchyId() {
return hierarchyId;
public HierarchyDescriptor getHierarchyDescriptor() {
return hierarchyDescriptor;
}

public void start(@Nonnull WebProtegeEventBus eventBus, @Nonnull HierarchyId hierarchyId) {
this.hierarchyId = checkNotNull(hierarchyId);
public void setHierarchyDescriptor(@Nonnull HierarchyDescriptor hierarchyDescriptor) {
if(this.hierarchyDescriptor.equals(hierarchyDescriptor)) {
return;
}
this.hierarchyDescriptor = hierarchyDescriptor;
parent2ChildMap.clear();
rootNodes.clear();
nodeCache.clear();
}

public void start(@Nonnull WebProtegeEventBus eventBus, @Nonnull HierarchyDescriptor hierarchyDescriptor) {
this.hierarchyDescriptor = checkNotNull(hierarchyDescriptor);
hierarchyNodeUpdater.start(eventBus, this);
eventBus.addProjectEventHandler(projectId, ON_HIERARCHY_CHANGED, this::handleEntityHierarchyChanged);
}

private void handleEntityHierarchyChanged(EntityHierarchyChangedEvent event) {
if (!event.getHierarchyId().equals(hierarchyId)) {
if (!event.getHierarchyDescriptor().equals(hierarchyDescriptor)) {
return;
}
GraphModelChangeProcessor changeProcessor = new GraphModelChangeProcessor(parent2ChildMap, rootNodes);
Expand Down Expand Up @@ -100,7 +111,7 @@ public void updateNode(@Nonnull EntityNode node) {

@Override
public void getRootNodes(GetRootNodesCallback<EntityNode> callback) {
dispatchServiceManager.execute(GetHierarchyRootsAction.create(projectId, hierarchyId), result -> {
dispatchServiceManager.execute(GetHierarchyRootsAction.create(projectId, hierarchyDescriptor), result -> {
cacheRootNodes(result);
try {
dispatchServiceManager.beginBatch();
Expand All @@ -124,7 +135,7 @@ private void cacheRootNodes(GetHierarchyRootsResult result) {
@Override
public void getSuccessorNodes(@Nonnull OWLEntity parent,
@Nonnull GetSuccessorNodesCallback<EntityNode> callback) {
dispatchServiceManager.execute(GetHierarchyChildrenAction.create(projectId, parent, hierarchyId),
dispatchServiceManager.execute(GetHierarchyChildrenAction.create(projectId, parent, hierarchyDescriptor),
result -> {
cacheEdges(parent, result);
callback.handleSuccessorNodes(result.getSuccessorMap());
Expand All @@ -143,7 +154,7 @@ private void cacheEdges(@Nonnull OWLEntity parent, GetHierarchyChildrenResult re
@Override
public void getPathsFromRootNodes(@Nonnull OWLEntity node,
@Nonnull GetPathsBetweenNodesCallback<EntityNode> callback) {
dispatchServiceManager.execute(GetHierarchyPathsToRootAction.create(projectId, node, hierarchyId),
dispatchServiceManager.execute(GetHierarchyPathsToRootAction.create(projectId, node, hierarchyDescriptor),
result -> {
try {
dispatchServiceManager.beginBatch();
Expand Down
Loading

0 comments on commit aa0e0d0

Please sign in to comment.