001/*
002 * Copyright (c) 1998-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2012-09-14 23:58:50 +0000 (Fri, 14 Sep 2012) $' 
007 * '$Revision: 30684 $'
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.kepler.gui;
031
032import java.awt.BorderLayout;
033import java.awt.event.ActionEvent;
034
035import javax.swing.AbstractAction;
036import javax.swing.JPanel;
037
038import org.apache.commons.logging.Log;
039import org.apache.commons.logging.LogFactory;
040
041import ptolemy.actor.gui.PtolemyFrame;
042import ptolemy.actor.gui.TableauFrame;
043import ptolemy.kernel.CompositeEntity;
044import ptolemy.kernel.util.IllegalActionException;
045import ptolemy.kernel.util.NameDuplicationException;
046import ptolemy.kernel.util.NamedObj;
047
048public class WorkflowOutlineTabPane extends JPanel implements TabPane {
049        private static final Log log = LogFactory
050                        .getLog(WorkflowOutlineTabPane.class.getName());
051        private static final boolean isDebugging = log.isDebugEnabled();
052
053        private TableauFrame _frame;
054        private String _tabName;
055
056        /** The outline panel object. */
057        private WorkflowOutlinePanel _outlinePanel;
058        
059        /** The search panel. */
060        private SearchUIJPanel _searchUIJPanel;
061        
062        public WorkflowOutlineTabPane() {
063        }
064
065        /*
066         * (non-Javadoc)
067         * 
068         * @see org.kepler.gui.TabPane#initializeTab()
069         */
070        public void initializeTab() throws Exception {
071                if (isDebugging) log.debug("initializeTab()");
072                this.setLayout(new BorderLayout());
073                
074                _initializeSearchPanel();
075                add(_searchUIJPanel, BorderLayout.NORTH);
076                
077                CompositeEntity entity = (CompositeEntity) ((PtolemyFrame) _frame).getModel();
078                _outlinePanel = new WorkflowOutlinePanel(entity, true, true, true);
079                add(_outlinePanel, BorderLayout.CENTER);
080        }       
081
082        /*
083         * (non-Javadoc)
084         * 
085         * @see org.kepler.gui.TabPane#getParentFrame()
086         */
087        public TableauFrame getParentFrame() {
088                return _frame;
089        }
090
091        /*
092         * (non-Javadoc)
093         * 
094         * @see org.kepler.gui.TabPane#getTabName()
095         */
096        public String getTabName() {
097                return _tabName;
098        }
099
100        public void setTabName(String tabName) {
101                _tabName = tabName;
102        }
103
104        /*
105         * (non-Javadoc)
106         * 
107         * @see
108         * org.kepler.gui.TabPane#setParentFrame(ptolemy.actor.gui.TableauFrame)
109         */
110        public void setParentFrame(TableauFrame parent) {
111                _frame = parent;
112        }
113        
114        /** Change the root of the workflow displayed in the tab. */
115        public void setWorkflow(CompositeEntity composite) {
116            _outlinePanel.initialize(composite);
117        }
118
119           /** Initialize the search panel. */
120    private void _initializeSearchPanel() {
121        
122        _searchUIJPanel = new SearchUIJPanel();
123        _searchUIJPanel.setBorderTitle("Search Workflow");
124        
125        // add action for search button
126        _searchUIJPanel.setSearchAction(new AbstractAction() {
127            public void actionPerformed(ActionEvent e) {
128                _searchUIJPanel.setCancelButtonEnabled(true);
129                String term = _searchUIJPanel.getSearchTerm();
130                _outlinePanel.search(term.trim());
131            }
132        });
133
134        // add action for cancel button, and on mac when X
135        // is pressed in search field
136        _searchUIJPanel.setCancelAction(new AbstractAction() {
137            public void actionPerformed(ActionEvent e) {
138                _searchUIJPanel.setCancelButtonEnabled(false);
139                _outlinePanel.search("");
140            }
141        });
142
143        _searchUIJPanel.init();
144    }
145
146        /**
147         * A factory that creates the library panel for the editors.
148         * 
149         *@author Aaron Schultz
150         */
151        public static class Factory extends TabPaneFactory {
152                /**
153                 * Create a factory with the given name and container.
154                 * 
155                 *@param container
156                 *            The container.
157                 *@param name
158                 *            The name of the entity.
159                 *@exception IllegalActionException
160                 *                If the container is incompatible with this attribute.
161                 *@exception NameDuplicationException
162                 *                If the name coincides with an attribute already in the
163                 *                container.
164                 */
165                public Factory(NamedObj container, String name)
166                                throws IllegalActionException, NameDuplicationException {
167                        super(container, name);
168                }
169
170                /**
171                 * Create a library pane that displays the given library of actors.
172                 * 
173                 * @return A new LibraryPaneTab that displays the library
174                 */
175                public TabPane createTabPane(TableauFrame parent) {
176                        WorkflowOutlineTabPane wotp = new WorkflowOutlineTabPane();
177                        wotp.setTabName(this.getName());
178                        return wotp;
179                }
180        }
181}