Skip to content
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
Expand Up @@ -901,6 +901,11 @@ public interface Messages extends com.google.gwt.i18n.client.Messages {
@Key("showIri")
String showIri();


@DefaultMessage("Change IRI...")
@Key("changeEntityIri")
String changeEntityIri();


@DefaultMessage("showing")
@Key("showing")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package edu.stanford.bmir.protege.web.client.entity;

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.client.library.msgbox.InputBox;
import edu.stanford.bmir.protege.web.shared.entity.ChangeEntityIRIAction;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import org.semanticweb.owlapi.model.IRI;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.Optional;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* A UI action that lets the user change (rename) the IRI of the selected entity. It prompts for the
* new IRI, pre-filled with the entity's current IRI, and dispatches a {@link ChangeEntityIRIAction}.
* The server side is gated on the EDIT_ONTOLOGY permission.
*/
public class ChangeEntityIRIUiAction extends AbstractUiAction {

@Nonnull
private final ProjectId projectId;

@Nonnull
private final DispatchServiceManager dispatchServiceManager;

@Nonnull
private final InputBox inputBox;

@Nonnull
private final Messages messages;

@Nonnull
private Supplier<Optional<OWLEntityData>> selectionSupplier = Optional::empty;

@Nonnull
private Runnable changeHandler = () -> {};

@Inject
public ChangeEntityIRIUiAction(@Nonnull ProjectId projectId,
@Nonnull DispatchServiceManager dispatchServiceManager,
@Nonnull InputBox inputBox,
@Nonnull Messages messages) {
super(messages.changeEntityIri());
this.projectId = checkNotNull(projectId);
this.dispatchServiceManager = checkNotNull(dispatchServiceManager);
this.inputBox = checkNotNull(inputBox);
this.messages = checkNotNull(messages);
}

/**
* Sets the supplier that provides the entity whose IRI should be changed.
*/
public void setSelectionSupplier(@Nonnull Supplier<Optional<OWLEntityData>> selectionSupplier) {
this.selectionSupplier = checkNotNull(selectionSupplier);
}

/**
* Sets a handler that is run after a successful IRI change, e.g. to refresh the tree.
*/
public void setChangeHandler(@Nonnull Runnable changeHandler) {
this.changeHandler = checkNotNull(changeHandler);
}

@Override
public void execute() {
selectionSupplier.get().ifPresent(this::changeIriForEntity);
}

private void changeIriForEntity(@Nonnull OWLEntityData entityData) {
String currentIri = entityData.getEntity().getIRI().toString();
inputBox.showDialog(messages.changeEntityIri(), false, currentIri, newIriValue -> {
String trimmedIri = newIriValue.trim();
if (trimmedIri.isEmpty() || trimmedIri.equals(currentIri)) {
return;
}
dispatchServiceManager.execute(
new ChangeEntityIRIAction(projectId, entityData.getEntity(), IRI.create(trimmedIri)),
result -> changeHandler.run());
});
}
}
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.entity.ChangeEntityIRIUiAction;
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 Down Expand Up @@ -66,6 +67,9 @@ public class EntityHierarchyContextMenuPresenter {
@Nonnull
private final MergeEntitiesUiAction mergeEntitiesAction;

@Nonnull
private final ChangeEntityIRIUiAction changeEntityIriAction;

@Nonnull
private final EditEntityTagsUiAction editEntityTagsAction;

Expand Down Expand Up @@ -96,6 +100,7 @@ public EntityHierarchyContextMenuPresenter(@Nonnull EntityHierarchyModel model,
@Nonnull UIAction deleteEntityAction,
@Provided @Nonnull SetAnnotationValueUiAction setAnnotationValueUiAction,
@Provided @Nonnull MoveToParentUiAction moveToParentUiAction, @Provided @Nonnull MergeEntitiesUiAction mergeEntitiesAction,
@Provided @Nonnull ChangeEntityIRIUiAction changeEntityIriAction,
@Provided @Nonnull EditAnnotationsUiAction editAnnotationsUiAction,
@Provided @Nonnull EditEntityTagsUiAction editEntityTagsAction,
@Provided Messages messages,
Expand All @@ -111,6 +116,7 @@ public EntityHierarchyContextMenuPresenter(@Nonnull EntityHierarchyModel model,
this.createEntityAction = checkNotNull(createEntityAction);
this.deleteEntityAction = checkNotNull(deleteEntityAction);
this.mergeEntitiesAction = checkNotNull(mergeEntitiesAction);
this.changeEntityIriAction = checkNotNull(changeEntityIriAction);
this.editEntityTagsAction = checkNotNull(editEntityTagsAction);
this.watchUiAction = checkNotNull(watchUiAction);
this.permissionChecker = checkNotNull(permissionChecker);
Expand Down Expand Up @@ -143,6 +149,7 @@ private void createContextMenu() {
contextMenu.addSeparator();
contextMenu.addItem(moveToParentUiAction);
contextMenu.addItem(mergeEntitiesAction);
contextMenu.addItem(changeEntityIriAction);
contextMenu.addItem(setAnnotationValueUiAction);
contextMenu.addItem(editAnnotationsUiAction);
contextMenu.addSeparator();
Expand All @@ -169,11 +176,14 @@ private void createContextMenu() {
moveToParentUiAction.setSelectionSupplier(selectionSupplier);
mergeEntitiesAction.setSelectionSupplier(selectionSupplier);
editAnnotationsUiAction.setSelectionSupplier(selectionSupplier);
changeEntityIriAction.setSelectionSupplier(() -> selectionSupplier.get().stream().findFirst());
changeEntityIriAction.setChangeHandler(this::handleRefresh);
updateActionStates();
}

private void updateActionStates() {
mergeEntitiesAction.setEnabled(false);
changeEntityIriAction.setEnabled(false);
editEntityTagsAction.setEnabled(false);
setAnnotationValueUiAction.setEnabled(false);
editAnnotationsUiAction.setEnabled(false);
Expand All @@ -197,6 +207,7 @@ private void updateActionStates() {
permissionChecker.hasPermission(EDIT_ONTOLOGY, setAnnotationValueUiAction::setEnabled);
permissionChecker.hasPermission(EDIT_ONTOLOGY, editAnnotationsUiAction::setEnabled);
permissionChecker.hasPermission(EDIT_ONTOLOGY, moveToParentUiAction::setEnabled);
permissionChecker.hasPermission(EDIT_ONTOLOGY, enabled -> changeEntityIriAction.setEnabled(selIsSingleton && enabled));
}
}

Expand Down