Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / RemoveTableUnion.java @ 24962

History | View | Annotate | Download (2.65 KB)

1
package com.iver.cit.gvsig;
2

    
3
import org.gvsig.fmap.dal.DALLocator;
4
import org.gvsig.fmap.dal.DataManager;
5
import org.gvsig.fmap.dal.DataStoreParameters;
6
import org.gvsig.fmap.dal.exception.CloseException;
7
import org.gvsig.fmap.dal.exception.InitializeException;
8
import org.gvsig.fmap.dal.feature.FeatureStore;
9
import org.gvsig.project.document.table.FeatureTableDocument;
10
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel;
11

    
12
import com.iver.andami.PluginServices;
13
import com.iver.andami.messages.NotificationManager;
14
import com.iver.andami.plugins.Extension;
15
import com.iver.andami.ui.mdiManager.IWindow;
16

    
17
/**
18
 * @author Fernando Gonz?lez Cort?s
19
 */
20
public class RemoveTableUnion extends Extension{
21

    
22
        /**
23
         * @see com.iver.andami.plugins.IExtension#initialize()
24
         */
25
        public void initialize() {
26
                // TODO Auto-generated method stub
27

    
28
        }
29

    
30
        /**
31
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
32
         */
33
        public void execute(String actionCommand) {
34
                FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) PluginServices.getMDIManager().getActiveWindow();
35
                FeatureTableDocument pt = t.getModel();
36
                FeatureStore fs = pt.getStore();
37
                if (fs instanceof JoinFeatureStore) {
38
                        DataManager dm = DALLocator.getDataManager();
39
                        DataStoreParameters originalParams = ((JoinFeatureStoreParameters) fs
40
                                        .getParameters()).getStorePrimary();
41
                        FeatureStore original = null;
42
                        try {
43
                                original = (FeatureStore) dm.createStore(originalParams);
44
                        } catch (InitializeException e) {
45
                                NotificationManager.addError(e.getMessage(), e);
46
                                return;
47
                        }
48

    
49
                        pt.setModel(original);
50
                        try {
51
                                fs.dispose();
52
                        } catch (CloseException e) {
53
                                NotificationManager.addError(e);
54
                        }
55
                        t.setModel(pt);
56

    
57
                }
58

    
59
                t.clearSelectedFields();
60
                t.getModel().setModified(true);
61
        }
62

    
63
        /**
64
         * @see com.iver.andami.plugins.IExtension#isEnabled()
65
         */
66
        public boolean isEnabled() {
67
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
68

    
69
                if (v == null) {
70
                        return false;
71
                }
72

    
73
                if (v.getClass() == FeatureTableDocumentPanel.class) {
74
                        FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) v;
75
                        // FIXME !!!! Asi se hacia antes
76
                        //                        if (t.getModel().getOriginal() != null){
77
                        //                                return true;
78
                        //                        }
79

    
80
                        FeatureTableDocument pt = t.getModel();
81
                        FeatureStore fs = pt.getStore();
82
                        if (fs instanceof JoinFeatureStore) {
83
                                return true;
84
                        }
85

    
86
                }
87
                return false;
88
        }
89

    
90
        /**
91
         * @see com.iver.andami.plugins.IExtension#isVisible()
92
         */
93
        public boolean isVisible() {
94
                IWindow v = PluginServices.getMDIManager().getActiveWindow();
95

    
96
                if (v == null) {
97
                        return false;
98
                }
99

    
100
                if (v instanceof FeatureTableDocumentPanel) {
101
                        return true;
102
                } else {
103
                        return false;
104
                }
105

    
106
        }
107

    
108
}