Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / RemoveTableUnion.java @ 22932

History | View | Annotate | Download (2.59 KB)

1
package com.iver.cit.gvsig;
2

    
3
import org.gvsig.fmap.data.CloseException;
4
import org.gvsig.fmap.data.DataManager;
5
import org.gvsig.fmap.data.DataStoreParameters;
6
import org.gvsig.fmap.data.InitializeException;
7
import org.gvsig.fmap.data.feature.FeatureStore;
8
import org.gvsig.fmap.data.feature.joinstore.JoinFeatureStore;
9
import org.gvsig.fmap.data.feature.joinstore.JoinFeatureStoreParameters;
10

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

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

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

    
29
        }
30

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

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

    
58
                }
59

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

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

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

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

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

    
87
                }
88
                return false;
89
        }
90

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

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

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

    
107
        }
108

    
109
}