Code Search for Developers
 
 
  

KnowledgeTree.java from ThinkCap Collaborative Knowledge Portal at Krugle


Show KnowledgeTree.java syntax highlighted

package org.integratedmodelling.thinkcap.components.portal;

import org.integratedmodelling.thinkcap.ThinkCap;
import org.integratedmodelling.thinkcap.ThinkcapSession;
import org.integratedmodelling.thinklab.ClassTree;
import org.integratedmodelling.thinklab.KnowledgeManager;
import org.integratedmodelling.thinklab.ClassTree.ClassNode;
import org.integratedmodelling.thinklab.exception.ThinklabException;
import org.integratedmodelling.thinklab.interfaces.IConcept;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zul.AbstractTreeModel;
import org.zkoss.zul.Tree;

public class KnowledgeTree extends Tree {

	private static final long serialVersionUID = 1L;

	public static class CTreeModel extends AbstractTreeModel {

		private static final long serialVersionUID = 1L;
		private String[] ignore = null;
		private String[] chosen = null;
 
    	public CTreeModel(ClassNode root, String[] ignoredPrefixes, String[] chosenPrefixes)  {
    		super(root);
    		ignore = ignoredPrefixes;
    		chosen = chosenPrefixes;
    	}
    	
    	private boolean isSelected(ClassNode cn) {

    		boolean ret = (chosen == null);
    		
    		if (chosen != null) {
    			for (String prefix : chosen) {
    				if ((ret = cn.ID.startsWith(prefix)))
    					break;
    			}
    		}
    		
    		if (ret && ignore != null) {
    			for (String prefix : ignore) {
    				if ((cn.ID.startsWith(prefix))) {
    					ret = false;
    					break;
    				}
    			}
    			
    		}
    		
    		return ret;
    	}
    	
		public Object getChild(Object arg0, int arg1) {
			if (ignore == null && chosen == null)
				return ((ClassNode)arg0).getChildAt(arg1);
			else {
				for (int i = 0, cnt = 0; i < ((ClassNode)arg0).getChildCount(); i++) {
					ClassNode cn = (ClassNode) ((ClassNode)arg0).getChildAt(i);
					if (isSelected(cn)) {
						if (cnt++ == arg1)
							return cn;
					}
				}
			}
			// shouldn't happen
			return null;
		}

		public int getChildCount(Object arg0) {
			
			int ret = 0;
			
			if (ignore == null && chosen == null)
				ret = ((ClassNode)arg0).getChildCount();
			else {
				
				for (int i = 0; i < ((ClassNode)arg0).getChildCount(); i++) {
					if (isSelected((ClassNode) ((ClassNode)arg0).getChildAt(i))) {
						ret++;
					}
				}
			}
		return ret;
			
		}

		
		public boolean isLeaf(Object arg0) {
			return getChildCount(arg0) == 0;
		}

    	
    }
    
    IConcept concept = null;
    String ontology = null;
    ClassTree ctree = null;
    
    ThinkcapSession tSession = null;
	private String[] ignoredPrefixes = null;
	private String[] chosenPrefixes = null;
    
    public KnowledgeTree() {

    	tSession = ThinkCap.getTkSession(Sessions.getCurrent());   
    	ctree = null;
    }
     
    public void setConcept(String concept) {

    	if (!concept.equals("owl:Thing")) {
    		try {
    			this.concept = KnowledgeManager.KM().retrieveConcept(concept);
    		} catch (ThinklabException e) {
    		}
    	} else {
    		this.concept = KnowledgeManager.Thing();
    	}

        ctree = new ClassTree(this.concept);

        try {
			this.setModel(new CTreeModel(ctree.getRootNode(), ignoredPrefixes, chosenPrefixes));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
        
    }
    
	public void setIgnore(String ignoredPrefixes) {
		this.ignoredPrefixes = ignoredPrefixes.split(",");
		if (ctree != null) {
			try {
				this.setModel(new CTreeModel(ctree.getRootNode(), this.ignoredPrefixes, chosenPrefixes));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public void setOnly(String chosenPrefixes) {
		this.chosenPrefixes = chosenPrefixes.split(",");
		if (ctree != null) {
			try {
				this.setModel(new CTreeModel(ctree.getRootNode(), ignoredPrefixes, this.chosenPrefixes));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}




See more files for this project here

ThinkCap Collaborative Knowledge Portal

A portal to explore and edit the knowledge contained in a set of ontologies in intuitive ways. Presents a Dictionary view (a Google-like interface), a Thesaurus view (a graphical display with simplified relationships) and a full graphical Concept view.

Project homepage: http://sourceforge.net/projects/thinkcap
Programming language(s): Java,JavaScript,XML
License: other

  KnowledgeTree.java