001    /*
002     * The contents of this file are subject to the Mozilla Public
003     * License Version 1.1 (the "License"); you may not use this file
004     * except in compliance with the License. You may obtain a copy of
005     * the License at http://www.mozilla.org/MPL/
006     *
007     * Software distributed under the License is distributed on an "AS
008     * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
009     * implied. See the License for the specific language governing
010     * rights and limitations under the License.
011     *
012     * The Original Code is Knowtator.
013     *
014     * The Initial Developer of the Original Code is University of Colorado.  
015     * Copyright (C) 2005-2008.  All Rights Reserved.
016     *
017     * Knowtator was developed by the Center for Computational Pharmacology
018     * (http://compbio.uchcs.edu) at the University of Colorado Health 
019     *  Sciences Center School of Medicine with support from the National 
020     *  Library of Medicine.  
021     *
022     * Current information about Knowtator can be obtained at 
023     * http://knowtator.sourceforge.net/
024     *
025     * Contributor(s):
026     *   Philip V. Ogren <philip@ogren.info> (Original Author)
027     */
028    package edu.uchsc.ccp.knowtator.ui;
029    
030    import edu.stanford.smi.protege.model.Project;
031    import edu.stanford.smi.protege.model.SimpleInstance;
032    import edu.stanford.smi.protege.ui.InstanceDisplay;
033    import edu.uchsc.ccp.knowtator.AnnotationUtil;
034    import edu.uchsc.ccp.knowtator.KnowtatorManager;
035    import edu.uchsc.ccp.knowtator.MentionUtil;
036    import edu.uchsc.ccp.knowtator.event.EventHandler;
037    import edu.uchsc.ccp.knowtator.event.SelectedAnnotationChangeEvent;
038    import edu.uchsc.ccp.knowtator.event.SelectedAnnotationChangeListener;
039    
040    public class MentionDisplay extends InstanceDisplay implements SelectedAnnotationChangeListener {
041            static final long serialVersionUID = 0;
042    
043            MentionUtil mentionUtil;
044    
045            AnnotationUtil annotationUtil;
046    
047            public MentionDisplay(KnowtatorManager manager, Project project) {
048                    super(project, false, false);
049                    mentionUtil = manager.getMentionUtil();
050                    annotationUtil = manager.getAnnotationUtil();
051                    EventHandler.getInstance().addSelectedAnnotationChangeListener(this);
052            }
053    
054            public MentionDisplay(MentionUtil mentionUtil, AnnotationUtil annotationUtil, Project project) {
055                    super(project);
056                    this.mentionUtil = mentionUtil;
057                    this.annotationUtil = annotationUtil;
058                    EventHandler.getInstance().addSelectedAnnotationChangeListener(this);
059            }
060    
061            public void annotationSelectionChanged(SelectedAnnotationChangeEvent sace) {
062                    SimpleInstance oldMention = (SimpleInstance) getCurrentInstance();
063                    if (oldMention != null) {
064                            mentionUtil.removeEmptySlotMentions(oldMention);
065                    }
066    
067                    SimpleInstance annotation = sace.getSelectedAnnotation();
068                    if (annotation != null) {
069                            SimpleInstance selectedMention = annotationUtil.getMention(annotation);
070                            mentionUtil.initializeSlotMentions(selectedMention);
071                            setInstance(selectedMention);
072                    } else {
073                            setInstance(null);
074                    }
075            }
076    
077    }