Statistics
| Revision:

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

History | View | Annotate | Download (2.47 KB)

1
package com.iver.cit.gvsig;
2

    
3
import org.gvsig.fmap.dal.DataManager;
4
import org.gvsig.fmap.dal.DataStoreParameters;
5
import org.gvsig.fmap.dal.exception.CloseException;
6
import org.gvsig.fmap.dal.exception.InitializeException;
7
import org.gvsig.fmap.dal.feature.FeatureStore;
8

    
9
import com.iver.andami.PluginServices;
10
import com.iver.andami.messages.NotificationManager;
11
import com.iver.andami.plugins.Extension;
12
import com.iver.andami.ui.mdiManager.IWindow;
13
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
14
import com.iver.cit.gvsig.project.documents.table.gui.Table;
15

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

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

    
27
        }
28

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

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

    
56
                }
57

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

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

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

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

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

    
85
                }
86
                return false;
87
        }
88

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

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

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

    
105
        }
106

    
107
}