001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    package graphlab.plugins.reports.extension;
005    
006    import graphlab.platform.core.AbstractAction;
007    import graphlab.platform.core.BlackBoard;
008    import graphlab.platform.extension.ExtensionHandler;
009    import graphlab.plugins.reports.ui.ReportsUI;
010    
011    /**
012     * @author azin azadi
013    
014     */
015    public class GraphReportExtensionHandler implements ExtensionHandler {
016        protected AbstractAction a = null;
017        public static final String REPORTS_UI = "reports ui";
018        public static final String REPORTS_SIDEBAR = "reports side_bar";
019    
020        /**
021         * @return null if ext doesn't implements GraphGeneratorExtension
022         */
023        public AbstractAction handle(BlackBoard b, Object ext) {
024            a = null;
025            if (ext instanceof GraphReportExtension) {
026                try {
027                    ReportsUI rsd = b.getData(REPORTS_UI);
028                    ReportsUI sb = b.getData(REPORTS_SIDEBAR);
029                    if (rsd == null) {
030                        rsd = new ReportsUI(b, true);
031                        sb = new ReportsUI(b, false);
032                        b.setData(REPORTS_UI, rsd);
033                        b.setData(REPORTS_SIDEBAR, sb);
034                    }
035                    GraphReportExtension gr = (GraphReportExtension) ext;
036                    a = new GraphReportExtensionAction(b, gr);
037                    rsd.addReport(gr);
038                    sb.addReport(gr);
039                } catch (Exception e) {
040                    e.printStackTrace();
041                }
042            }
043            return a;
044        }
045    
046    }