Skip to content

Commit

Permalink
Filtered hierarchies (#81)
Browse files Browse the repository at this point in the history
* Changes to implement hierarchy filtering

- Changed all hierarchy related actions to use hierarchy descriptors

* Changes to support named hierarchies

- Added NamedHierarchy and tests
- Added HierarchyId tests and JSON serialization
- Removed AddNamedHierarchyAction and result
- Added SetNamedHierarchiesAction and result

* Bumped version to 7.0.0-SNAPSHOT
  • Loading branch information
matthewhorridge authored Oct 28, 2024
1 parent 0915cd3 commit cf54b8b
Show file tree
Hide file tree
Showing 51 changed files with 622 additions and 593 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gwt-ui</artifactId>
<version>6.0.11</version>
<version>7.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion webprotege-gwt-ui-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gwt-ui</artifactId>
<version>6.0.11</version>
<version>7.0.0-SNAPSHOT</version>
</parent>

<artifactId>webprotege-gwt-ui-client</artifactId>
Expand Down
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
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,10 +92,15 @@ 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,
Expand All @@ -102,6 +109,8 @@ public EntityHierarchyContextMenuPresenter(@Nonnull EntityHierarchyModel model,
@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 +167,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 +178,7 @@ private void createContextMenu() {
moveToParentUiAction.setSelectionSupplier(selectionSupplier);
mergeEntitiesAction.setSelectionSupplier(selectionSupplier);
editAnnotationsUiAction.setSelectionSupplier(selectionSupplier);

updateActionStates();
}

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


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 cf54b8b

Please sign in to comment.