001/*
002 * Copyright (c) 2004-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.ecoinformatics.seek.ecogrid;
031
032import java.awt.event.ActionEvent;
033import java.util.Vector;
034
035import javax.swing.AbstractAction;
036
037import org.apache.commons.logging.Log;
038import org.apache.commons.logging.LogFactory;
039
040/**
041 * This action will add selected service in registry search reslut frame to
042 * current service search frame.
043 * 
044 * @author Jing Tao
045 * 
046 */
047
048public class AddServicesFromRegistrySearchAction extends AbstractAction {
049        private EcogridPreferencesTab current = null;
050        private EcogridPreferencesTab parent = null;
051        private static Log log;
052
053        static {
054                log = LogFactory
055                                .getLog("org.ecoinformatics.seek.ecogrid.AddServicesFromRegistrySearchAction");
056        }
057
058        /**
059         * Constructor
060         * 
061         * @param name
062         *            String
063         * @param current
064         *            ServicesDisplayFrame
065         * @param parent
066         *            ServicesDisplayFrame
067         */
068        public AddServicesFromRegistrySearchAction(String name,
069                        EcogridPreferencesTab current, EcogridPreferencesTab parent) {
070                super(name);
071                this.current = current;
072                this.parent = parent;
073        }// AddServicesFromRegistrySearchAction
074
075        public void actionPerformed(ActionEvent e) {
076                if (current != null) {
077                        ServicesDisplayPanel displayPanel = current
078                                        .getServicesDisplayPanel();
079                        EcoGridServicesController controller = parent
080                                        .getEcoGridServicesController();
081                        // get the selected service list
082                        Vector allSelectedService = displayPanel
083                                        .getAllSelectedServicesList();
084                        Vector partialSelectedService = displayPanel
085                                        .getPartialSelectedServicesList();
086                        // add service list to controller
087                        addSerivcesVectorToController(controller, allSelectedService);
088                        addSerivcesVectorToController(controller, partialSelectedService);
089
090                        // create a another current service list display frame
091                        if (controller != null) {
092                                Vector currentServiceList = controller.getServicesList();
093                                /*
094                                 * Vector defaultSelectedServiceList =SelectableEcoGridService.
095                                 * transferServiceVectToDefaultSelectedServiceVect
096                                 * (currentServiceList);
097                                 */
098                                //current.setVisible(false);
099                                //current.dispose();
100                                //current = null;
101
102                                EcogridPreferencesTab frame = new EcogridPreferencesTab();
103                                Vector original = parent.getOriginalServiceList();
104
105                                frame.setOriginalServiceList(original);
106                                frame.updateButtonPanel();
107                                //parent.setVisible(false);
108                                //parent.dispose();
109                                //parent = null;
110
111                        }// if
112                }// if
113        }// actionPerformed
114
115        /*
116         * Method to add vector a service to a controller
117         */
118        private void addSerivcesVectorToController(
119                        EcoGridServicesController controller, Vector serviceList) {
120                if (controller != null) {
121                        if (serviceList != null) {
122                                int size = serviceList.size();
123                                for (int i = 0; i < size; i++) {
124                                        EcoGridService service = (EcoGridService) serviceList
125                                                        .elementAt(i);
126                                        try {
127                                                controller.addService(service);
128                                        } catch (Exception ee) {
129                                                log.debug("The error adding service is ", ee);
130                                        }
131                                }// for
132                        }// if
133                }// if
134        }// addSerivcesVectorToController
135}// AddServicesFromRegistrySearchAction