001    /**
002     * Copyright (C) 2007-2008, Jens Lehmann
003     *
004     * This file is part of DL-Learner.
005     * 
006     * DL-Learner is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation; either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * DL-Learner is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018     *
019     */
020    
021    package org.dllearner.tools.ore;
022    
023    import java.awt.event.ActionEvent;
024    import java.awt.event.ActionListener;
025    
026    import javax.swing.event.DocumentEvent;
027    import javax.swing.event.DocumentListener;
028    
029    /**
030     * Wizard panel descriptor where knowledge source is selected.
031     * @author Lorenz Buehmann
032     *
033     */
034    public class KnowledgeSourcePanelDescriptor extends WizardPanelDescriptor implements ActionListener, DocumentListener{
035        
036        public static final String IDENTIFIER = "KNOWLEDGESOURCE_CHOOSE_PANEL";
037        public static final String INFORMATION = "Select the type of knowledgesource you want to work with and then enter the URI."
038                                                                                 + " After all press \"Next\"-button";
039        
040        private KnowledgeSourcePanel knowledgePanel;
041        
042        public KnowledgeSourcePanelDescriptor() {
043            
044            knowledgePanel = new KnowledgeSourcePanel();
045        
046            knowledgePanel.addListeners(this, this);
047            
048            setPanelDescriptorIdentifier(IDENTIFIER);
049            setPanelComponent(knowledgePanel);
050            
051        }
052        
053        @Override
054            public Object getNextPanelDescriptor() {
055            if(getWizard().getKnowledgeSourceType() == 0){
056                    return ClassPanelOWLDescriptor.IDENTIFIER;
057            } else{
058                    return ClassPanelSparqlDescriptor.IDENTIFIER;
059            }
060        }
061        
062        @Override
063            public Object getBackPanelDescriptor() {
064            return IntroductionPanelDescriptor.IDENTIFIER;
065        }
066        
067        
068        @Override
069            public void aboutToDisplayPanel() {
070            getWizard().getInformationField().setText(INFORMATION);
071            setNextButtonAccordingToExistingOWLFile();
072        }    
073    
074        /**
075         * Actions for buttons.
076         * @param e ActionListener
077         */
078        public void actionPerformed(ActionEvent e) {
079            String cmd = e.getActionCommand();
080            if(cmd.equals("browse")){
081                            knowledgePanel.openFileChooser();
082                    }else if(cmd.equals("OWL")){
083                            knowledgePanel.setOWLMode();
084                            getWizard().setKnowledgeSourceType(0);
085                    }else if(cmd.equals("SPARQL")){
086                            knowledgePanel.setSPARQLMode();
087                            getWizard().setKnowledgeSourceType(1);
088                    }
089                    
090            setNextButtonAccordingToExistingOWLFile();
091        }
092        
093      
094                
095        
096        private void setNextButtonAccordingToExistingOWLFile() {
097             
098            if (knowledgePanel.isExistingOWLFile()){
099                    getWizardModel().getOre().setKnowledgeSource(knowledgePanel.getOWLFile());
100                    getWizard().setNextFinishButtonEnabled(true);
101            }else{
102                getWizard().setNextFinishButtonEnabled(false); 
103            }
104        
105        }
106       
107    
108            public void changedUpdate(DocumentEvent e) {
109                    setNextButtonAccordingToExistingOWLFile();
110                    
111            }
112    
113            public void insertUpdate(DocumentEvent e) {
114                    setNextButtonAccordingToExistingOWLFile();
115                    
116            }
117    
118            public void removeUpdate(DocumentEvent e) {
119                    setNextButtonAccordingToExistingOWLFile();
120                    
121            }
122        public KnowledgeSourcePanel getPanel() {
123                    return knowledgePanel;
124            }
125      
126    
127    }