Statistics
| Revision:

gvsig-plugintemplates / org.gvsig.fortunecookies / trunk / basic-with-user-interface / org.gvsig.fortunecookies.app / org.gvsig.fortunecookies.app.mainplugin / src / main / java / org / gvsig / fortunecookies / app / mainplugin / FortuneCookieExtension.java @ 185

History | View | Annotate | Download (2.8 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fortunecookies.app.mainplugin;
23

    
24
import org.gvsig.andami.messages.NotificationManager;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.fortunecookies.FortuneCookieLocator;
27
import org.gvsig.fortunecookies.FortuneCookieManager;
28
import org.gvsig.fortunecookies.FortuneCookieService;
29
import org.gvsig.fortunecookies.swing.FortuneCookieSwingLocator;
30
import org.gvsig.fortunecookies.swing.FortuneCookieSwingManager;
31
import org.gvsig.fortunecookies.swing.JFortuneCookieServicePanel;
32
import org.gvsig.tools.service.ServiceException;
33
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
34

    
35
/**
36
 * Andami extension to show fortune cookies in the application.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class FortuneCookieExtension extends Extension {
42

    
43
    private FortuneCookieManager manager;
44
    private FortuneCookieSwingManager swingManager;
45

    
46
    public void initialize() {
47
        // Do nothing
48
    }
49

    
50
    @Override
51
    public void postInitialize() {
52
        super.postInitialize();
53
        manager = FortuneCookieLocator.getManager();
54
        // Asignamos el locator e iniciamos la instancia
55
        swingManager = FortuneCookieSwingLocator.getSwingManager();
56
    }
57

    
58
    public void execute(String actionCommand) {
59
        showFortuneCookie(manager);
60
    }
61

    
62
    public void showFortuneCookie(FortuneCookieManager manager) {
63
        try {
64
            FortuneCookieService service =
65
                (FortuneCookieService) manager.getFortuneCookieService();
66
            JFortuneCookieServicePanel panel =
67
                swingManager.createFortuneCookie(service);
68
            swingManager.getWindowManager().showWindow(panel, "Fortune Cookie",
69
                WindowManager.MODE.DIALOG);
70

    
71
        } catch (ServiceException e) {
72
            NotificationManager.addError(e);
73
        }
74
    }
75

    
76
    public boolean isEnabled() {
77
        return true;
78
    }
79

    
80
    public boolean isVisible() {
81
        return true;
82
    }
83

    
84
}