weka.gui.beans.SQLViewerPerspective Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weka-stable Show documentation
Show all versions of weka-stable Show documentation
The Waikato Environment for Knowledge Analysis (WEKA), a machine
learning workbench. This is the stable version. Apart from bugfixes, this version
does not receive any other updates.
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/*
* SQLViewerPerspective.java
* Copyright (C) 2011-2012 University of Waikato, Hamilton, New Zealand
*
*/
package weka.gui.beans;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.beancontext.BeanContextSupport;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPanel;
import weka.core.Instances;
import weka.core.converters.DatabaseLoader;
import weka.gui.beans.KnowledgeFlowApp.MainKFPerspective;
import weka.gui.sql.SqlViewer;
import weka.gui.sql.event.ConnectionEvent;
import weka.gui.sql.event.ConnectionListener;
/**
* Simple Knowledge Flow perspective that wraps the SqlViewer class
*
* @author Mark Hall (mhall{[at]}pentaho{[dot]}com)
* @version $Revision: 11286 $
*/
public class SQLViewerPerspective extends JPanel implements
KnowledgeFlowApp.KFPerspective {
/**
* For serialization
*/
private static final long serialVersionUID = 3684166225482042972L;
protected MainKFPerspective m_mainPerspective;
protected SqlViewer m_viewer;
protected JButton m_newFlowBut;
/**
* Constructor
*/
public SQLViewerPerspective() {
setLayout(new BorderLayout());
m_viewer = new SqlViewer(null);
add(m_viewer, BorderLayout.CENTER);
m_newFlowBut = new JButton("New Flow");
m_newFlowBut.setToolTipText("Set up a new Knowledge Flow with the "
+ "current connection and query");
JPanel butHolder = new JPanel();
butHolder.add(m_newFlowBut);
add(butHolder, BorderLayout.SOUTH);
m_newFlowBut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (m_mainPerspective != null) {
newFlow();
}
}
});
m_newFlowBut.setEnabled(false);
m_viewer.addConnectionListener(new ConnectionListener() {
@Override
public void connectionChange(ConnectionEvent evt) {
if (evt.getType() == ConnectionEvent.DISCONNECT) {
m_newFlowBut.setEnabled(false);
} else {
m_newFlowBut.setEnabled(true);
}
}
});
}
protected void newFlow() {
m_newFlowBut.setEnabled(false);
String user = m_viewer.getUser();
String password = m_viewer.getPassword();
String uRL = m_viewer.getURL();
String query = m_viewer.getQuery();
if (query == null) {
query = "";
}
try {
DatabaseLoader dbl = new DatabaseLoader();
dbl.setUser(user);
dbl.setPassword(password);
dbl.setUrl(uRL);
dbl.setQuery(query);
BeanContextSupport bc = new BeanContextSupport();
bc.setDesignTime(true);
Loader loaderComp = new Loader();
bc.add(loaderComp);
loaderComp.setLoader(dbl);
KnowledgeFlowApp singleton = KnowledgeFlowApp.getSingleton();
m_mainPerspective.addTab("DBSource");
// The process of creating a BeanInstance integrates will result
// in it integrating itself into the flow in the specified tab
new BeanInstance(m_mainPerspective.getBeanLayout(m_mainPerspective
.getNumTabs() - 1), loaderComp, 50, 50,
m_mainPerspective.getNumTabs()
- 1);
// Vector