Skip to content

Commit

Permalink
Closes #466
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Jul 20, 2016
1 parent 45a7581 commit 6bd16c6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,6 @@ public void visit(SWRLRule rule) {

protected class UsageTreeNode extends DefaultMutableTreeNode {

/**
*
*/
private static final long serialVersionUID = -53617232488795863L;

private OWLOntology ont;

private OWLAxiom axiom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.ui.renderer.OWLCellRenderer;
import org.protege.editor.owl.ui.tree.OWLLinkedObjectTree;
import org.protege.editor.owl.ui.view.ChangeListenerMediator;
import org.protege.editor.owl.ui.view.Copyable;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLObject;

import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.util.*;
import java.util.List;

import static java.util.stream.Collectors.toList;


/**
Expand All @@ -17,20 +28,83 @@
* Bio-Health Informatics Group<br>
* Date: 21-Feb-2007<br><br>
*/
public class UsageTree extends OWLLinkedObjectTree {
public class UsageTree extends OWLLinkedObjectTree implements Copyable {


private OWLEditorKit owlEditorKit;

private OWLEntity entity;

private final ChangeListenerMediator changeListenerMediator = new ChangeListenerMediator();

public UsageTree(OWLEditorKit owlEditorKit) {
super(owlEditorKit);
this.owlEditorKit = owlEditorKit;
setCellRenderer(new UsageTreeCellRenderer(owlEditorKit));
getSelectionModel().addTreeSelectionListener(e -> changeListenerMediator.fireStateChanged(UsageTree.this));
}

/**
* Determines whether or not at least one <code>OWLObject</code>
* can be copied.
*
* @return <code>true</code> if at least one object can be copied, or
* <code>false</code> if no objects can't be copied.
*/
@Override
public boolean canCopy() {
TreePath[] selectionPaths = getSelectionPaths();
if(selectionPaths == null) {
return false;
}
return Arrays.stream(selectionPaths)
.map(TreePath::getLastPathComponent)
.filter(node -> node instanceof UsageByEntityTreeModel.UsageTreeNode)
.findFirst()
.isPresent();
}

/**
* Gets the objects that will be copied.
*
* @return A <code>List</code> of <code>OWLObjects</code> that will be
* copied to the clip board
*/
@Override
public List<OWLObject> getObjectsToCopy() {
TreePath[] selectionPaths = getSelectionPaths();
if(selectionPaths == null) {
return Collections.emptyList();
}
return Arrays.stream(selectionPaths)
.map(TreePath::getLastPathComponent)
.filter(node -> node instanceof UsageByEntityTreeModel.UsageTreeNode)
.map(node -> ((UsageByEntityTreeModel.UsageTreeNode) node).getAxiom())
.collect(toList());
}

/**
* Adds a change listener. If the ability to copy OWL objects changes, the
* copyable component should notify listeners through a change of state event.
*
* @param changeListener The listener to be added.
* @see ChangeListenerMediator Components may want to use the <code>ChangeListenerMediator</code>
* class to manage event notifcation and addition/removal of listeners
*/
@Override
public void addChangeListener(ChangeListener changeListener) {
changeListenerMediator.addChangeListener(changeListener);
}

/**
* Removes a previously added change listener.
*
* @param changeListener The ChangeListener to be removed.
*/
@Override
public void removeChangeListener(ChangeListener changeListener) {
changeListenerMediator.removeChangeListener(changeListener);
}

public void setOWLEntity(OWLEntity entity) {
this.entity = entity;
Expand Down

0 comments on commit 6bd16c6

Please sign in to comment.