Skip to content

Commit

Permalink
added linearization parent
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilaghi committed Aug 7, 2024
1 parent 3be554d commit aa0d55a
Show file tree
Hide file tree
Showing 18 changed files with 414 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@
import edu.stanford.bmir.protege.web.client.library.modal.ModalViewImpl;
import edu.stanford.bmir.protege.web.client.library.msgbox.InputBoxView;
import edu.stanford.bmir.protege.web.client.library.msgbox.InputBoxViewImpl;
import edu.stanford.bmir.protege.web.client.linearization.LinearizationCommentsView;
import edu.stanford.bmir.protege.web.client.linearization.LinearizationCommentsViewImpl;
import edu.stanford.bmir.protege.web.client.linearization.LinearizationPortletView;
import edu.stanford.bmir.protege.web.client.linearization.LinearizationPortletViewImpl;
import edu.stanford.bmir.protege.web.client.linearization.*;
import edu.stanford.bmir.protege.web.client.login.LoginView;
import edu.stanford.bmir.protege.web.client.login.LoginViewImpl;
import edu.stanford.bmir.protege.web.client.login.SignInRequestHandler;
Expand Down Expand Up @@ -496,6 +493,11 @@ EntityTagsSelectorView provideEntityTagsSelectorView(EntityTagsSelectorViewImpl
EditorPortletView provideEditorPortletView(EditorPortletViewImpl impl) {
return impl;
}
@Provides
LinearizationParentView provideLinearizationParentView(LinearizationParentViewImpl impl) {
return impl;
}


@Provides
LinearizationPortletView provideLinearizationPortletView(LinearizationPortletViewImpl impl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,69 @@
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
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 java.util.logging.Logger;

public class LinearizationParentLabel implements ClickHandler {


private Label label;

private LinearizationParentModal linearizationParentModal;

private IRI selectedEntityIri;


private ProjectId projectId;

private ParentSelectedHandler selectedHandler;

private boolean readOnly = true;

// Constructor
public LinearizationParentLabel(String text, LinearizationParentModal linearizationParentModal) {
public LinearizationParentLabel(String text, LinearizationParentModal linearizationParentModal, IRI entityIri, ProjectId projectId, ParentSelectedHandler parentSelectedHandler) {
label = new Label(text);
label.addStyleName(LinearizationTableResourceBundle.INSTANCE.style().getLinearizationParentCell());
this.linearizationParentModal = linearizationParentModal;
label.addClickHandler(this); // Register this class as the ClickHandler for the Label
this.selectedEntityIri = entityIri;
this.projectId = projectId;
this.selectedHandler = parentSelectedHandler;
}

// Method to set the text of the label
public void setText(String text) {
label.setText(text);
}

// Method to get the text of the label
public String getText() {
return label.getText();
}

// Method to set the style of the label
public void setStyleName(String style) {
label.setStyleName(style);
}

// Method to get the underlying widget
public Widget asWidget() {
return label;
}

// Implement the onClick method from ClickHandler interface

public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}

@Override
public void onClick(ClickEvent event) {
// Handle the click event here
// For example, you can change the label's text on click
this.linearizationParentModal.showModal();
if(!readOnly) {
this.linearizationParentModal.showModal(selectedEntityIri, projectId, selectedHandler);
}
}

// Method to add external ClickHandlers
public HandlerRegistration addClickHandler(ClickHandler handler) {
return label.addClickHandler(handler);
}


public interface ParentSelectedHandler {
void handleParentSelected(OWLEntityData selectedParent);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package edu.stanford.bmir.protege.web.client.linearization;

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.icd.GetClassAncestorsAction;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import org.semanticweb.owlapi.model.IRI;


import javax.annotation.Nonnull;
Expand All @@ -12,16 +18,35 @@ public class LinearizationParentModal {
@Nonnull
private final ModalManager modalManager;


private final DispatchServiceManager dispatchServiceManager;


Logger logger = java.util.logging.Logger.getLogger("LinearizationParentModal");

@Inject
public LinearizationParentModal(@Nonnull ModalManager modalManager) {
public LinearizationParentModal(@Nonnull ModalManager modalManager, DispatchServiceManager dispatchServiceManager) {
this.modalManager = modalManager;
this.dispatchServiceManager = dispatchServiceManager;
}


public void showModal() {

public void showModal(IRI selectedEntityIri, ProjectId projectId, LinearizationParentLabel.ParentSelectedHandler parentSelectedHandler) {
dispatchServiceManager.execute(GetClassAncestorsAction.create(selectedEntityIri, projectId), getHierarchyParentsResult -> {
ModalPresenter presenter = modalManager.createPresenter();
LinearizationParentView view = new LinearizationParentViewImpl(getHierarchyParentsResult.getAncestorsTree());
presenter.setTitle("Set linearization parent");
presenter.setView(view);
presenter.setEscapeButton(DialogButton.CANCEL);
presenter.setPrimaryButton(DialogButton.OK);
presenter.setButtonHandler(DialogButton.OK, closer -> {
parentSelectedHandler.handleParentSelected(view.getSelectedParent());
presenter.closeModal();
});
modalManager.showModal(presenter);
});
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.linearizationParentLabel tr {
width : 100%;
cursor: pointer;
}

.parentSelected {
background-color: rgb(17, 108, 214);
color: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.stanford.bmir.protege.web.client.linearization;

import com.google.gwt.user.client.ui.IsWidget;
import edu.stanford.bmir.protege.web.shared.HasDispose;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.icd.AncestorClassHierarchy;

import java.util.List;
import java.util.Set;

public interface LinearizationParentView extends IsWidget, HasDispose {

void setAncestorsTree(AncestorClassHierarchy ancestorTree);

OWLEntityData getSelectedParent();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package edu.stanford.bmir.protege.web.client.linearization;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.OpenEvent;
import com.google.gwt.event.logical.shared.OpenHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.icd.AncestorClassHierarchy;
import com.google.gwt.user.client.ui.TreeItem;

import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;

public class LinearizationParentViewImpl extends Composite implements LinearizationParentView {

Logger logger = java.util.logging.Logger.getLogger("LinearizationParentViewImpl");

@UiField
Tree tree;

private OWLEntityData selectedEntity;
LinearizationParentsResourceBundle.LinearizationParentCss style = LinearizationParentsResourceBundle.INSTANCE.style();

public LinearizationParentViewImpl(AncestorClassHierarchy ancestorsTree) {
style.ensureInjected();
initWidget(ourUiBinder.createAndBindUi(this));

String browserText = ancestorsTree.getCurrentNode().getBrowserText();
browserText = browserText != null && !browserText.isEmpty() ? browserText : " ";
TreeItem root = new TreeItem(new Label(browserText));
addTreeItems(root, ancestorsTree.getChildren());
root.setState(true);
tree.addItem(root);
tree.setAnimationEnabled(true);

tree.addSelectionHandler(event -> {
Iterator<TreeItem> iter = tree.treeItemIterator();
while(iter.hasNext()) {
TreeItem item = iter.next();
if(event.getSelectedItem().equals(item)) {
item.getWidget().addStyleName(style.getParentSelected());
} else {
item.getWidget().removeStyleName(style.getParentSelected());
}
}
});

}


@Override
public void setAncestorsTree(AncestorClassHierarchy ancestorsTree) {


}

@Override
public OWLEntityData getSelectedParent() {
return selectedEntity;
}


private void addTreeItems(TreeItem parentItem, List<AncestorClassHierarchy> nodes) {
for (AncestorClassHierarchy node : nodes) {
String browserText = node.getCurrentNode().getBrowserText();
browserText = browserText != null && !browserText.isEmpty() ? browserText : " ";
Label label = new Label(browserText);

TreeItem treeItem = new TreeItem(label);
treeItem.setStyleName(style.getLinearizationParentLabel());
label.addClickHandler(event -> {
selectedEntity = node.getCurrentNode();
tree.setSelectedItem(treeItem);
});
parentItem.addItem(treeItem);

if (node.getChildren() != null) {
addTreeItems(treeItem, node.getChildren());
}
treeItem.setState(true);

}
}
@Override
public void dispose() {
tree.clear();
}

interface LinearizationParentViewImpllUiBinder extends UiBinder<HTMLPanel, LinearizationParentViewImpl> {

}
private static LinearizationParentViewImpllUiBinder ourUiBinder = GWT.create(LinearizationParentViewImpllUiBinder.class);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>

<ui:style>
.gwt-Tree {
}

.gwt-TreeItem-selected {
background-color: #ebeff9;
}
</ui:style>
<g:HTMLPanel>
<g:ScrollPanel>
<g:Tree ui:field="tree" addStyleNames="{style.gwt-Tree}"></g:Tree>
</g:ScrollPanel>
</g:HTMLPanel >
</ui:UiBinder>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package edu.stanford.bmir.protege.web.client.linearization;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;

public interface LinearizationParentsResourceBundle extends ClientBundle {

LinearizationParentsResourceBundle INSTANCE = GWT.create(LinearizationParentsResourceBundle.class);

@Source("LinearizationParentTree.css")
LinearizationParentCss style();


interface LinearizationParentCss extends CssResource {

@ClassName("linearizationParentLabel")
String getLinearizationParentLabel();
@ClassName("parentSelected")
String getParentSelected();
}
}
Loading

0 comments on commit aa0d55a

Please sign in to comment.