package com.mockturtlesolutions.jpHtools.manager;
//Copyright (C) 2005 Daniel P. Dougherty
//
//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 2 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, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//$Id: jpHtoolsManagerFrame.java,v 1.4 2007/06/20 00:39:07 mock_turtle Exp $
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.Box;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.Container;
import java.awt.event.*;
import java.awt.Dimension;
import com.mockturtlesolutions.jpHtools.database.*;
import com.mockturtlesolutions.snifflib.guitools.components.*;
import com.mockturtlesolutions.snifflib.reposconfig.database.*;
import com.mockturtlesolutions.snifflib.reposconfig.graphical.ReposConfigFrame;
import com.mockturtlesolutions.snifflib.graphics.*;
import com.mockturtlesolutions.snifflib.datatypes.DblMatrix;
import com.mockturtlesolutions.snifflib.datatypes.DataSet;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.util.Vector;
public class jpHtoolsManagerFrame extends JFrame
{
private JButton srcRepos;
//private JButton destRepos;
private JButton expClean;
private JButton buffClean;
private Container contentPane;
private ActionListener okcancelListener;
private JButton okButton;
private JButton cancelButton;
private ReposConfigFrame srcEditor;
private ReposConfigFrame destEditor;
private FindNameDialog expFind;
private FindNameDialog buffFind;
protected pHtoolsConfig Config;
private pHtoolsConnection Connection;
protected pHtoolsPrefs Prefs;
private IconServer iconServer;
private Vector selectedBuffers;
private Vector selectedExperiments;
public jpHtoolsManagerFrame()
{
super("Manage repositories...");
this.selectedExperiments = new Vector();
this.selectedBuffers = new Vector();
this.setSize(400,400);
this.contentPane = this.getContentPane();
this.contentPane.setLayout(new BoxLayout(this.contentPane,BoxLayout.Y_AXIS));
this.iconServer = new PhtoolsIconServer();
this.Config = new pHtoolsConfig();
this.Config.initialize();
this.Prefs = new pHtoolsPrefs();
this.Prefs.initialize();
this.Connection = new pHtoolsConnection(this.Config);
this.srcEditor = new ReposConfigFrame(this.Config);
this.srcEditor.setVisible(false);
this.srcEditor.addSelectListener(new SrcSelectListener());
Box reposBox = Box.createHorizontalBox();
JLabel srcLabel = new JLabel("Repository");
this.srcRepos = new JButton("default");
this.srcRepos.addActionListener(new ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
selectedExperiments = new Vector();
selectedBuffers = new Vector();
srcEditor.setVisible(true);
}
}
);
srcLabel.setLabelFor(this.srcRepos);
Box srcBox = Box.createVerticalBox();
srcBox.add(srcLabel);
srcBox.add(this.srcRepos);
reposBox.add(srcBox);
Box cleanBox = Box.createVerticalBox();
JLabel transLabel = new JLabel("Remove disabled...");
this.expClean = new JButton("Experiments");
this.buffClean = new JButton("Buffers");
this.buffClean.setSize(this.expClean.getSize());
this.buffClean.setMaximumSize(this.expClean.getMaximumSize());
this.buffClean.setPreferredSize(this.expClean.getPreferredSize());
this.expFind = new FindNameDialog(this.Config,this.iconServer,FindNameDialog.EXPERIMENT_SEARCH);
this.expFind.setEnabled(false);
this.expFind.setEnabledEnabled(false);
this.buffFind = new FindNameDialog(this.Config,this.iconServer,FindNameDialog.BUFFER_SEARCH);
this.buffFind.setEnabled(false);
this.buffFind.setEnabledEnabled(false);
this.expFind.setVisible(false);
this.expFind.setMaxSelections(-1); //Arbitrary number of selections.
this.buffFind.setVisible(false);
this.buffFind.setMaxSelections(-1); //Arbitrary number of selections.
this.expFind.addOkListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String[] sel = (String[])expFind.getSelectedNames();
selectedExperiments = new Vector();
for (int k=0;k<sel.length;k++)
{
selectedExperiments.add(sel[k]);
}
expFind.setVisible(false);
}
}
);
this.expFind.addCancelListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
expFind.setVisible(false);
}
}
);
this.buffFind.addOkListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String[] sel = (String[])buffFind.getSelectedNames();
selectedBuffers = new Vector();
for (int k=0;k<sel.length;k++)
{
selectedBuffers.add(sel[k]);
}
buffFind.setVisible(false);
}
}
);
this.buffFind.addCancelListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
buffFind.setVisible(false);
}
}
);
this.expClean.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String restrict_repos = srcRepos.getText();
expFind.restrictToRepository(restrict_repos);
expFind.setVisible(true);
}
}
);
this.buffClean.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String restrict_repos = srcRepos.getText();
buffFind.restrictToRepository(restrict_repos);
buffFind.setVisible(true);
}
}
);
cleanBox.add(transLabel);
cleanBox.add(this.expClean);
cleanBox.add(this.buffClean);
Box aBox = Box.createHorizontalBox();
aBox.add(Box.createHorizontalGlue());
aBox.add(reposBox);
aBox.add(Box.createHorizontalGlue());
Box bBox = Box.createHorizontalBox();
bBox.add(Box.createHorizontalGlue());
bBox.add(cleanBox);
bBox.add(Box.createHorizontalGlue());
TitledBorder border = BorderFactory.createTitledBorder("Purge disabled:");
Box removeBox = Box.createVerticalBox();
removeBox.add(aBox);
//removeBox.add(Box.createVerticalGlue());
removeBox.add(bBox);
removeBox.add(Box.createVerticalGlue());
removeBox.setBorder(border);
//this.add(removeBox);
// border = BorderFactory.createTitledBorder("Optimizer settings:");
// JButton optimizerbut = new JButton("Configure optimizer...");
// Box optimizerBox = Box.createHorizontalBox();
// optimizerBox.add(Box.createHorizontalGlue());
// optimizerBox.add(optimizerbut);
// optimizerBox.add(Box.createHorizontalGlue());
// optimizerBox.setBorder(border);
// //this.add(optimizerBox);
Box organizeThingsBox = Box.createVerticalBox();
//organizeThingsBox.add(optimizerBox);
organizeThingsBox.add(removeBox);
this.add(organizeThingsBox);
//
this.okButton = new JButton("Ok");
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
pHtoolsConnection Connection = null;
pHtoolsConfig Config = null;
Config = new pHtoolsConfig();
Config.initialize();
Connection = new pHtoolsConnection(Config);
//String[] repos = Config.getRepositories();
String repos = srcRepos.getText();
try
{
if (Config.isEnabled(repos))
{
jpHtoolsManagement man = (jpHtoolsManagement)Connection.getManager(repos);
man.cleanOnlyExperiments(selectedExperiments);
man.cleanOnlyBuffers(selectedBuffers);
man.cleanExperiments();
man.cleanBuffers();
}
// for (int j=0;j<repos.length;j++)
// {
//
// jpHtoolsManagement man = (jpHtoolsManagement)Connection.getManager(repos[j]);
//
// man.cleanExperiments();
// man.cleanBuffers();
// }
}
catch (Exception err)
{
throw new RuntimeException("Problem performing transfer.",err);
}
if (okcancelListener != null)
{
okcancelListener.actionPerformed(e);
}
}
}
);
this.cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//nameText.setText(name);
//System.out.println("Cancel pushed");
if (okcancelListener != null)
{
//System.out.println("Listener not null");
okcancelListener.actionPerformed(e);
}
//setVisible(false);
}
}
);
Box controlBox = Box.createHorizontalBox();
controlBox.add(Box.createHorizontalGlue());
controlBox.add(this.okButton);
controlBox.add(this.cancelButton);
controlBox.add(Box.createHorizontalGlue());
this.add(controlBox);
//this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.pack();
this.setVisible(false);
}
private class SrcSelectListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
srcRepos.setText(srcEditor.getCurrentRepository());
srcEditor.setVisible(false);
}
}
// private class DestSelectListener implements ActionListener
// {
// public void actionPerformed(ActionEvent e)
// {
// destRepos.setText(destEditor.getCurrentRepository());
// destEditor.setVisible(false);
//
// }
// }
//
public void setOkCancelListener(ActionListener listen)
{
this.okcancelListener = listen;
}
public void showError(String msg)
{ JOptionPane dialog = new JOptionPane();
JTextArea area = new JTextArea(msg);
JScrollPane jsp = new JScrollPane(area);
jsp.setPreferredSize(new Dimension(500,200));
dialog.showMessageDialog(this,jsp,"Error",JOptionPane.ERROR_MESSAGE);
}
}