001    // This file is part of the Attempto Java Packages.
002    // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
003    //
004    // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the
005    // terms of the GNU Lesser General Public License as published by the Free Software Foundation,
006    // either version 3 of the License, or (at your option) any later version.
007    //
008    // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY
009    // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
010    // PURPOSE. See the GNU Lesser General Public License for more details.
011    //
012    // You should have received a copy of the GNU Lesser General Public License along with the Attempto
013    // Java Packages. If not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.acewiki.gui.page;
016    
017    import nextapp.echo2.app.Color;
018    import nextapp.echo2.app.event.ActionEvent;
019    import ch.uzh.ifi.attempto.acewiki.Wiki;
020    import ch.uzh.ifi.attempto.acewiki.core.ontology.Concept;
021    import ch.uzh.ifi.attempto.acewiki.core.ontology.NounConcept;
022    import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement;
023    import ch.uzh.ifi.attempto.acewiki.core.ontology.Sentence;
024    import ch.uzh.ifi.attempto.acewiki.gui.editor.SentenceEditorHandler;
025    
026    /**
027     * This class stands for an article page showing the article of a concept. At the
028     * moment, concepts are represented only by nouns.
029     * 
030     * @author Tobias Kuhn
031     */
032    public class ConceptPage extends ArticlePage {
033            
034            private static final long serialVersionUID = -505381176379658743L;
035    
036            private NounConcept concept;
037            
038            /**
039             * Creates a new article page for a concept.
040             * 
041             * @param concept The concept.
042             * @param wiki The wiki instance.
043             */
044            protected ConceptPage(Concept concept, Wiki wiki) {
045                    super(wiki, concept);
046                    this.concept = (NounConcept) concept;
047                    
048                    addTab("Individuals", this);
049                    addTab("Hierarchy", this);
050            }
051            
052            public OntologyElement getOntologyElement() {
053                    return concept;
054            }
055    
056            public void actionPerformed(ActionEvent e) {
057                    super.actionPerformed(e);
058                    if ("Individuals".equals(e.getActionCommand())) {
059                            getWiki().showPage(new IndividualsPage(this));
060                    } else if ("Hierarchy".equals(e.getActionCommand())) {
061                            getWiki().showPage(new HierarchyPage(this));
062                    }
063            }
064            
065            protected void doUpdate() {
066                    super.doUpdate();
067                    
068                    getTitle().setText(concept.getHeadword());
069                    
070                    Thread thread = new Thread() {
071                            public void run() {
072                                    getWiki().enqueueTask(new Runnable() {
073                                            public void run() {
074                                                    if (concept.getOntology().isSatisfiable(concept)) {
075                                                            getTitle().setColor(Color.BLACK);
076                                                    } else {
077                                                            getTitle().setColor(new Color(193, 0, 0));
078                                                    }
079                                            }
080                                    });
081                            }
082                    };
083                    thread.start();
084            }
085            
086            public void edit(Sentence sentence) {
087                    if (concept.getSentences().contains(sentence)) {
088                            getWiki().showWindow(SentenceEditorHandler.generatePreditorEditWindow(sentence, this));
089                    }
090            }
091    
092    }