Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / ShowTableAsForm.java @ 42489

History | View | Annotate | Download (2.53 KB)

1
package org.gvsig.app.extension;
2

    
3
import java.awt.Dimension;
4
import javax.swing.JOptionPane;
5
import org.gvsig.andami.plugins.Extension;
6
import org.gvsig.app.ApplicationLocator;
7
import org.gvsig.app.ApplicationManager;
8
import org.gvsig.app.project.documents.Document;
9
import org.gvsig.app.project.documents.table.TableDocument;
10
import org.gvsig.app.project.documents.table.TableManager;
11
import org.gvsig.featureform.swing.CreateJFeatureFormException;
12
import org.gvsig.featureform.swing.JFeatureForm;
13
import org.gvsig.fmap.dal.exception.DataException;
14
import org.gvsig.fmap.dal.feature.FeatureStore;
15
import org.gvsig.fmap.dal.swing.DALSwingLocator;
16
import org.gvsig.fmap.dal.swing.DataSwingManager;
17
import org.gvsig.tools.service.ServiceException;
18
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

    
22
public class ShowTableAsForm extends Extension {
23

    
24
    private static final Logger logger = LoggerFactory.getLogger(ShowTableAsForm.class);
25

    
26
    @Override
27
    public void initialize() {
28
    }
29

    
30
    @Override
31
    public void execute(String actionCommand) {
32
        ApplicationManager application = ApplicationLocator.getManager();
33
        if ("table-show-form".equalsIgnoreCase(actionCommand)) {
34
            TableDocument doc = (TableDocument) application.getActiveDocument(TableManager.TYPENAME);
35
            if (doc == null) {
36
                return;
37
            }
38
            try {
39
                JFeatureForm form = this.createform(doc.getStore());
40
                form.showForm(WindowManager.MODE.WINDOW);
41
            } catch (Exception ex) {
42
                String msg = "Can't show form for table '" + doc.getName() + "'.";
43
                logger.warn(msg, ex);
44
                application.messageDialog(msg + "\n\n(See the error log for more information)", "Warning", JOptionPane.WARNING_MESSAGE);
45
            }
46
        }
47
    }
48

    
49
    private JFeatureForm createform(FeatureStore featureStore) throws CreateJFeatureFormException, ServiceException, DataException {
50
        final DataSwingManager swingManager = DALSwingLocator.getSwingManager();
51
        final JFeatureForm form = swingManager.createJFeatureForm(featureStore);
52
        form.setPreferredSize(new Dimension(400, 300));
53
        return form;
54
    }
55

    
56
    @Override
57
    public boolean isEnabled() {
58
        return true;
59
    }
60

    
61
    @Override
62
    public boolean isVisible() {
63
        ApplicationManager application = ApplicationLocator.getManager();
64
        Document doc = application.getActiveDocument(TableManager.TYPENAME);
65
        return doc != null;
66
    }
67
}