versionedontology.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,850 行 · 第 1/5 页
JAVA
1,850 行
changeTree.updateUI();
// need to refresh UI
this.refreshUI();
// also set repChanges to equal all changes beneath newCommitNode
this.repChanges = this.getDescendantChanges(newCommitNode);
}
/*
* Delete selected changes from a given TreeTable
*/
private void deleteChanges(JTreeTable source) {
List changes = null;
boolean selectedOntChangeTT = true;
if (source == ontChangeTT) {
changes = new ArrayList(ontChanges);
}
else {
selectedOntChangeTT = false;
changes = new ArrayList(repChanges);
}
// get selected changes in source
if (source.getTree().getSelectionPath()==null) return;
TreePath[] paths = source.getTree().getSelectionPaths();
for (int i=0; i<paths.length; i++) {
TreePath path = paths[i];
TreeTableNode selNode = (TreeTableNode) path.getLastPathComponent();
SwoopChange swc = selNode.swoopChange;
changes.remove(swc);
}
// refresh UI of source after removing changes
if (selectedOntChangeTT) this.refreshOntTreeTable();
else {
// add (new) repChanges to newCommit node directly
newCommitNode.children = new Vector();
for (Iterator iter = changes.iterator(); iter.hasNext();) {
SwoopChange swc = (SwoopChange) iter.next();
TreeTableNode swcNode = new TreeTableNode(swc);
newCommitNode.addChild(swcNode);
}
this.refreshRepTreeTable(false);
}
}
/*
* Recursive method to find all descendant SwoopChanges of a particular TreeTableNode
*/
private List getDescendantChanges(TreeTableNode node) {
List changes = new ArrayList();
// start with node and recurse over children
// dont add the top node which has children
if (node.children.size()>0) {
for (Iterator iter = node.children.iterator(); iter.hasNext();) {
TreeTableNode child = (TreeTableNode) iter.next();
changes.addAll(getDescendantChanges(child));
}
}
else if (!node.swoopChange.isTopNode) changes.add(node.swoopChange);
return changes;
}
/*
* Rewrite Repository Header..
*/
private void rewriteRepHeader() {
// assume that the value of headVersionNum has been
// incremented before coming here
try {
// 1. delete current header
if (client==null) this.initAnnoteaClient();
client.delete(this.repHeaderLoc);
// 2. post new header
Description header = new Description();
URI[] headerURI = new URI[1];
headerURI[0] = new URI(this.repositoryURI.toString() + "#header");
header.setAnnotates(headerURI);
header.setAuthor(this.repositoryAuthor);
header.setCreated(this.reposityCreatedDate);
header.setAnnotatedEntityDefinition(this.baseOntologyURI.toString());
header.setBody(String.valueOf(this.headVersionNumber));
header.setBodyType("text/html");
header.setAnnotationType(this.annotType);
// 3. update new header location URL
repHeaderLoc = client.post(header);
// 4. update value in versionDescriptions array and update swoopModel' versionRepository
this.versionDescriptions[0] = header;
swoopModel.updateVersionRepository(this.repositoryURI, versionDescriptions);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
/*
* Commit Changes to the Swoop Ontology (LOCALLY)
*/
private void commitOntChanges(boolean sync) {
String status = "Status: [ACTION - Commit to Local Ontology]...";
// load base ontology first
OWLOntology baseOntology = null;
if (!sync) {
if (existingOntRadio.isSelected()) {
// get existing ontology from swoopModel
baseOntology = (OWLOntology) ontBox.getSelectedItem();
try {
baseOntology = swoopModel.getOntology(baseOntology.getURI());
} catch (OWLException e) {
e.printStackTrace();
}
}
else {
URI ontURI = null;
try {
// load ontology with URI
ontURI = new URI(swoopOntFld.getText());
baseOntology = swoopModel.loadOntology(ontURI);
}
catch (Exception ex) {
// create new ontology
OWLBuilder builder = new OWLBuilder();
try {
builder.createOntology(ontURI, ontURI);
} catch (OWLException e) {
e.printStackTrace();
}
baseOntology = builder.getOntology();
}
try {
//*** remember to add new baseOntology (not currently in SwoopModel) to the model
swoopModel.addOntology(baseOntology);
} catch (OWLException e) {
e.printStackTrace();
}
}
}
else {
// if sync ontology is specified (i.e. not advanced mode)
if (syncOntology == null) {
try {
URI ontURI = new URI(this.repBaseOntFld.getText());
// check if ontology is already in Swoop
if (swoopModel.getOntology(ontURI)!=null) {
//TODO: currently commit changes to present ontology
syncOntology = swoopModel.getOntology(ontURI);
}
else {
// add new ontology to swoop
syncOntology = swoopModel.loadOntology(ontURI);
swoopModel.addOntology(syncOntology);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
baseOntology = syncOntology;
}
if (baseOntology == null) {
statusBar.setText(status+"Unable to load base ontology");
return;
}
// test changes
boolean success = true;
List commitChanges = null;
if (!sync) {
// if sync is not set, i.e. advanced mode is enabled
// commit only ontside changes
commitChanges = ontChanges;
success = this.testChanges(false);
}
else {
// if sync is set, commit all repository-side changes
commitChanges = new ArrayList(this.getDescendantChanges(repRoot));
// need to test any repChanges to check for changes already applied to ontology
try {
List alreadyOntChanges = swoopModel.getChangesCache().getChangeList(syncOntology.getURI());
for (Iterator iter = new ArrayList(commitChanges).iterator(); iter.hasNext();) {
SwoopChange swc = (SwoopChange) iter.next();
if (this.isPresent(alreadyOntChanges, swc)) commitChanges.remove(swc);
}
}
catch (OWLException e) {
e.printStackTrace();
}
}
if (success){
try {
// commit all changes in commitChanges List
for (int i=0; i<commitChanges.size(); i++) {
SwoopChange swc = (SwoopChange) commitChanges.get(i);
if (sync && !swc.isOnRepository) continue; //*** dont commit anything but repository changes to synched ontology
OntologyChange oc = swc.getChange();
//*** need to align changes with base ontology! ***/
OntologyChange alignOC = (OntologyChange) controlHandler.swoopHandler.changeLog.getChangeInformation(oc, ChangeLog.CHANGE_ALIGN, null, new ArrayList(), baseOntology);
// APPLY CHANGE
if (alignOC instanceof BooleanElementChange) {
swoopModel.applyBooleanElementChange(alignOC);
}
else if (alignOC instanceof EnumElementChange) {
swoopModel.applyEnumElementChange(alignOC);
}
else alignOC.accept((ChangeVisitor) baseOntology);
// update changesCache in swoopModel
// first reset aligned ontology change in swc
swc.setChange(alignOC);
// and add *clones* to changesCache in SwoopModel
swoopModel.getChangesCache().addChange(swc.owlObjectURI, (SwoopChange) swc.clone());
// do the same for entities referred to by swc.ontologyChange
// & also add changed entity URI to swoopModel dirty set
OWLEntity entity = swoopModel.getEntity(baseOntology, swc.owlObjectURI, true);
if (swc.getOwlObjectURI().equals(baseOntology.getURI()) && swc.extraSubjects!=null) {
for (Iterator iter = swc.extraSubjects.iterator(); iter.hasNext();) {
URI entityURI = (URI) iter.next();
// add to cache
swoopModel.getChangesCache().addChange(entityURI, (SwoopChange) swc.clone());
// add to dirty set
entity = swoopModel.getEntity(baseOntology, entityURI, true);
}
}
}
//* notify swoopModel!
Set changedOntologies = new HashSet();
changedOntologies.add(baseOntology);
swoopModel.notifyListeners(new ModelChangeEvent(swoopModel, ModelChangeEvent.ONTOLOGY_CHANGED, changedOntologies));
statusBar.setText(status+"Committed "+commitChanges.size()+" changes");
}
catch (OWLException ex) {
ex.printStackTrace();
}
}
}
public void valueChanged(TreeSelectionEvent e) {
if (e.getSource() instanceof JTree) {
// get tree whose selection has changed
JTree source = (JTree) e.getSource();
if (source.getSelectionPath()==null) return;
TreePath path = source.getSelectionPath();
// get selected tree(table) node
TreeTableNode selNode = (TreeTableNode) path.getLastPathComponent();
// display change information based on selected node
this.displayChange(source, selNode);
}
}
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (e.getSource() == ontChangeEdPane || e.getSource() == repChangeEdPane) {
String hLink = e.getDescription();
// edit comment of a swoopchange (in a treetablenode)
if (hLink.startsWith("EDIT")) {
String hashCode = hLink.substring(hLink.indexOf(":")+1, hLink.length());
TreeTableNode node = (TreeTableNode) nodeMap.get(hashCode);
String comment = node.swoopChange.comment;
// prompt for new comment
String newComment = (String) JOptionPane.showInputDialog(this, "Specify New Comment", "Comment on Change", JOptionPane.INFORMATION_MESSAGE, null, null, comment);
if (newComment!=null) node.swoopChange.comment = newComment;
String sourceStr = hLink.substring(4, hLink.indexOf(":"));
// depending on local/remote change, refresh display
if (sourceStr.equals("LOCAL")) this.displayChange(ontChangeTT.getTree(), node);
else this.displayChange(repChangeTT.getTree(), node);
}
}
}
}
private void displayChange(JTree source, TreeTableNode node) {
// create HTML description of selected TreeTableNode
// (based on its SwoopChange value)
SwoopChange swc = node.swoopChange;
String html = "<FONT FACE=\""+swoopModel.getFontFace()+"\" SIZE="+swoopModel.getFontSize()+">";
html += "<b>Author</b>: "+swc.getAuthor()+"<br>";
html += "<b>Time</b>: "+swc.getTimeStamp()+"<br>";
html += "<b>Comment</b>: "+swc.comment;
// add 'Edit' Comment link
if (!swc.isOnRepository && !swc.isTopNode) {
String sourceStr = "LOCAL";
if (source == repChangeTT.getTree()) sourceStr = "REMOTE";
html += " <font color=\"green\"><a href=\"EDIT"+sourceStr+":"+node.hashCode()+"\">Edit</a></font>";
nodeMap.put(String.valueOf(node.hashCode()), node);
}
html += "<br><br>";
html += swc.getDescription();
html += "</FONT>";
if (source == ontChangeTT.getTree()) {
this.ontChangeEdPane.setText(html);
}
else if (source == repChangeTT.getTree()) {
this.repChangeEdPane.setText(html);
}
}
/*
* Clone an OWL Ontology by serializing it into RDF/XML
* and deserializing it!
*/
public OWLOntology cloneOntology(OWLOntology source) {
OWLOntology copy = null;
try {
CorrectedRDFRenderer rdfRend = new CorrectedRDFRenderer();
StringWriter st = new StringWriter();
rdfRend.renderOntology(source, st);
copy = swoopModel.loadOntologyInRDF(new StringReader(st.toString()), source.getURI(), true);
}
catch (OWLException ex) {
ex.printStackTrace();
}
return copy;
}
public void mouseClicked(MouseEvent arg0) {
}
public void mousePressed(MouseEvent evt) {
if (evt.getSource() == swoFilterBtn) {
this.swoFilterMenu.show(evt.getComponent(), evt.getX(), evt.getY());
}
else if (evt.getSource() == repFilterBtn) {
this.repFilterMenu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseReleased(MouseEvent evt) {
if (evt.getSource() == swoFilterBtn) {
this.swoFilterMenu.show(evt.getComponent(), evt.getX(), evt.getY());
}
else if (evt.getSource() == repFilterBtn) {
this.repFilterMenu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
/*
* Filter out all nodes from the corresponding changeTreeTable (swo or rep)
* depending on boolean and type passed to it.
* type is one of REDUNDANT_CHANGE, REPOSITORY_CHANGE, LOCAL_CHANGE
*/
public void filter(boolean onRepository, int type) {
List changes = null;
if (!onRepository) {
// filter from ontChangeTT
changes = this.ontChanges
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?