Package jsynoptic.plugins.merge

Source Code of jsynoptic.plugins.merge.JSMergeDSCollectionProvider

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*
* (C) Copyright 2001-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: JSMergeDSCollectionProvider.java,v 1.2 2008/04/08 11:54:11 ogor Exp $
*
* Changes
* -------
* 18 mai 2006  : Initial public release (CC);
*
*/
package jsynoptic.plugins.merge;

import javax.swing.JOptionPane;

import jsynoptic.plugins.merge.JSAsynchronousMergeDSCollection.AsynchronousMergeDSCollectionInformation;
import jsynoptic.plugins.merge.JSSynchronousMergeDSCollection.SynchronousMergeDSCollectionInformation;
import jsynoptic.ui.JSynoptic;
import simtools.data.DataSource;
import simtools.data.DataSourceCollection;
import simtools.data.DataSourcePool;
import simtools.data.DataSourceProvider;
import simtools.data.merge.MergeDataException;
import simtools.ui.ReportingDialog;

/**
* Get MergedCollection back from ids...
* @author zxpletran007
*
*/
public class JSMergeDSCollectionProvider implements  DataSourceProvider{


  /* (non-Javadoc)
   * @see simtools.data.DataSourceProvider#getOptionalInformation(simtools.data.DataSource, simtools.data.DataSourceCollection)
   */
  public Object getOptionalInformation(DataSource ds, DataSourceCollection dsc){
    if (dsc instanceof JSAsynchronousMergeDSCollection)
      return ((JSAsynchronousMergeDSCollection)dsc).getMergeInformation();

    if (dsc instanceof JSSynchronousMergeDSCollection)
      return ((JSSynchronousMergeDSCollection)dsc).getMergeInformation();

    return null;
  }
 
 
  /* (non-Javadoc)
   * @see simtools.data.DataSourceProvider#provide(java.lang.String, java.lang.String, java.lang.Object, simtools.data.DataSourcePool)
   */
  public DataSource provide(String id, String dscId, Object optionalInformation, DataSourcePool pool){
    if ((id==null) || (dscId==null) || !(dscId.startsWith(JSAsynchronousMergeDSCollection.ID_MARKER) || dscId.startsWith(JSSynchronousMergeDSCollection.ID_MARKER)))
      return null;

    DataSource foundDS = null;
    DataSourceCollection adsc = null;
   
    MergeDataException.mergeDataErrors.clear();   // clear merge errors list
    try {
     
      if (dscId.startsWith(JSAsynchronousMergeDSCollection.ID_MARKER))
        adsc = new JSAsynchronousMergeDSCollection((AsynchronousMergeDSCollectionInformation)optionalInformation);
      else
        adsc = new JSSynchronousMergeDSCollection((SynchronousMergeDSCollectionInformation)optionalInformation);

      if ((adsc==null) || !(adsc instanceof DataSourceCollection)){
        return null;
      }
      for (int i = 0; i < adsc.size(); ++i) {
        if (id.equals( adsc.getInformation(i).id)) {
          foundDS = (DataSource) adsc.get(i);
          break;
        }
      }
    } catch (Exception e) {} 

    // Diplay merge errorrs list
    // Display warnings and errors messages
    if (!MergeDataException.mergeDataErrors.isEmpty()) {
        JOptionPane.showMessageDialog(
                JSynoptic.gui.getOwner(),
                new ReportingDialog(
                        "Following errors have occured during merging process:",
                        MergeDataException.mergeDataErrors
                ),
                "Merging process errors",
                JOptionPane.INFORMATION_MESSAGE
        );
    }

   
    if ( (foundDS != null) && (adsc!=null) && (pool != null))
      pool.addDataSourceCollection(adsc);
    return foundDS;
  }




}
TOP

Related Classes of jsynoptic.plugins.merge.JSMergeDSCollectionProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.