Package jsynoptic.data

Source Code of jsynoptic.data.DataSourceCollectionAnimatorProvider

/* ========================
* 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 2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: DataSourceCollectionAnimatorProvider.java,v 1.4 2007/06/05 14:17:45 ogor Exp $
*
* Changes
* -------
* 24-Nov-2003 : Creation date (NB);
*
*/
package jsynoptic.data;

import java.util.Iterator;

import javax.swing.JOptionPane;
import jsynoptic.ui.JSynoptic;
import simtools.data.CollectiveDataSource;
import simtools.data.DataInfo;
import simtools.data.DataSource;
import simtools.data.DataSourceCollection;
import simtools.data.DataSourcePool;
import simtools.data.DefaultEmptyDataSource;
import simtools.data.DuplicateIdException;
import simtools.data.EmptyDataSource;
import simtools.data.EmptyDataSourcePool;
import simtools.data.buffer.BufferedDataSource;
import simtools.ui.BasicMessageWriter;
import simtools.ui.ResourceFinder;

/**
* Overloads the collection animator and provides actions for the popup menu in the source tree
*/
public class DataSourceCollectionAnimatorProvider extends simtools.data.DataSourceCollectionAnimatorProvider {

 

    public static BasicMessageWriter resources =  ResourceFinder.getMessages((DataSourceProvider.class));
  
   
   
   /*
    * Same method as DataSourceProvider...
    * (non-Javadoc)
     * @see simtools.data.BasicDataSourceProvider#chooseUseCollection(simtools.data.DataSourceCollection, java.lang.String, java.lang.String)
     */
    public int chooseUseCollection(DataSourceCollection existingDsc, String dscId, String id) {
      if (JSynoptic.gui!=null) {
        return JOptionPane.showConfirmDialog(
            JSynoptic.gui.getOwner(),
            new String[] {
              resources.print0args("dscReplaceMsg1"),
              id,
              resources.print0args("dscReplaceMsg2"),
              DataInfo.getId(existingDsc),
              resources.print0args("dscReplaceMsg3"),
              dscId
            },
            resources.print0args("dscReplaceTitle"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE
        );
      }else {
        return super.chooseUseCollection(existingDsc, dscId, id);
      }
    } 
   
    public DataSource provide(String id, String dscId, Object optionalInformation, DataSourcePool pool) {
    if (! (optionalInformation instanceof Object[]))
      return null;

    if (!((Object[])optionalInformation)[0].equals(marker))
      return null;

    if (!dscId.startsWith(marker))
      return null;


    dscId = dscId.substring(marker.length());

    // Try to get data source from pool
    // If conflicts with other data source collections, consider the fisrt DataSourceCollectionAnimator
    DataSourceCollection existingDsc=null;
    if (pool != null){
      try {
        existingDsc = pool.getCollectionForDataSourceId(id);
      } catch (DuplicateIdException e) {
        //  Eliminates the collections that are not TimeStamped
        for (Iterator it = e.conflicts.iterator(); it.hasNext();) {
          DataSourceCollection d = (DataSourceCollection) it.next();
          if (!(d instanceof DataSourceCollectionAnimator)){
            it.remove();
            continue;
          }
        }
        if (e.conflicts.size() == 0)
          existingDsc = null;

        else if (e.conflicts.size() > 0)
          existingDsc = (DataSourceCollectionAnimator) e.conflicts.get(0);
      }
    }

    if ( (existingDsc!=null) &&  (existingDsc instanceof DataSourceCollectionAnimator)){
      if (chooseUseCollection(existingDsc, dscId, id)==YES_OPTION)
        return existingDsc.get(id);
    }


    // Otherwise create a new collection
    long period = ((Long)(((Object[])optionalInformation)[1])).longValue();
    boolean autostop = ((Boolean)(((Object[])optionalInformation)[2])).booleanValue();
    Object realOption = ((Object[])optionalInformation)[3];

    DataSourcePool poolToSearch = pool;
    if (pool==null) poolToSearch=DataSourcePool.global;

    // Do not add the result in the datapool yet, but rather add this object on success
    DataSource ds = poolToSearch.provide(id,dscId,realOption,false);
    if (ds==null) return null;

    if (ds instanceof EmptyDataSource){
      DefaultEmptyDataSource emptyDs = new DefaultEmptyDataSource(id, marker + dscId, optionalInformation);
      EmptyDataSourcePool.global.addEmptyDaSource(id, emptyDs);
          return emptyDs;
    }
   
    if (ds instanceof BufferedDataSource) ds = ((BufferedDataSource)ds).dataSource;
    if (!(ds instanceof CollectiveDataSource)) return null;
    DataSourceCollection dsc = ((CollectiveDataSource)ds).getCollection();
    int i = ((CollectiveDataSource)ds).getPosition();

    DataSourceCollectionAnimator dsca = new DataSourceCollectionAnimator(dsc);
    dsca.setPeriod(period);
    dsca.setAutoStop(autostop);

    if (pool!=null) pool.addDataSourceCollection(dsca);

    return (DataSource)dsca.get(i);
  }
}
TOP

Related Classes of jsynoptic.data.DataSourceCollectionAnimatorProvider

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.