All Downloads are FREE. Search and download functionalities are using the official Maven repository.

decodes.tsdb.compedit.AlgorithmsListPanel Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!
/*
*  $Id$
*
*  This is open-source software written by ILEX Engineering, Inc., under
*  contract to the federal government. You are free to copy and use this
*  source code for your own purposes, except that no part of the information
*  contained in this file may be claimed to be proprietary.
*
*  Except for specific contractual terms between ILEX and the federal
*  government, this source code is provided completely without warranty.
*  For more information contact: [email protected]
*/
package decodes.tsdb.compedit;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.util.*;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import opendcs.dai.AlgorithmDAI;

import decodes.db.Constants;
import decodes.gui.SortingListTable;
import decodes.gui.SortingListTableModel;

import decodes.tsdb.*;
import decodes.tsdb.compedit.algotab.LoadNewDialog;

public class AlgorithmsListPanel extends ListPanel
{
	private static final Logger log = LoggerFactory.getLogger(AlgorithmsListPanel.class);
	JPanel getFieldPanel() {
		return getJContentPane();
	}

	private JPanel jContentPane = null;

	JTable algoListTable = null;

	AlgoListTableModel algoListTableModel = null;

	private String openErr;
	private String newInputText;
	private String newError;
	private String cpyErr1;
	private String cpyErr2;
	private String cpyInput;
	private String deleteErr1;
	private String deleteErr2;

	AlgorithmsListPanel() {
		setLayout(new BorderLayout());
		fillLabels();
		this.add(getJContentPane(), java.awt.BorderLayout.CENTER);
	}

	private void fillLabels()
	{
		openErr = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.OpenError");
		newInputText = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.NewInputText");
		newError = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.NewError");
		cpyErr1 = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.CopyError1");
		cpyErr2 = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.CopyError2");
		cpyInput = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.CopyInput");
		deleteErr1 = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.DeleteError1");
		deleteErr2 = CAPEdit.instance().compeditDescriptions.getString("AlgorithmsListPanel.DeleteError2");
	}

	/**
	 * This method initializes jContentPane
	 *
	 * @return javax.swing.JPanel
	 */
	protected JPanel getJContentPane()
	{
		if (jContentPane == null)
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			JPanel buttonPanel = getButtonPanel();
			JButton checkForNew = new JButton(ResourceBundle.getBundle("ilex/resources/gui").getString("EditorMenuSet.checkForNew"));
			checkForNew.addActionListener(e -> checkForNew());
			buttonPanel.add(checkForNew);
			jContentPane.add(buttonPanel, java.awt.BorderLayout.SOUTH);
			JScrollPane scrollPane = new JScrollPane(getAlgoListTable());

			jContentPane.add(scrollPane, java.awt.BorderLayout.CENTER);
		}
		return jContentPane;
	}

	private void checkForNew()
	{

		LoadNewDialog loadNew = new LoadNewDialog(CAPEdit.instance().getFrame(), CAPEdit.theDb);
		log.info("Starting Load new dialog");
		if (loadNew.importNew())
		{
			new SwingWorker()
			{
				@Override
				protected Void doInBackground() throws Exception
				{
					AlgorithmsListPanel.this.algoListTableModel.fill();
					return null;
				}
			}.execute();
		}
	}

	protected JTable getAlgoListTable()
	{
		if (algoListTableModel == null)
		{
			algoListTableModel = new AlgoListTableModel();
			algoListTableModel.fill();
			algoListTable = new SortingListTable(algoListTableModel,
				AlgoListTableModel.columnWidths);
			algoListTable.addMouseListener(
				new MouseAdapter()
				{
					public void mouseClicked(MouseEvent e)
					{
						if (e.getClickCount() == 2)
						{
							doOpen();
						}
					}
				});
		}
		return algoListTable;
	}

	protected void doOpen()
	{
		int r = algoListTable.getSelectedRow();
		if (r == -1)
		{
			showError(openErr);
			return;
		}
		//Get the correct row from the table model
		int modelrow = algoListTable.convertRowIndexToModel(r);
		AlgoListTableModel tablemodel = (AlgoListTableModel)algoListTable.getModel();
		DbCompAlgorithm dca = (DbCompAlgorithm)tablemodel.getRowAlgorithm(modelrow);
		openEditTab(dca);
	}

	private void openEditTab(DbCompAlgorithm dca)
	{
		JTabbedPane tabbedPane =
			CAPEdit.instance().getAlgorithmsTab();
		int n = tabbedPane.getTabCount();
		for(int idx = 1; idx




© 2015 - 2024 Weber Informatics LLC | Privacy Policy