root/trunk/plugins/GexPlugin/src/org/pathvisio/plugins/gex/GexPlugin.java @ 3128

Revision 3128, 3.5 KB (checked in by martijn, 6 months ago)

Updated to new org.bridgedb.rdb.construct pacakge

Line 
1// PathVisio,
2// a tool for data visualization and analysis using Biological Pathways
3// Copyright 2006-2009 BiGCaT Bioinformatics
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17package org.pathvisio.plugins.gex;
18
19import java.awt.event.ActionEvent;
20
21import javax.swing.AbstractAction;
22import javax.swing.JOptionPane;
23
24import org.bridgedb.rdb.construct.DBConnector;
25import org.pathvisio.data.DBConnectorSwing;
26import org.pathvisio.debug.Logger;
27import org.pathvisio.gui.swing.PvDesktop;
28import org.pathvisio.plugin.Plugin;
29
30/**
31 * This plugin enables Gex functionality. Currently only adds menu items
32 * to import or load a Gex
33 * @author thomas
34 */
35public class GexPlugin implements Plugin {
36
37        public void init(PvDesktop desktop)
38        {
39                ImportGexDataAction importAction = new ImportGexDataAction(desktop);
40                SelectGexAction selectAction = new SelectGexAction(desktop);
41
42                desktop.registerMenuAction ("Data", importAction);
43                desktop.registerMenuAction ("Data", selectAction);
44        }
45
46        public void done() {};
47
48        /**
49         * Import gex data and create a new gex database from it
50         */
51        public static class ImportGexDataAction extends AbstractAction
52        {
53                private static final long serialVersionUID = 1L;
54
55                private final PvDesktop sae;
56
57                public ImportGexDataAction(PvDesktop sae)
58                {
59                        super();
60                        this.sae = sae;
61                        putValue (NAME, "Import expression data");
62                        putValue (SHORT_DESCRIPTION, "Import data from a tab delimited text file, for example experimental data from a high-throughput experiment");
63                }
64
65                public void actionPerformed (ActionEvent e)
66                {
67                        GexImportWizard wizard = new GexImportWizard(sae);
68                        wizard.showModalDialog(sae.getSwingEngine().getFrame());
69                }
70        }
71
72        /**
73         * Let the user open an expression dataset
74         * @author thomas
75         */
76        public static class SelectGexAction extends AbstractAction
77        {
78                private static final long serialVersionUID = 1L;
79                private final PvDesktop se;
80
81                public SelectGexAction(PvDesktop standaloneEngine) {
82                        se = standaloneEngine;
83                        putValue(NAME, "Select expression dataset");
84                        putValue(SHORT_DESCRIPTION, "Select expression dataset");
85                }
86
87                public void actionPerformed(ActionEvent e) {
88                        try
89                        {
90                                /**
91                                 * Get the preferred database connector to connect to Gex databases,
92                                 * and try to cast it to swingDbConnector.
93                                 * throws an exception if that fails
94                                 */
95                                DBConnectorSwing dbcon;
96                                DBConnector dbc = se.getGexManager().getDBConnector();
97                                if(dbc instanceof DBConnectorSwing)
98                                {
99                                        dbcon = (DBConnectorSwing)dbc;
100                                }
101                                else
102                                {
103                                        //TODO: better handling of error
104                                        throw new IllegalArgumentException("Not a Swing database connector");
105                                }
106                                String dbName = dbcon.openChooseDbDialog(null);
107
108                                if(dbName == null) return;
109
110                                se.getGexManager().setCurrentGex(dbName, false);
111                                se.loadGexCache();
112                        }
113                        catch(Exception ex)
114                        {
115                                String msg = "Failed to open expression dataset; " + ex.getMessage();
116                                JOptionPane.showMessageDialog(null,
117                                                "Error: " + msg + "\n\n" + "See the error log for details.",
118                                                "Error",
119                                                JOptionPane.ERROR_MESSAGE);
120                                Logger.log.error(msg, ex);
121                        }
122                }
123        }
124}
Note: See TracBrowser for help on using the browser.